Hi
I want to map materials from a Revit model by letting playcanvas run through the json file and find the materials that are in the assetsfolder to replace with the ones that are originally from the model.
The code is :
var jsonMaterial = definition.Materials[definition.BuildingElements[id].MaterialId];
console.log(definition.Materials[definition.BuildingElements[id].MaterialId]);
var instance = null;
var originalName = jsonMaterial.OriginalName;
var jsonMaterialMap = this.materialJSON.resource;
debugger;
var material;
if(jsonMaterialMap.hasOwnProperty(originalName))
{
var targetMaterialName = jsonMaterialMap[originalName];
material = this.app.assets.find(targetMaterialName);
// I can get the information of the material but here is were the error shows up
ERROR : Cannot read property 'push' of undefined
console.log(material);
} else {
// create a custom material
material = new pc.scene.PhongMaterial();
material.diffuse.set(jsonMaterial.ColorR, jsonMaterial.ColorG, jsonMaterial.ColorB);
material.opacity= jsonMaterial.Opacity;
material.reflectivity = (jsonMaterial.Transparent ? 1 : 0.2);
material.update();
}
instance = new pc.MeshInstance(node, mesh,material);
instance.castShadow = true;
instance.receiveShadows = !jsonMaterial.Transparent;
I think the problem is that it gets back an ASSET and not a material to implement.
Hopefully you can help me out, thanks .
Maybe a quick example on how to add a material to a object when retrieving it from the assetsfolder through a script.
Thanks in advance