diff options
author | Armen Kesablyan | 2012-06-20 15:00:19 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-06-20 15:00:19 -0700 |
commit | 120e31dcf1e11eed11ee430d77c438e7b073e9f8 (patch) | |
tree | 8c07b1203de42f6efdeebfc8663072fffb4a567b /js/lib/rdge | |
parent | c59eb371559a3061ce53223e249ca97daace5968 (diff) | |
parent | 52833c3d8a485944c42acc6ac0ae5139b3427da8 (diff) | |
download | ninja-120e31dcf1e11eed11ee430d77c438e7b073e9f8.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
Diffstat (limited to 'js/lib/rdge')
26 files changed, 1851 insertions, 1947 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 27d5793c..99a80da2 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js | |||
@@ -6,6 +6,8 @@ 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 Texture = require("js/lib/rdge/texture").Texture; | ||
10 | |||
9 | /////////////////////////////////////////////////////////////////////// | 11 | /////////////////////////////////////////////////////////////////////// |
10 | // Class GLMaterial | 12 | // Class GLMaterial |
11 | // RDGE representation of a material. | 13 | // RDGE representation of a material. |
@@ -14,184 +16,61 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
14 | /////////////////////////////////////////////////////////////////////// | 16 | /////////////////////////////////////////////////////////////////////// |
15 | // Instance variables | 17 | // Instance variables |
16 | /////////////////////////////////////////////////////////////////////// | 18 | /////////////////////////////////////////////////////////////////////// |
17 | this._name = "BumpMetalMaterial"; | 19 | this._name = "Bump Metal"; |
18 | this._shaderName = "bumpMetal"; | 20 | this._shaderName = "bumpMetal"; |
19 | 21 | ||
20 | this._lightDiff = [0.3, 0.3, 0.3, 1.0]; | ||
21 | this._diffuseTexture = "assets/images/metal.png"; | ||
22 | this._specularTexture = "assets/images/silver.png"; | ||
23 | this._normalTexture = "assets/images/normalMap.png"; | ||
24 | |||
25 | /////////////////////////////////////////////////////////////////////// | ||
26 | // Property Accessors | ||
27 | /////////////////////////////////////////////////////////////////////// | ||
28 | this.getName = function() { | ||
29 | return this._name; | ||
30 | }; | ||
31 | 22 | ||
32 | this.getShaderName = function() { | 23 | this._defaultDiffuseTexture = "assets/images/metal.png"; |
33 | return this._shaderName; | 24 | this._defaultSpecularTexture = "assets/images/silver.png"; |
34 | }; | 25 | this._defaultNormalTexture = "assets/images/normalMap.png"; |
35 | |||
36 | this.getLightDiff = function() { | ||
37 | return this._lightDiff; | ||
38 | }; | ||
39 | |||
40 | this.setLightDiff = function(ld) { | ||
41 | this._lightDiff = ld; | ||
42 | // Bad property name. Commenting for now | ||
43 | |||
44 | if (this._shader && this._shader['default']){ | ||
45 | this._shader['default'].u_light0Diff.set( ld ); | ||
46 | } | ||
47 | 26 | ||
48 | }; | 27 | // array textures indexed by shader uniform name |
28 | this._glTextures = []; | ||
49 | 29 | ||
50 | this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null }; | 30 | this._speed = 1.0; |
51 | this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.updateTexture(1); }; | ||
52 | |||
53 | this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null }; | ||
54 | this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.updateTexture(2); }; | ||
55 | |||
56 | this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null }; | ||
57 | this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.updateTexture(3); }; | ||
58 | 31 | ||
32 | /////////////////////////////////////////////////////////////////////// | ||
33 | // Property Accessors | ||
34 | /////////////////////////////////////////////////////////////////////// | ||
59 | this.isAnimated = function() { return true; }; | 35 | this.isAnimated = function() { return true; }; |
36 | this.getShaderDef = function() { return bumpMetalMaterialDef; }; | ||
60 | 37 | ||
61 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
62 | // Material Property Accessors | 39 | // Material Property Accessors |
63 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
64 | this._propNames = ["lightDiff", "diffuseTexture", "normalMap", "specularTexture"]; | 41 | this._propNames = ["u_light0Diff", "u_colMap", "u_normalMap", "u_glowMap" ]; |
65 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; | 42 | this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map" ]; |
66 | this._propTypes = ["color", "file", "file", "file"]; | 43 | this._propTypes = ["color", "file", "file", "file" ]; |
67 | this._propValues = []; | 44 | this._propValues = []; |
68 | 45 | ||
69 | this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); | 46 | this._propValues[ this._propNames[0] ] = [0.3, 0.3, 0.3, 1.0]; |
70 | this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); | 47 | this._propValues[ this._propNames[1] ] = this._defaultDiffuseTexture.slice(0); |
71 | this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); | 48 | this._propValues[ this._propNames[2] ] = this._defaultNormalTexture.slice(0); |
72 | this._propValues[ this._propNames[3] ] = this._specularTexture.slice(0); | 49 | this._propValues[ this._propNames[3] ] = this._defaultSpecularTexture.slice(0); |
73 | |||
74 | // TODO - shader techniques are not all named the same, i.e., FlatMaterial uses "colorMe" and BrickMaterial uses "default" | ||
75 | this.setProperty = function( prop, value ) | ||
76 | { | ||
77 | // every material should do something with the "color" property | ||
78 | if (prop === "color") return; | ||
79 | |||
80 | // make sure we have legitimate imput | ||
81 | var ok = this.validateProperty( prop, value ); | ||
82 | if (!ok) | ||
83 | { | ||
84 | console.log( "invalid property in Bump Metal Materia;" + prop + " : " + value ); | ||
85 | return; | ||
86 | } | ||
87 | 50 | ||
88 | switch (prop) | ||
89 | { | ||
90 | case "lightDiff": this.setLightDiff( value ); break; | ||
91 | case "diffuseTexture": this.setDiffuseTexture( value ); break; | ||
92 | case "specularTexture": this.setSpecularTexture( value ); break; | ||
93 | case "normalMap": this.setNormalTexture( value ); break; | ||
94 | |||
95 | default: | ||
96 | console.log( "invalid property to Bump Metal Material: " + prop + ", value: " + value ); | ||
97 | break; | ||
98 | } | ||
99 | }; | ||
100 | 51 | ||
101 | /////////////////////////////////////////////////////////////////////// | 52 | /////////////////////////////////////////////////////////////////////// |
102 | // Methods | 53 | // Methods |
103 | /////////////////////////////////////////////////////////////////////// | 54 | /////////////////////////////////////////////////////////////////////// |
104 | // duplcate method requirde | ||
105 | this.dup = function() { return new BumpMetalMaterial(); }; | ||
106 | 55 | ||
107 | this.init = function( world ) | 56 | this.init = function( world ) |
108 | { | 57 | { |
109 | // save the world | 58 | // save the world |
110 | if (world) { | 59 | if (world) { |
111 | this.setWorld( world ); | 60 | this.setWorld( world ); |
112 | } | 61 | } |
113 | 62 | ||
114 | // set up the shader | 63 | // set up the shader |
115 | this._shader = new RDGE.jshader(); | 64 | this._shader = new RDGE.jshader(); |
116 | this._shader.def = bumpMetalMaterialDef; | 65 | this._shader.def = bumpMetalMaterialDef; |
117 | this._shader.init(); | 66 | this._shader.init(); |
118 | this._shader['default'].u_light0Diff.set( this.getLightDiff() ); | ||
119 | 67 | ||
120 | // set up the material node | 68 | // set up the material node |
121 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); | 69 | this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); |
122 | this._materialNode.setShader(this._shader); | 70 | this._materialNode.setShader(this._shader); |
123 | 71 | ||
124 | // set some image maps | 72 | this.setShaderValues(); |
125 | this.updateTexture(1); | 73 | this.update(0); |
126 | this.updateTexture(2); | ||
127 | this.updateTexture(3); | ||
128 | }; | ||
129 | |||
130 | this.updateTexture = function( index ) | ||
131 | { | ||
132 | var material = this._materialNode; | ||
133 | if (material) | ||
134 | { | ||
135 |