diff options
Diffstat (limited to 'js/helper-classes/RDGE/runtime/RuntimeMaterial.js')
-rw-r--r-- | js/helper-classes/RDGE/runtime/RuntimeMaterial.js | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/runtime/RuntimeMaterial.js b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js new file mode 100644 index 00000000..2ba3006e --- /dev/null +++ b/js/helper-classes/RDGE/runtime/RuntimeMaterial.js | |||
@@ -0,0 +1,140 @@ | |||
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 | // Class RuntimeMaterial | ||
9 | // Runtime representation of a material. | ||
10 | /////////////////////////////////////////////////////////////////////// | ||
11 | function 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 | |||
47 | |||
48 | function RuntimeFlatMaterial() | ||
49 | { | ||
50 | // inherit the members of RuntimeMaterial | ||
51 | this.inheritedFrom = RuntimeMaterial; | ||
52 | this.inheritedFrom(); | ||
53 | |||
54 | this._name = "FlatMaterial"; | ||
55 | this._shaderName = "flat"; | ||
56 | |||
57 | // assign a default color | ||
58 | this._color = [1,0,0,1]; | ||
59 | |||
60 | this.import = function( importStr ) | ||
61 | { | ||
62 | var colorStr = getPropertyFromString( "color: ", importStr ); | ||
63 | if (colorStr) | ||
64 | this._color = eval( "[" + colorStr + "]" ); | ||
65 | }; | ||
66 | |||
67 | |||
68 | this.init = function() | ||
69 | { | ||
70 | if (this._shader) | ||
71 | { | ||
72 | this._shader.colorMe["color"].set( this._color ); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | function RuntimePulseMaterial() | ||
78 | { | ||
79 | // inherit the members of RuntimeMaterial | ||
80 | this.inheritedFrom = RuntimeMaterial; | ||
81 | this.inheritedFrom(); | ||
82 | |||
83 | this._name = "PulseMaterial"; | ||
84 | this._shaderName = "pulse"; | ||
85 | |||
86 | this._texMap = 'assets/images/cubelight.png'; | ||
87 | |||
88 | this.isAnimated = function() { return true; } | ||
89 | |||
90 | |||
91 | this.import = function( importStr ) | ||
92 | { | ||
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 | |||
140 | |||