aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/lib/drawing/world.js1
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js25
-rwxr-xr-xjs/lib/rdge/materials/material.js23
-rw-r--r--js/lib/rdge/materials/pulse-material.js42
-rw-r--r--js/lib/rdge/texture.js377
5 files changed, 211 insertions, 257 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index d314760b..e3818178 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -327,6 +327,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
327 var rtnVal = false; 327 var rtnVal = false;
328 if (root) { 328 if (root) {
329 rtnVal = this.hHasAnimatedMaterials( root ); 329 rtnVal = this.hHasAnimatedMaterials( root );
330 this._hasAnimatedMaterials = rtnVal;
330 } 331 }
331 332
332 return rtnVal; 333 return rtnVal;
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js
index 9c9a189a..a3ef9d37 100755
--- a/js/lib/rdge/materials/bump-metal-material.js
+++ b/js/lib/rdge/materials/bump-metal-material.js
@@ -146,33 +146,10 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
146 var world = this.getWorld(); 146 var world = this.getWorld();
147 var tex = new Texture( world ); 147 var tex = new Texture( world );
148 this._diffuseTextureObj = tex; 148 this._diffuseTextureObj = tex;
149 tex.loadFromCanvas( world.getCanvas() ); 149 tex.loadFromCanvas( this._diffuseWorld.getCanvas() );
150 } 150 }
151 } 151 }
152 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
176 this.updateTexture = function( index ) 153 this.updateTexture = function( index )
177 { 154 {
178 var material = this._materialNode; 155 var material = this._materialNode;
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index c1d13b15..157fa7db 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -252,6 +252,29 @@ var Material = function GLMaterial( world ) {
252 return tex; 252 return tex;
253 }; 253 };
254 254
255 this.findWorld = function( id, elt )
256 {
257 if (elt.id && elt.id === id)
258 {
259 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
260 {
261 var world = elt.elementModel.shapeModel.GLWorld;
262 return world;
263 }
264 }
265
266 if (elt.children)
267 {
268 var nKids = elt.children.length;
269 for (var i=0; i<nKids; i++)
270 {
271 var child = elt.children[i];
272 var world = this.findWorld( id, child );
273 if (world) return world;
274 }
275 }
276 }
277
255 this.export = function() { 278 this.export = function() {
256 // this function should be overridden by subclasses 279 // this function should be overridden by subclasses
257 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n"; 280 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n";
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
index 2075d1ff..5461c5fb 100644
--- a/js/lib/rdge/materials/pulse-material.js
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -5,19 +5,28 @@
5 </copyright> */ 5 </copyright> */
6 6
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Texture = require("js/lib/rdge/texture").Texture;
8var Material = require("js/lib/rdge/materials/material").Material; 9var Material = require("js/lib/rdge/materials/material").Material;
9/////////////////////////////////////////////////////////////////////// 10///////////////////////////////////////////////////////////////////////
10// Class GLMaterial 11// Class GLMaterial
11// RDGE representation of a material. 12// RDGE representation of a material.
12/////////////////////////////////////////////////////////////////////// 13///////////////////////////////////////////////////////////////////////
13var PulseMaterial = function PulseMaterial() { 14var PulseMaterial = function PulseMaterial()
15{
16 var MaterialLibrary = require("js/models/materials-model").MaterialsModel;
17
18 // initialize the inherited members
19 this.inheritedFrom = Material;
20 this.inheritedFrom();
21
14 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
15 // Instance variables 23 // Instance variables
16 /////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////
17 this._name = "PulseMaterial"; 25 this._name = "PulseMaterial";
18 this._shaderName = "pulse"; 26 this._shaderName = "pulse";
19 27
20 this._texMap = 'assets/images/cubelight.png'; 28 //this._texMap = 'assets/images/cubelight.png';
29 this._texMap = 'texture';
21 30
22 this._time = 0.0; 31 this._time = 0.0;
23 this._dTime = 0.01; 32 this._dTime = 0.01;
@@ -109,6 +118,16 @@ var PulseMaterial = function PulseMaterial() {
109 this._shader['default'].u_time.set( [this._time] ); 118 this._shader['default'].u_time.set( [this._time] );
110 } 119 }
111 120
121 // check if the texture uses a canvas as the source
122 var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
123 var root = viewUtils.application.ninja.currentDocument.documentRoot;
124 var texMapName = this._propValues[this._propNames[0]];
125 var texWorld = this.findWorld( texMapName, root );
126 if (texWorld)
127 {
128 this._glTex = new Texture( this.getWorld() );
129 this._glTex.loadFromCanvas( texWorld.getCanvas() );
130 }
112 131
113 // set the shader values in the shader 132 // set the shader values in the shader
114 this.updateTexture(); 133 this.updateTexture();
@@ -122,9 +141,18 @@ var PulseMaterial = function PulseMaterial() {
122 var technique = material.shaderProgram['default']; 141 var technique = material.shaderProgram['default'];
123 var renderer = g_Engine.getContext().renderer; 142 var renderer = g_Engine.getContext().renderer;
124 if (renderer && technique) { 143 if (renderer && technique) {
125 var texMapName = this._propValues[this._propNames[0]];
126 var wrap = 'REPEAT', mips = true; 144 var wrap = 'REPEAT', mips = true;
127 var tex = this.loadTexture( texMapName, wrap, mips ); 145 var tex;
146 if (this._glTex)
147 {
148 this._glTex.rerender();
149 tex = this._glTex.getTexture();
150 }
151 else
152 {
153 var texMapName = this._propValues[this._propNames[0]];
154 tex = this.loadTexture( texMapName, wrap, mips );
155 }
128 156
129 if (tex) { 157 if (tex) {
130 technique.u_tex0.set( tex ); 158 technique.u_tex0.set( tex );
@@ -138,6 +166,9 @@ var PulseMaterial = function PulseMaterial() {
138 var material = this._materialNode; 166 var material = this._materialNode;
139 if (material) 167 if (material)
140 { 168 {
169 if (this._glTex && this._glTex.isAnimated())
170 this.updateTexture();
171
141 var technique = material.shaderProgram['default']; 172 var technique = material.shaderProgram['default'];
142 var renderer = g_Engine.getContext().renderer; 173 var renderer = g_Engine.getContext().renderer;
143 if (renderer && technique) { 174 if (renderer && technique) {
@@ -279,7 +310,8 @@ var pulseMaterialDef =
279 } 310 }
280}; 311};
281 312
282PulseMaterial.prototype = new Material(); 313// doing the inheritance here introtudes bugs. Local instance variables are overwritten in the base class
314//PulseMaterial.prototype = new Material();
283 315
284if (typeof exports === "object") { 316if (typeof exports === "object") {
285 exports.PulseMaterial = PulseMaterial; 317 exports.PulseMaterial = PulseMaterial;
diff --git a/js/lib/rdge/texture.js b/js/lib/rdge/texture.js
index c72864b8..b349ee62 100644
--- a/js/lib/rdge/texture.js
+++ b/js/lib/rdge/texture.js
@@ -15,267 +15,188 @@ function Texture( dstWorld )
15 /////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////
16 // Instance variables 16 // Instance variables
17 /////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////
18 this._texture; 18 this._texture;
19 19
20 // texture attributes 20 // texture attributes
21 this._texMapName; 21 this._texMapName;
22 this._wrap; 22 this._wrap;
23 this._mips; 23 this._mips;
24 24
25 this._srcCanvas; // the canvas generating the texture map. 25 this._srcCanvas; // the canvas generating the texture map.
26 this._dstWorld; // the world that will use the texture map 26 this._dstWorld; // the world that will use the texture map
27 this._dstWorld = dstWorld; 27 this._dstWorld = dstWorld;
28 28
29 /////////////////////////////////////////////////////////////////////// 29 ///////////////////////////////////////////////////////////////////////
30 // Property Accessors 30 // Property Accessors