From 13e2155e043990170a05f57bf7aad63d23120ecf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 13 Jun 2012 15:50:04 -0700 Subject: Fixes for runtime Taper material --- assets/canvas-runtime.js | 73 +++++++++++++++++++-------------- js/io/system/ninjalibrary.json | 2 +- js/lib/rdge/materials/taper-material.js | 6 ++- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 2035d2e0..cd673854 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -608,6 +608,7 @@ NinjaCvsRt.RuntimeGeomObj = Object.create(Object.prototype, { case "uber": mat = Object.create(NinjaCvsRt.RuntimeUberMaterial, {}); break; case "plasma": mat = Object.create(NinjaCvsRt.RuntimePlasmaMaterial, {}); break; case "water": mat = Object.create(NinjaCvsRt.RuntimeWaterMaterial, {}); break; + case "taper": mat = Object.create(NinjaCvsRt.RuntimeTaperMaterial, {}); break; case "deform": case "paris": @@ -1518,20 +1519,23 @@ NinjaCvsRt.RuntimeTaperMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { isAnimated: { value: function() { return true; }}, - + importJSON: { value: function(jObj) { - this._tex0 = jObj.tex0; - this._tex1 = jObj.tex1; - - this._speed = jObj.speed; + for (var prop in jObj) + { + if ((prop != 'material') && (prop != 'name')) + { + var value = jObj[prop]; + this[prop] = value; + } + } - this._limit1 = jObj.limit1; - this._limit2 = jObj.limit2; - this._twistAmount = jObj.angle; - } + this._dTime = jObj.dTime; + } }, + init: { value: function(world) { var material = this._materialNode; @@ -1541,15 +1545,18 @@ NinjaCvsRt.RuntimeTaperMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { - var wrap = 'REPEAT', mips = true; - var tex = renderer.getTextureByName(this._tex0, wrap, mips ); - if (tex) technique.u_tex0.set( tex ); - tex = renderer.getTextureByName(this._tex1, wrap, mips ); - if (tex) technique.u_tex1.set( tex ); +// var wrap = 'REPEAT', mips = true; +// var tex = renderer.getTextureByName(this._tex0, wrap, mips ); +// if (tex) technique.u_tex0.set( tex ); +// tex = renderer.getTextureByName(this._tex1, wrap, mips ); +// if (tex) technique.u_tex1.set( tex ); - technique.u_twistAmount.set( [this._angle] ); - technique.u_limit1.set( [this._limit1] ); + technique.u_limit1.set( [this.u_limit1] ); technique.u_limit2.set( [this._limit2] ); + technique.u_limit3.set( [this._limit3] ); + technique.u_minVal.set( [this.u_minVal] ); + technique.u_maxVal.set( [this.u_maxVal] ); + technique.u_taperAmount.set( [this.u_taperAmount] ); } } } @@ -1560,21 +1567,25 @@ NinjaCvsRt.RuntimeTaperMaterial = Object.create(NinjaCvsRt.RuntimeMaterial, { update: { value: function(time) { - var angle = this._angle; - angle += this._dTime * this._speed; - if (angle > this._twistAmount) - { - angle = this._twistAmount; - this._dTime = -this._dTime; - } - else if (angle < 0.0) - { - angle = 0; - this._dTime = -this._dTime; - } - this._angle = angle; - this._shader.twistMe["u_twistAmount"].set([angle]); - } + var speed = this.u_speed; + this._dTime += 0.01 * speed; + + if (this._shader && this._shader.colorMe) { + var t3 = this.u_limit3 - this._dTime; + if (t3 < 0) { + this._dTime = this.u_limit1 - 1.0; + t3 = this.u_limit3 - this._dTime; + } + + var t1 = this.u_limit1 - this._dTime, + t2 = this.u_limit2 - this._dTime; + + + this._shader.colorMe["u_limit1"].set([t1]); + this._shader.colorMe["u_limit2"].set([t2]); + this._shader.colorMe["u_limit3"].set([t3]); + } + } } }); diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index fb108937..f8e61ca5 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json @@ -1,6 +1,6 @@ { "libraries": [ {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.10.1.0"}, - {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.6.0.0"} + {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.6.0.1"} ] } \ No newline at end of file diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index a44314b6..0ae039f7 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js @@ -32,6 +32,7 @@ var TaperMaterial = function TaperMaterial() this.isAnimated = function () { return true; }; this.getShaderDef = function() { return taperShaderDef; }; + this.getTechniqueName = function() { return 'colorMe' }; this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; this._hasVertexDeformation = true; @@ -50,12 +51,12 @@ var TaperMaterial = function TaperMaterial() // set up the material node this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); + this._materialNode.setShader(this._shader); this._time = 0; if (this._shader && this._shader['default']) { this._shader['default'].u_time.set([this._time]); } - this._materialNode.setShader(this._shader); // initialize the taper properties this.setShaderValues(); @@ -133,7 +134,8 @@ taperShaderDef = { 'u_minVal': { 'type': 'float' }, 'u_maxVal': { 'type': 'float' }, 'u_center': { 'type': 'float' }, - 'u_taperAmount': { 'type': 'float' } + 'u_taperAmount': { 'type': 'float' }, + 'u_speed': { 'type': 'float' } } } ] -- cgit v1.2.3