小编Jam*_*ent的帖子

如何在three.js中覆盖GLTF材料

我正在尝试创建一种动态方式来在 Three.js 中的 gltf 导入模型上显示太阳能数据。目的是将不同的纯色与模型的不同部分相关联,并能够关闭和打开这些部分。我目前的障碍是更改 gltf 中材料的颜色。

我曾尝试使用 ObjLoader 来代替我输入自己的材料,但这不起作用:/

这是我目前拥有的js:

        const gltfLoader = new THREE.GLTFLoader();
        gltfLoader.load('Building.glb', (gltf) => {
            const root = gltf.scene;
            scene.add(root);

            const box = new THREE.Box3().setFromObject(root);
            const boxSize = box.getSize(new THREE.Vector3()).length();
            const boxCenter = box.getCenter(new THREE.Vector3());

            frameArea(boxSize * 0.5, boxSize, boxCenter, camera);

            controls.maxDistance = boxSize * 10;
            controls.target.copy(boxCenter);
            controls.update();
          });


    function frameArea(sizeToFitOnScreen, boxSize, boxCenter, camera) {
        const halfSizeToFitOnScreen = sizeToFitOnScreen * 0.5;
        const halfFovY = THREE.Math.degToRad(camera.fov * .5);
        const distance = halfSizeToFitOnScreen / Math.tan(halfFovY);
        const direction …
Run Code Online (Sandbox Code Playgroud)

rhino three.js grasshopper gltf

6
推荐指数
1
解决办法
6042
查看次数

标签 统计

gltf ×1

grasshopper ×1

rhino ×1

three.js ×1