diff options
Diffstat (limited to 'js/lib/rdge/materials/material.js')
-rwxr-xr-x | js/lib/rdge/materials/material.js | 101 |
1 files changed, 70 insertions, 31 deletions
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 34524097..a7183187 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js | |||
@@ -1,7 +1,31 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | 3 | All Rights Reserved. |
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | BSD License. |
5 | |||
6 | Redistribution and use in source and binary forms, with or without | ||
7 | modification, are permitted provided that the following conditions are met: | ||
8 | |||
9 | - Redistributions of source code must retain the above copyright notice, | ||
10 | this list of conditions and the following disclaimer. | ||
11 | - Redistributions in binary form must reproduce the above copyright | ||
12 | notice, this list of conditions and the following disclaimer in the | ||
13 | documentation and/or other materials provided with the distribution. | ||
14 | - Neither the name of Motorola Mobility nor the names of its contributors | ||
15 | may be used to endorse or promote products derived from this software | ||
16 | without specific prior written permission. | ||
17 | |||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
28 | POSSIBILITY OF SUCH DAMAGE. | ||
5 | </copyright> */ | 29 | </copyright> */ |
6 | 30 | ||
7 | var Texture = require("js/lib/rdge/texture").Texture; | 31 | var Texture = require("js/lib/rdge/texture").Texture; |
@@ -173,6 +197,8 @@ var Material = function GLMaterial( world ) { | |||
173 | }; | 197 | }; |
174 | 198 | ||
175 | this.validateProperty = function( prop, value ) { | 199 | this.validateProperty = function( prop, value ) { |
200 | if(prop === "gradient") return true; | ||
201 | |||
176 | var rtnVal = false; | 202 | var rtnVal = false; |
177 | try | 203 | try |
178 | { | 204 | { |
@@ -236,33 +262,37 @@ var Material = function GLMaterial( world ) { | |||
236 | var material = this._materialNode; | 262 | var material = this._materialNode; |
237 | if (material) technique = material.shaderProgram[this.getTechniqueName()]; | 263 | if (material) technique = material.shaderProgram[this.getTechniqueName()]; |
238 | 264 | ||
239 | switch (this.getPropertyType(prop)) | 265 | if(prop === "gradient") { |
240 | { | 266 | this.setGradientData(value); |
241 | case "angle": | 267 | } else { |
242 | case "float": | 268 | switch (this.getPropertyType(prop)) |
243 | this._propValues[prop] = value; | 269 | { |
244 | if (technique) technique[prop].set( [value] ); | 270 | case "angle": |
245 | break; | 271 | case "float": |
246 | 272 | this._propValues[prop] = value; | |
247 | case "file": | 273 | if (technique) technique[prop].set( [value] ); |
248 | this._propValues[prop] = value.slice(); | 274 | break; |
249 | if (technique) | 275 | |
250 | { | 276 | case "file": |
251 | var glTex = new Texture( this.getWorld(), value ); | 277 | this._propValues[prop] = value.slice(); |
252 | this._glTextures[prop] = glTex; | 278 | if (technique) |
253 | glTex.render(); | 279 | { |
254 | var tex = glTex.getTexture(); | 280 | var glTex = new Texture( this.getWorld(), value ); |
255 | if (tex) technique[prop].set( tex ); | 281 | this._glTextures[prop] = glTex; |
256 | } | 282 | glTex.render(); |
257 | break; | 283 | var tex = glTex.getTexture(); |
258 | 284 | if (tex) technique[prop].set( tex ); | |
259 | case "color": | 285 | } |
260 | case "vector2d": | 286 | break; |
261 | case "vector3d": | 287 | |
262 | this._propValues[prop] = value.slice(); | 288 | case "color": |
263 | if (technique) technique[prop].set( value ); | 289 | case "vector2d": |
264 | break; | 290 | case "vector3d": |
265 | } | 291 | this._propValues[prop] = value.slice(); |
292 | if (technique) technique[prop].set( value ); | ||
293 | break; | ||
294 | } | ||
295 | } | ||
266 | }; | 296 | }; |
267 | 297 | ||
268 | this.setShaderValues = function() | 298 | this.setShaderValues = function() |
@@ -402,8 +432,17 @@ var Material = function GLMaterial( world ) { | |||
402 | return tex; | 432 | return tex; |
403 | }; | 433 | }; |
404 | 434 | ||
435 | this.gradientType = null; | ||
436 | |||
437 | this.getGradientData = function() { | ||
438 | return null; | ||
439 | }; | ||
440 | |||
441 | this.setGradientData = function() { | ||
442 | // override in linear-gradient-material and radial-gradient-material | ||
443 | }; | ||
405 | }; | 444 | }; |
406 | 445 | ||
407 | if (typeof exports === "object") { | 446 | if (typeof exports === "object") { |
408 | exports.Material = Material; | 447 | exports.Material = Material; |
409 | } \ No newline at end of file | 448 | } |