A question about loading materials

Hello,I added a material to the car body and gave this material a cubemap,as shown in illustration:


It works well.

But when I load this material with the function:
app.assets.loadFromUrl(url, 'material', function (err, asset) { ... })
the result is there are no cubemap in the ‘asset.resourse’.
I don’t konw why and I don’t know how to add this cubemap to this material either,please help ,thank you!

Are you using engine only or trying to load a non-preloaded asset?

I use engine only

Can you provide an example project/code with data of the issue you are having please?

It’s difficult to tell with the information provided. Eg is the cubemap texture and data being referenced by the material JSON correctly?

I’ll do a demo, which contains the materials I downloaded from the editor, and then send out the address for you to have a look,give me some minutes,thank you

This is a demo,you can see my way of load material
and you can see In the loaded material there is no cubemap in the console,but the material data downloaded from the editor,you can find cubemap

This is a demo,you can see my way of load material
and you can see In the loaded material there is no cubemap in the console,but the material data downloaded from the editor,you can find cubemap,may I send you the demo which contains the materials I downloaded from the editor?

In the material, I can see the reference to the Cubemap:

Have you tried loading the cube map first? It’s possible that the material doesn’t trigger the loading of the cubemap :thinking:

I also noticed you are using an old version of the engine (1.36.0) which could be a factor. (bug fixes etc)

First,the cubemap’s type is texture,I don’t know how to load this cubemap,second ,I will use the lastest version to try if it is ok.

You should be able to load it the same way (app.assets.loadFromUrl), using the URL to the cubemap JSON file

Yeah,I loaded it success,but it is a material and API says it should be a texture type,I got confused

app.assets.loadFromUrl('./polestar2/47347309//New Cubemap.json', 'material', function (err, asset) {
            console.log(asset);
            // mat.cubemap = asset.resource;
        })
app.assets.loadFromUrl('./polestar2/47347309//New Cubemap.json', 'cubemap', function (err, asset) {
            console.log(asset);
        });

Please note that you will need to upload the textures for the cubemap too to the server.

Yes,It is,I can send you the demo,you can take a look.the material was downloaded from Editor,and I have checked it,it truely have all the assets that this material need.

I used v1.41.2,but it still didn’t load the cubemap,you can refresh that address,too


The code here is not loading the cubemap JSON.

When trying to load the cubemap, it doesn’t find the textures

When going to the URL where the cubemap textures should be, they don’t exist:

Could you give me your email address,I send the demo to you, the reason you got 404 is because I changed the name which is contain chinese characters,but I forgot to change all.

You can refresh the address,But it still get the Error:6 Error loading Texture from: 'New Cubemap.json'

this is my project hierachy

Had a good look at this.

The JSON that is downloaded from the Editor is not the same as the JSON used by the engine when it is published. I don’t know if this is by design or bug though.

It looks like your best bet is to either use the prefiltered DDS file (if you are using one) or construct the cubemap yourself in code.

Example: https://playcanvas.com/editor/scene/1164378

CubemapAtRuntime.prototype.initialize = function() {
    var app = this.app;
    var textureUrls = [
        "https://raw.githubusercontent.com/yaustar/yaustar.github.io/master/skybox/Helipad_negx.png",
        "https://raw.githubusercontent.com/yaustar/yaustar.github.io/master/skybox/Helipad_negy.png",
        "https://raw.githubusercontent.com/yaustar/yaustar.github.io/master/skybox/Helipad_negz.png",
        "https://raw.githubusercontent.com/yaustar/yaustar.github.io/master/skybox/Helipad_posx.png",
        "https://raw.githubusercontent.com/yaustar/yaustar.github.io/master/skybox/Helipad_posy.png",
        "https://raw.githubusercontent.com/yaustar/yaustar.github.io/master/skybox/Helipad_posz.png"
    ];
    
    // Create assets from the texture URLs
    var textures = textureUrls.map(function(url, i) {
        var asset = new pc.Asset('skybox' + '-' + i, 'texture', { url: url }); 
        app.assets.add(asset);
        return asset.id;
    });

    var cubemap = new pc.Asset(
        'skybox',
        'cubemap',
        null,
        {
            textures: textures
        }
    );

    app.setSkybox(cubemap);
};

Reference from the PlayCanvas Viewer: https://github.com/playcanvas/playcanvas-viewer/blob/4b2868ef938db592c358685f6b3c130ec73c0716/src/viewer.ts#L411

I think it is a bug,because I usually don’t change the resource file downloaded from the Editor. last time I changed the name of textures because it containes chinese characters, it is just a debug.
In addition, I’m worried that the problem is that the downloaded resources are not fully decompressed. Therefore, after downloading and decompressing several times, but the cubumap of this material can’t be loaded normally,by the way,if you need,I can send the material resources downloaded from Editor to do tests,sorry for that I can’t give you more information because of disclosure agreement.thank you very much!