-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
GLTFExporter generates unnecessary attributes #15649
Comments
Make sure to export as binary for smaller size. It's 693kb with the binary option enabled.
This is something I've observed as well. It would be useful to avoid creating unused attributes. |
It is exactly the case that the size decreases by adding binary option. However, we can further reduce the size by optimizing the output attributes. I noticed the following comment in GLTFExporter.js. three.js/examples/js/exporters/GLTFExporter.js Lines 1095 to 1097 in 02b5ba0
Perhaps by adding conditions here, I think that it can be solved. |
Can you try to replace |
@takahirox Thank you for the advice. |
GLTFExporter has to convert from Geometry to BufferGeometry to get binary data suited for export, and currently BufferGeometry.fromGeometry (1) adds empty vertex colors, and (2) significantly increases the number of vertices. As @takahirox suggests it would be best to use BufferGeometry instead. To merge buffer geometries, use BufferGeometryUtils.mergeBufferGeometries(). Possible changes:
I’m not sure the duplicate vertices can be fixed automatically, but the new mergeVertices function can be used to clean that up manually: |
I'd go for the first option, fixing the vertex colors and I'd keep a warning when using |
+1 but I'm no longer familiar with
Warning sounds good. Personally I also like rejecting because probably
I think so too. The current behavior seems like copying for me. BTW, noticed that |
I don't necessarily know that this bug is easy or worthwhile to fix; I haven't looked into it. There may be a reason the vertex colors are added based on the Face3 representation as you say. In a PR for a converter (#15552) I did something like this, which seemed to work: var hasVertexColors = geometry.colors.length > 0;
geometry = new THREE.BufferGeometry().fromGeometry( geometry );
if ( ! hasVertexColors ) geometry.removeAttribute( 'color' );
The |
According to the doc, https://threejs.org/docs/#api/en/core/Geometry.colors
Ah, |
@takahirox I was able to create a sample using
I confirmed that color attributes will not be generated using
|
If you don't need them, can't you use https://threejs.org/docs/#api/en/core/BufferGeometry.removeAttribute |
@takahirox Thanks! I was able to use your suggestion method.
The output glTF file can be displayed with no error in glTF Viewer, so I think that it is a practical range. |
BTW, I tried to Draco compression using gltf-pipeline for reference.
In the model exported from CubeGeometry somehow Draco compression could not be done. |
it requires indices, see CesiumGS/gltf-pipeline#420. Using BufferGeometryUtils.mergeVertices() before exporting will reduce the number of vertices and create indices for Draco, so I'd recommend that generally. |
@donmccurdy I noticed that PR was submitted to gltf-pipeline to solve the above problem. I would like to expect it to be merged. |
Here's an updated TODO list for this issue:
|
@donmccurdy BTW, I noticed that the PR of gltf-pipeline was merged.
|
Nice, thanks! |
Since |
Description of the problem
I tried exporting the mesh using the latest version of GLTFExporter.
However, the size of the output model is larger than I thought.
The size when exporting
scene.gltf
with the following sample is928 KB
.three.js + GLTFExporter result:

In this model, vertex colors are not used, but it seems that attributes of white vertex colors are generated in the output glTF file. Perhaps by excluding unused attributes I think that the size can be made even smaller.
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
ThinkPad X260 + Intel HD Graphics 520
Modified: Link of GLTFExporter was GLTFLoader, it was fixed.
The text was updated successfully, but these errors were encountered: