-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
GLTFLoader: Allow multiple associations #21737
Conversation
I think it's okay to not include |
/cc @elalish |
Sounds fine to me. We may want to have unit tests on this behavior. The changed API may affect @drcmda as well. |
Sounds good to me. I added a unit test. |
@donmccurdy @cdata @elalish @drcmda Do you think it's good to go with this change? I hope we can get it into r129. |
i see nothing that could be a blocker. 👍 |
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.
It shouldn't be hard to update our code to match this, I think. And I too want to support variant editing, so I imagine I'd run into the same problem before long. I suppose it's natural that we might start associating with more parts of the glTF as we go along.
type: 'textures', | ||
index: textureIndex | ||
} ); | ||
parser.associations.set( texture, { textures: textureIndex } ); |
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.
nit: I might change textures
to texture
and make the rest singular too, since we're only giving a single index.
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 guess the reason why they are plural is to easily access json data because they are plural in glTF json.
// The existing associations
const def = json[association.type][association.index];
// The new associations
for (const key in associations) {
const def = json[key][associations[key]];
}
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.
Just looking at this PR as I'm pondering the same issue. I'm actually doing a deeper integration of code you graciously added to Model-Viewer. I have not tried to tackle the issue in three.js code but my initial thought would be to just associate the Mesh with a glTF primitive instead of with a glTF node. Your suggestion is a nice work-around but it I'm not sure it helps in the case of a skinned mesh where there are multiple primitives per mesh (see BrainStem sample for example). It seems to me the because a three.js Mesh is associated with a glTF node (instead of a Primitive) the issue will keep arising as the format gets more complicated and tries to allow for more interaction, with Variants just being the first most obvious problem of the moment. I think the issue boils down to the fact that in glTF a Node represents transform and can hold Mesh which can have multiple primitives and in three.js a Mesh has all three but is limited to one primitive.
Allows for multiple glTF associations per Three.js Object. Provides glTF self look up indices on a Three.js Object in order to facilitate easy identification of the objects glTF counterparts. Related mrdoob#21737 When Three.js loads a glTF file it combines the glTF node, mesh, and primitive components into single objects in some cases, this changes provides a map of those combinations in order to preserve an objects relationship to the original glTF file.
Thanks! |
* Updates apply the latest changes coming down from Three.js in regards to multiple-associations (mrdoob/three.js#22544) * Updates to multiple-associations changes in Three.js mrdoob/three.js#21737 * Adds tests to exercise updated correlations/associations * remove test.only * remove unneeded awaits * Added default material e2e test to primitive * remove test.only * Update Three to r133, update types/three to 0.132.1 * updates package-lock * updates to test
…d changes in Three.js PR mrdoob/three.js#21737 (#55977)" This reverts commit 754e0c8.
…d changes in Three.js PR mrdoob/three.js#21737 (#55977)" (#56100) This reverts commit 754e0c8.
Related issue: #19359 (comment)
Description
This PR allows
GLTFLoader
to save multiple associations by changing fromto
and newly saves mesh and primitive indices.
Regarding adding mesh and primitive indices, from @donmccurdy comment #19359 (comment)
My use case is I want to get mesh and primitive definitions for
KHR_materials_variants
extension from Three.js Mesh object because the extension definition is under primitivehttps://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md#example
and different variants can be selected after the loader parses glTF.
And a Three.js Mesh can be associated to both a node definition and mesh definition so I would like to suggest to allow multiple associations.
This change requires users who already use
parser.associations
to update their code because ofassociations
data structure change. Is it ok? @cdataBTW who should run
npm run build-examples
? Me and I should addexamples/js/loaders/GLTFLoader.js
change in this PR?