Problem while creating new entities using models from decoded base64 data

Hello everyone,

This problem possibly has a simple origin but I have not been able to find it yet. The thing is, I have some base64 encoded models and textures stored in a JSON that I need to decode and drop into a scene. I’ve been able to successfully decode both the models and textures, but for some reason I’ve only been able to use the textures in the scene. I have created this public test project to illustrate the issue: Base64 Asset Loading Test. In the TestInitializer script, you can see how I load both a texture and a model, using base64 encoded data from a local JSON. The texture is then successfully integrated into a material and this in turn is successfully mapped to the scene’s default plane. However, when I try to create a new entity with a model component with our newly decoded model asset, it is nowhere to be seen on the scene. I know, thought, that the entity is indeed created and has the model asset assigned to it, as I can see in the browser debugger. I’m confused cause I have already created new entities with models in the past using this pattern. Also, no errors show up in the console. Any clues as to why this may be happening?

Thank you very much in advance

Hi @Mediotaku,

I am not sure why that happens but the model component is legacy right now. Here is a quick way to do it with the render component, get your model to render:

    // create render component
    newEntity.addComponent("render");
    newEntity.render.meshInstances = modelAsset.resource.meshInstances;

2 Likes

Alternatively, you can load the GLB as a container and with that, pull the model asset or create a render component hierarchy from it.

https://playcanvas.com/project/898763/overview/f-asset-loading-test

2 Likes

Thank you very much for your answers. Both solutions work, I’m still curious why my pattern doesn’t work in this situation, but for the moment I’ll use your way.

Thank you again.