aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/flat-material.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-04 17:24:27 -0700
committerNivesh Rajbhandari2012-04-04 17:24:27 -0700
commit01cf259da7aaa7d70789d9a7c32111d88b477463 (patch)
tree0bff3395ac681e5f685d2267f7dbc03a8e32bc4a /js/lib/rdge/materials/flat-material.js
parent331ea08655245e3532e48bf160d5f68a04d8723f (diff)
parent13368ca6ebbc13adeafccd898dfffd7ce37cb28a (diff)
downloadninja-01cf259da7aaa7d70789d9a7c32111d88b477463.tar.gz
Merge branch 'refs/heads/ToolFixes' into WebGLMaterials
Conflicts: js/document/templates/montage-html/default_html.css js/mediators/element-mediator.js js/panels/properties.reel/properties.js js/tools/BrushTool.js js/tools/LineTool.js js/tools/PenTool.js js/tools/SelectionTool.js js/tools/ShapeTool.js js/tools/TranslateObject3DTool.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/flat-material.js')
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js141
1 files changed, 52 insertions, 89 deletions
diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js
index 5030cc88..9442ae5b 100755
--- a/js/lib/rdge/materials/flat-material.js
+++ b/js/lib/rdge/materials/flat-material.js
@@ -14,129 +14,92 @@ var FlatMaterial = function FlatMaterial() {
14 /////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables 15 // Instance variables
16 /////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////
17 this._name = "FlatMaterial"; 17 this._name = "FlatMaterial";
18 this._shaderName = "flat"; 18 this._shaderName = "flat";
19 19
20 this._color = [1,0,0,1]; 20 this._color = [1, 0, 0, 1];
21 21
22 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
23 // Property Accessors 23 // Property Accessors
24 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
25 this.getColor = function() { return this._color; }; 25 this.getColor = function () { return this._color; };
26 this.getShaderName = function() { return this._shaderName; }; 26 this.getShaderName = function () { return this._shaderName; };
27 27
28 this.isAnimated = function() { return false; }; 28 this.isAnimated = function () { return false; };
29 this.hasVertexDeformation = function() { return true; }; 29 this.hasVertexDeformation = function () { return true; };
30 this._hasVertexDeformation = true; 30 this._hasVertexDeformation = true;
31 this._vertexDeformationTolerance = 0.2; 31 this._vertexDeformationTolerance = 0.2;
32 32
33 //////////////////////////////////s///////////////////////////////////// 33 //////////////////////////////////s/////////////////////////////////////
34 // Methods 34 // Methods
35 /////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////
36 // duplcate method requirde 36 // duplcate method requirde
37 this.dup = function() { return new FlatMaterial(); } ; 37 this.dup = function () { return new FlatMaterial(); };
38 38
39 this.init = function( world ) 39 this.init = function (world) {
40 { 40 // save the world
41 // save the world 41 if (world) {
42 if (world) 42 this.setWorld(world);
43 {
44 this.setWorld( world );
45 43
46 // set up the shader 44 // set up the shader
47 this._shader = new jshader(); 45 this._shader = new RDGE.jshader();
48 this._shader.def = flatShaderDef; 46 this._shader.def = flatShaderDef;
49 this._shader.init(); 47 this._shader.init();
50 48
51 // set the defaults 49 // set the defaults
52 this._shader.colorMe.color.set( this.getColor() ); 50 this._shader.colorMe.color.set(this.getColor());
53 51
54 // set up the material node 52 // set up the material node
55 this._materialNode = createMaterialNode("flatMaterial_" + world.generateUniqueNodeID() ); 53 this._materialNode = RDGE.createMaterialNode("flatMaterial_" + world.generateUniqueNodeID());
56 this._materialNode.setShader(this._shader); 54 this._materialNode.setShader(this._shader);
57 } 55 }
58 else 56 else
59 throw new Error( "GLWorld not supplied to material initialization" ); 57 throw new Error("GLWorld not supplied to material initialization");
60 }; 58 };
61 59
62 60
63 /////////////////////////////////////////////////////////////////////// 61 ///////////////////////////////////////////////////////////////////////
64 // Material Property Accessors 62 // Material Property Accessors
65 /////////////////////////////////////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////
66 this._propNames = ["color"]; 64 this._propNames = ["color"];
67 this._propLabels = ["Color"]; 65 this._propLabels = ["Color"];
68 this._propTypes = ["color"]; 66 this._propTypes = ["color"];
69 this._propValues = []; 67 this._propValues = [];
70 68
71 this._propValues[ this._propNames[0] ] = this._color; 69 this._propValues[this._propNames[0]] = this._color;
72 70
73 this.setProperty = function( prop, value ) { 71 this.setProperty = function (prop, value) {
74 // make sure we have legitimate input 72 // make sure we have legitimate input
75 if (this.validateProperty( prop, value )) { 73 if (this.validateProperty(prop, value)) {
76 this._propValues[prop] = value; 74 this._propValues[prop] = value;
77 if (this._shader && this._shader.colorMe) { 75 if (this._shader && this._shader.colorMe) {
78 this._shader.colorMe[prop].set(value); 76 this._shader.colorMe[prop].set(value);
79 } 77 }
80 }
81 };
82 ///////////////////////////////////////////////////////////////////////
83
84 this.export = function()
85 {
86 // this function should be overridden by subclasses
87 var exportStr = "material: " + this.getShaderName() + "\n";
88 exportStr += "name: " + this.getName() + "\n";
89 exportStr += "color: " + String(this._propValues["color"]) + "\n";
90 exportStr += "endMaterial\n";
91
92 return exportStr;
93 };
94
95 this.import = function( importStr ) {
96 var pu = new MaterialParser( importStr );
97 var material = pu.nextValue( "material: " );
98 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
99 this.setName( pu.nextValue( "name: ") );
100
101 var rtnStr;
102 try
103 {
104 var color = eval( "[" + pu.nextValue( "color: " ) + "]" );
105 this.setProperty( "color", color);
106 }
107 catch (e)
108 {
109 throw new Error( "could not import material: " + importStr );
110 } 78 }
111
112 return rtnStr;
113 }; 79 };
80 ///////////////////////////////////////////////////////////////////////
114 81
115 this.exportJSON = function() 82 this.exportJSON = function () {
116 { 83 var jObj =
117 var jObj =
118 { 84 {
119 'material' : this.getShaderName(), 85 'material': this.getShaderName(),
120 'name' : this.getName(), 86 'name': this.getName(),
121 'color' : this._propValues["color"] 87 'color': this._propValues["color"]
122 }; 88 };
123 89
124 return jObj; 90 return jObj;
125 } 91 };
126 92
127 this.importJSON = function( jObj ) 93 this.importJSON = function (jObj) {
128 { 94 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
129 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); 95 this.setName(jObj.name);
130 this.setName( jObj.name );
131
132 var color = jObj.color;
133 this.setProperty( "color", color);
134 }
135 96
136 this.update = function( time ) 97 var color = jObj.color;
137 { 98 this.setProperty("color", color);
138 }; 99 };
139 100
101 this.update = function (time) {
102 };
140}; 103};
141 104
142/////////////////////////////////////////////////////////////////////////////////////// 105///////////////////////////////////////////////////////////////////////////////////////