-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
BufferGeometryUtils: Add mergeBufferGeometries() helper. #13241
BufferGeometryUtils: Add mergeBufferGeometries() helper. #13241
Conversation
This is very nice! I believe it does not make sense to merge geometries that require different materials, as the merged geometry must be rendered with separate draw calls anyway. If I understand correctly, it seems you are ignoring the existing groups in each geometry, while simultaneously creating new groups by assigning each merged geometry a different material index. (Please correct me if I am wrong.) I'm thinking a reasonable argument can be made that it makes sense to ignore groups altogether when merging. But I don't have a strong opinion on this one way or the other. |
For the multi-materials case I'm thinking of #11944 in GLTFLoader, and just trying to have a simpler single-mesh output when glTF specifies one mesh with multiple materials. But optimizing performance seems like the more important use case for merging geometry, so happy to treat that as the primary goal here, not multiple materials.
Correct, this code isn't checking for existing groups.
Groups could still be added after calling this method, yes. It would also be fairly easy to change the signature to: |
I'm fine with however you want to handle this. :) |
Ok thanks — removed the creation of groups. I think that part could be generalized to a With that change, this doesn't fully address #11944, but still covers everything else. I'll adjust GLTFLoader accordingly soon. |
Removed the GLTFLoader part of this PR for now, since that would need to deal with multiple materials. |
Do you mind resolving the conflicts? 😇 |
3e06102
to
fbbda22
Compare
Done ✅ |
Thanks! |
too bad you guys lost matrices args along the way. the use case I was hoping to use this for was to group a bunch of separate objects together, but it looks like now I have to explicitly apply their transformations to geometries before merging. |
There are several use cases for merging geometries, and not all involve merging transformations. E.g. my use case had more to do with multi-material meshes. This utility tries to remain generic and handles only the geometry portion of that, but you're welcome to use this to create a |
The matrix transformation is applied at the But a |
|
||
mergedGeometry.userData = mergedGeometry.userData || {}; | ||
mergedGeometry.userData.mergedUserData = mergedGeometry.userData.mergedUserData || []; | ||
mergedGeometry.userData.mergedUserData.push( geometry.userData ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BufferGeometry
doesn't have .userData
property. Perhaps only GLTFLoader
can set from glTF primitive.extras
. (Any other loaders/modules can also set?) So, is this merging for GLTFLoader
special?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good point. Yes apparently it is glTF-specific. Probably deserves a comment, or maybe we can revisit whether GLTFLoader should do this..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to pollute BufferGeometry
with Three.js unofficial property. For example, it can be lost in serialization. I prefer officially adding .userData
property to BufferGeometry
.
@mrdoob What do you think of adding .userData
property to BufferGeometry
?
Fixes #9468, #6188, and partially addresses #11944.
Alternative to #8162, #9529, #12795, and #12804.
I'd like to have this utility for GLTFLoader, so that primitives can be loaded as BufferGeometry groups. Adds a warning to
BufferGeometry.prototype.merge()
when it is called without an offset, as I believe the current behavior is probably not what many are expecting.I think this approach is comparatively complete, covering indexed and non-indexed geometry, preserving morph targets,
and creating geometry groups. Users who do not want the groups may simply call.clearGroups()
on the result. Although, perhaps a better name would begroupBufferGeometries( geometries )
?