有没有关于在没有 cloneNode() 的情况下在 A-Frame 上重新设置父级的解决方案?
Is there any solution about re-parenting on A-Frame without cloneNode()?
在 A-Frame 场景中,我想更改实体的(a-box)父级。
所以我做了 removeChild() 和 appendChild()。
但是这项工作没有达到我的预期。
似乎在完成 removeChild() 后,Object3D 丢失了。 (盒子不见了!)
有没有不用 cloneNode() 来改变父节点的方法?
我想移动原始盒子,而不是盒子的克隆。
A-Frame 版本为 0.9.1
<a-scene>
<a-sphere position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>
<a-box position="-1 0.5 1" rotation="0 45 0" width="1" height="1" depth="1" color="#4CC3D9"></a-box>
<a-cylinder position="1 0.75 1" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
<a-entity position="0 0 3.8">
<a-camera></a-camera>
</a-entity>
</a-scene>
<script>
// this code doesn't work as my intended
var plane = document.querySelector('a-plane');
var box = document.querySelector('a-box');
box.parentEl.removeChild(box);
plane.appendChild(box);
// is this the only way?
// var plane = document.querySelector('a-plane');
// var box = document.querySelector('a-box');
// var copyBox = box.cloneNode(true);
// box.parentEl.removeChild(box);
// plane.appendChild(copyBox);
</script>
我们希望移动 DOM 节点有效,但尚未完全测试。可能只是一个问题。您也可以只移动 three.js object3D,这样会快很多。
const obj = el.object3D;
anotherEl.object3D.add(obj);
在 A-Frame 场景中,我想更改实体的(a-box)父级。
所以我做了 removeChild() 和 appendChild()。
但是这项工作没有达到我的预期。
似乎在完成 removeChild() 后,Object3D 丢失了。 (盒子不见了!)
有没有不用 cloneNode() 来改变父节点的方法?
我想移动原始盒子,而不是盒子的克隆。
A-Frame 版本为 0.9.1
<a-scene>
<a-sphere position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>
<a-box position="-1 0.5 1" rotation="0 45 0" width="1" height="1" depth="1" color="#4CC3D9"></a-box>
<a-cylinder position="1 0.75 1" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
<a-entity position="0 0 3.8">
<a-camera></a-camera>
</a-entity>
</a-scene>
<script>
// this code doesn't work as my intended
var plane = document.querySelector('a-plane');
var box = document.querySelector('a-box');
box.parentEl.removeChild(box);
plane.appendChild(box);
// is this the only way?
// var plane = document.querySelector('a-plane');
// var box = document.querySelector('a-box');
// var copyBox = box.cloneNode(true);
// box.parentEl.removeChild(box);
// plane.appendChild(copyBox);
</script>
我们希望移动 DOM 节点有效,但尚未完全测试。可能只是一个问题。您也可以只移动 three.js object3D,这样会快很多。
const obj = el.object3D;
anotherEl.object3D.add(obj);