diff options
Diffstat (limited to 'js/lib/rdge')
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 46 | ||||
-rwxr-xr-x | js/lib/rdge/materials/material.js | 4 | ||||
-rwxr-xr-x | js/lib/rdge/materials/radial-gradient-material.js | 64 |
3 files changed, 86 insertions, 28 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 586948bb..2df76d61 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | ||
9 | 10 | ||
10 | var LinearGradientMaterial = function LinearGradientMaterial() { | 11 | var LinearGradientMaterial = function LinearGradientMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
@@ -25,6 +26,8 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
25 | // this._colorCount = 4; | 26 | // this._colorCount = 4; |
26 | this._angle = 0.0; // the shader takes [cos(a), sin(a)] | 27 | this._angle = 0.0; // the shader takes [cos(a), sin(a)] |
27 | 28 | ||
29 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; | ||
30 | |||
28 | /////////////////////////////////////////////////////////////////////// | 31 | /////////////////////////////////////////////////////////////////////// |
29 | // Property Accessors | 32 | // Property Accessors |
30 | /////////////////////////////////////////////////////////////////////// | 33 | /////////////////////////////////////////////////////////////////////// |
@@ -136,12 +139,6 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
136 | } | 139 | } |
137 | }; | 140 | }; |
138 | 141 | ||
139 | // this.getColorCount = function() { return this._colorCount; }; | ||
140 | // this.setColorCount = function(c) { this._colorCount = c; | ||
141 | // if (this._shader && this._shader['default']) | ||
142 | // this._shader['default'].u_colorCount.set([c]); | ||
143 | // }; | ||
144 | |||
145 | this.getAngle = function () { | 142 | this.getAngle = function () { |
146 | return this._angle; | 143 | return this._angle; |
147 | }; | 144 | }; |
@@ -204,23 +201,21 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
204 | // Methods | 201 | // Methods |
205 | /////////////////////////////////////////////////////////////////////// | 202 | /////////////////////////////////////////////////////////////////////// |
206 | // duplcate method requirde | 203 | // duplcate method requirde |
207 | this.dup = function () | 204 | this.dup = function () { |
208 | { | 205 | // allocate a new material |
209 | // get the current values; | 206 | var newMat = new LinearGradientMaterial(); |
210 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
211 | this.getAllProperties(propNames, propValues, propTypes, propLabels); | ||
212 | |||
213 | // allocate a new material | ||
214 | var newMat = new LinearGradientMaterial(); | ||
215 | 207 | ||
216 | // copy over the current values; | 208 | // copy over the current values; |
217 | var n = propNames.length; | 209 | var propNames = [], propValues = [], propTypes = [], propLabels = []; |
218 | for (var i = 0; i < n; i++) | 210 | this.getAllProperties( propNames, propValues, propTypes, propLabels); |
219 | newMat.setProperty(propNames[i], propValues[i]); | 211 | var n = propNames.length; |
220 | 212 | for (var i=0; i<n; i++) { | |
221 | return newMat; | 213 | newMat.setProperty( propNames[i], propValues[i] ); |
222 | } | 214 | } |
215 | newMat._textureTransform = this._textureTransform.slice(); | ||
223 | 216 | ||
217 | return newMat; | ||
218 | }; | ||
224 | 219 | ||
225 | this.init = function (world) { | 220 | this.init = function (world) { |
226 | this.setWorld(world); | 221 | this.setWorld(world); |
@@ -265,7 +260,9 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
265 | this._shader['default'].u_colorStop4.set([s]); | 260 | this._shader['default'].u_colorStop4.set([s]); |
266 | 261 | ||
267 | this.setAngle(this.getAngle()); | 262 | this.setAngle(this.getAngle()); |
268 | } | 263 | |
264 | this._shader['default'].u_texTransform.set( this._textureTransform ); | ||
265 | } | ||
269 | }; | 266 | }; |
270 | 267 | ||
271 | this.exportJSON = function () { | 268 | this.exportJSON = function () { |
@@ -281,7 +278,8 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
281 | 'colorStop2': this.getColorStop2(), | 278 | 'colorStop2': this.getColorStop2(), |
282 | 'colorStop3': this.getColorStop3(), | 279 | 'colorStop3': this.getColorStop3(), |
283 | 'colorStop4': this.getColorStop4(), | 280 | 'colorStop4': this.getColorStop4(), |
284 | 'angle': this.getAngle() | 281 | 'angle': this.getAngle(), |
282 | 'textureTransform': this._textureTransform | ||
285 | }; | 283 | }; |
286 | 284 | ||
287 | return jObj; | 285 | return jObj; |
@@ -301,6 +299,7 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
301 | colorStop3 = jObj.colorStop3, | 299 | colorStop3 = jObj.colorStop3, |
302 | colorStop4 = jObj.colorStop4, | 300 | colorStop4 = jObj.colorStop4, |
303 | angle = jObj.angle; | 301 | angle = jObj.angle; |
302 | this._textureTransform = jObj.textureTransform; | ||
304 | 303 | ||
305 | this.setProperty("color1", color1); | 304 | this.setProperty("color1", color1); |
306 | this.setProperty("color2", color2); | 305 | this.setProperty("color2", color2); |
@@ -387,7 +386,8 @@ var linearGradientMaterialDef = | |||
387 | 'u_colorStop2': { 'type' : 'float' }, | 386 | 'u_colorStop2': { 'type' : 'float' }, |
388 | 'u_colorStop3': { 'type' : 'float' }, | 387 | 'u_colorStop3': { 'type' : 'float' }, |
389 | 'u_colorStop4': { 'type' : 'float' }, | 388 | 'u_colorStop4': { 'type' : 'float' }, |
390 | 'u_cos_sin_angle' : { 'type' : 'vec2' } | 389 | 'u_cos_sin_angle': { 'type' : 'vec2' }, |
390 | 'u_texTransform': { 'type' : 'mat3' } | ||
391 | //'u_colorCount': {'type' : 'int' } | 391 | //'u_colorCount': {'type' : 'int' } |
392 | 392 | ||
393 | }, | 393 | }, |
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 77220bf7..9f0ae6f1 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js | |||
@@ -233,6 +233,10 @@ var Material = function GLMaterial( world ) { | |||
233 | // animated materials should implement the update method | 233 | // animated materials should implement the update method |
234 | }; | 234 | }; |
235 | 235 | ||
236 | this.fitToPrimitive = function( prim ) { | ||
237 | // some materials need to preserve an aspect ratio - or someting else. | ||
238 | }; | ||
239 | |||
236 | this.registerTexture = function( texture ) { | 240 | this.registerTexture = function( texture ) { |
237 | // the world needs to know about the texture map | 241 | // the world needs to know about the texture map |
238 | var world = this.getWorld(); | 242 | var world = this.getWorld(); |
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index 083b7371..67a85041 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js | |||
@@ -6,6 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | ||
9 | 10 | ||
10 | var RadialGradientMaterial = function RadialGradientMaterial() { | 11 | var RadialGradientMaterial = function RadialGradientMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
@@ -24,6 +25,8 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
24 | this._colorStop4 = 1.0; | 25 | this._colorStop4 = 1.0; |
25 | // this._colorCount = 4; | 26 | // this._colorCount = 4; |
26 | 27 | ||
28 | this._textureTransform = [1,0,0, 0,1,0, 0,0,1]; | ||
29 | |||
27 | /////////////////////////////////////////////////////////////////////// | 30 | /////////////////////////////////////////////////////////////////////// |
28 | // Property Accessors | 31 | // Property Accessors |
29 | /////////////////////////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////////////////////////// |
@@ -191,9 +194,21 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
191 | // Methods | 194 | // Methods |
192 | /////////////////////////////////////////////////////////////////////// | 195 | /////////////////////////////////////////////////////////////////////// |
193 | // duplcate method requirde | 196 | // duplcate method requirde |
194 | this.dup = function () { | 197 | this.dup = function () { |
195 | return new RadialGradientMaterial(); | 198 | // allocate a new material |
196 | }; | 199 | var newMat = new RadialGradientMaterial(); |
200 | |||
201 | // copy over the current values; | ||
202 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
203 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
204 | var n = propNames.length; | ||
205 | for (var i=0; i<n; i++) { | ||
206 | newMat.setProperty( propNames[i], propValues[i] ); | ||
207 | } | ||
208 | newMat._textureTransform = this._textureTransform.slice(); | ||
209 | |||
210 | return newMat; | ||
211 | }; | ||
197 | 212 | ||
198 | this.init = function (world) { | 213 | this.init = function (world) { |
199 | this.setWorld(world); | 214 | this.setWorld(world); |
@@ -234,9 +249,45 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
234 | this._shader['default'].u_colorStop3.set([s]); | 249 | this._shader['default'].u_colorStop3.set([s]); |
235 | s = this.getColorStop4(); | 250 | s = this.getColorStop4(); |
236 | this._shader['default'].u_colorStop4.set([s]); | 251 | this._shader['default'].u_colorStop4.set([s]); |
252 | |||
253 | this._shader['default'].u_texTransform.set( this._textureTransform ); | ||
237 | } | 254 | } |
238 | }; | 255 | }; |
239 | 256 | ||
257 | this.fitToPrimitive = function( prim ) | ||
258 | { | ||
259 | var bounds = ShapePrimitive.getBounds( prim ); | ||
260 | if (bounds) | ||
261 | { | ||
262 | var dx = Math.abs( bounds[3] - bounds[0] ), | ||
263 | dy = Math.abs( bounds[4] |