A-Frame: How do you add multiple meshes to an enti

2019-06-06 10:55发布

问题:

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/