diff options
author | Nivesh Rajbhandari | 2012-03-06 14:09:44 -0800 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-06 14:09:44 -0800 |
commit | 792793cd3991032b4840ade67f98ae8eae2d30a0 (patch) | |
tree | 69d3df003d2bb58fa1ab562fbd1058ff91851f01 /js/helper-classes/RDGE/Materials/FlatMaterial.js | |
parent | 2346d8ab9db06573d8672c64988c46b6c672e015 (diff) | |
parent | 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f (diff) | |
download | ninja-792793cd3991032b4840ade67f98ae8eae2d30a0.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/helper-classes/RDGE/Materials/FlatMaterial.js')
-rwxr-xr-x | js/helper-classes/RDGE/Materials/FlatMaterial.js | 161 |
1 files changed, 0 insertions, 161 deletions
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js deleted file mode 100755 index 570e7f9e..00000000 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ /dev/null | |||
@@ -1,161 +0,0 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | /////////////////////////////////////////////////////////////////////// | ||
9 | // Class GLMaterial | ||
10 | // RDGE representation of a material. | ||
11 | /////////////////////////////////////////////////////////////////////// | ||
12 | function FlatMaterial() | ||
13 | { | ||
14 | // initialize the inherited members | ||
15 | this.inheritedFrom = GLMaterial; | ||
16 | this.inheritedFrom(); | ||
17 | |||
18 | /////////////////////////////////////////////////////////////////////// | ||
19 | // Instance variables | ||
20 | /////////////////////////////////////////////////////////////////////// | ||
21 | this._name = "FlatMaterial"; | ||
22 | this._shaderName = "flat"; | ||
23 | |||
24 | this._color = [1,0,0,1]; | ||
25 | |||
26 | /////////////////////////////////////////////////////////////////////// | ||
27 | // Property Accessors | ||
28 | /////////////////////////////////////////////////////////////////////// | ||
29 | this.getColor = function() { return this._color; }; | ||
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; | ||
36 | |||
37 | //////////////////////////////////s///////////////////////////////////// | ||
38 | // Methods | ||
39 | /////////////////////////////////////////////////////////////////////// | ||
40 | // duplcate method requirde | ||
41 | this.dup = function() { return new FlatMaterial(); } ; | ||
42 | |||
43 | this.init = function() | ||
44 | { | ||
45 | // set up the shader | ||
46 | this._shader = new jshader(); | ||
47 | this._shader.def = flatShaderDef; | ||
48 | this._shader.init(); | ||
49 | |||
50 | // set the defaults | ||
51 | this._shader.colorMe.color.set( this.getColor() ); | ||
52 | |||
53 | // set up the material node | ||
54 | this._materialNode = createMaterialNode("flatMaterial"); | ||
55 | this._materialNode.setShader(this._shader); | ||
56 | }; | ||
57 | |||
58 | |||
59 | /////////////////////////////////////////////////////////////////////// | ||
60 | // Material Property Accessors | ||
61 | /////////////////////////////////////////////////////////////////////// | ||
62 | this._propNames = ["color"]; | ||
63 | this._propLabels = ["Color"]; | ||
64 | this._propTypes = ["color"]; | ||
65 | this._propValues = []; | ||
66 | |||
67 | this._propValues[ this._propNames[0] ] = this._color; | ||
68 | |||
69 | this.setProperty = function( prop, value ) | ||
70 | { | ||
71 | // make sure we have legitimate input | ||
72 | if (this.validateProperty( prop, value )) | ||
73 | { | ||
74 | this._propValues[prop] = value; | ||
75 | if (this._shader && this._shader.colorMe) | ||
76 | this._shader.colorMe[prop].set(value); | ||
77 | } | ||
78 | }; | ||
79 | /////////////////////////////////////////////////////////////////////// | ||
80 | |||
81 | this.export = function() | ||
82 | { | ||
83 | // this function should be overridden by subclasses | ||
84 | var exportStr = "material: " + this.getShaderName() + "\n"; | ||
85 | exportStr += "name: " + this.getName() + "\n"; | ||
86 | |||
87 | if (this._shader) | ||
88 | exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; | ||
89 | else | ||
90 | exportStr += "color: " + this.getColor() + "\n"; | ||
91 | exportStr += "endMaterial\n"; | ||
92 | |||
93 | return exportStr; | ||
94 | }; | ||
95 | |||
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 ) | ||
124 | { | ||
125 | }; | ||
126 | |||
127 | } | ||
128 | |||
129 | /////////////////////////////////////////////////////////////////////////////////////// | ||
130 | // RDGE shader | ||
131 | |||
132 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
133 | flatShaderDef = | ||
134 | { | ||
135 | 'shaders': { // shader files | ||
136 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | ||
137 | 'defaultFShader':"assets/shaders/Basic.frag.glsl" | ||
138 | }, | ||
139 | 'techniques': { // rendering control | ||
140 | 'colorMe':[ // simple color pass | ||
141 | { | ||
142 | 'vshader' : 'defaultVShader', | ||
143 | 'fshader' : 'defaultFShader', | ||
144 | |||
145 | // attributes | ||
146 | 'attributes' : | ||
147 | { | ||
148 | 'vert' : { 'type' : 'vec3' }, | ||
149 | 'normal' : { 'type' : 'vec3' }, | ||
150 | 'texcoord' : { 'type' : 'vec2' } | ||
151 | }, | ||
152 | // attributes | ||
153 | 'params' : | ||
154 | { | ||
155 | 'color' : { 'type' : 'vec4' } | ||
156 | } | ||
157 | } | ||
158 | ] | ||
159 | } | ||
160 | }; | ||
161 | |||