aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/FlatMaterial.js
diff options
context:
space:
mode:
authorArmen Kesablyan2012-02-13 11:59:19 -0800
committerArmen Kesablyan2012-02-13 11:59:19 -0800
commit90d0c8c0e98d062c628c061fe5765ce991fda409 (patch)
tree9780e9dcf475bf319f3cacc1a1ad52fcf9f133af /js/helper-classes/RDGE/Materials/FlatMaterial.js
parent8110e01dc5093ac6baf621103dcaa5f769e5be92 (diff)
parente142611e22718b1f1d1696902ad9161ec5f33f98 (diff)
downloadninja-90d0c8c0e98d062c628c061fe5765ce991fda409.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
Conflicts: css/ninja.css js/stage/stage.reel/stage.html js/tools/TextTool.js node_modules/labs/rich-text-editor.reel/rich-text-editor.css node_modules/labs/rich-text-editor.reel/rich-text-editor.html node_modules/labs/rich-text-editor.reel/rich-text-editor.js node_modules/labs/rich-text-editor.reel/rich-text-resizer.js node_modules/labs/rich-text-editor.reel/rich-text-sanitizer.js Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/Materials/FlatMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/FlatMaterial.js98
1 files changed, 55 insertions, 43 deletions
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js
index 5177a8a0..570e7f9e 100644
--- a/js/helper-classes/RDGE/Materials/FlatMaterial.js
+++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js
@@ -26,14 +26,19 @@ function FlatMaterial()
26 /////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors 27 // Property Accessors
28 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
29 this.getColor = function() { return this._color; } 29 this.getColor = function() { return this._color; };
30 this.getShaderName = function() { return this._shaderName; } 30 this.getShaderName = function() { return this._shaderName; };
31
32 this.isAnimated = function() { return false; };
33 this.hasVertexDeformation = function() { return true; };
34 this._hasVertexDeformation = true;
35 this._vertexDeformationTolerance = 0.2;
31 36
32 //////////////////////////////////s///////////////////////////////////// 37 //////////////////////////////////s/////////////////////////////////////
33 // Methods 38 // Methods
34 /////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////
35 // duplcate method requirde 40 // duplcate method requirde
36 this.dup = function() { return new FlatMaterial(); } 41 this.dup = function() { return new FlatMaterial(); } ;
37 42
38 this.init = function() 43 this.init = function()
39 { 44 {
@@ -48,7 +53,7 @@ function FlatMaterial()
48 // set up the material node 53 // set up the material node
49 this._materialNode = createMaterialNode("flatMaterial"); 54 this._materialNode = createMaterialNode("flatMaterial");
50 this._materialNode.setShader(this._shader); 55 this._materialNode.setShader(this._shader);
51 } 56 };
52 57
53 58
54 /////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////
@@ -63,20 +68,21 @@ function FlatMaterial()
63 68
64 this.setProperty = function( prop, value ) 69 this.setProperty = function( prop, value )
65 { 70 {
66 // make sure we have legitimate imput 71 // make sure we have legitimate input
67 if (this.validateProperty( prop, value )) 72 if (this.validateProperty( prop, value ))
68 { 73 {
69 this._color = value.slice(0); 74 this._propValues[prop] = value;
70 this._shader.colorMe[prop].set(value); 75 if (this._shader && this._shader.colorMe)
76 this._shader.colorMe[prop].set(value);
71 } 77 }
72 } 78 };
73 /////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////
74 80
75 this.export = function() 81 this.export = function()
76 { 82 {
77 // this function should be overridden by subclasses 83 // this function should be overridden by subclasses
78 var exportStr = "material: " + this.getShaderName() + "\n"; 84 var exportStr = "material: " + this.getShaderName() + "\n";
79 exportStr = "name: " + this.getName() + "\n"; 85 exportStr += "name: " + this.getName() + "\n";
80 86
81 if (this._shader) 87 if (this._shader)
82 exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; 88 exportStr += "color: " + String(this._shader.colorMe.color) + "\n";
@@ -85,25 +91,40 @@ function FlatMaterial()
85 exportStr += "endMaterial\n"; 91 exportStr += "endMaterial\n";
86 92
87 return exportStr; 93 return exportStr;
88 } 94 };
89 95
90 this.import = function( importStr ) 96 this.import = function( importStr )
97 {
98 var pu = new ParseUtils( importStr );
99 var material = pu.nextValue( "material: " );
100 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
101 this.setName( pu.nextValue( "name: ") );
102
103 var rtnStr;
104 try
105 {
106 var color = eval( "[" + pu.nextValue( "color: " ) + "]" );
107
108 this.setProperty( "color", color);
109
110 var endKey = "endMaterial\n";
111 var index = importStr.indexOf( endKey );
112 index += endKey.length;
113 rtnStr = importStr.substr( index );
114 }
115 catch (e)
116 {
117 throw new Error( "could not import material: " + importStr );
118 }
119
120 return rtnStr;
121 };
122
123 this.update = function( time )
91 { 124 {
92 var pu = new ParseUtils( importStr ); 125 };
93 var material = pu.nextValue( "material: " );
94 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
95 this.setName( pu.nextValue( "material: ") );
96 var color = pu.nextValue( "color: " );
97
98 var endKey = "endMaterial\n";
99 var index = importStr.indexOf( endKey ) + endKey.len;
100 var rtnStr = importStr.substr( index );
101 return rtnStr;
102 }
103}
104 126
105// used to create unique names 127}
106var flatMaterialCounter = 0;
107 128
108/////////////////////////////////////////////////////////////////////////////////////// 129///////////////////////////////////////////////////////////////////////////////////////
109// RDGE shader 130// RDGE shader
@@ -112,37 +133,28 @@ var flatMaterialCounter = 0;
112flatShaderDef = 133flatShaderDef =
113{ 134{
114 'shaders': { // shader files 135 'shaders': { // shader files
115 'defaultVShader': "\ 136 'defaultVShader':"assets/shaders/Basic.vert.glsl",
116 uniform mat4 u_mvMatrix;\ 137 'defaultFShader':"assets/shaders/Basic.frag.glsl"
117 uniform mat4 u_projMatrix;\
118 attribute vec3 a_pos;\
119 void main() {\
120 gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0);\
121 }",
122 'defaultFShader': "\
123 precision highp float;\
124 uniform vec4 color;\
125 void main() {\
126 gl_FragColor = color;\
127 }",
128 }, 138 },
129 'techniques': { // rendering control 139 'techniques': { // rendering control
130 'colorMe':[ // simple color pass 140 'colorMe':[ // simple color pass
131 { 141 {
132 'vshader' : 'defaultVShader', 142 'vshader' : 'defaultVShader',
133 'fshader' : 'defaultFShader', 143 'fshader' : 'defaultFShader',
134 144
135 // attributes 145 // attributes
136 'attributes' : 146 'attributes' :
137 { 147 {
138 'a_pos' : { 'type' : 'vec3' } // only using position for this shader 148 'vert' : { 'type' : 'vec3' },
149 'normal' : { 'type' : 'vec3' },
150 'texcoord' : { 'type' : 'vec2' }
139 }, 151 },
140 // attributes 152 // attributes
141 'params' : 153 'params' :
142 { 154 {
143 'color' : { 'type' : 'vec4' } 155 'color' : { 'type' : 'vec4' }
144 }, 156 }
145 }, 157 }
146 ] 158 ]
147 } 159 }
148}; 160};