Loadin and create model

Hello. I will have a model loaded in my project. Right now my code looks like this

PreloadModel.prototype.fetchModel = function(){
    fetch('https://render.cloudsgoods.com/images/avatars/24/texture/model.obj')
    .then(res=>res.blob()).then(blb => {
        let files  = new File([blb], 'new_model.obj')
        this.createAssetModel(files)
    })
}

PreloadModel.prototype.createAssetModel = function(file){
    const asset = new pc.Asset('newModel','model',{file})
    console.log(asset)
}

Next, I want to create a model from the asset. But so far I have nothing in my asset. I guess I’m not writing the parameters for asset correctly. Tell me how to create an asset correctly in my case.

Asset Registry can do it for you and has convenience methods for such cases:

Example:
https://playcanvas.github.io/#graphics/model-asset.html

1 Like

Thanks. But on a remote resource, I have a file with the .obj extension, and when I upload it to playcanvas with my hands, it is converted to .a glb model that I can insert into the scene. And when I load the model .obj via loadFromUrl, here’s what I see that the resources:null field, the file name is correctly pulled up, but there seems to be nothing inside. Maybe there is another way to load obj containers?

 this.app.assets.loadFromUrl('https://render.cloudsgoods.com/images/avatars/24/texture/model.obj','model',(a,b)=>console.log('1',a,'2',b))

There is a runtime OBJ loader http://playcanvas.github.io/#loaders/loader-obj.html

Parser here: https://github.com/playcanvas/playcanvas.github.io/blob/master/scripts/parsers/obj-model.js

However, it probably would be better to convert the OBJs to GLBs first (if you can).

2 Likes

Thank you very much. One more question. How to properly connect the parser inside the editor? Where to attach the parser and where to register it.

You can have the ‘glue’ code in global space. Eg: https://playcanvas.com/project/790341/overview/obj-parser

1 Like
  • Hello again. Is there a parser for glft?

The engine has a support for binary GLTF (ie GLBs). Example here: http://playcanvas.github.io/#graphics/model-asset.html