【发布时间】:2021-05-18 08:49:08
【问题描述】:
在 A-Frame 上,实体相对于其父级。如果您移动父实体,子实体也会移动。那太棒了。但是我认为如果有一种方法可以指定一个实体相对于另一个实体(不一定是它的父实体),那就太好了。甚至要相对于屏幕。这是一个代码 sn-p 来说明我的意思:
<a-entity id="entity1" position="0 0 0">
<a-entity id="entity2" relative = ""></a-entity> <!-- "" or "#entity1" would make it relative to "entity1". This is the way it already works, so the relative component would have "" as the default value -->
<a-entity id="entity3" relative = "#entity4"></a-entity> <!-- This makes "entity3" relative to "entity4", not "entity1" -->
<a-entity id="entity5" relative = "#entity1 #entity4" relativeWeight = "0.5 0.5"></a-entity> <!-- This makes "entity5" half influenced by "entity1" and half by "entity4". But it could have other values like "0.8 0.2" or "1 0"(80% affected by entity1 and 20% by entity 4, then 100% affected by entity1 and 0% by entity4) -->
</a-entity>
<a-entity id="entity4" position="0 1 0">
</a-entity>
<a-entity id="entity6" relative="Screen"> <!-- I was thinking of some special values, like "Screen", "TopScreen", "BottomScreen", to make elements be relative to the center of the screen, top, bottom, etc. -->
</a-entity>
<a-entity id="entity7" relative="#entity5"> <!-- This entity is relative to entity5, which in turn is relative to both entity1 and entity4. In practice, this makes entity7 be indirectly affected by entity1 and entity4 as well because of entity5. -->
</a-entity>
然后,您将能够为 relativeWeight 组件设置动画,以将实体的相对性平滑地转换到另一个实体。
Unity 有这个:https://docs.unity3d.com/Manual/Constraints.html
ZapWorks Studio 也有这个:https://docs.zap.works/studio/scripting/reference/node/functions/relativeto-setter/ 和 https://docs.zap.works/studio/scripting/reference/node/functions/relativetoprop-setter/。
我认为这是一个非常有用的功能。
这方面的一个示例用法是在增强现实体验中拥有一个与跟踪相关的 UI,但如果用户离开跟踪,则 UI 会转到屏幕。
【问题讨论】:
-
也许从用例
UI that is relative to the tracking in an augmented reality experience, but if the user moves away from the tracking, the UI goes to the screen开始,并用你尝试过的代码来展示代码,这样可以更有效地帮助人们提供帮助和建议解决方案。给猫剥皮的方法总是不止一种。祝你好运。
标签: javascript entity augmented-reality aframe virtual-reality