A-Frame: How do you add multiple meshes to an entity with setObject3D?

浪子不回头ぞ 提交于 2020-01-03 03:03:07

问题


With A-Frames tags, one can add multiple components as children to an entity:

<a-scene>
  <a-entity>
   <a-box>...</a-box>
   <a-box>...</a-box> 
 </a-entity>
<a-scene>

How would you duplicate this in a registered component with the setObject3D method?

CodePen: https://codepen.io/ubermario/pen/wrwjVG


回答1:


Yup, you can name the object3D however you want. The mesh word is just sort of commonly accepted for meshes and used by geometry/material components. To clarify:

setObject3D('mesh')

setObject3D('yourobject')

setObject3D('whateveryouwantbox');




回答2:


As far as i know, setObject3D only maps the Three object as the root of the object3D, like merging child entities with the parent. In order to achieve what You want, You need to:

  • get the parent entity object3D reference
  • create the three objects
  • add the objects to the parent using parent.add(three.object)

fiddle here: https://jsfiddle.net/kzv3rj6m/1/



来源:https://stackoverflow.com/questions/46165250/a-frame-how-do-you-add-multiple-meshes-to-an-entity-with-setobject3d

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