From 22cbc9644b79df60b3f6336f9563debd47fb3ea1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 28 Jun 2012 11:44:15 -0700 Subject: Added capability to split a mesh into multiiple parts to avoid buffer overflow situations. --- js/lib/rdge/materials/twist-vert-material.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'js/lib/rdge/materials/twist-vert-material.js') diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 7c2dae5e..870e068d 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -81,6 +81,20 @@ var TwistVertMaterial = function TwistVertMaterial() this.setShaderValues(); }; + this.resetToDefault = function() + { + this._propValues[this._propNames[0]] = 0.0; + this._propValues[this._propNames[1]] = 1.0; + this._propValues[this._propNames[2]] = 2.0 * Math.PI; + this._propValues[this._propNames[3]] = this._speed; + this._propValues[this._propNames[4]] = this._tex0.slice(); + this._propValues[this._propNames[5]] = this._tex1.slice(); + + var nProps = this._propNames.length; + for (var i=0; i this._propValues["u_twistAmount"]) - { - angle = this._propValues["u_twistAmount"]; - this._deltaTime = -this._deltaTime; - } - else if (angle < 0.0) - { - angle = 0; - this._deltaTime = -this._deltaTime; - } - this._angle = angle; - this._shader.twistMe["u_twistAmount"].set([angle]); - - var tex; - var glTex = this._glTextures["u_tex0"]; - if (glTex) - { - //if (glTex.isAnimated()) - glTex.render(); - tex = glTex.getTexture(); - if (tex) - technique.u_tex0.set( tex ); - } - - glTex = this._glTextures["u_tex1"]; - if (glTex) - { - //if (glTex.isAnimated()) - glTex.render(); - tex = glTex.getTexture(); - if (tex) - technique.u_tex1.set( tex ); - } - - } - } + }; + + this.update = function (time) + { + if (this._shader && this._shader.twistMe) + { + var technique = this._shader.twistMe; + + var angle = this._angle; + angle += this._deltaTime * this._propValues["speed"]; + if (angle > this._propValues["u_twistAmount"]) + { + angle = this._propValues["u_twistAmount"]; + this._deltaTime = -this._deltaTime; + } + else if (angle < 0.0) + { + angle = 0; + this._deltaTime = -this._deltaTime; + } + this._angle = angle; + this._shader.twistMe["u_twistAmount"].set([angle]); + + var tex; + var glTex = this._glTextures["u_tex0"]; + if (glTex) + { + //if (glTex.isAnimated()) + glTex.render(); + tex = glTex.getTexture(); + if (tex) + technique.u_tex0.set( tex ); + } + + glTex = this._glTextures["u_tex1"]; + if (glTex) + { + //if (glTex.isAnimated()) + glTex.render(); + tex = glTex.getTexture(); + if (tex) + technique.u_tex1.set( tex ); + } + + } + } }; // shader spec (can also be loaded from a .JSON file, or constructed at runtime) twistVertShaderDef = { - 'shaders': { // shader files - 'defaultVShader': "assets/shaders/TwistVert.vert.glsl", - 'defaultFShader': "assets/shaders/TwistVert.frag.glsl" - }, - 'techniques': { // rendering control - 'twistMe': [ // simple color pass - { - 'vshader': 'defaultVShader', - 'fshader': 'defaultFShader', - - // attributes - 'attributes': - { - 'vert': { 'type': 'vec3' }, - 'normal': { 'type': 'vec3' }, - 'texcoord': { 'type': 'vec2' } - }, - // attributes - 'params': - { - 'u_tex0': { 'type' : 'tex2d' }, - 'u_tex1': { 'type' : 'tex2d' }, - 'u_limit1': { 'type': 'float' }, - 'u_limit2': { 'type': 'float' }, - 'u_minVal': { 'type': 'float' }, - 'u_maxVal': { 'type': 'float' }, - 'u_center': { 'type': 'float' }, - 'u_twistAmount': { 'type': 'float' }, - 'speed': { 'type': 'float' } - } - } - ] - } + 'shaders': { // shader files + 'defaultVShader': "assets/shaders/TwistVert.vert.glsl", + 'defaultFShader': "assets/shaders/TwistVert.frag.glsl" + }, + 'techniques': { // rendering control + 'twistMe': [ // simple color pass + { + 'vshader': 'defaultVShader', + 'fshader': 'defaultFShader', + + // attributes + 'attributes': + { + 'vert': { 'type': 'vec3' }, + 'normal': { 'type': 'vec3' }, + 'texcoord': { 'type': 'vec2' } + }, + // attributes + 'params': + { + 'u_tex0': { 'type' : 'tex2d' }, + 'u_tex1': { 'type' : 'tex2d' }, + 'u_limit1': { 'type': 'float' }, + 'u_limit2': { 'type': 'float' }, + 'u_minVal': { 'type': 'float' }, + 'u_maxVal': { 'type': 'float' }, + 'u_center': { 'type': 'float' }, + 'u_twistAmount': { 'type': 'float' }, + 'speed': { 'type': 'float' } + } + } + ] + } }; if (typeof exports === "object") { - exports.TwistVertMaterial = TwistVertMaterial; + exports.TwistVertMaterial = TwistVertMaterial; } -- cgit v1.2.3 From 04343eda8c2f870b0da55cfdc8003c99fe1cc4de Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:53:10 -0700 Subject: Remove trailing spaces --- js/lib/rdge/materials/twist-vert-material.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/lib/rdge/materials/twist-vert-material.js') diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 6ab2662e..1c04a90c 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -61,7 +61,7 @@ var TwistVertMaterial = function TwistVertMaterial() this.isAnimated = function () { return true; }; this.getShaderDef = function() { return twistVertShaderDef; }; this.getTechniqueName = function() { return 'twistMe' }; - + this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; this._hasVertexDeformation = true; this._vertexDeformationTolerance = 0.02; // should be a property @@ -110,7 +110,7 @@ var TwistVertMaterial = function TwistVertMaterial() if (this._shader && this._shader.twistMe) { var technique = this._shader.twistMe; - + var angle = this._angle; angle += this._deltaTime * this._propValues["speed"]; if (angle > this._propValues["u_twistAmount"]) -- cgit v1.2.3