aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/bump-metal-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/bump-metal-material.js')
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js58
1 files changed, 55 insertions, 3 deletions
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js
index 2ef83227..9c9a189a 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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material; 8var Material = require("js/lib/rdge/materials/material").Material;
9var 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.
@@ -18,8 +20,13 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
18 this._shaderName = "bumpMetal"; 20 this._shaderName = "bumpMetal";
19 21
20 this._lightDiff = [0.3, 0.3, 0.3, 1.0]; 22 this._lightDiff = [0.3, 0.3, 0.3, 1.0];
21 this._diffuseTexture = "assets/images/metal.png"; 23
22 this._specularTexture = "assets/images/silver.png"; 24 //this._diffuseTexture = "assets/images/metal.png";
25 this._diffuseTexture = "texture";
26 this._diffuseWorld = null; // the world that the texture is derived from (if there is one).
27 this._diffuseTextureObj = null;
28
29 this._specularTexture = "assets/images/silver.png";
23 this._normalTexture = "assets/images/normalMap.png"; 30 this._normalTexture = "assets/images/normalMap.png";
24 31
25 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
@@ -119,12 +126,53 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
119 this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); 126 this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() );
120 this._materialNode.setShader(this._shader); 127 this._materialNode.setShader(this._shader);
121 128
129 // DEBUG CODE
130 this.initWorldTextures();
131
122 // set some image maps 132 // set some image maps
123 this.updateTexture(1); 133 this.updateTexture(1);
124 this.updateTexture(2); 134 this.updateTexture(2);
125 this.updateTexture(3); 135 this.updateTexture(3);
126 }; 136 };
127 137
138 this.initWorldTextures = function()
139 {
140 // find the world with the given id
141 var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
142 var root = viewUtils.application.ninja.currentDocument.documentRoot;
143 this._diffuseWorld = this.findWorld( this._diffuseTexture, root );
144 if (this._diffuseWorld)
145 {
146 var world = this.getWorld();
147 var tex = new Texture( world );
148 this._diffuseTextureObj = tex;
149 tex.loadFromCanvas( world.getCanvas() );
150 }
151 }
152
153 this.findWorld = function( id, elt )
154 {
155 if (elt.id && elt.id === id)
156 {
157 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
158 {
159 var world = elt.elementModel.shapeModel.GLWorld;
160 return world;
161 }
162 }
163
164 if (elt.children)
165 {
166 var nKids = elt.children.length;
167 for (var i=0; i<nKids; i++)
168 {
169 var child = elt.children[i];
170 var world = this.findWorld( id, child );
171 if (world) return world;
172 }
173 }
174 }
175
128 this.updateTexture = function( index ) 176 this.updateTexture = function( index )
129 { 177 {
130 var material = this._materialNode; 178 var material = this._materialNode;
@@ -136,7 +184,11 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
136 { 184 {
137 var texMapName = this._propValues[this._propNames[index]]; 185 var texMapName = this._propValues[this._propNames[index]];
138 var wrap = 'REPEAT', mips = true; 186 var wrap = 'REPEAT', mips = true;
139 var tex = this.loadTexture( texMapName, wrap, mips ); 187 var tex;
188 if ((index === 1) && this._diffuseTextureObj)
189 tex = this._diffuseTextureObj.getTexture();
190 else
191 tex = this.loadTexture( texMapName, wrap, mips );
140 192
141 if (tex) 193 if (tex)
142 { 194 {