【发布时间】:2019-04-10 23:34:55
【问题描述】:
基本上在我的场景中,我有一个带有激光控制和光线投射器的实体,结构如下:
<a-scene>
<a-entity laser-controls raycaster ...>
<!--<a-entity id="inventory" ...> Could be inserted here-->
</a-entity>
<!--<a-entity id="inventory" ...> Could be inserted here-->
</a-scene>
我的目标是在激光线的当前 x,y 位置召唤库存,我已经可以访问对应于激光线末端的点。我不希望库存再次从那个位置移动。如果我将库存设置为 raycaster 的子级,它总是随线移动。如果我将库存设置为场景的子节点,同时将它的位置设置为它应该在的点的世界坐标,它就是行不通的。
我尝试过但失败的方法:
- 将库存作为 raycaster 子级启动并将父级更改为场景并应用 raycaster 的世界矩阵
- 将库存保持为 raycaster 子项,捕获其初始世界矩阵并在每个刻度上设置相同的世界矩阵
最后,我目前的方法(使用代码)仍然失败
1.将线端的局部坐标转换为世界坐标
2.将库存附加到场景
3.将线端的世界坐标转换为场景的局部坐标
4.将3中的位置应用到库存
let v = this.emptyVec
v.copy(this.raycaster.components.line.data.end)
this.raycaster.object3D.localToWorld(v);
this.el.appendChild(inventoryNode) //this.el is the scene
this.el.object3D.worldToLocal(v);
const {x,y} = v
inventoryNode.object3D.position.set(x,y,inventoryZDistance)
TLDR:如何在将实体添加到场景的时间点将实体设置到光线投射器线端的位置并让它永远保持在该位置
【问题讨论】:
标签: three.js aframe coordinate-transformation webvr