three.js - 对象的属性在场景中不更新
问题描述
在场景中,我有两个盒子。我正在尝试让一个盒子实时克隆另一个盒子的旋转角度。
<a-entity id="original" mixin="cube" position="0 1.6 -1" material="color: red" sleepy collision-filter="group: red; collidesWith: default, hands, blue" rotation="0 0 0">
<a-entity id="clone" mixin="cube" position="2 1.6 -1" material="color: blue" sleepy
collision-filter="group: blue; collidesWith: default, red" rotation="0 0 0">
我可以看到克隆盒子的属性通过console.log()正确更新,但在场景中盒子并没有改变它的角度。我错过了什么?
下面的代码是我尝试使它工作。
var check = document.querySelector('.controllers');
var ori = document.getElementById('original');
var clo = document.getElementById('clone');
check.addEventListener('xbuttondown', () => {
var ori_pos = ori.getAttribute("rotation");
//console.log(ori_pos.x);
clo.object3D.rotation.set(
THREE.Math.degToRad(ori_pos.x),
THREE.Math.degToRad(ori_pos.y),
THREE.Math.degToRad(ori_pos.z)
);
console.log(clo.getAttribute("rotation"));
});
解决方案
来自A-Frame 常见问题解答:To improve performance, A-Frame does not update the HTML to save on stringification operations. This also means mutation observations will not fire. Use the debug component or .flushToDOM methods if you need to sync to the DOM
推荐阅读
- c++ - boost::process::child 在关闭输入流后不会退出
- php - 如何在mysql的第二个表上使用INNER JOIN和数组?
- php - 如何谷歌 Linechars 在 php 中显示年/月/日/小时/分钟/秒?
- javascript - Firestore 基于 orderBy 和限制从集合中检索单个文档,而不使用 forEach
- angular - 每当左键单击节点时提示自定义上下文菜单
- c++ - 我应该在没有有意义的恢复的情况下捕获异常吗?
- autofac - 如何在 Autofac 中获取已注册服务的列表
- c++ - 访问与父类是朋友的类的私有成员
- c# - 代码中添加到面板的标签控件不显示
- azure - 使用 terraform 创建 azure webhook