Aframe: How do I link entities, so the user can link/unlink entities, and so entities will animate together, and interact together

不打扰是莪最后的温柔 提交于 2019-12-24 23:56:42

问题


How would I link and unlink multiple entities together so that they can be animated together.

An example is that there is a small pile of entities. When I click on this pile it spreads apart and floats upwards towards the user, so it's not a pile any more but a series of discreet entities each separated by a small distance.

The pile exists of 3 entities A, B, and C

If I click on the entity with id A then they all scale/position/rotate back into a pile.

If I click on entity id B then all entities move to the left. If I click on entity C then C leaves the pile and it's movements are no longer associated with the pile.

There is another pile with entities X, Y and Z

If entity X, Y, or Z is near entity C, then entity C joins the X, Y, Z pile. If the user clicks on entity Z and drags it over to be near entity A or B then entity Z joins pile A & B,

So then if entity A is clicked then A, B and Z will scale, rotate, and position together.


回答1:


I believe the core question is how to re-parent entities to and from entity containers, assuming it is understood that animating/moving an entity container moves all its children, and how to listen to click events. Here's a container:

<a-entity id="groupContainer" animation__position="..." animation__scale="..." animation__rotation="...">
  <a-entity class="child"></a-entity>
  <a-entity class="child"></a-entity>
  <a-entity class="child"></a-entity>
</a-entity>

There isn't a clean way to re-parent the A-Frame entities at the DOM level yet since detaching/re-attaching will remove/reinitialize all components. You can move the entity out with three.js.

var someOtherContainer = document.getElementById('someOtherContainer').object3D;
var childToReparent = document.querySelector('#someChildToRemoveFromContainer');
someOtherContainer.add(childToReparent);


来源:https://stackoverflow.com/questions/53404248/aframe-how-do-i-link-entities-so-the-user-can-link-unlink-entities-and-so-ent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!