diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/lib/drawing/world.js | 2 | ||||
-rwxr-xr-x | js/lib/rdge/materials/bump-metal-material.js | 35 | ||||
-rwxr-xr-x | js/lib/rdge/materials/material.js | 23 | ||||
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 42 | ||||
-rw-r--r-- | js/lib/rdge/texture.js | 206 |
5 files changed, 300 insertions, 8 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 781695b6..ebeeeb20 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js | |||
@@ -30,6 +30,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { | |||
30 | 30 | ||
31 | this._canvas = canvas; | 31 | this._canvas = canvas; |
32 | if (this._useWebGL) { | 32 | if (this._useWebGL) { |
33 | preserveDrawingBuffer = true; | ||
33 | if(preserveDrawingBuffer) { | 34 | if(preserveDrawingBuffer) { |
34 | this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); | 35 | this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); |
35 | } else { | 36 | } else { |
@@ -326,6 +327,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { | |||
326 | var rtnVal = false; | 327 | var rtnVal = false; |
327 | if (root) { | 328 | if (root) { |
328 | rtnVal = this.hHasAnimatedMaterials( root ); | 329 | rtnVal = this.hHasAnimatedMaterials( root ); |
330 | this._hasAnimatedMaterials = rtnVal; | ||
329 | } | 331 | } |
330 | 332 | ||
331 | 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 2ef83227..a3ef9d37 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. |
@@ -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,30 @@ 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( this._diffuseWorld.getCanvas() ); | ||
150 | } | ||
151 | } | ||
152 | |||
128 | this.updateTexture = function( index ) | 153 | this.updateTexture = function( index ) |
129 | { | 154 | { |
130 | var material = this._materialNode; | 155 | var material = this._materialNode; |
@@ -136,7 +161,11 @@ var BumpMetalMaterial = function BumpMetalMaterial() { | |||
136 | { | 161 | { |
137 | var texMapName = this._propValues[this._propNames[index]]; | 162 | var texMapName = this._propValues[this._propNames[index]]; |
138 | var wrap = 'REPEAT', mips = true; | 163 | var wrap = 'REPEAT', mips = true; |
139 | var tex = this.loadTexture( texMapName, wrap, mips ); | 164 | var tex; |
165 | if ((index === 1) && this._diffuseTextureObj) | ||
166 | tex = this._diffuseTextureObj.getTexture(); | ||
167 | else | ||
168 | tex = this.loadTexture( texMapName, wrap, mips ); | ||
140 | 169 | ||
141 | if (tex) | 170 | if (tex) |
142 | { | 171 | { |
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 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Texture = require("js/lib/rdge/texture").Texture; | ||
8 | var Material = require("js/lib/rdge/materials/material").Material; | 9 | var 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 | /////////////////////////////////////////////////////////////////////// |
13 | var PulseMaterial = function PulseMaterial() { | 14 | var 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]]; | ||