aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/Materials/FlatMaterial.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/Materials/FlatMaterial.js')
-rw-r--r--js/helper-classes/RDGE/Materials/FlatMaterial.js70
1 files changed, 46 insertions, 24 deletions
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js
index 5177a8a0..e2f23d75 100644
--- a/js/helper-classes/RDGE/Materials/FlatMaterial.js
+++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js
@@ -29,6 +29,8 @@ function FlatMaterial()
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 31
32 this.isAnimated = function() { return false; }
33
32 //////////////////////////////////s///////////////////////////////////// 34 //////////////////////////////////s/////////////////////////////////////
33 // Methods 35 // Methods
34 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
@@ -48,6 +50,12 @@ function FlatMaterial()
48 // set up the material node 50 // set up the material node
49 this._materialNode = createMaterialNode("flatMaterial"); 51 this._materialNode = createMaterialNode("flatMaterial");
50 this._materialNode.setShader(this._shader); 52 this._materialNode.setShader(this._shader);
53
54 // initialize the taper properties
55// this._shader.colorMe.u_limit1.set( [0.25] );
56// this._shader.colorMe.u_limit2.set( [0.5] );
57// this._shader.colorMe.u_limit3.set( [0.75] );
58// this._shader.colorMe.u_taperAmount.set( [0.5] );
51 } 59 }
52 60
53 61
@@ -63,10 +71,11 @@ function FlatMaterial()
63 71
64 this.setProperty = function( prop, value ) 72 this.setProperty = function( prop, value )
65 { 73 {
66 // make sure we have legitimate imput 74 // make sure we have legitimate input
67 if (this.validateProperty( prop, value )) 75 if (this.validateProperty( prop, value ))
68 { 76 {
69 this._color = value.slice(0); 77 this._propValues[prop] = value;
78 if (this._shader && this._shader.colorMe)
70 this._shader.colorMe[prop].set(value); 79 this._shader.colorMe[prop].set(value);
71 } 80 }
72 } 81 }
@@ -76,7 +85,7 @@ function FlatMaterial()
76 { 85 {
77 // this function should be overridden by subclasses 86 // this function should be overridden by subclasses
78 var exportStr = "material: " + this.getShaderName() + "\n"; 87 var exportStr = "material: " + this.getShaderName() + "\n";
79 exportStr = "name: " + this.getName() + "\n"; 88 exportStr += "name: " + this.getName() + "\n";
80 89
81 if (this._shader) 90 if (this._shader)
82 exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; 91 exportStr += "color: " + String(this._shader.colorMe.color) + "\n";
@@ -92,16 +101,33 @@ function FlatMaterial()
92 var pu = new ParseUtils( importStr ); 101 var pu = new ParseUtils( importStr );
93 var material = pu.nextValue( "material: " ); 102 var material = pu.nextValue( "material: " );
94 if (material != this.getShaderName()) throw new Error( "ill-formed material" ); 103 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
95 this.setName( pu.nextValue( "material: ") ); 104 this.setName( pu.nextValue( "name: ") );
96 var color = pu.nextValue( "color: " ); 105
106 var rtnStr;
107 try
108 {
109 var color = eval( "[" + pu.nextValue( "color: " ) + "]" );
110
111 this.setProperty( "color", color);
97 112
98 var endKey = "endMaterial\n"; 113 var endKey = "endMaterial\n";
99 var index = importStr.indexOf( endKey ) + endKey.len; 114 var index = importStr.indexOf( endKey );
100 var rtnStr = importStr.substr( index ); 115 index += endKey.length;
116 rtnStr = importStr.substr( index );
117 }
118 catch (e)
119 {
120 throw new Error( "could not import material: " + importStr );
121 }
122
101 return rtnStr; 123 return rtnStr;
102 } 124 }
103}
104 125
126 this.update = function( time )
127 {
128 }
129
130}
105// used to create unique names 131// used to create unique names
106var flatMaterialCounter = 0; 132var flatMaterialCounter = 0;
107 133
@@ -112,35 +138,31 @@ var flatMaterialCounter = 0;
112flatShaderDef = 138flatShaderDef =
113{ 139{
114 'shaders': { // shader files 140 'shaders': { // shader files
115 'defaultVShader': "\ 141 'defaultVShader':"assets/shaders/Basic.vert.glsl",
116 uniform mat4 u_mvMatrix;\ 142 '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 }, 143 },
129 'techniques': { // rendering control 144 'techniques': { // rendering control
130 'colorMe':[ // simple color pass 145 'colorMe':[ // simple color pass
131 { 146 {
132 'vshader' : 'defaultVShader', 147 'vshader' : 'defaultVShader',
133 'fshader' : 'defaultFShader', 148 'fshader' : 'defaultFShader',
134 149
135 // attributes 150 // attributes
136 'attributes' : 151 'attributes' :
137 { 152 {
138 'a_pos' : { 'type' : 'vec3' } // only using position for this shader 153 'vert' : { 'type' : 'vec3' },
154 'normal' : { 'type' : 'vec3' },
155 'texcoord' : { 'type' : 'vec2' },
139 }, 156 },
140 // attributes 157 // attributes
141 'params' : 158 'params' :
142 { 159 {
143 'color' : { 'type' : 'vec4' } 160 'color' : { 'type' : 'vec4' },
161
162 //'u_limit1': { 'type': 'float' },
163 //'u_limit2': { 'type': 'float' },
164 //'u_limit3': { 'type': 'float' },
165 //'u_taperAmount': { 'type': 'float' }
144 }, 166 },
145 }, 167 },
146 ] 168 ]