three.js - 更新几何值
问题描述
我正在使用“dat.gui”进行用户输入,并希望tableBoardGeometry和tableLegsGeometry在我的渲染方法中使用来自输入的值进行更新。
几何声明
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
编辑: 问题是子网格在缩放时遵循父网格
解决方案
推荐阅读
- reactjs - 如何从 react.createref() 获取回调
- angular - 如何解决打字稿中的“不可分配给永不类型的参数”错误?
- python - 意外的 Parquet 文件大小
- ruby-on-rails - 如何延迟 Rails 控制器操作,直到 Stripe 的 webhook 成功?
- excel - VBA:将超链接从单元格分配到对象
- gitlab - 如何使用 GitLab AutoDevOps 部署 Dockerfile
- python - 在烧瓶中运行后端进程时如何不影响用户体验?
- java - 将编辑文本输入显示为 toast
- c# - IEnumerator 方法在后台计算下一个结果以获得更快的响应
- ipython - 如何解决解析错误?使用 rpy2 时