From 0f31002ca696c1ef303d2926a504afd27305e94f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 05:52:54 -0700 Subject: Added Flag material --- js/lib/rdge/materials/twist-vert-material.js | 1 + 1 file changed, 1 insertion(+) (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 2d2cdcc5..802690a2 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -36,6 +36,7 @@ function TwistVertMaterial() this.getShaderName = function() { return this._shaderName; } this.isAnimated = function() { return true; } + this.hasVertexDeformation = function() { return this._hasVertexDeformation; } this._hasVertexDeformation = true; this._vertexDeformationTolerance = 0.02; // should be a property -- cgit v1.2.3 From b6a8f72f670a8edee35554a4ca3a0618c526d651 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 5 Apr 2012 05:30:55 -0700 Subject: Re-added taper and twist-vert materials. --- js/lib/rdge/materials/twist-vert-material.js | 53 +++++----------------------- 1 file changed, 9 insertions(+), 44 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 802690a2..f093fbca 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -4,15 +4,17 @@ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; +var Material = require("js/lib/rdge/materials/material").Material; +var Texture = require("js/lib/rdge/texture").Texture; + /////////////////////////////////////////////////////////////////////// // Class GLMaterial // RDGE representation of a material. /////////////////////////////////////////////////////////////////////// -function TwistVertMaterial() +var TwistVertMaterial = function TwistVertMaterial() { // initialize the inherited members - this.inheritedFrom = GLMaterial; + this.inheritedFrom = Material; this.inheritedFrom(); /////////////////////////////////////////////////////////////////////// @@ -131,47 +133,6 @@ function TwistVertMaterial() } } - this.export = function() - { - // this function should be overridden by subclasses - var exportStr = "material: " + this.getShaderName() + "\n"; - exportStr += "name: " + this.getName() + "\n"; - - if (this._shader) - exportStr += "color: " + String(this._shader.twistMe.color) + "\n"; - else - exportStr += "color: " + this.getColor() + "\n"; - exportStr += "endMaterial\n"; - - return exportStr; - } - - this.import = function( importStr ) - { - var pu = new MaterialParser( importStr ); - var material = pu.nextValue( "material: " ); - if (material != this.getShaderName()) throw new Error( "ill-formed material" ); - this.setName( pu.nextValue( "name: ") ); - - var rtnStr; - try - { - var color = eval( "[" + pu.nextValue( "color: " ) + "]" ); - - this.setProperty( "color", color); - - var endKey = "endMaterial\n"; - var index = importStr.indexOf( endKey ); - index += endKey.length; - rtnStr = importStr.substr( index ); - } - catch (e) - { - throw new Error( "could not import material: " + importStr ); - } - - return rtnStr; - } this.update = function( time ) { @@ -277,3 +238,7 @@ twistVertShaderDef = } }; +if (typeof exports === "object") { + exports.TwistVertMaterial = TwistVertMaterial; +} + -- cgit v1.2.3 From 80715f4f0c45d29926184fa02e0a01b4e7642a79 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 30 Apr 2012 09:52:59 -0700 Subject: twist vertex material changes --- js/lib/rdge/materials/twist-vert-material.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 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 892e975f..b27c0b11 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -47,7 +47,21 @@ var TwistVertMaterial = function TwistVertMaterial() // Methods /////////////////////////////////////////////////////////////////////// // duplcate method requirde - this.dup = function () { return new TwistVertMaterial(); }; + this.dup = function() { + // get the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties(propNames, propValues, propTypes, propLabels); + + // allocate a new material + var newMat = new TwistVertMaterial(); + + // copy over the current values; + var n = propNames.length; + for (var i = 0; i < n; i++) + newMat.setProperty(propNames[i], propValues[i]); + + return newMat; + }; this.init = function (world) { @@ -162,8 +176,15 @@ var TwistVertMaterial = function TwistVertMaterial() { case "u_tex0": case "u_tex1": - case "color": this._shader.twistMe[propName].set(propValue); break; - default: this._shader.twistMe[propName].set([propValue]); break; + break; + + case "color": + this._shader.twistMe[propName].set(propValue); + break; + + default: + this._shader.twistMe[propName].set([propValue]); + break; } } } -- cgit v1.2.3 From d21aaca3d7093b6af968b7f9f764ab54e004f02b Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 3 May 2012 16:42:56 -0700 Subject: Cleanup of indirect textures. --- js/lib/rdge/materials/twist-vert-material.js | 43 ++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 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 b27c0b11..7d9dd6d6 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -28,6 +28,9 @@ var TwistVertMaterial = function TwistVertMaterial() this._tex0 = 'assets/images/rocky-normal.jpg'; this._tex1 = 'assets/images/metal.png'; + this._glTex0; + this._glTex1; + this._angle = 0.0; this._deltaTime = 0.01; @@ -79,6 +82,9 @@ var TwistVertMaterial = function TwistVertMaterial() this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); + // set up the texture maps + this.updateTextures(); + // initialize the twist vert properties this.updateShaderValues(); }; @@ -146,7 +152,9 @@ var TwistVertMaterial = function TwistVertMaterial() { if (this._shader && this._shader.twistMe) { - var angle = this._angle; + var technique = this._shader.twistMe; + + var angle = this._angle; angle += this._deltaTime; if (angle > this._propValues["u_twistAmount"]) { @@ -160,6 +168,25 @@ var TwistVertMaterial = function TwistVertMaterial() } this._angle = angle; this._shader.twistMe["u_twistAmount"].set([angle]); + + var tex; + if (this._glTex0) + { + if (this._glTex0.isAnimated()) + this._glTex0.render(); + tex = this._glTex0.getTexture(); + if (tex) + technique.u_tex0.set( tex ); + } + if (this._glTex1) + { + if (this._glTex1.isAnimated()) + this._glTex1.render(); + tex = this._glTex1.getTexture(); + if (tex) + technique.u_tex1.set( tex ); + } + } }; @@ -195,17 +222,22 @@ var TwistVertMaterial = function TwistVertMaterial() var material = this._materialNode; if (material) { - var technique = material.shaderProgram['default']; + var technique = material.shaderProgram['twistMe']; var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { - var texMapName = this._propValues[this._propNames[5]]; + var texMapName; + texMapName = this._propValues[this._propNames[5]]; var wrap = 'REPEAT', mips = true; - var tex = this.loadTexture(texMapName, wrap, mips); + //var tex = this.loadTexture(texMapName, wrap, mips); + this._glTex0 = new Texture( this.getWorld(), texMapName, wrap, mips ); + tex = this._glTex0.getTexture(); if (tex) technique.u_tex0.set(tex); texMapName = this._propValues[this._propNames[6]]; - tex = this.loadTexture(texMapName, wrap, mips); + //tex = this.loadTexture(texMapName, wrap, mips); + this._glTex1 = new Texture( this.getWorld(), texMapName, wrap, mips ); + tex = this._glTex1.getTexture(); if (tex) technique.u_tex1.set(tex); } } @@ -242,7 +274,6 @@ twistVertShaderDef = 'u_limit1': { 'type': 'float' }, 'u_limit2': { 'type': 'float' }, - 'u_limit3': { 'type': 'float' }, 'u_minVal': { 'type': 'float' }, 'u_maxVal': { 'type': 'float' }, 'u_center': { 'type': 'float' }, -- cgit v1.2.3 From 725c2175f20b5e0829518f725fd26cc077748bdf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 25 May 2012 13:35:10 -0700 Subject: Parameters for twistVertex material --- js/lib/rdge/materials/twist-vert-material.js | 362 +++++++++++++-------------- 1 file changed, 176 insertions(+), 186 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 7d9dd6d6..4d5ab88d 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -13,235 +13,227 @@ var Texture = require("js/lib/rdge/texture").Texture; /////////////////////////////////////////////////////////////////////// var TwistVertMaterial = function TwistVertMaterial() { - // initialize the inherited members + // initialize the inherited members this.inheritedFrom = Material; - this.inheritedFrom(); + this.inheritedFrom(); - /////////////////////////////////////////////////////////////////////// - // Instance variables - /////////////////////////////////////////////////////////////////////// - this._name = "TwistVertMaterial"; - this._shaderName = "twistVert"; + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "TwistVertMaterial"; + this._shaderName = "twistVert"; - this._color = [1, 0, 0, 1]; - - this._tex0 = 'assets/images/rocky-normal.jpg'; - this._tex1 = 'assets/images/metal.png'; + this._tex0 = 'assets/images/rocky-normal.jpg'; + this._tex1 = 'assets/images/metal.png'; this._glTex0; this._glTex1; - this._angle = 0.0; - this._deltaTime = 0.01; + this._angle = 0.0; + this._deltaTime = 0.01; + this._speed = 1.0; - /////////////////////////////////////////////////////////////////////// - // Property Accessors - /////////////////////////////////////////////////////////////////////// - this.getColor = function () { return this._color; }; - this.getShaderName = function () { return this._shaderName; }; + /////////////////////////////////////////////////////////////////////// + // Property Accessors + /////////////////////////////////////////////////////////////////////// + this.getShaderName = function () { return this._shaderName; }; - this.isAnimated = function () { return true; }; + this.isAnimated = function () { return true; }; - this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; - this._hasVertexDeformation = true; - this._vertexDeformationTolerance = 0.02; // should be a property - - /////////////////////////////////////////////////////////////////////// - // Methods - /////////////////////////////////////////////////////////////////////// - // duplcate method requirde + this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; + this._hasVertexDeformation = true; + this._vertexDeformationTolerance = 0.02; // should be a property + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde this.dup = function() { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new TwistVertMaterial(); + // get the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties(propNames, propValues, propTypes, propLabels); + + // allocate a new material + var newMat = new TwistVertMaterial(); // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); + var n = propNames.length; + for (var i = 0; i < n; i++) + newMat.setProperty(propNames[i], propValues[i]); - return newMat; + return newMat; }; - this.init = function (world) + this.init = function (world) { - this.setWorld(world); - - // set up the shader - this._shader = new RDGE.jshader(); - this._shader.def = twistVertShaderDef; - this._shader.init(); + this.setWorld(world); - // set the defaults - this._shader.twistMe.color.set(this.getColor()); + // set up the shader + this._shader = new RDGE.jshader(); + this._shader.def = twistVertShaderDef; + this._shader.init(); - // set up the material node - this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); - this._materialNode.setShader(this._shader); + // set up the material node + this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); + this._materialNode.setShader(this._shader); // set up the texture maps this.updateTextures(); - // initialize the twist vert properties - this.updateShaderValues(); - }; - - - /////////////////////////////////////////////////////////////////////// - // Material Property Accessors - /////////////////////////////////////////////////////////////////////// - this._propNames = ["color", "u_limit1", "u_limit2", "u_center", "u_twistAmount", "u_tex0", "u_tex1"]; - this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Center", "Twist Amount", "Front facing texture map", "Back facing texture map"]; - this._propTypes = ["color", "float", "float", "float", "float", "file", "file"]; - this._propValues = []; - - // initialize the property values - this._propValues[this._propNames[0]] = this._color.slice(); - this._propValues[this._propNames[1]] = 0.25; - this._propValues[this._propNames[2]] = 0.75; - this._propValues[this._propNames[3]] = 0.0; - this._propValues[this._propNames[4]] = 2.0 * Math.PI; - this._propValues[this._propNames[5]] = this._tex0.slice(); - this._propValues[this._propNames[6]] = this._tex1.slice(); - - this.setProperty = function (prop, value) + // initialize the twist vert properties + this.updateShaderValues(); + }; + + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; + this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; + this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; + this._propValues = []; + + // initialize the property values + 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(); + + this.setProperty = function (prop, value) { - // make sure we have legitimate input - if (this.validateProperty(prop, value)) + // make sure we have legitimate input + if (this.validateProperty(prop, value)) { - switch (prop) { - case "color": - case "u_tex1": - case "u_tex0": this._propValues[prop] = value.slice(); break; - default: this._propValues[prop] = value; break; - } - - this.updateShaderValues(); - } - }; - /////////////////////////////////////////////////////////////////////// - - this.exportJSON = function () { - var jObj = + switch (prop) { + case "u_tex1": + case "u_tex0": this._propValues[prop] = value ? value.slice() : null; + this.updateTextures(); + break; + + default: + this._propValues[prop] = value; + break; + } + + this.updateShaderValues(); + } + }; + /////////////////////////////////////////////////////////////////////// + + this.exportJSON = function () { + var jObj = { - 'material': this.getShaderName(), - 'name': this.getName(), - 'color': this._propValues["color"] + 'material': this.getShaderName(), + 'name': this.getName(), } - return jObj; - }; + return jObj; + }; - this.importJSON = function (jObj) { - if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); - this.setName(jObj.name); + this.importJSON = function (jObj) { + if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); + this.setName(jObj.name); - try { - var color = jObj.color; - this.setProperty("color", color); - } - catch (e) { - throw new Error("could not import material: " + importStr); - } - }; + try { + } + catch (e) { + throw new Error("could not import material: " + importStr); + } + }; - this.update = function (time) + this.update = function (time) { - if (this._shader && this._shader.twistMe) + if (this._shader && this._shader.twistMe) { var technique = this._shader.twistMe; - - var angle = this._angle; - angle += this._deltaTime; - if (angle > this._propValues["u_twistAmount"]) + + 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 = 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]); + angle = 0; + this._deltaTime = -this._deltaTime; + } + this._angle = angle; + this._shader.twistMe["u_twistAmount"].set([angle]); var tex; if (this._glTex0) - { - if (this._glTex0.isAnimated()) - this._glTex0.render(); - tex = this._glTex0.getTexture(); + { + if (this._glTex0.isAnimated()) + this._glTex0.render(); + tex = this._glTex0.getTexture(); if (tex) technique.u_tex0.set( tex ); - } + } if (this._glTex1) - { - if (this._glTex1.isAnimated()) - this._glTex1.render(); - tex = this._glTex1.getTexture(); + { + if (this._glTex1.isAnimated()) + this._glTex1.render(); + tex = this._glTex1.getTexture(); if (tex) technique.u_tex1.set( tex ); - } + } - } - }; + } + }; - this.updateShaderValues = function () + this.updateShaderValues = function () { - if (this._shader && this._shader.twistMe) + if (this._shader && this._shader.twistMe) { - var nProps = this._propNames.length; - for (var i = 0; i < nProps; i++) + var nProps = this._propNames.length; + for (var i = 0; i < nProps; i++) { - var propName = this._propNames[i]; - var propValue = this._propValues[propName]; - switch (propName) + var propName = this._propNames[i]; + var propValue = this._propValues[propName]; + switch (propName) { - case "u_tex0": - case "u_tex1": - break; - - case "color": - this._shader.twistMe[propName].set(propValue); + case "u_tex0": + case "u_tex1": break; - default: - this._shader.twistMe[propName].set([propValue]); + default: + if (this._shader.twistMe[propName]) + this._shader.twistMe[propName].set([propValue]); break; - } - } - } - }; + } + } + } + }; - this.updateTextures = function () + this.updateTextures = function () { - var material = this._materialNode; - if (material) + var material = this._materialNode; + if (material) { - var technique = material.shaderProgram['twistMe']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) + var technique = material.shaderProgram['twistMe']; + var renderer = RDGE.globals.engine.getContext().renderer; + if (renderer && technique) { var texMapName; - texMapName = this._propValues[this._propNames[5]]; - var wrap = 'REPEAT', mips = true; - //var tex = this.loadTexture(texMapName, wrap, mips); + texMapName = this._propValues[this._propNames[4]]; + var wrap = 'REPEAT', mips = true; this._glTex0 = new Texture( this.getWorld(), texMapName, wrap, mips ); tex = this._glTex0.getTexture(); - if (tex) technique.u_tex0.set(tex); + //if (tex) + technique.u_tex0.set(tex); - texMapName = this._propValues[this._propNames[6]]; - //tex = this.loadTexture(texMapName, wrap, mips); + texMapName = this._propValues[this._propNames[5]]; this._glTex1 = new Texture( this.getWorld(), texMapName, wrap, mips ); tex = this._glTex1.getTexture(); - if (tex) technique.u_tex1.set(tex); - } - } - } + //if (tex) + technique.u_tex1.set(tex); + } + } + } }; /////////////////////////////////////////////////////////////////////////////////////// @@ -250,12 +242,12 @@ var TwistVertMaterial = function TwistVertMaterial() // 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 + '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', @@ -263,28 +255,26 @@ twistVertShaderDef = // attributes 'attributes': { - 'vert': { 'type': 'vec3' }, - 'normal': { 'type': 'vec3' }, - 'texcoord': { 'type': 'vec2' } + 'vert': { 'type': 'vec3' }, + 'normal': { 'type': 'vec3' }, + 'texcoord': { 'type': 'vec2' } }, // attributes 'params': { - 'color': { 'type': 'vec4' }, - - 'u_limit1': { 'type': 'float' }, - 'u_limit2': { 'type': 'float' }, - 'u_minVal': { 'type': 'float' }, - 'u_maxVal': { 'type': 'float' }, - 'u_center': { 'type': 'float' }, - 'u_twistAmount': { 'type': 'float' } + 'u_limit1': { 'type': 'float' }, + 'u_limit2': { 'type': 'float' }, + 'u_minVal': { 'type': 'float' }, + 'u_maxVal': { 'type': 'float' }, + 'u_center': { 'type': 'float' }, + 'u_twistAmount': { 'type': 'float' } } - } + } ] - } + } }; if (typeof exports === "object") { - exports.TwistVertMaterial = TwistVertMaterial; + exports.TwistVertMaterial = TwistVertMaterial; } -- cgit v1.2.3 From 129b5282ef35f320ea39d1878d2b5f77ae73a3e2 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 29 May 2012 14:36:59 -0700 Subject: Fixed authortime & runtime for twist vertex shader. --- js/lib/rdge/materials/twist-vert-material.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 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 4d5ab88d..cc232444 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -125,8 +125,17 @@ var TwistVertMaterial = function TwistVertMaterial() this.exportJSON = function () { var jObj = { - 'material': this.getShaderName(), - 'name': this.getName(), + 'material' : this.getShaderName(), + 'name' : this.getName(), + + 'tex0' : this._propValues[this._propNames[4]], + 'tex1' : this._propValues[this._propNames[5]], + + 'speed' : this._propValues[this._propNames[3]], + + 'limit1' : this._propValues[this._propNames[0]], + 'limit2' : this._propValues[this._propNames[1]], + 'angle' : this._propValues[this._propNames[2]] } return jObj; @@ -137,6 +146,17 @@ var TwistVertMaterial = function TwistVertMaterial() this.setName(jObj.name); try { + + this._propValues[this._propNames[4]] = jObj.tex0; + this._propValues[this._propNames[5]] = jObj.tex1; + + this._propValues[this._propNames[3]] = jObj.speed; + + this._propValues[this._propNames[0]] = jObj.limit1; + this._propValues[this._propNames[1]] = jObj.limit2; + this._propValues[this._propNames[2]] = jObj.angle; + + this.updateShaderValues(); } catch (e) { throw new Error("could not import material: " + importStr); -- cgit v1.2.3 From d4ca478ad313c6c20834e410ba14ad3a5e7b20bf Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 12 Jun 2012 10:28:26 -0700 Subject: Material cleanup & bug fixes. --- js/lib/rdge/materials/twist-vert-material.js | 197 +++++---------------------- 1 file changed, 34 insertions(+), 163 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 cc232444..6cffa29f 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -26,9 +26,6 @@ var TwistVertMaterial = function TwistVertMaterial() this._tex0 = 'assets/images/rocky-normal.jpg'; this._tex1 = 'assets/images/metal.png'; - this._glTex0; - this._glTex1; - this._angle = 0.0; this._deltaTime = 0.01; this._speed = 1.0; @@ -37,32 +34,34 @@ var TwistVertMaterial = function TwistVertMaterial() // Property Accessors /////////////////////////////////////////////////////////////////////// this.getShaderName = function () { return this._shaderName; }; - 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 /////////////////////////////////////////////////////////////////////// - // Methods + // Material Property Accessors /////////////////////////////////////////////////////////////////////// - // duplcate method requirde - this.dup = function() { - // get the current values; - var propNames = [], propValues = [], propTypes = [], propLabels = []; - this.getAllProperties(propNames, propValues, propTypes, propLabels); - - // allocate a new material - var newMat = new TwistVertMaterial(); + this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; + this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; + this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; + this._propValues = []; - // copy over the current values; - var n = propNames.length; - for (var i = 0; i < n; i++) - newMat.setProperty(propNames[i], propValues[i]); + // initialize the property values + 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(); + /////////////////////////////////////////////////////////////////////// - return newMat; - }; + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// this.init = function (world) { @@ -77,90 +76,9 @@ var TwistVertMaterial = function TwistVertMaterial() this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); this._materialNode.setShader(this._shader); - // set up the texture maps - this.updateTextures(); // initialize the twist vert properties - this.updateShaderValues(); - }; - - - /////////////////////////////////////////////////////////////////////// - // Material Property Accessors - /////////////////////////////////////////////////////////////////////// - this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; - this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; - this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; - this._propValues = []; - - // initialize the property values - 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(); - - this.setProperty = function (prop, value) - { - // make sure we have legitimate input - if (this.validateProperty(prop, value)) - { - switch (prop) { - case "u_tex1": - case "u_tex0": this._propValues[prop] = value ? value.slice() : null; - this.updateTextures(); - break; - - default: - this._propValues[prop] = value; - break; - } - - this.updateShaderValues(); - } - }; - /////////////////////////////////////////////////////////////////////// - - this.exportJSON = function () { - var jObj = - { - 'material' : this.getShaderName(), - 'name' : this.getName(), - - 'tex0' : this._propValues[this._propNames[4]], - 'tex1' : this._propValues[this._propNames[5]], - - 'speed' : this._propValues[this._propNames[3]], - - 'limit1' : this._propValues[this._propNames[0]], - 'limit2' : this._propValues[this._propNames[1]], - 'angle' : this._propValues[this._propNames[2]] - } - - return jObj; - }; - - this.importJSON = function (jObj) { - if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); - this.setName(jObj.name); - - try { - - this._propValues[this._propNames[4]] = jObj.tex0; - this._propValues[this._propNames[5]] = jObj.tex1; - - this._propValues[this._propNames[3]] = jObj.speed; - - this._propValues[this._propNames[0]] = jObj.limit1; - this._propValues[this._propNames[1]] = jObj.limit2; - this._propValues[this._propNames[2]] = jObj.angle; - - this.updateShaderValues(); - } - catch (e) { - throw new Error("could not import material: " + importStr); - } + this.setShaderValues(); }; this.update = function (time) @@ -185,80 +103,30 @@ var TwistVertMaterial = function TwistVertMaterial() this._shader.twistMe["u_twistAmount"].set([angle]); var tex; - if (this._glTex0) + var glTex = this._glTextures["u_tex0"]; + if (glTex) { - if (this._glTex0.isAnimated()) - this._glTex0.render(); - tex = this._glTex0.getTexture(); + //if (glTex.isAnimated()) + glTex.render(); + tex = glTex.getTexture(); if (tex) technique.u_tex0.set( tex ); } - if (this._glTex1) + + glTex = this._glTextures["u_tex1"]; + if (glTex) { - if (this._glTex1.isAnimated()) - this._glTex1.render(); - tex = this._glTex1.getTexture(); + //if (glTex.isAnimated()) + glTex.render(); + tex = glTex.getTexture(); if (tex) technique.u_tex1.set( tex ); } } - }; - - this.updateShaderValues = function () - { - if (this._shader && this._shader.twistMe) - { - var nProps = this._propNames.length; - for (var i = 0; i < nProps; i++) - { - var propName = this._propNames[i]; - var propValue = this._propValues[propName]; - switch (propName) - { - case "u_tex0": - case "u_tex1": - break; - - default: - if (this._shader.twistMe[propName]) - this._shader.twistMe[propName].set([propValue]); - break; - } - } - } - }; - - this.updateTextures = function () - { - var material = this._materialNode; - if (material) - { - var technique = material.shaderProgram['twistMe']; - var renderer = RDGE.globals.engine.getContext().renderer; - if (renderer && technique) - { - var texMapName; - texMapName = this._propValues[this._propNames[4]]; - var wrap = 'REPEAT', mips = true; - this._glTex0 = new Texture( this.getWorld(), texMapName, wrap, mips ); - tex = this._glTex0.getTexture(); - //if (tex) - technique.u_tex0.set(tex); - - texMapName = this._propValues[this._propNames[5]]; - this._glTex1 = new Texture( this.getWorld(), texMapName, wrap, mips ); - tex = this._glTex1.getTexture(); - //if (tex) - technique.u_tex1.set(tex); - } - } } }; -/////////////////////////////////////////////////////////////////////////////////////// -// RDGE shader - // shader spec (can also be loaded from a .JSON file, or constructed at runtime) twistVertShaderDef = { @@ -282,12 +150,15 @@ twistVertShaderDef = // 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' } + 'u_twistAmount': { 'type': 'float' }, + 'speed': { 'type': 'float' } } } ] -- cgit v1.2.3 From f0fc7a5678093cce986bd99fef2c5c88add19b68 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 14 Jun 2012 16:09:31 -0700 Subject: Fix for line color. Name change for all materials --- js/lib/rdge/materials/twist-vert-material.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 6cffa29f..7c2dae5e 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -20,7 +20,7 @@ var TwistVertMaterial = function TwistVertMaterial() /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// - this._name = "TwistVertMaterial"; + this._name = "Twist Vertex"; this._shaderName = "twistVert"; this._tex0 = 'assets/images/rocky-normal.jpg'; -- cgit v1.2.3