aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/runtime/RuntimeMaterial.js
diff options
context:
space:
mode:
authorhwc4872012-03-07 16:48:48 -0800
committerhwc4872012-03-07 16:48:48 -0800
commit818582d389f504c915be0c9052fafa33e3e76c92 (patch)
treeff686f52903d91f27f983b19e18c9909af5957d9 /js/helper-classes/RDGE/runtime/RuntimeMaterial.js
parent855e8727b147771ff7b05e71bed481e65fe4b6b0 (diff)
downloadninja-818582d389f504c915be0c9052fafa33e3e76c92.tar.gz
File IO
Diffstat (limited to 'js/helper-classes/RDGE/runtime/RuntimeMaterial.js')
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeMaterial.js282
1 files changed, 0 insertions, 282 deletions
diff --git a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js
deleted file mode 100644
index 6c57d102..00000000
--- a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js
+++ /dev/null
@@ -1,282 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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// Class RuntimeMaterial
9// Runtime representation of a material.
10///////////////////////////////////////////////////////////////////////
11function RuntimeMaterial( world )
12{
13 ///////////////////////////////////////////////////////////////////////
14 // Instance variables
15 ///////////////////////////////////////////////////////////////////////
16 this._name = "GLMaterial";
17 this._shaderName = "undefined";
18
19 // variables for animation speed
20 this._time = 0.0;
21 this._dTime = 0.01;
22
23 // RDGE variables
24 this._shader;
25 this._materialNode;
26
27 ///////////////////////////////////////////////////////////////////////
28 // Property Accessors
29 ///////////////////////////////////////////////////////////////////////
30
31 // a material can be animated or not. default is not.
32 // Any material needing continuous rendering should override this method
33 this.isAnimated = function() { return false; }
34
35 ///////////////////////////////////////////////////////////////////////
36 // Methods
37 ///////////////////////////////////////////////////////////////////////
38 this.init = function()
39 {
40 }
41
42 this.update = function( time )
43 {
44 }
45}
46
47function RuntimeFlatMaterial()
48{
49 // inherit the members of RuntimeMaterial
50 this.inheritedFrom = RuntimeMaterial;
51 this.inheritedFrom();
52
53 this._name = "FlatMaterial";
54 this._shaderName = "flat";
55
56 // assign a default color
57 this._color = [1,0,0,1];
58
59 this.import = function( importStr )
60 {
61 var colorStr = getPropertyFromString( "color: ", importStr );
62 if (colorStr)
63 this._color = eval( "[" + colorStr + "]" );
64 };
65
66
67 this.init = function()
68 {
69 if (this._shader)
70 {
71 this._shader.colorMe["color"].set( this._color );
72 }
73 }
74}
75
76function RuntimePulseMaterial()
77{
78 // inherit the members of RuntimeMaterial
79 this.inheritedFrom = RuntimeMaterial;
80 this.inheritedFrom();
81
82 this._name = "PulseMaterial";
83 this._shaderName = "pulse";
84
85 this._texMap = 'assets/images/cubelight.png';
86
87 this.isAnimated = function() { return true; }
88
89
90 this.import = function( importStr )
91 {
92 this._texMap = getPropertyFromString( "texture: ", importStr );
93 }
94
95 this.init = function()
96 {
97 var material = this._materialNode;
98 if (material)
99 {
100 var technique = material.shaderProgram.default;
101 var renderer = g_Engine.getContext().renderer;
102 if (renderer && technique)
103 {
104 if (this._shader && this._shader.default)
105 {
106 var res = [ renderer.vpWidth, renderer.vpHeight ];
107 technique.u_resolution.set( res );
108
109 var wrap = 'REPEAT', mips = true;
110 var tex = renderer.getTextureByName(this._texMap, wrap, mips );
111 if (tex)
112 technique.u_tex0.set( tex );
113
114 this._shader.default.u_time.set( [this._time] );
115 }
116 }
117 }
118 }
119
120 // several materials inherit from pulse.
121 // they may share this update method
122 this.update = function( time )
123 {
124 var material = this._materialNode;
125 if (material)
126 {
127 var technique = material.shaderProgram.default;
128 var renderer = g_Engine.getContext().renderer;
129 if (renderer && technique)
130 {
131 if (this._shader && this._shader.default)
132 this._shader.default.u_time.set( [this._time] );
133 this._time += this._dTime;
134 if (this._time > 200.0) this._time = 0.0;
135 }
136 }
137 }
138}
139
140function RuntimeRadialGradientMaterial()
141{
142 // inherit the members of RuntimeMaterial
143 this.inheritedFrom = RuntimeMaterial;
144 this.inheritedFrom();
145
146 this._name = "RadialGradientMaterial";
147 this._shaderName = "radialGradient";
148
149 // setup default values
150 this._color1 = [1,0,0,1]; this._colorStop1 = 0.0;
151 this._color2 = [0,1,0,1]; this._colorStop2 = 0.3;
152 this._color3 = [0,1,0,1]; this._colorStop3 = 0.6;
153 this._color4 = [0,1,0,1]; this._colorStop4 = 1.0;
154
155 this.init = function()
156 {
157 var material = this._materialNode;
158 if (material)
159 {
160 var technique = material.shaderProgram.default;
161 var renderer = g_Engine.getContext().renderer;
162 if (renderer && technique)
163 {
164 if (this._shader && this._shader.default)
165 {
166 this._shader.default.u_color1.set( this._color1 );
167 this._shader.default.u_color2.set( this._color2 );
168 this._shader.default.u_color3.set( this._color3 );
169 this._shader.default.u_color4.set( this._color4 );
170
171 this._shader.default.u_colorStop1.set( [this._colorStop1] );
172 this._shader.default.u_colorStop2.set( [this._colorStop2] );
173 this._shader.default.u_colorStop3.set( [this._colorStop3] );
174 this._shader.default.u_colorStop4.set( [this._colorStop4] );
175
176 if (this._angle !== undefined)
177 this._shader.default.u_cos_sin_angle.set([Math.cos(this._angle), Math.sin(this._angle)]);
178 }
179 }
180 }
181 }
182
183 this.import = function( importStr )
184 {
185 var colorStr;
186 colorStr = getPropertyFromString( "color1: ", importStr );
187 this._color1 = eval( "[" + colorStr + "]" );
188 colorStr = getPropertyFromString( "color2: ", importStr );
189 this._color2 = eval( "[" + colorStr + "]" );
190 colorStr = getPropertyFromString( "color3: ", importStr );
191 this._color3 = eval( "[" + colorStr + "]" );
192 colorStr = getPropertyFromString( "color4: ", importStr );
193 this._color4 = eval( "[" + colorStr + "]" );
194
195 this._colorStop1 = Number( getPropertyFromString( "colorStop1: ", importStr ) );
196 this._colorStop2 = Number( getPropertyFromString( "colorStop2: ", importStr ) );
197 this._colorStop3 = Number( getPropertyFromString( "colorStop3: ", importStr ) );
198 this._colorStop4 = Number( getPropertyFromString( "colorStop4: ", importStr ) );
199
200 if (this._angle !== undefined)
201 this._angle = getPropertyFromString( "angle: ", importStr );
202 }
203
204}
205
206function RuntimeLinearGradientMaterial()
207{
208 // inherit the members of RuntimeMaterial
209 this.inheritedFrom = RuntimeRadialGradientMaterial;
210 this.inheritedFrom();
211
212 this._name = "LinearGradientMaterial";