如何从搅拌机 GLTF 形状键更新 threejs 变形目标
How to update threejs morph targets from blender GLTF shape keys
我有一个包含多个形状键的搅拌器文件。当我在 0 和 1 之间拖动 blender 中的滑块时,我可以操纵形状键。
(截图):
https://share.getcloudapp.com/bLuw8L0W
我正在导出 GLTF 并在 threejs 中导入它。
如果我 console.log
来自 GLTF 的网格,我可以在 morphTargetDictionary
中看到来自搅拌机的形状键,并且我已经设置了一个 GUI 来更新 morphTargetInfluences
每个形状键:
https://share.getcloudapp.com/6quP71l7
folder
.add(params, "influence2", 0, 1)
.step(0.01)
.onChange(function (value) {
console.log(dodec.morphTargetInfluences[1]);
dodec.morphTargetInfluences[1] = value;
//dodec.updateMorphTargets();
});
但更新这些 morphTargetInfluences 似乎没有影响。我该如何设置它,以便我可以在 Three.js 中实现与我在搅拌机中通过移动每个形状键的滑块可以获得相同的效果?
更新
这是我目前拥有的代码笔:
您要定位的对象是网格,即 dodec = scene.getObjectByName("Solid_0");
。检查 dodec
是什么,直到找到网格为止。
GLTF 导出嵌套组,因此您的网格通常可能在一个组中。
您还需要在 material:
上设置 morphTargets: true
const material = new THREE.MeshStandardMaterial({
color: 0xffa400,
emissive: 0xbb5a5a,
side: THREE.DoubleSide,
flatShading: true,
morphTargets: true, // you need this
});
我有一个包含多个形状键的搅拌器文件。当我在 0 和 1 之间拖动 blender 中的滑块时,我可以操纵形状键。
(截图): https://share.getcloudapp.com/bLuw8L0W
我正在导出 GLTF 并在 threejs 中导入它。
如果我 console.log
来自 GLTF 的网格,我可以在 morphTargetDictionary
中看到来自搅拌机的形状键,并且我已经设置了一个 GUI 来更新 morphTargetInfluences
每个形状键:
https://share.getcloudapp.com/6quP71l7
folder
.add(params, "influence2", 0, 1)
.step(0.01)
.onChange(function (value) {
console.log(dodec.morphTargetInfluences[1]);
dodec.morphTargetInfluences[1] = value;
//dodec.updateMorphTargets();
});
但更新这些 morphTargetInfluences 似乎没有影响。我该如何设置它,以便我可以在 Three.js 中实现与我在搅拌机中通过移动每个形状键的滑块可以获得相同的效果?
更新
这是我目前拥有的代码笔:
您要定位的对象是网格,即 dodec = scene.getObjectByName("Solid_0");
。检查 dodec
是什么,直到找到网格为止。
GLTF 导出嵌套组,因此您的网格通常可能在一个组中。
您还需要在 material:
上设置 morphTargets: trueconst material = new THREE.MeshStandardMaterial({
color: 0xffa400,
emissive: 0xbb5a5a,
side: THREE.DoubleSide,
flatShading: true,
morphTargets: true, // you need this
});