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

glTF2Exporter includes materials used by excluded meshes. #10009

Closed
Drigax opened this issue Mar 4, 2021 · 4 comments · Fixed by #11386
Closed

glTF2Exporter includes materials used by excluded meshes. #10009

Drigax opened this issue Mar 4, 2021 · 4 comments · Fixed by #11386

Comments

@Drigax
Copy link
Contributor

Drigax commented Mar 4, 2021

See:
https://forum.babylonjs.com/t/can-gltf-export-a-specific-mesh-from-scene/10641/3

Repro:
https://www.babylonjs-playground.com/#YBEKDT#4

Expected result:
Fan materials and textures should not be included in exported glTF from this playground.

@Drigax Drigax self-assigned this Mar 4, 2021
@thomlucc thomlucc added this to the 5.0 milestone Mar 9, 2021
@bghgary bghgary assigned bghgary and unassigned Drigax Jun 10, 2021
@sebavan sebavan added enhancement and removed bug labels Sep 8, 2021
@BabylonJS BabylonJS deleted a comment Sep 26, 2021
@daoshengmu
Copy link
Contributor

daoshengmu commented Nov 2, 2021

Hi @sebavan and @Drigax, I have a local fix to exclude unused materials when exporting a gltf file. But, I am aware another issue in glTFExporter.ts that is regarding to the mesh's sideOrientation. Maybe I can file another issue to follow it up.

Per glTFExporter.ts#L1586, I notice due to (sideOrientation == Material.ClockWiseSideOrientation && convertToRightHandedSystem && bufferMesh.overrideMaterialSideOrientation !== bufferMesh.material?.sideOrientation) is true, it makes the index data of primitives be reorder when exporting. On the other hand, It looks like gltfLoader.ts doesn't do any reorder in indices, we only make this reorder in glTFExporter.ts. So, when importing the exported gltf data, we will see the index winding is wrong.

IIUC, gltf file should be right-handed coordinate system according to its spec. In https://www.babylonjs-playground.com/#YBEKDT#4 demo, we are using left-handed. It supposes to reorder the gltf model's index data while loading, but we didn't. So, I am wondering if we choose counterclockwise frontface instead of clockwise which is supposed to be chosen in left-handed system backface culling.

@bghgary
Copy link
Contributor

bghgary commented Nov 3, 2021

The loader compensates for handedness change with a root transform with a negative scale. Loaders need to be as fast as possible, so updating the winding order of indices on load is not an option.

@sebavan
Copy link
Member

sebavan commented Nov 3, 2021

Thanks a lot Gary I completely missed the ping somehow... @daoshengmu sorry for the delay

@daoshengmu
Copy link
Contributor

daoshengmu commented Nov 4, 2021

The loader compensates for handedness change with a root transform with a negative scale. Loaders need to be as fast as possible, so updating the winding order of indices on load is not an option.

I agree updating the winding order of indices on load is too slow. It looks like we did something wrong with _convertToRightHandedSystemMap that is supposed for a root transform with a negative scale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants