Skip to content

Reduce to unique materials#1072

Merged
cdata merged 8 commits intomasterfrom
reduce-to-unique-materials
Mar 4, 2020
Merged

Reduce to unique materials#1072
cdata merged 8 commits intomasterfrom
reduce-to-unique-materials

Conversation

@cdata
Copy link
Contributor

@cdata cdata commented Mar 3, 2020

This started out as a fix for the problem where 3DOM scene graphs expressed a unique material for every location in the scene graph where a material occurred. It turned out that this was an implementation problem caused in CachingGLTFLoader and related to how models are cloned. So, to address the issue I made a light refactor of the related code (which was overdue anyway). Some highlights from the change:

  • Refactored CachingGLTFLoader and cloneGltf
    • Separate loading/caching from model preparation/cloning
    • Introduced GLTFInstance, a conveniently clone-able, dispose-able, API-compatible alternative to GLTF
    • CachingGLTFLoader now loads a full GLTF-like, rather than just a scene
    • RoughnessMipmapper is created once, rather than per-instance of CachingGLTFLoader
    • Ensure that discrete materials are only cloned once

Depends on #1063

Fixes #1061

@cdata cdata changed the base branch from master to expose-names-of-elements March 3, 2020 16:40
@cdata cdata marked this pull request as ready for review March 3, 2020 19:44
@cdata cdata requested a review from elalish March 3, 2020 19:44
moveChildren(gltf.scene, this.modelContainer);
}

this.modelContainer.traverse(obj => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was duplicate work, and now consolidated in ModelViewerGLTFInstance implementation.

this[$currentScene]![$releaseFromCache]();
this[$currentScene] = null;
if (gltf != null) {
moveChildren(this.modelContainer, gltf.scene);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving children around like this is probably not necessary; Three.js allows a Scene to be a child of another Object3D, so we could probably just take advantage of that and insert the gltf.scene directly into the graph. Punting for the future, though.

@cdata cdata mentioned this pull request Mar 3, 2020
elalish
elalish previously approved these changes Mar 3, 2020
Copy link
Contributor

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Great to have all the Three.js cloning tweaks in one place!

suite('preparing the GLTF', () => {
test('creates a prepared GLTF', () => {
const rawGLTF = createFakeGLTF();
const preparedGLTF = GLTFInstance.prepare(rawGLTF);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could be part of the suite above, since it uses the same setup.


test('disables frustum culling on meshes', () => {
(preparedGLTF.scene.children as [Mesh, Mesh, Mesh])
.forEach(mesh => expect(mesh.frustumCulled).to.be.false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cdata cdata force-pushed the reduce-to-unique-materials branch from ab3a62b to c25ae6c Compare March 4, 2020 02:47
@cdata cdata dismissed elalish’s stale review March 4, 2020 16:43

The base branch was changed.

@cdata cdata changed the base branch from expose-names-of-elements to master March 4, 2020 16:43
@cdata cdata merged commit 31664d7 into master Mar 4, 2020
@cdata cdata deleted the reduce-to-unique-materials branch March 4, 2020 16:44
@cdata cdata added this to the v0.10.0 milestone Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3DOM materials are not reduced to sparse set

2 participants