Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T79104: Exporting a valid GLTF (was valid before import) causes GLTF validation errors #1138

Closed
julienduroure opened this issue Jul 23, 2020 · 9 comments · Fixed by #1214
Closed
Labels
exporter This involves or affects the export process Mesh_&_Object

Comments

@julienduroure
Copy link
Collaborator

See https://developer.blender.org/T79104
On 2.83

@julienduroure
Copy link
Collaborator Author

Linked to #372 ?

@julienduroure
Copy link
Collaborator Author

Confirmed that using "Degenerative dissolve" solve the issue.
No issue when importing with "merging vertices" too

@julienduroure julienduroure added exporter This involves or affects the export process Mesh_&_Object labels Jul 23, 2020
@scurest
Copy link
Contributor

scurest commented Jul 23, 2020

Yeah, there are tris with collinear verts.

There are two solutions I can think of...

We could just write some fixed value (say, (0,1,0)) whenever we have a zero normal. This would satisfy the validator and it shouldn't matter since degenerate tris are invisible.

Or we could try to filter out any tris that have at least one zero normal.

@julienduroure
Copy link
Collaborator Author

Filtering will probably be more time consuming that writing some fixed value, doesn't it?

My vote goes for writing some fixed value, since tris are invisible, no matter the value

@scurest
Copy link
Contributor

scurest commented Aug 12, 2020

Fixed value would be easier to code :)

Can this wait until after #1120? I think setting a fixed value would just be

# Change all zero normals to [0,1,0]
is_zero = ~normals.any(axis=1)
normals[is_zero, 1] = 1

@julienduroure
Copy link
Collaborator Author

Yes, sure, let's wait after #1120

(BTW, test are in progress, i will batch merge lot's of PR after 2.90 release)

@scurest
Copy link
Contributor

scurest commented Sep 5, 2020

Patch I guess (I didn't test it)

diff --git a/addons/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/addons/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
index ca38aa7..19d3b35 100644
--- a/addons/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
+++ b/addons/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
@@ -348,6 +348,12 @@ def __get_normals(blender_mesh, key_blocks, armature, blender_object, export_set
             ns[:] = __apply_mat_to_all(normal_transform, ns)
             __normalize_vecs(ns)
 
+    for ns in [normals, *morph_normals]:
+        # Replace zero normals with the unit UP vector.
+        # This happens (only?) for degenerate tris.
+        is_zero = ~ns.any(axis=1)
+        ns[is_zero, 2] = 1
+
     # glTF stores deltas in morph targets
     for ns in morph_normals:
         ns -= normals

@julienduroure
Copy link
Collaborator Author

Do you plan to open a PR, or do you want me to to it?

@scurest
Copy link
Contributor

scurest commented Sep 16, 2020

I can do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter This involves or affects the export process Mesh_&_Object
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants