Changing a material with downloaded material

Hi All,

I want to change a material of my model with one that I downloaded from Playcanvas editor.
First of all, when I unzip the downloaded material the folder contains only sub folders where some of them has texture image and the other has JSON file.

I did something like this:
pc.app.assets.loadFromUrl(’/materials/wood/11087024/Wood_Pine.json’, ‘material’, function(err, asset) {
var entity = pc.app.root.findByName(‘Some Entity’);
entity.model.meshInstances[0].material = asset.resource;
}

It changes but I don’t see the correct texture - it’s all black without texture image.
If a material includes any texture images, will not work? or what am I doing wrong?

1 Like

Looks like there’s a bug there. Loading a material from a URL when just using the engine does not load the dependent textures first. Loading a model on the other hand, does do this. As a workaround, I can suggest the following. In Maya/Max, create a bunch of quads, maybe a 5x5 grid or something (assuming you only need up to 25 materials from the Editor, say. Then import the FBX into PlayCanvas. Consider it an artist’s palette. Create your materials and assign each to a quad. Then, whenever you want to export all the materials, just download the model ZIP. Load the model into your application and fish out the materials as required.

In the meantime, I’ve created this issue on GitHub.

1 Like

Eh…I just ran into this bug. Any ETA on this fix? I got a project set to go live in nine weeks. I can implement the workaround if I have to, but would prefer not to.

Urghh, I have the same issue. Any ETA on this bug fix guys?

When I used v1.31.0, I also encountered this bug, but when I tried to use v1.32.3 (the latest version), the bug was still not solved, so I am confused. could you help me,please!
UPDATE:sorry, maybe I don’t have a clear description. What I do now is to use this method to load materials dynamically without Editor. This material is downloaded from the Editor and put on my own server. It is normal to change the material in the editor. However, when I do not use the Editor to load the material dynamically(I did something like this:
pc.app.assets.loadFromUrl…), the effect is not the same, so I print and check it and I found that the“ materia.sphereMap " is null, I compared it and found that texture is missing. It does not load normally

Hi @fengyu,

That was definitely solved here, but there may be a regression: https://github.com/playcanvas/engine/pull/1692

Can you provide the code you are using to load the material and also your remote url serving the material file?

I loaded the model with code like this:
var url = “…/FYPlaycanvas/paint_whit/paint_whit.json”;
app.assets.loadFromUrl(url, “model”, function (err, asset) {
console.log(asset);
self.car = new pc.Entity();
self.car.addComponent(“model”, {
type: “asset”,
asset: -2,
castShadows: true
});
app.root.addChild(self.car);
});
It all worked well,but when I did like this:
var url = “…/FYPlaycanvas/TG86_carpaint_red/32569723/TG86_carpaint_red_01_mat.json”;
app.assets.loadFromUrl(url, “material”, function (err, asset) {
console.log(asset);
self.material = new pc.StandardMaterial();
self.material = asset.resource;
self.material.update();
});
the“ materia.sphereMap " is null,which means the texture did not load,this is what I didnot understand

Thank you for your help.
Sorry,I can not give you the material file because it belong to the company.
These are screenshots of my files:model 15.34.11

.
they were downloaded from Playcanvas Editor

From what I see all texture files are in place and correctly referenced by this material.

Your loading code seems correct, minor fix: the following line isn’t required as the asset.resource property already contains an instance of the pc.StandardMaterial():

// can be removed
self.material = new pc.StandardMaterial();

Though this won’t fix your issue. Sorry for not being of more help, try logging an issue on the Playcanvas repository about this in case there is a regression with the engine.

1 Like

Thank you very much,the minor fix is also impornt.
Have a good day!

1 Like

PR in progress for this issue: https://github.com/playcanvas/engine/pull/2325

1 Like

PR now merged. We might be able to deploy it tomorrow. :smile:

1 Like

@Leonidas @yaustar @will you are so nice,thank you,and it was solved when I used V1.27.4.