A-Frame 相对论组件请求

A-Frame Relativity Component Request

在 A-Frame 上,实体是相对于其父实体的。如果您移动父实体,则子实体也会移动。那太棒了。但我认为,如果有一种方法可以指定一个实体相对于另一个实体(不一定是其父实体),那就太好了。甚至要相对于屏幕。这是一个代码片段来说明我的意思:

<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/ and https://docs.zap.works/studio/scripting/reference/node/functions/relativetoprop-setter/ .

我认为这是一个非常有用的功能。

这方面的一个示例用法是在增强现实体验中有一个与跟踪相关的 UI,但是如果用户离开跟踪,UI 会转到屏幕。

约束的概念在物理库中很常见,最近在 2D UI 中通过这样的项目很常见:https://www.react-spring.io/

我还没有看到一个 A-Frame 库来支持 UI 的 spring 约束的这种特定用例,但去年我做了几个我自己的例子。

基本示例显示 spring 约束与 A 帧物理组件:https://aframe-ammo-spring.glitch.me/

这是一个使用 spring 约束将剪贴板保持在 VR 用户的 oculus 控制器附近的示例:https://aframe-signals-clipboard-spring.glitch.me/

这是另一个实验。在桌面模式下,颜色选择器“停靠”在天空中。当您进入 VR 模式时,它会与用户的手腕“对接”:https://glitch.com/edit/#!/aframe-vr-menu-dock 效果不如我希望的好

您会注意到 spring 约束不适用于 A-Frame 物理库上的弹药驱动程序。它已在这张票中解决但尚未推入主回购:https://github.com/n5ro/aframe-physics-system/issues/171

您可以使用此 A-Frame 组件实现此功能。

https://github.com/diarmidmackenzie/screen-display#blend-transforms

而不是这个语法:

<a-entity id="entity5" relative = "#entity1 #entity4" relativeWeight = "0.5 0.5">
</a-entity>

...该组件使用以下语法:

<a-entity id="entity5" blend-transforms="objectA:#entity1;
                                         objectB:#entity4;
                                         percentage: 50">
</a-entity>

基本上这完全符合这里的要求。

对于 AR,当你想在屏幕上移动对象时 to/from,这可以与屏幕显示组件(在同一个 repo 中)结合使用,它提供了在屏幕上定位对象的简单语法.