So, here is the code:
var Startup = pc.createScript('startup');
// initialize code called once per entity
Startup.prototype.initialize = function() {
// Assign app
var app = this.app;
// assign the mesh instances of the phone and return the material array of the object
var phoneMats = app.root.findByName("iPhone5s").model.model.meshInstances.map(function(obj) {
return obj.material;
});
// Assign each material a cubemap as environment texture
for(var i in phoneMats) {
var currMat = phoneMats[i];
currMat.cubemap = app.assets.get(9191094);
// Assign normap and glossy maps to housing, buttons etc.
switch(currMat.name) {
case "housingColor":
case "volumeButtonsColor":
case "muteSwitchColor":
case "simTrayColor":
case "powerButtonColor":
currMat.useMetalness = true;
currMat.metalness = 100;
currMat.glossMap = app.assets.get(9191517);
currMat.shininess = 100;
currMat.normalMap = app.assets.get(9191519);
currMat.bumpiness = 1;
}
console.log(currMat);
currMat.update(); // THE ERROR OCCURS HERE
app.root.findByName("iPhone5s").model.model.meshInstances[i].material = currMat;
}
};
Basically, on startup i want to add a cubemap and glossy map etc. to each material attatched to an object (the phone). When i call currMat.update(), the proto function which is defined in the object and can be seen via a console.log of the material, it says it is undefined…
I am new to playcanvas but have had experience in other gameengines and languages but this one has stumped me as the error logging isn’t the clearest… Thanks.