glTF export doesn't export tangents for non-triangulated meshes #81746

Closed
opened 2020-10-15 20:46:03 +02:00 by Dusan Maliarik · 10 comments

System Information
Operating system: Linux-5.8.14-zen1-1-zen-x86_64-with-glibc2.29 64 Bits
Graphics card: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2) Intel Open Source Technology Center 4.2 (Core Profile) Mesa 20.2.0

Blender Version
Broken: version: 2.91.0 Alpha, branch: makepkg (modified), commit date: 2020-09-09 20:10, hash: blender/blender@0721fbb6e1
Worked: (newest version of Blender that worked as expected)

Short description of error

Vertex tangents are not calculated/exported for non-triangulated meshes. When I manually triangulate the mesh, and re-export, tangents are exported. Since the export has to triangulate the mesh anyway, I don't see any reason for this not to work out of the box. Having the user manually triangulate the meshes before exporting degrades the model as it makes it less editable.

Exact steps for others to reproduce the error

Create face with more than 4 vertices. Export to glTF, check tangents, observe the result.

.blend tan.blend
.glb untitled.glb

  "meshes": [
    {
      "name": "Cube",
      "primitives": [
        {
          "attributes": {
            "POSITION": 0,
            "NORMAL": 1,
            "TANGENT": 2,
            "TEXCOORD_0": 3
          },
          "indices": 4,
          "material": 0
        }
      ]
    },
    {
      "name": "Plane",
      "primitives": [
        {
          "attributes": {
            "POSITION": 5,
            "NORMAL": 6,
            "TEXCOORD_0": 7
          },
          "indices": 8
        }
      ]
    },
    {
      "name": "Plane.001",
      "primitives": [
        {
          "attributes": {
            "POSITION": 9,
            "NORMAL": 10,
            "TANGENT": 11,
            "TEXCOORD_0": 12
          },
          "indices": 13
        }
      ]
    }
  ],

**System Information** Operating system: Linux-5.8.14-zen1-1-zen-x86_64-with-glibc2.29 64 Bits Graphics card: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2) Intel Open Source Technology Center 4.2 (Core Profile) Mesa 20.2.0 **Blender Version** Broken: version: 2.91.0 Alpha, branch: makepkg (modified), commit date: 2020-09-09 20:10, hash: `blender/blender@0721fbb6e1` Worked: (newest version of Blender that worked as expected) **Short description of error** Vertex tangents are not calculated/exported for non-triangulated meshes. When I manually triangulate the mesh, and re-export, tangents are exported. Since the export has to triangulate the mesh anyway, I don't see any reason for this not to work out of the box. Having the user manually triangulate the meshes before exporting degrades the model as it makes it less editable. **Exact steps for others to reproduce the error** Create face with more than 4 vertices. Export to glTF, check tangents, observe the result. .blend [tan.blend](https://archive.blender.org/developer/F8995811/tan.blend) .glb [untitled.glb](https://archive.blender.org/developer/F8995812/untitled.glb) ``` "meshes": [ { "name": "Cube", "primitives": [ { "attributes": { "POSITION": 0, "NORMAL": 1, "TANGENT": 2, "TEXCOORD_0": 3 }, "indices": 4, "material": 0 } ] }, { "name": "Plane", "primitives": [ { "attributes": { "POSITION": 5, "NORMAL": 6, "TEXCOORD_0": 7 }, "indices": 8 } ] }, { "name": "Plane.001", "primitives": [ { "attributes": { "POSITION": 9, "NORMAL": 10, "TANGENT": 11, "TEXCOORD_0": 12 }, "indices": 13 } ] } ], ```
Author

Added subscriber: @skrat

Added subscriber: @skrat
Author

Added subscriber: @JulienDuroure

Added subscriber: @JulienDuroure
Author

This over here:

https://developer.blender.org/diffusion/BA/browse/master/io_scene_gltf2/blender/exp/gltf2_blender_extract.py$35

So it seems @JulienDuroure would be the most familiar person with this part of codebase? To me it seems that the code is giving up too soon. Or perhaps the order in which this is called is not right, ie. triangulate first, then try calc_tangents()

This over here: https://developer.blender.org/diffusion/BA/browse/master/io_scene_gltf2/blender/exp/gltf2_blender_extract.py$35 So it seems @JulienDuroure would be the most familiar person with this part of codebase? To me it seems that the code is giving up too soon. Or perhaps the order in which this is called is not right, ie. triangulate first, then try `calc_tangents()`
Member

Meshes are not triangulated during export. There are extracted using data.loop_triangles (after using data.calc_loop_triangles() )
Tangents are not known neither after these steps

Meshes are not triangulated during export. There are extracted using data.loop_triangles (after using data.calc_loop_triangles() ) Tangents are not known neither after these steps
Author

Right, but isn't it the same thing at the end? We're getting triangles because that's what we need for the export, so we either use data.loop_triangles or we clone the mesh, triangulate, get tangents. And rather than keeping it the way it is, which IMO is broken, because if user requests tangents in the export, then the export should give him tangents, right?

Right, but isn't it the same thing at the end? We're getting triangles because that's what we need for the export, so we either use `data.loop_triangles` or we clone the mesh, triangulate, get tangents. And rather than keeping it the way it is, which IMO is broken, because if user requests tangents in the export, then the export should give him tangents, right?
Author

What I don't understand is that, if we have normals (calc_normals), why don't we have tangents available? IMO it's in the same domain space, I see no reason for this to be unavailable for export.

What I don't understand is that, if we have normals (`calc_normals`), why don't we have tangents available? IMO it's in the same domain space, I see no reason for this to be unavailable for export.
Member

Added subscriber: @ideasman42

Added subscriber: @ideasman42
Member

I don't have more information on how it works internally. Result is that it's not available via bpy
Maybe @ideasman42 can have more information on that.

Note that there exactly the same behaviour in fbx export, so I supposed there is no easy way.

I don't have more information on how it works internally. Result is that it's not available via bpy Maybe @ideasman42 can have more information on that. Note that there exactly the same behaviour in fbx export, so I supposed there is no easy way.
Member

Changed status from 'Needs Triage' to: 'Archived'

Changed status from 'Needs Triage' to: 'Archived'
Member

Closing this ticket.
As explained, we can't get tangent if mesh is not triangulated by user before export.
If you need more information, please refer to this explanation : https://github.com/KhronosGroup/glTF-Blender-IO/issues/172#issuecomment-693684218

Note that there is already a ticket open to make warning more visible (https://github.com/KhronosGroup/glTF-Blender-IO/issues/1273)

Closing this ticket. As explained, we can't get tangent if mesh is not triangulated by user before export. If you need more information, please refer to this explanation : https://github.com/KhronosGroup/glTF-Blender-IO/issues/172#issuecomment-693684218 Note that there is already a ticket open to make warning more visible (https://github.com/KhronosGroup/glTF-Blender-IO/issues/1273)
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#81746
No description provided.