Model loads without textures and got HTTPS 403 forbidden error

I’ll download a js script from S3 and that script will have a JSON with objects like this:

this.s3Assets = 
    {
        "S3-Assets":
            {
                'filename': 'Asset test',
                'asset': 'https://3dsvent.s3.amazonaws.com/assets/Laughing.json',
                'textureUrl': 'https://3dsvent.s3.amazonaws.com/assets/texture.jpg',
                'posX': -74.379,
                'posY': -1.581,
                'posZ': -7.967,
                'scaleX': '',
                'scaleY': '',
                'scaleZ': '',
                'scale': 1.6,
                'parent': '',
                'entityName': 'Test'
            }
}

I tried to load that object using this script but I got a HTTPS 403 forbidden warning, despite that error my model was successfully loaded without it’s texture. And just for the record, I already checked AWS CORS.

StartActions.prototype.loadAssets2 = function()
{
    var assets = this.s3Assets;
    
    for(var asset in assets)
    {
        var parent = this.app.root.findByName(asset);
        var ent = new pc.Entity(assets[asset].entityName);
        
        this.app.assets.loadFromUrl(assets[asset].asset, "model", function(err, model)
        {
            if (err) { console.log(err); }
            ent.addComponent("model", {asset: model, material:assets[asset].textureUrl});
        });
        
        ent.setLocalPosition(assets[asset].posX, assets[asset].posY, assets[asset].posZ);
        ent.setLocalScale(assets[asset].scale, assets[asset].scale, assets[asset].scale);
        ent.enabled = true;
        parent.addChild(ent);
    }
    
    console.log(parent.children, ent);
};

There’s usually a .mapping file with every model .json file that the loader is probably trying to load that maps materials to the models.

That’s probably what is causing the 403. This can be checked in the network tab of the devtools.

Right!, Now I tried to load the .fbx file instead of the .json and it seems to work without errors and it appears that the model was added into the entity but now the model is not in the visible. Do you have an idea why the model could not be visible if the entity is loaded?

PlayCanvas doesn’t support FBX at runtime.

Your best bet here is to use GLBs or upload the JSON files with the mapping files.

Eg, when you download JSON from the Editor, you can see the mapping.json file in the same directory as the model JSON file along side the material JSON files

image

The engine expects this layout in general.

All that said, GLBs as containers would be less messy and allow you to have textures and materials too.

Example: https://playcanvas.com/editor/scene/922242
Code: https://playcanvas.com/editor/code/655732?tabs=30952649

var LoadGlbExternalContainer = pc.createScript('loadGlbExternalContainer');
LoadGlbExternalContainer.attributes.add('url', {type: 'string'});

// initialize code called once per entity
LoadGlbExternalContainer.prototype.initialize = function() {
    var app = this.app;
    var self = this;

    app.assets.loadFromUrlAndFilename(self.url, null, "container", function (err, asset) {
        // Add the loaded scene to the hierarchy
        self.entity.addComponent('model', {
            asset: asset.resource.model
        });
                
        if (asset.resource.animations.length > 0) {
            self.entity.addComponent('animation', {
                assets: asset.resource.animations    
            });
        }
        
    });
};