使用 GLTF 的一部分作为 InstancedMesh

时间:2021-02-03 07:50:48

标签: javascript three.js

我一直在练习在 Three.js 存储库中克隆 example 代码。

在这个例子中,我有一些不明白的地方。

为什么 THREE.InstancedBufferGeometry 应该被 THREE.BufferGeomtry.prototype 复制?

loader.load( './models/gltf/Flower/Flower.glb', function ( gltf ) {

            const _stemMesh = gltf.scene.getObjectByName( 'Stem' );
            const _blossomMesh = gltf.scene.getObjectByName( 'Blossom' );

            stemGeometry = new THREE.InstancedBufferGeometry();
            blossomGeometry = new THREE.InstancedBufferGeometry();

            THREE.BufferGeometry.prototype.copy.call( stemGeometry, _stemMesh.geometry );
            THREE.BufferGeometry.prototype.copy.call( blossomGeometry, _blossomMesh.geometry );

也许是关于 javascript,但我还是不明白。

为什么我不能直接使用 InstancedBufferGeometry.copy()?

谢谢,

1 个答案:

答案 0 :(得分:2)

<块引用>

为什么 THREE.InstancedBufferGeometry 应该被 THREE.BufferGeomtry.prototype 复制?

InstancedBufferGeometryBufferGeometry 的子类,带有覆盖的 copy() 方法。如果您直接使用 InstancedBufferGeometry.copy(),该方法将尝试从 InstancedBufferGeometry 复制名为 instanceCountBufferGeometry 特定属性。所以派生类的属性会变成undefined

相关问题