Skip to content

Commit 93ee481

Browse files
author
Christopher Joel
authored
Ignore default material (#1236)
1 parent 1f47718 commit 93ee481

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

packages/3dom/src/facade/three-js/correlated-scene-graph-spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16-
import {Mesh, MeshStandardMaterial, Object3D} from 'three';
17-
import {GLTFReference} from 'three/examples/jsm/loaders/GLTFLoader.js';
16+
import {Group, Mesh, MeshStandardMaterial, Object3D} from 'three';
17+
import {GLTF, GLTFReference} from 'three/examples/jsm/loaders/GLTFLoader.js';
18+
import {SkeletonUtils} from 'three/examples/jsm/utils/SkeletonUtils.js';
1819

1920
import {Material, PBRMetallicRoughness, Texture, TextureInfo} from '../../gltf-2.0.js';
2021
import {assetPath, loadThreeGLTF} from '../../test-helpers.js';
@@ -23,6 +24,8 @@ import {CorrelatedSceneGraph} from './correlated-scene-graph.js';
2324

2425
const HORSE_GLB_PATH = assetPath('models/Horse.glb');
2526
const ORDER_TEST_GLB_PATH = assetPath('models/order-test/order-test.glb');
27+
const KHRONOS_TRIANGLE_GLB_PATH =
28+
assetPath('models/glTF-Sample-Models/2.0/Triangle/glTF/Triangle.gltf');
2629

2730
const getObject3DByName =
2831
<T extends Object3D>(root: Object3D, name: string): T|null => {
@@ -87,5 +90,26 @@ suite('facade/three-js/correlated-scene-graph', () => {
8790

8891
expect(referencedGltfTexture).to.be.equal(gltfTexture);
8992
});
93+
94+
suite('when correlating a cloned glTF', () => {
95+
test('ignores the GLTFLoader "default" material', async () => {
96+
const threeGLTF = await loadThreeGLTF(KHRONOS_TRIANGLE_GLB_PATH);
97+
const correlatedSceneGraph = CorrelatedSceneGraph.from(threeGLTF);
98+
99+
const scene = SkeletonUtils.clone(threeGLTF.scene) as Group;
100+
const scenes: Group[] = [scene];
101+
102+
const cloneThreeGLTF: GLTF = {...threeGLTF, scene, scenes};
103+
104+
const cloneCorrelatedSceneGraph =
105+
CorrelatedSceneGraph.from(cloneThreeGLTF, correlatedSceneGraph);
106+
107+
for (const threeObject of
108+
cloneCorrelatedSceneGraph.threeObjectMap.keys()) {
109+
expect((threeObject as MeshStandardMaterial).isMaterial)
110+
.to.be.undefined;
111+
}
112+
});
113+
});
90114
});
91115
});

packages/3dom/src/facade/three-js/correlated-scene-graph.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ export class CorrelatedSceneGraph {
6868

6969
// NOTE: IE11 does not have Map iterator methods
7070
associations.forEach((gltfElementReference, threeObject) => {
71+
// Note: GLTFLoader creates a "default" material that has no corresponding
72+
// glTF element in the case that no materials are specified in the source
73+
// glTF. This means that for basic models without any of their own
74+
// materials, we might accidentally try to present a configurable glTF
75+
// material that doesn't exist. It might be valuable to make this default
76+
// material configurable in the future, but for now we ignore it.
77+
if (gltfElementReference == null) {
78+
return;
79+
}
80+
7181
const {type, index} = gltfElementReference;
7282
const gltfElement = gltf[type][index] as GLTFElement;
7383

0 commit comments

Comments
 (0)