diff options
Diffstat (limited to 'js/lib/rdge/materials/plasma-material.js')
-rw-r--r-- | js/lib/rdge/materials/plasma-material.js | 109 |
1 files changed, 7 insertions, 102 deletions
diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 1db207d6..c1e5524c 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js | |||
@@ -24,7 +24,7 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
24 | /////////////////////////////////////////////////////////////////////// | 24 | /////////////////////////////////////////////////////////////////////// |
25 | // Properties | 25 | // Properties |
26 | /////////////////////////////////////////////////////////////////////// | 26 | /////////////////////////////////////////////////////////////////////// |
27 | this._propNames = ["wave", "wave1", "wave2", "speed"]; | 27 | this._propNames = ["u_wave", "u_wave1", "u_wave2", "u_speed"]; |
28 | this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; | 28 | this._propLabels = ["Wave", "Wave 1", "Wave 2", "Speed"]; |
29 | this._propTypes = ["float", "float", "float", "float"]; | 29 | this._propTypes = ["float", "float", "float", "float"]; |
30 | 30 | ||
@@ -39,68 +39,17 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
39 | // Property Accessors | 39 | // Property Accessors |
40 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
41 | this.getShaderName = function() { return this._shaderName; }; | 41 | this.getShaderName = function() { return this._shaderName; }; |
42 | |||
43 | this.isAnimated = function() { return true; }; | 42 | this.isAnimated = function() { return true; }; |
43 | this.getShaderDef = function() { return plasmaShaderDef; }; | ||
44 | 44 | ||
45 | /////////////////////////////////////////////////////////////////////// | 45 | /////////////////////////////////////////////////////////////////////// |
46 | // Material Property Accessors | 46 | // Material Property Accessors |
47 | /////////////////////////////////////////////////////////////////////// | 47 | /////////////////////////////////////////////////////////////////////// |
48 | // duplcate method requirde | ||
49 | this.dup = function (world) { | ||
50 | // get the current values; | ||
51 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
52 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
53 | |||
54 | // allocate a new material | ||
55 | var newMat = new PlasmaMaterial(); | ||
56 | |||
57 | // copy over the current values; | ||
58 | var n = propNames.length; | ||
59 | for (var i = 0; i < n; i++) | ||
60 | newMat.setProperty(propNames[i], propValues[i]); | ||
61 | |||
62 | return newMat; | ||
63 | }; | ||
64 | |||
65 | this.setProperty = function( prop, value ) | ||
66 | { | ||
67 | // make sure we have legitimate imput | ||
68 | var ok = this.validateProperty( prop, value ); | ||
69 | if (!ok) { | ||
70 | console.log( "invalid property in Water Material:" + prop + " : " + value ); | ||
71 | } | ||
72 | |||
73 | switch (prop) | ||
74 | { | ||
75 | case "wave": | ||
76 | this._wave = value; | ||
77 | break; | ||
78 | |||
79 | case "wave1": | ||
80 | this._wave1 = value; | ||
81 | break; | ||
82 | |||
83 | case "wave2": | ||
84 | this._wave2 = value; | ||
85 | break; | ||
86 | |||
87 | case "speed": | ||
88 | this._speed = value; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | this.updateParameters(); | ||
93 | }; | ||
94 | |||
95 | /////////////////////////////////////////////////////////////////////// | ||
96 | 48 | ||
97 | /////////////////////////////////////////////////////////////////////// | 49 | /////////////////////////////////////////////////////////////////////// |
98 | // Methods | 50 | // Methods |
99 | /////////////////////////////////////////////////////////////////////// | 51 | /////////////////////////////////////////////////////////////////////// |
100 | // duplcate method requirde | 52 | // duplcate method requirde |
101 | this.dup = function() { | ||
102 | return new PlasmaMaterial(); | ||
103 | }; | ||
104 | 53 | ||
105 | this.init = function( world) | 54 | this.init = function( world) |
106 | { | 55 | { |
@@ -114,67 +63,23 @@ var PlasmaMaterial = function PlasmaMaterial() { | |||
114 | // set the default value | 63 | // set the default value |
115 | this._time = 0; | 64 | this._time = 0; |
116 | this._shader['default'].u_time.set( [this._time] ); | 65 | this._shader['default'].u_time.set( [this._time] ); |
117 | this._shader['default'].u_speed.set( [this._speed] ); | ||
118 | |||
119 | this._shader['default'].u_wave.set( [this._wave] ); | ||
120 | this._shader['default'].u_wave1.set( [this._wave1] ); | ||
121 | this._shader['default'].u_wave2.set( [this._wave2] ); | ||
122 | 66 | ||
123 | // set up the material node | 67 | // set up the material node |
124 | this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); | 68 | this._materialNode = RDGE.createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); |
125 | this._materialNode.setShader(this._shader); | 69 | this._materialNode.setShader(this._shader); |
126 | }; | ||
127 | 70 | ||
128 | this.updateParameters = function() | 71 | this._time = 0; |
129 | { | 72 | if (this._shader && this._shader['default']) { |
130 | this._propValues[ this._propNames[0] ] = this._wave; | 73 | this._shader['default'].u_time.set( [this._time] ); |
131 | this._propValues[ this._propNames[1] ] = this._wave1; | ||
132 | this._propValues[ this._propNames[2] ] = this._wave2; | ||
133 | this._propValues[ this._propNames[3] ] = this._speed; | ||
134 | |||
135 | var material = this._materialNode; | ||
136 | if (material) { | ||
137 | var technique = material.shaderProgram['default']; | ||
138 | var renderer = RDGE.globals.engine.getContext().renderer; | ||
139 | if (renderer && technique) { | ||
140 | technique.u_wave.set( [this._wave] ); | ||
141 | technique.u_wave1.set( [this._wave1] ); | ||
142 | technique.u_wave2.set( [this._wave2] ); | ||
143 | technique.u_speed.set( [this._speed] ); | ||
144 | } | ||
145 | } | 74 | } |
75 | |||
76 | this.setShaderValues(); | ||
146 | }; | 77 | }; |
147 | 78 | ||
148 | this.update = function( time ) { | 79 | this.update = function( time ) { |
149 | this._shader['default'].u_time.set( [this._time] ); | 80 | this._shader['default'].u_time.set( [this._time] ); |
150 | this._time += this._dTime; | 81 | this._time += this._dTime; |
151 | }; | 82 | }; |
152 | |||
153 | this.exportJSON = function() | ||
154 | { | ||
155 | var jObj = | ||
156 | { | ||
157 | 'material' : this.getShaderName(), | ||
158 | 'name' : this.getName(), | ||
159 | 'speed' : this._speed, | ||
160 | 'dTime' : this._dTime, | ||
161 | 'wave' : this._wave, | ||
162 | 'wave1' : this._wave1, | ||
163 | 'wave2' : this._wave2 | ||
164 | }; | ||
165 | |||
166 | return jObj; | ||
167 | }; | ||
168 | |||
169 | this.importJSON = function( jObj ) | ||
170 | { | ||
171 | this._speed = jObj.speed; | ||
172 | this._dTime = jObj.dTime; | ||
173 | |||
174 | this._wave = jObj.wave; | ||
175 | this._wave1 = jObj.wave1; | ||
176 | this._wave2 = jObj.wave2; | ||
177 | }; | ||
178 | }; | 83 | }; |
179 | 84 | ||
180 | /////////////////////////////////////////////////////////////////////////////////////// | 85 | /////////////////////////////////////////////////////////////////////////////////////// |