From 6c994c4b90023cecf4fd0caafb404b859fe28f54 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 6 Jun 2012 16:34:41 -0700 Subject: material cleanup and rearchitecture --- js/lib/geom/circle.js | 22 ++++++++++++++-------- js/lib/geom/geom-obj.js | 21 +++++++++++++-------- js/lib/geom/rectangle.js | 23 +++++++++++++++-------- 3 files changed, 42 insertions(+), 24 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index b2709ce4..6627b4b7 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -57,16 +57,18 @@ exports.Circle = Object.create(GeomObj, { this.m_world = world; if(strokeMaterial) { - this._strokeMaterial = strokeMaterial; + this._strokeMaterial = strokeMaterial.dup(); } else { - this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); if(fillMaterial) { - this._fillMaterial = fillMaterial; + this._fillMaterial = fillMaterial.dup(); } else { - this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); } }, @@ -702,19 +704,23 @@ exports.Circle = Object.create(GeomObj, { var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); + var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); if (!strokeMat) { console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._strokeMaterial = strokeMat; + if (this._strokeMaterial.hasProperty( 'color' )) + this._strokeMaterial.setProperty( 'color', this._strokeColor ); - var fillMat = MaterialsModel.getMaterial( fillMaterialName ); + var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); if (!fillMat) { console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._fillMaterial = fillMat; + if (this._fillMaterial.hasProperty( 'color' )) + this._fillMaterial.setProperty( 'color', this._fillColor ); this.importMaterialsJSON( jObj.materials ); } diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 417c8731..3a7a5619 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -281,9 +281,11 @@ exports.GeomObj = Object.create(Object.prototype, { this._materialArray.push(strokeMaterial); this._materialTypeArray.push("stroke"); - if (this._strokeColor) { - this.setStrokeColor(this._strokeColor); - } + // don't set the value here. The material editor may set a color directly + // to the material without setting this value in the obj. The following + // lines of code will clobber the value in the material + //if (this._strokeColor) + // this.setStrokeColor(this._strokeColor); this._strokeMaterial = strokeMaterial; @@ -306,12 +308,14 @@ exports.GeomObj = Object.create(Object.prototype, { this._materialArray.push(fillMaterial); this._materialTypeArray.push("fill"); + + // don't set the value here. The material editor may set a color directly + // to the material without setting this value in the obj. The following + // lines of code will clobber the value in the material + //if (this._fillColor) + // this.setFillColor(this._fillColor); - if (this._fillColor) { - this.setFillColor(this._fillColor); - } - - this._fillMaterial = fillMaterial; + this._fillMaterial = fillMaterial; return fillMaterial; } @@ -389,6 +393,7 @@ exports.GeomObj = Object.create(Object.prototype, { case "radialBlur": case "pulse": case "twistVert": + case "taper": mat = MaterialsModel.getMaterialByShader(shaderName); if (mat) mat = mat.dup(); break; diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 42d51e74..81a8556d 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -73,16 +73,19 @@ exports.Rectangle = Object.create(GeomObj, { this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; if(strokeMaterial) { - this._strokeMaterial = strokeMaterial; + this._strokeMaterial = strokeMaterial.dup(); } else { - this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); + if(fillMaterial) { - this._fillMaterial = fillMaterial; + this._fillMaterial = fillMaterial.dup(); } else { - this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); } }, @@ -289,19 +292,23 @@ exports.Rectangle = Object.create(GeomObj, { var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); + var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); if (!strokeMat) { console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._strokeMaterial = strokeMat; + if (this._strokeMaterial.hasProperty( 'color' )) + this._strokeMaterial.setProperty( 'color', this._strokeColor ); - var fillMat = MaterialsModel.getMaterial( fillMaterialName ); + var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); if (!fillMat) { console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._fillMaterial = fillMat; + if (this._fillMaterial.hasProperty( 'color' )) + this._fillMaterial.setProperty( 'color', this._fillColor ); this.importMaterialsJSON( jObj.materials ); } -- cgit v1.2.3