Niraj
Niraj

Reputation: 373

aframe get object3d children

I am working with a gltf model for a game. It is referenced as -

<a-asset-item id="orca1" src="../images/models/orca/scene.gltf"></a-asset-item>

and then accessed as

<a-entity id="orca" position="-1 0.4 -40" gltf-model="#orca1"></a-entity>

and

<a-entity model-subset="target: #orca"></a-entity>

So, in the model-subset component, I am trying to get a hold on the object3d scene so that I can clone it. Here is how I access the object3d there

AFRAME.registerComponent('model-subset', {
  schema: {
    target: { default: '', type: 'selector' }
  },
  init: function() {
    var data = this.data;
    var el = this.el;
    console.log(data.target.object3D.children);
    data.target.addEventListener('model-loaded', function(e) {
      this.model = e.detail.model;
      console.log(this.model)
    })
    }
})

What I am trying to understand is - when I do the data.target.object3D.children, I get the following in my console log -

enter image description here

but the e.detail.model gives the following in the console log -

enter image description here

So, when I try to access the "OSG_Scene" from data.target.object3d.children[0], I get "undefined" in the console.log.

Also, why am I not able to get "OSG_Scene" via either of these methods -

  1. data.target.getObject3D('Scene') OR
  2. data.target.getobjectbyname("OSG_Scene")

Thank you so much for your help.

Upvotes: 1

Views: 1388

Answers (1)

ngokevin
ngokevin

Reputation: 13233

It should be data.target.getObject3D('mesh')

Upvotes: 1

Related Questions