forked from google/model-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure traversal order (google#1166)
* Enforce scene graph order * Remove local-dev specific file * WIP * Make it possible to correlate clones * Use canonical GLTFInstance instead of partial clone * Fix test failures * WIP * Clean up correlation based on tweaked GLTFLoader * Sync-ify CorrelatedSceneGraph * Use temporary Three.js dependency, update m-v * Fix object-key-order-dependent bug in test * De-async-ify prepare/clone, fix test helper * Remove vestigial debugger * IE11 doesn't support Map.prototype.entries * IE11 doesn't support any Map iteration, actually * Really, no iteration in IE11 * Update to more recent Three.js revision * Use Three.js dev branch * Remove vestigial comments * Fix typo * Fix typo * Add commentary about active scenes * Remove vestigial async/await
- Loading branch information
Christopher Joel
authored
May 18, 2020
1 parent
93d81d2
commit b3f48eb
Showing
37 changed files
with
8,462 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/3dom/src/facade/three-js/correlated-scene-graph-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* @license | ||
* Copyright 2020 Google LLC. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an 'AS IS' BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {Mesh, MeshStandardMaterial, Object3D} from 'three'; | ||
import {GLTFReference} from 'three/examples/jsm/loaders/GLTFLoader.js'; | ||
|
||
import {Material, PBRMetallicRoughness, Texture, TextureInfo} from '../../gltf-2.0.js'; | ||
import {assetPath, loadThreeGLTF} from '../../test-helpers.js'; | ||
|
||
import {CorrelatedSceneGraph} from './correlated-scene-graph.js'; | ||
|
||
const HORSE_GLB_PATH = assetPath('models/Horse.glb'); | ||
const ORDER_TEST_GLB_PATH = assetPath('models/order-test/order-test.glb'); | ||
|
||
const getObject3DByName = | ||
<T extends Object3D>(root: Object3D, name: string): T|null => { | ||
const objects = [root]; | ||
while (objects.length) { | ||
const next = objects.shift()!; | ||
if (next.name === name) { | ||
return next as T; | ||
} | ||
objects.push(...next.children); | ||
} | ||
return null; | ||
}; | ||
|
||
suite('facade/three-js/correlated-scene-graph', () => { | ||
suite('CorrelatedSceneGraph', () => { | ||
test('maps Three.js materials to glTF elements', async () => { | ||
const threeGLTF = await loadThreeGLTF(HORSE_GLB_PATH); | ||
const correlatedSceneGraph = CorrelatedSceneGraph.from(threeGLTF); | ||
|
||
const threeMaterial = | ||
((threeGLTF.scene.children[0] as Mesh).material as | ||
MeshStandardMaterial); | ||
const gltfMaterial = threeGLTF.parser.json.materials[0]! as Material; | ||
const gltfReference = | ||
correlatedSceneGraph.threeObjectMap.get(threeMaterial); | ||
|
||
expect(gltfReference).to.be.ok; | ||
|
||
const {type, index} = gltfReference as GLTFReference; | ||
|
||
const referencedGltfMaterial = threeGLTF.parser.json[type][index]; | ||
|
||
expect(referencedGltfMaterial).to.be.equal(gltfMaterial); | ||
}); | ||
|
||
test('maps Three.js textures to glTF elements', async () => { | ||
const threeGLTF = await loadThreeGLTF(ORDER_TEST_GLB_PATH); | ||
const correlatedSceneGraph = CorrelatedSceneGraph.from(threeGLTF); | ||
|
||
const threeMaterial = | ||
getObject3DByName<Mesh>(threeGLTF.scene, 'Node0')!.material as | ||
MeshStandardMaterial; | ||
const threeTexture = threeMaterial.map!; | ||
|
||
const gltfMaterial = threeGLTF.parser.json.materials[2]! as Material; | ||
const textureIndex = | ||
((gltfMaterial.pbrMetallicRoughness as PBRMetallicRoughness) | ||
.baseColorTexture as TextureInfo) | ||
.index; | ||
|
||
const gltfTexture = | ||
threeGLTF.parser.json.textures[textureIndex] as Texture; | ||
const gltfReference = | ||
correlatedSceneGraph.threeObjectMap.get(threeTexture); | ||
|
||
expect(gltfReference).to.be.ok; | ||
|
||
const {type, index} = gltfReference as GLTFReference; | ||
|
||
const referencedGltfTexture = threeGLTF.parser.json[type][index]; | ||
|
||
expect(referencedGltfTexture).to.be.equal(gltfTexture); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.