From 9e812f35ffa751e9215c5427c0c44005bd357924 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 7 Mar 2012 17:18:38 -0800 Subject: Fixed a few problems with Plasma material. --- js/lib/rdge/materials/plasma-material.js | 30 +++++++--------------------- js/lib/rdge/runtime/RuntimeGeomObj.js | 4 +++- js/lib/rdge/runtime/RuntimeMaterial.js | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 24 deletions(-) (limited to 'js/lib/rdge') diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 62d0db70..86b1a93c 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -17,8 +17,6 @@ var PlasmaMaterial = function PlasmaMaterial() { this._dTime = 0.01; this._speed = 1.0; - this._color = [1,0,0,1]; - /////////////////////////////////////////////////////////////////////// // Property Accessors @@ -30,20 +28,12 @@ var PlasmaMaterial = function PlasmaMaterial() { /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["color"]; - this._propLabels = ["Color"]; - this._propTypes = ["color"]; - this._propValues = []; - - this._propValues[ this._propNames[0] ] = this._color; - - this.setProperty = function( prop, value ) { - // make sure we have legitimate imput - if (this.validateProperty( prop, value )) { - this._color = value.slice(0); - this._shader['default'][prop].set(value); - } + + this.setProperty = function( prop, value ) + { + // plasma has no properties }; + /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// @@ -65,8 +55,7 @@ var PlasmaMaterial = function PlasmaMaterial() { // set the default value this._time = 0; - this._shader['default'].u_time = this._time; - this.setProperty( "color", [this._time, 0, 0, 1] ); + this._shader['default'].u_time.set( [this._time] ); // set up the material node this._materialNode = createMaterialNode("plasmaMaterial" + "_" + world.generateUniqueNodeID()); @@ -74,11 +63,7 @@ var PlasmaMaterial = function PlasmaMaterial() { }; this.update = function( time ) { - this._shader['default'].u_time = this._time; - var color = this.getProperty( "color" ); - color[0] = this._time; - this.setProperty( "color", color ); - //console.log( "update color to: " + color ); + this._shader['default'].u_time.set( [this._time] ); this._time += this._dTime; } @@ -112,7 +97,6 @@ var plasmaShaderDef = 'params' : { 'u_time' : { 'type' : 'float' }, - 'color' : { 'type' : 'vec4' } }, // render states diff --git a/js/lib/rdge/runtime/RuntimeGeomObj.js b/js/lib/rdge/runtime/RuntimeGeomObj.js index 5b212dce..93d4d9a1 100644 --- a/js/lib/rdge/runtime/RuntimeGeomObj.js +++ b/js/lib/rdge/runtime/RuntimeGeomObj.js @@ -11,7 +11,8 @@ var RuntimeFlatMaterial = RuntimeMaterial.RuntimeFlatMaterial, RuntimeLinearGradientMaterial = RuntimeMaterial.RuntimeLinearGradientMaterial, RuntimeBumpMetalMaterial = RuntimeMaterial.RuntimeBumpMetalMaterial, RuntimeUberMaterial = RuntimeMaterial.RuntimeUberMaterial, - RuntimePulseMaterial = RuntimeMaterial.RuntimePulseMaterial; + RuntimePulseMaterial = RuntimeMaterial.RuntimePulseMaterial, + RuntimePlasmaMaterial = RuntimeMaterial.RuntimePlasmaMaterial; @@ -94,6 +95,7 @@ var RuntimeGeomObj = function RuntimeGeomObj() case "linearGradient": mat = new RuntimeLinearGradientMaterial(); break; case "bumpMetal": mat = new RuntimeBumpMetalMaterial(); break; case "uber": mat = new RuntimeUberMaterial(); break; + case "plasma": mat = new RuntimePlasmaMaterial(); break; case "deform": case "water": diff --git a/js/lib/rdge/runtime/RuntimeMaterial.js b/js/lib/rdge/runtime/RuntimeMaterial.js index 294c4787..1bbbc3b1 100644 --- a/js/lib/rdge/runtime/RuntimeMaterial.js +++ b/js/lib/rdge/runtime/RuntimeMaterial.js @@ -54,6 +54,10 @@ var RuntimeMaterial = function RuntimeMaterial( world ) { } + this.import = function( importStr ) + { + } + this.getPropertyFromString = function( prop, str ) { var index = str.indexOf( prop ); @@ -304,6 +308,35 @@ function RuntimeUberMaterial() { } +function RuntimePlasmaMaterial() +{ + // inherit the members of RuntimeMaterial + this.inheritedFrom = RuntimeMaterial; + this.inheritedFrom(); + + this.init = function( ) + { + this.update(); + } + + this.update = function( time ) + { + var material = this._materialNode; + if (material) + { + var technique = material.shaderProgram.default; + var renderer = g_Engine.getContext().renderer; + if (renderer && technique) + { + if (this._shader && this._shader.default) + this._shader.default.u_time.set( [this._time] ); + this._time += this._dTime; + if (this._time > 200.0) this._time = 0.0; + } + } + } +} + if (typeof exports === "object") { @@ -314,4 +347,5 @@ if (typeof exports === "object") exports.RuntimeLinearGradientMaterial = RuntimeLinearGradientMaterial; exports.RuntimeBumpMetalMaterial = RuntimeBumpMetalMaterial; exports.RuntimeUberMaterial = RuntimeUberMaterial; + exports.RuntimePlasmaMaterial = RuntimePlasmaMaterial; } -- cgit v1.2.3