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?
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.
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.
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
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
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.