Obj import generate some not valid meshes #119823
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
EEVEE & Viewport
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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#119823
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
System Information
Operating system: Mint
Graphics card: Nvidia
Blender Version
Broken: current build 4.2 alpha
Broken: current build 4.1 candidate
Broken: current 3.6.10 LTS
Worked: ?
Short description of error
Obj import generate some not valid meshes.
With this file : https://casual-effects.com/g3d/data10/research/model/San_Miguel/San_Miguel.zip.
Exact steps for others to reproduce the error
This was first reported in glTF repository (here https://github.com/KhronosGroup/glTF-Blender-IO/issues/2171), but the root issue is an invalid mesh created by obj importer.
Can confirm, will check in more detail...
Will still try to strip down the OBJ to a minimal example (and provide info where it fails), but will already raise the priority so this does not slip under the carpet
Can be reproduced with just the
Portraits
object from the original OBJNoting that we of course have the Validate Meshes option which gets rid of the corruptions (still think this deserves to be looked at since that option is OFF by default)
CC @aras_p
The issue that the OBJ in question does have literally duplicate faces, which in Blender is considered "invalid". E.g. from
Portraits
repro that Philipp made (around line 3925):Now, originally I made "validate" option be off since it is very costly, and I went with how already existing other importers did (Alembic has option to validate, which is off by default; whereas USD never validates meshes).
OK, thx checking @aras_p
I also asked in #pipeline-assets-io-module what the best approach here would be:
Validate Meshes
by default (costly)?I would also vote for making
Validate Meshes
a proper operator that could be accesses via a menu entry, I use the API almost on a daily basisNote that the glTF exporter already calls validate on every object it exports.
e21b4d4bfd/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py (L251)
This shows that, at least in this workflow, the cost of validation isn't gone, just moved around, and is in fact paid double if the mesh was already validated. But more pertinently, it means just calling validate on this mesh does not make the glTF export work. OTOH if you use the "Validate Meshes" option when importing, the export will work. Something else is going on.
Import san-miguel-low-poly-portraits.obj from the UI, then run this script
Importing with "Validate Meshes" off (default) produces
while importing with "Validate Meshes" on produces
So my guess is the real root cause of the export not working is that
validate()
does not invalidate loop_triangles when it changes the mesh.To test this, I tried importing and then exporting in the same script. It works, presumably because you don't see the mesh in the viewport, which would evaluate loop_triangles, so loop_triangles is not calculated until the glTF exporter accesses it, which is after it calls validate. If you do something to force loop_triangles to be evaluated in between the import and export (ie before the validate call), the export stops working again.
This is not a new issue, and not a regression, no reason for this to be high prio.
The fact that the OBJ import -> glTF export does not work is a regression. It worked in 3.6.
But was the mesh generated by OBJ import valid in 3.6?
Saying that it's a regression does not really help by itself, we need to understand what is actually happening. Given current info, the OBJ data itself is invalid. So the fact that at some point handling this invalid data worked for some reason does not mean that it not working anymore is a regression by itself.
The OBJ import was not valid in 3.6.
Again, the fact that the import->export worked in 3.6 despite the import also being invalid, and the fact that the glTF exporter itself calls validate on every mesh it exports, and the fact that the export works when the OBJ importer calls validate but not when the glTF exporter does, means that the mesh being invalid is not itself the problem here.
The problem is that
mesh.validate()
does not appear to purge cached loop_triangles data, so accessing loop_triangles after calling validate gives the stale data from when the mesh was invalid.If you do something to force loop_triangles to be recalculated after a validate call, like toggle in and out of edit mode, or save and reopen the .blend file, it will work again.
@scurest I have not validated (ha :)) this, but if you say so, then to me it sounds like neither OBJ nor glTF are directly related, but actual issue/regression would be along the lines of "in blender 3.6, mesh.validate() actually fixed it, but now it keeps garbage cached loop_triangles data and so the mesh stays invalid after validate call". If my understanding of this is correct, then I'd defer to @HooglyBoogly perhaps, maybe all the mesh data changes after 3.6 broke something, or similar.
@aras_p Yes, you can demonstrate this without either glTF or OBJ. For example, open this file (from this Q) and call validate on the single invalid mesh in it (via the Python console). The visual appearance in the 3D view breaks. If you do something to force loop_triangles to be recalculated, it's fixed. Calling validate before it is rendered in the 3D view (thus presumably before loop_triangles is calculated), or trying this in 3.6, also does not manifest the issue.
The change since 3.6 is probably related to the fact loop_triangles is no longer explicitly calculated via
calc_loop_triangles()
but is calculated on demand.So this should be fixed by #120159, right?
Can confirm that with latest nightly, import san-miguel-low-poly-portraits.obj -> export glTF works again. So #120159 has fixed the original issue.
Note that this was actually noticed in 4.0, but the glTF exporter silently swallows the error. That try/except should be removed so it doesn't hide bugs in Blender.
Is there another thread to track if this
validate mesh data
would be implemented as an operator? Might indeed be useful, thanks!Can confirm this behavior on a fresh 4.1.0 install with one of our non-valid mesh which has both unused loops and faces using same vertices. When doing in console
mesh.validate()
, I then need to toggle/detoggle Edit Mode so that gltf-export successfully export without crash. Note that other exporters like fbx-export seem to take care of that themselves.