https://playcanvas.com/project/573655/overview/configurateur-simple
Hi,
I’m trying to do a very simple configurator and I’m having some issue.
I can’t get my script to change my materials working.
When I lauch i get the error “Error loading scripts. Open the browser console for details.”
Uncaught TypeError: Cannot read property 'dirty' of undefined
at ForwardRenderer.renderForward (playcanvas-stable.dbg.js:10074)
at ForwardRenderer.renderComposition (playcanvas-stable.dbg.js:11022)
at Application.render (playcanvas-stable.dbg.js:22385)
at playcanvas-stable.dbg.js:22720
What am I missing?
var ButtonClick = pc.createScript('buttonClick');
// Create an array of materials to cycle the model through
ButtonClick.attributes.add("materials", {
type: "asset",
assetType: "material",
array: true,
title: "Materials"
});
// Create an id for the switch
ButtonClick.attributes.add('typeForSwitch', {
type: 'number',
title: 'Type',
default: 0
});
// Select the seadoo
ButtonClick.attributes.add('Seadoo_Optimized', {
type: 'entity',
title: 'Seadoo_Optimized'
});
// initialize code called once per entity
ButtonClick.prototype.initialize = function() {
// mouse events
this.entity.element.on('mousedown', this.onPress, this);
// touch events
this.entity.element.on('touchstart', this.onPress, this);
};
// update code called every frame
ButtonClick.prototype.update = function(dt) {
};
ButtonClick.prototype.onPress = function (event) {
switch(this.typeForSwitch){
case 0: // Blue
this.Seadoo_Optimized.model.model.meshInstances[0].material = this.materials[0];
this.Seadoo_Optimized.model.model.meshInstances[1].material = this.materials[1];
this.Seadoo_Optimized.model.model.meshInstances[2].material = this.materials[2];
this.Seadoo_Optimized.model.model.meshInstances[15].material = this.materials[3];
break;
case 1: // Green
this.Seadoo_Optimized.model.model.meshInstances[0].material = this.materials[0];
this.Seadoo_Optimized.model.model.meshInstances[1].material = this.materials[1];
this.Seadoo_Optimized.model.model.meshInstances[2].material = this.materials[2];
this.Seadoo_Optimized.model.model.meshInstances[15].material = this.materials[3];
break;
case 2: // Yellow
this.Seadoo_Optimized.model.model.meshInstances[0].material = this.materials[0];
this.Seadoo_Optimized.model.model.meshInstances[1].material = this.materials[1];
this.Seadoo_Optimized.model.model.meshInstances[2].material = this.materials[2];
this.Seadoo_Optimized.model.model.meshInstances[15].material = this.materials[3];
break;
}
};