Fix #117367: OBJ: fix vertex colors imported scrambled up #126065
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#126065
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "scurest/blender:fix-117367"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lift certain incorrect assumptions about the order of vertices in
an OBJ file when processing vertex colors, which could lead to
missing or randomly permuted colors.
Replaces the list-of-blocks representation, attuned to assumptions
that the verts in an object form a contiguous subrange, with a
flat array better suited for random-access.
Recall that an OBJ has a global list of vertices (
v
), each of which may or may not have a vertex color. Each object (o
) references a subset of vertices in this global list. For each referenced vert, the importer creates one Blender vert in the imported mesh. The vertex index in the global OBJ list is the global index, and the index in the Blender mesh's list of verts is the local index.Specifically, the incorrect assumption in the importer appears to be that an object always references a contiguous range of vertices in the global list (no gaps) between the first and last referenced verts, and therefore (1) whether it has vertex colors just depends on if that range lies in a range that has vertex colors, and (2) the local index for a vert is just the distance to the start of the range in the global list.
(Note that vertex positions are stored the same way as colors, but the code for them does not make this assumption, so it's okay.)
So this does the following:
color_attr_data[local_index] = global_vertex_colors[global_index]
. Reusing the global-to-local mapping fromcreate_vertices
. This is the part that actually fixes the misaligned color problem.In terms of performance, there should be no cost to importing files without vertex colors. Others are expected to slow down.
Fixes all the files posted in #117367 in my tests.
@blender-bot build
@ -440,0 +423,4 @@
/* First pass to determine if we need to create a color attribute.
* Only when all vertices used specify a vertex color. */
for (int vi : mesh_geometry_.vertices_) {
const float3 color = global_vertices_.get_vertex_color(vi);
Could this check be made a bit faster by having something like
bool has_vertex_color(vi)
that simply returns true or false? Right now this creates a whole "dummy" float3 only to check the validity.And then seemingly whole
get_vertex_color
is not even actually needed elsewhereHow's that?
Good! Does your latest push fix the obj tests by chance? They were all crashing on the buildbot this morning.
If by crashing you mean the tests failed, no that is not fixed.
Since you force-pushed it's hard to see the buildbot failures on the previous commit. But IIRC the output of the failing test simply said "segfault", which I assume means something within the test crashed. Which makes them fail, yes.
599ef78a25
to8c5148042b
So I have broken #MRGB colors. AFAICT they work like this
This is easier to handle with the list-of-blocks representation (perhaps that's why it was used?), since you don't know when you process each #MRGB line what vertex index it affects until you have seen the rest of the #MRGB lines up to the next
v
(or EOF).My current idea is to buffer one
Vector<float3> mrgb_block
inGlobalVertices
, accumulate into it on every #MRGB line, and flush it out the to thevertex_colors
list at eachv
or EOF. How does that sound?Quite probably. I forget which order I implemented those in, but possibly I first tried to make MRGB work, and that is indeed very much "block based", and quite poorly defined (as in, it is not clear at all what should happen when multiple objects are present, etc.). And as you figured out, I did some poorly thought out decisions in handling various xyzrgb cases.
Sounds sensible to me.
Okay, the
mrgb_block
is implemented. Tests are passing locally.@blender-bot build
Excellent, thanks! Merged to main for 4.3, also added an item for backporting into 4.2.2.