首页 > 解决方案 > 更新几何值

问题描述

我正在使用“dat.gui”进行用户输入,并希望tableBoardGeometrytableLegsGeometry在我的渲染方法中使用来自输入的值进行更新。

几何声明

const boxWidth = 2; 
const boxHeight = 0.1; 
const boxDepth = 1;
const tableBoardGeometry = new THREE.BoxGeometry(boxWidth, boxHeight, boxDepth);

const tableLegPosition = (boxWidth * 0.45);
const tableLegHeight = 1.6
const tableLegHeightPosition = (tableLegHeight/2)
const tableLegsGeometry = new THREE.BoxGeometry(0.05, tableLegHeight, 0.05);

大贵

     var gui = new dat.GUI();
     var controls = function() {
         this.TableWidth = 1;
         this.TableHeight = 1;
         this.LegsWidth = 1;
         this.LegsHeight = 1;
         this.RotationSpeed = 0.005;
    }
    var title = new controls();
        gui.add(title, 'RotationSpeed', 0.005, 0.1);

渲染方法

    const render = () => {
        requestAnimationFrame(render);
        tableBoard.rotation.y -= title.RotationSpeed;
        /* I'd like to update the Geomtrics here depending on user input */
        renderer.render(scene, camera);
        orbitCamera()
     }

我试过使用:

tableBoard.scale.x = title.TableWidth;

并且由于获取正确数字的变量依赖关系而无法正常工作。我要更新的变量是tableLegHeightPosition

编辑: 问题是子网格在缩放时遵循父网格

标签: three.jsdat.gui

解决方案


推荐阅读