Problem with positioning a glb using a render component

I’ve a got a glb asset, created from loading in an FBX.

If I create an instance of it by using a model component, everything is fine. If I create an instance of it by using a render component, I can’t transform it and it stays fixed at (0, 0, 0).with its default rotation and scale.

Here’s the relevant code:

let glbAsset = this.app.assets.find('myGlbAsset');
let newEntity = new pc.Entity(); // Create an Entity
newEntity.addComponent("model", { asset: glbAsset} );
newEntity.setPosition(1, 2, 3);
this.app.root.addChild(newEntity);

The above code will result in the model being positioned at (1, 2, 3);

let glbAsset = this.app.assets.find('myGlbAsset');
let newEntity = new pc.Entity();
newEntity.addComponent('render', { type: 'asset', meshInstances: glbAsset.resource.meshInstances });
newEntity.setPosition(1, 2, 3);
this.app.root.addChild(newEntity);

The above code will result in the model being positioned at (0, 0, 0);

Is there something I’m misunderstanding about the render component works?

Are you trying to use a Model Asset with a render component? If not, can you provide a public example of the setup please?

Well I suppose I am trying to use a Model Asset with a render component. I’m accessing the meshes from the model and putting them in the render component. From the documentation that I’ve read, I get the impression that the model component is going to be deprecated.

The Model Component and the Model Asset will be deprecated but both features and the code will still intended be supported. Just no new features are expected.

The Render Component is intended to be used with render assets created by the ‘Import Hierarchy’ feature (Import Hierarchy | Learn PlayCanvas)

1 Like