对象的属性不会在场景中更新

时间:2018-08-04 05:04:30

标签: three.js aframe

在现场,我有两个盒子。我正在尝试使一个框实时克隆另一个框的旋转角度。

<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"));
});

1 个答案:

答案 0 :(得分:1)

A-Frame FAQTo 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