aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/material.js')
-rwxr-xr-xjs/lib/rdge/materials/material.js115
1 files changed, 79 insertions, 36 deletions
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index 65448c0c..a7183187 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -1,7 +1,31 @@
1/* <copyright> 1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2Copyright (c) 2012, Motorola Mobility, Inc
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3All Rights Reserved.
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4BSD License.
5
6Redistribution and use in source and binary forms, with or without
7modification, 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
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE.
5</copyright> */ 29</copyright> */
6 30
7var Texture = require("js/lib/rdge/texture").Texture; 31var Texture = require("js/lib/rdge/texture").Texture;
@@ -32,16 +56,12 @@ var Material = function GLMaterial( world ) {
32 // vertex deformation variables 56 // vertex deformation variables
33 this._hasVertexDeformation = false; 57 this._hasVertexDeformation = false;
34 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) 58 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
35 this._vertexDeformationTolerance = 0.1; 59 this._vertexDeformationTolerance = 0.02;
36 60
37 // RDGE variables 61 // RDGE variables
38 this._shader = null; 62 this._shader = null;
39 this._materialNode = null; 63 this._materialNode = null;
40 64
41 // vertex deformation variables
42 this._hasVertexDeformation = false;
43 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
44 this._vertexDeformationTolerance = 0.02;
45 65
46 /////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////
47 // Property Accessors 67 // Property Accessors
@@ -177,6 +197,8 @@ var Material = function GLMaterial( world ) {
177 }; 197 };
178 198
179 this.validateProperty = function( prop, value ) { 199 this.validateProperty = function( prop, value ) {
200 if(prop === "gradient") return true;
201
180 var rtnVal = false; 202 var rtnVal = false;
181 try 203 try
182 { 204 {
@@ -240,33 +262,37 @@ var Material = function GLMaterial( world ) {
240 var material = this._materialNode; 262 var material = this._materialNode;
241 if (material) technique = material.shaderProgram[this.getTechniqueName()]; 263 if (material) technique = material.shaderProgram[this.getTechniqueName()];
242 264
243 switch (this.getPropertyType(prop)) 265 if(prop === "gradient") {
244 { 266 this.setGradientData(value);
245 case "angle": 267 } else {
246 case "float": 268 switch (this.getPropertyType(prop))
247 this._propValues[prop] = value; 269 {
248 if (technique) technique[prop].set( [value] ); 270 case "angle":
249 break; 271 case "float":
250 272 this._propValues[prop] = value;
251 case "file": 273 if (technique) technique[prop].set( [value] );
252 this._propValues[prop] = value.slice(); 274 break;
253 if (technique) 275
254 { 276 case "file":
255 var glTex = new Texture( this.getWorld(), value ); 277 this._propValues[prop] = value.slice();
256 this._glTextures[prop] = glTex; 278 if (technique)
257 glTex.render(); 279 {
258 var tex = glTex.getTexture(); 280 var glTex = new Texture( this.getWorld(), value );
259 if (tex) technique[prop].set( tex ); 281 this._glTextures[prop] = glTex;
260 } 282 glTex.render();
261 break; 283 var tex = glTex.getTexture();
262 284 if (tex) technique[prop].set( tex );
263 case "color": 285 }
264 case "vector2d": 286 break;
265 case "vector3d": 287
266 this._propValues[prop] = value.slice(); 288 case "color":
267 if (technique) technique[prop].set( value ); 289 case "vector2d":
268 break; 290 case "vector3d":
269 } 291 this._propValues[prop] = value.slice();
292 if (technique) technique[prop].set( value );
293 break;
294 }
295 }
270 }; 296 };
271 297
272 this.setShaderValues = function() 298 this.setShaderValues = function()
@@ -366,6 +392,10 @@ var Material = function GLMaterial( world ) {
366 throw new Error( "Material.init() must be overridden by subclass" ); 392 throw new Error( "Material.init() must be overridden by subclass" );
367 }; 393 };
368 394
395 this.resetToDefault = function() {
396 // materials should override this functinon
397 };
398
369 this.update = function( time ) { 399 this.update = function( time ) {
370 // animated materials should implement the update method 400 // animated materials should implement the update method
371 }; 401 };
@@ -374,6 +404,10 @@ var Material = function GLMaterial( world ) {
374 // some materials need to preserve an aspect ratio - or someting else. 404 // some materials need to preserve an aspect ratio - or someting else.
375 }; 405 };
376 406
407 this.fitToPrimitiveArray = function( primArray ) {
408 // some materials need to preserve an aspect ratio - or someting else.
409 };
410
377 this.registerTexture = function( texture ) { 411 this.registerTexture = function( texture ) {
378 // the world needs to know about the texture map 412 // the world needs to know about the texture map
379 var world = this.getWorld(); 413 var world = this.getWorld();
@@ -398,8 +432,17 @@ var Material = function GLMaterial( world ) {
398 return tex; 432 return tex;
399 }; 433 };
400 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 };
401}; 444};
402 445
403if (typeof exports === "object") { 446if (typeof exports === "object") {
404 exports.Material = Material; 447 exports.Material = Material;
405} \ No newline at end of file 448}