diff options
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 42 |
1 files changed, 37 insertions, 5 deletions
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]]; | ||
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 | ||
282 | PulseMaterial.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 | ||
284 | if (typeof exports === "object") { | 316 | if (typeof exports === "object") { |
285 | exports.PulseMaterial = PulseMaterial; | 317 | exports.PulseMaterial = PulseMaterial; |