From a0d23354802ebc6b437698acb4b18d3395d47cd1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 16 Mar 2012 12:26:30 -0700 Subject: Conversion to JSON based file IO for canvas2D and WebGL rendering --- js/lib/rdge/materials/bump-metal-material.js | 44 +++++ js/lib/rdge/materials/flat-material.js | 21 +++ js/lib/rdge/materials/linear-gradient-material.js | 53 +++++++ js/lib/rdge/materials/pulse-material.js | 32 ++++ js/lib/rdge/materials/radial-blur-material.js | 36 +++++ js/lib/rdge/materials/radial-gradient-material.js | 54 ++++++- js/lib/rdge/materials/taper-material.js | 27 ++++ js/lib/rdge/materials/twist-vert-material.js | 28 ++++ js/lib/rdge/materials/uber-material.js | 185 +++++++++++++++++++++- 9 files changed, 475 insertions(+), 5 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index fa6f5300..4a6e9ab8 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -152,6 +152,50 @@ var BumpMetalMaterial = function BumpMetalMaterial() { } }; + this.exportJSON = function() + { + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'lightDiff' : this.getLightDiff(), + 'diffuseTexture' : this.getDiffuseTexture(), + 'specularTexture' : this.getSpecularTexture(), + 'normalMap' : this.getNormalTexture() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var lightDiff = jObj.lightDiff, + dt = jObj.diffuseTexture, + st = jObj.specularTexture, + nt = jObj.normalMap; + + this.setProperty( "lightDiff", lightDiff); + this.setProperty( "diffuseTexture", dt ); + this.setProperty( "specularTexture", st ); + this.setProperty( "normalMap", nt ); + } + catch (e) + { + throw new Error( "could not import BumpMetal material: " + jObj ); + } + + return; + }; + this.export = function() { // every material needs the base type and instance name diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index fff0e68e..5030cc88 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js @@ -112,6 +112,27 @@ var FlatMaterial = function FlatMaterial() { return rtnStr; }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"] + }; + + return jObj; + } + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + var color = jObj.color; + this.setProperty( "color", color); + } + this.update = function( time ) { }; diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 8e05e23d..0db6fc90 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js @@ -249,6 +249,59 @@ var LinearGradientMaterial = function LinearGradientMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color1' : this.getColor1(), + 'color2' : this.getColor2(), + 'color3' : this.getColor3(), + 'color4' : this.getColor4(), + 'colorStop1' : this.getColorStop1(), + 'colorStop2' : this.getColorStop2(), + 'colorStop3' : this.getColorStop3(), + 'colorStop4' : this.getColorStop4(), + 'angle' : this.getAngle() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color1 = jObj.color1, + color2 = jObj.color2, + color3 = jObj.color3, + color4 = jObj.color4, + colorStop1 = jObj.colorStop1, + colorStop2 = jObj.colorStop2, + colorStop3 = jObj.colorStop3, + colorStop4 = jObj.colorStop4, + angle = jObj.angle; + + this.setProperty( "color1", color1 ); + this.setProperty( "color2", color2 ); + this.setProperty( "color3", color3 ); + this.setProperty( "color4", color4 ); + this.setProperty( "colorStop1", colorStop1 ); + this.setProperty( "colorStop2", colorStop2 ); + this.setProperty( "colorStop3", colorStop3 ); + this.setProperty( "colorStop4", colorStop4 ); + this.setProperty( "angle", angle ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + }; + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 81db36c6..1e2cd2a9 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -174,6 +174,38 @@ var PulseMaterial = function PulseMaterial() { } }; + // JSON export + this.exportJSON = function() + { + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]] + }; + + 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[0]] = jObj.texture; + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } + + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 46cdda74..e76b302f 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -157,6 +157,42 @@ var RadialBlurMaterial = function RadialBlurMaterial() { } }; + this.exportJSON = function() + { + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"], + 'texture' : this._propValues[this._propNames[0]] + }; + + return jObj; + }; + + this.importJSON = function( importStr ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + var rtnStr; + try + { + this._propValues[this._propNames[0]] = jObj.texture; + this.updateTexture(); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + + return rtnStr; + } + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index d19b44b7..87e20ad4 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js @@ -158,7 +158,8 @@ var RadialGradientMaterial = function RadialGradientMaterial() { this._propValues[ this._propNames[6] ] = this._colorStop3; this._propValues[ this._propNames[7] ] = this._colorStop4; - this.setProperty = function( prop, value ) { + this.setProperty = function( prop, value ) + { if (prop === "color") prop = "color1"; // make sure we have legitimate imput @@ -236,6 +237,57 @@ var RadialGradientMaterial = function RadialGradientMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + + 'color1' : this.getColor1(), + 'color2' : this.getColor2(), + 'color3' : this.getColor3(), + 'color4' : this.getColor4(), + 'colorStop1' : this.getColorStop1(), + 'colorStop2' : this.getColorStop2(), + 'colorStop3' : this.getColorStop3(), + 'colorStop4' : this.getColorStop4() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color1 = jObj.color1, + color2 = jObj.color2, + color3 = jObj.color3, + color4 = jObj.color4, + colorStop1 = jObj.colorStop1, + colorStop2 = jObj.colorStop2, + colorStop3 = jObj.colorStop3, + colorStop4 = jObj.colorStop4; + + this.setProperty( "color1", color1 ); + this.setProperty( "color2", color2 ); + this.setProperty( "color3", color3 ); + this.setProperty( "color4", color4 ); + this.setProperty( "colorStop1", colorStop1 ); + this.setProperty( "colorStop2", colorStop2 ); + this.setProperty( "colorStop3", colorStop3 ); + this.setProperty( "colorStop4", colorStop4 ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + }; + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index 03a7ba9c..15b7b2b0 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js @@ -96,6 +96,33 @@ function TaperMaterial() } } /////////////////////////////////////////////////////////////////////// + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"] + }; + + return jObj; + } + + 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: " + jObj ); + } + } this.export = function() { diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 05172a1b..2d2cdcc5 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js @@ -102,6 +102,34 @@ function TwistVertMaterial() } /////////////////////////////////////////////////////////////////////// + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"] + }; + + return jObj; + } + + 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 ); + } + } + this.export = function() { // this function should be overridden by subclasses diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 91f43754..0868e3e9 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -483,6 +483,187 @@ var UberMaterial = function UberMaterial() { this.rebuildShader(); } + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + if (jObj.materialProps) + { + var ambientColor = jObj.materialProps.ambientColor; this.setProperty( "ambientColor", ambientColor ); + var diffuseColor = jObj.materialProps.diffuseColor; this.setProperty( "diffuseColor", diffuseColor ); + var specularColor = jObj.materialProps.specularColor; this.setProperty( "specularColor", specularColor ); + var specularPower = jObj.materialProps.specularPower; this.setProperty( "specularPower", specularPower ); + } + + var lightArray = jObj.lights; + if (lightArray) + { + this._lights = []; + for (var i=0; i 0) + { + this._ubershaderCaps.lighting = + { + 'light0' : this._lights[0], + 'light1' : this._lights[1], + 'light2' : this._lights[2], + 'light3' : this._lights[3] + } + } + } + + var diffuseMap = jObj['diffuseMap']; + if(diffuseMap) + this.setProperty( "diffuseMap", diffuseMap ); + + var normalMap = jObj['normalMap']; + if(normalMap) + this.setProperty( "normalMap", normalMap ); + + var specularMap = jObj['specularMap']; + if(specularMap) + this.setProperty( "specularMap", specularMap ); + + var environmentMap = jObj['environmentMap']; + if(environmentMap) + { + this.setProperty( "environmentMap", environmentMap ); + this.setProperty( "environmentAmount", jObj['environmentAmount'] ); + } + + this.rebuildShader(); + } + + this.exportJSON = function() + { + // we will be needing the world. Make sure it is there + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + // every material needs the base type and instance name + var caps = this._ubershaderCaps; + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName() + }; + + // export the material properties + if (typeof caps.material != 'undefined') + { + jObj.materialProps = + { + 'ambientColor' : this._ambientColor, + 'diffuseColor' : this._diffuseColor, + 'specularColor' : this._specularColor, + 'specularPower' : this._specularPower + }; + + } + + if (typeof caps.lighting != 'undefined') + { + var lightArray = []; + for (var i=0; i 0) + jObj.lights = lightArray; + } + + if(typeof caps.diffuseMap != 'undefined') + jObj['diffuseMap'] = caps.diffuseMap.texture; + + if(typeof caps.normalMap != 'undefined') + jObj['normalMap'] = caps.normalMap.texture; + + if(typeof caps.specularMap != 'undefined') + jObj['specularMap'] = caps.specularMap.texture; + + if(typeof caps.environmentMap != 'undefined') + { + jObj['environmentMap'] = caps.environmentMap.texture; + jObj['environmentAmount'] = caps.environmentMap.envReflection; + } + + return jObj; + } + + this.export = function() { // every material needs the base type and instance name @@ -539,10 +720,6 @@ var UberMaterial = function UberMaterial() { } } -// this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; -// this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' }; -// this._specularMapOb = { 'texture' : 'assets/images/rocky-spec.jpg', 'wrap' : 'REPEAT' }; -// this._environmentMapOb = { 'texture' : 'assets/images/silver.png', 'wrap' : 'CLAMP', 'envReflection' : this._environmentAmount }; var world = this.getWorld(); if (!world) throw new Error( "no world in material.export, " + this.getName() ); -- cgit v1.2.3 From 43ea2515f1482eeb77454f407111f0568c056f72 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 16 Mar 2012 15:32:23 -0700 Subject: removing dead code --- js/lib/rdge/materials/pulse-material.js | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 1e2cd2a9..6f19ab2b 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -125,18 +125,6 @@ var PulseMaterial = function PulseMaterial() { var texMapName = this._propValues[this._propNames[0]]; var wrap = 'REPEAT', mips = true; var tex = this.loadTexture( texMapName, wrap, mips ); - - /* - var glTex = new GLTexture( this.getWorld() ); - var prevWorld = this.findPreviousWorld(); - if (prevWorld) - { - var srcCanvas = prevWorld.getCanvas(); - tex = glTex.loadFromCanvas( srcCanvas ); - } - else - tex = glTex.loadFromFile( texMapName, wrap, mips ); - */ if (tex) { technique.u_tex0.set( tex ); -- cgit v1.2.3 From 98a02c1ac6f189aba93d7cce64ba5bdbc0617f6c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 20 Mar 2012 16:26:52 -0700 Subject: Bug Fixes for Canvas & WebGL File IO --- js/lib/rdge/materials/julia-material.js | 6 +----- js/lib/rdge/materials/mandel-material.js | 6 +----- js/lib/rdge/materials/plasma-material.js | 19 ++++++++++++++++++ js/lib/rdge/materials/pulse-material.js | 1 + js/lib/rdge/materials/radial-blur-material.js | 29 ++++++++++++++++++++++++--- js/lib/rdge/materials/water-material.js | 25 +++++++++++++++++++++++ 6 files changed, 73 insertions(+), 13 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index 976dfad3..a85bd6f7 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js @@ -21,11 +21,7 @@ var JuliaMaterial = function JuliaMaterial() { /////////////////////////////////////////////////////////////////////// // Properties /////////////////////////////////////////////////////////////////////// - // no properties - this._propNames = []; - this._propLabels = []; - this._propTypes = []; - this._propValues = []; + // properties inherited from PulseMaterial /////////////////////////////////////////////////////////////////////// // Methods diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index d9f00383..e7b105e1 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -21,11 +21,7 @@ var MandelMaterial = function MandelMaterial() { /////////////////////////////////////////////////////////////////////// // Properties /////////////////////////////////////////////////////////////////////// - // no properties - this._propNames = []; - this._propLabels = []; - this._propTypes = []; - this._propValues = []; + // properties inherited from PulseMaterial /////////////////////////////////////////////////////////////////////// // Material Property Accessors diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 86b1a93c..316a5989 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -67,6 +67,25 @@ var PlasmaMaterial = function PlasmaMaterial() { this._time += this._dTime; } + this.exportJSON = function() + { + + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'speed' : this._speed, + 'dTime' : this._dTime + } + + return jObj; + } + + this.importJSON = function( jObj ) + { + this._speed = jObj.speed; + this._dTime = jObj.dTime; + } }; /////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 6f19ab2b..fd2cbe0b 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -186,6 +186,7 @@ var PulseMaterial = function PulseMaterial() { try { this._propValues[this._propNames[0]] = jObj.texture; + this._texMap = jObj.texture; } catch (e) { diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index e76b302f..d67a3d43 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -174,7 +174,7 @@ var RadialBlurMaterial = function RadialBlurMaterial() { return jObj; }; - this.importJSON = function( importStr ) + this.importJSON = function( jObj ) { if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); this.setName( jObj.name ); @@ -278,10 +278,33 @@ var radialBlurMaterialDef = } }; + +/* +var RaidersMaterial = function RaidersMaterial() +{ + // initialize the inherited members + this.inheritedFrom = RadialBlurMaterial; + this.inheritedFrom(); + + this._name = "RaidersMaterial"; + this._shaderName = "radialBlur"; + + this._texMap = 'assets/images/raiders.png'; + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); +} + +RaidersMaterial.prototype = new Material(); + +if (typeof exports === "object") +{ + exports.RaidersMaterial = RaidersMaterial; +} +*/ + + RadialBlurMaterial.prototype = new Material(); -if (typeof exports === "object") { +if (typeof exports === "object") exports.RadialBlurMaterial = RadialBlurMaterial; -} diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index cac5a249..565055a1 100644 --- a/js/lib/rdge/materials/water-material.js +++ b/js/lib/rdge/materials/water-material.js @@ -18,6 +18,7 @@ var WaterMaterial = function WaterMaterial() { this._shaderName = "water"; this._texMap = 'assets/images/rocky-normal.jpg'; + //this._texMap = 'assets/images/powderblue.png'; this._time = 0.0; this._dTime = 0.01; @@ -27,6 +28,7 @@ var WaterMaterial = function WaterMaterial() { /////////////////////////////////////////////////////////////////////// // all defined in parent PulseMaterial.js // load the local default value + this._propValues = []; this._propValues[ this._propNames[0] ] = this._texMap.slice(0); /////////////////////////////////////////////////////////////////////// @@ -115,6 +117,29 @@ var waterMaterialDef = } }; +/* +var ParisMaterial = function ParisMaterial() +{ + // initialize the inherited members + this.inheritedFrom = WaterMaterial; + this.inheritedFrom(); + + this._name = "ParisMaterial"; + this._shaderName = "water"; + + this._texMap = 'assets/images/paris.png'; + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; + this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); +} +ParisMaterial.prototype = new PulseMaterial(); +if (typeof exports === "object") { + exports.ParisMaterial = ParisMaterial; +} +*/ + + WaterMaterial.prototype = new PulseMaterial(); if (typeof exports === "object") { -- cgit v1.2.3 From eb59a523258cad3351cba9bf8de986e90a8e5b1c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 21 Mar 2012 15:17:58 -0700 Subject: Added material library data to the canvas data. --- js/lib/rdge/materials/bump-metal-material.js | 4 - js/lib/rdge/materials/cloud-material.js | 300 ++++++++++++++++++++++++++ js/lib/rdge/materials/plasma-material.js | 1 - js/lib/rdge/materials/pulse-material.js | 4 - js/lib/rdge/materials/radial-blur-material.js | 4 - js/lib/rdge/materials/uber-material.js | 5 - 6 files changed, 300 insertions(+), 18 deletions(-) create mode 100644 js/lib/rdge/materials/cloud-material.js (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 4a6e9ab8..2ef83227 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -154,10 +154,6 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this.exportJSON = function() { - var world = this.getWorld(); - if (!world) - throw new Error( "no world in material.export, " + this.getName() ); - var jObj = { 'material' : this.getShaderName(), diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js new file mode 100644 index 00000000..85088f91 --- /dev/null +++ b/js/lib/rdge/materials/cloud-material.js @@ -0,0 +1,300 @@ +/* + This file contains proprietary software owned by Motorola Mobility, Inc.
+ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+ (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; +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +var CloudMaterial = function CloudMaterial() { + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "CloudMaterial"; + this._shaderName = "cloud"; + + this._texMap = 'assets/images/cloud2.jpg'; + this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Property Accessors + /////////////////////////////////////////////////////////////////////// + this.getName = function() { return this._name; }; + this.getShaderName = function() { return this._shaderName; }; + + this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; + this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; + + this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); }; + this.getDiffuseColor = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; }; + + this.isAnimated = function() { return true; }; + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + this._propNames = ["texmap", "diffusecolor"]; + this._propLabels = ["Texture map", "Diffuse Color"]; + this._propTypes = ["file", "color"]; + this._propValues = []; + + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); + + this.setProperty = function( prop, value ) + { + if (prop === 'color') prop = 'diffusecolor'; + + // make sure we have legitimate imput + var ok = this.validateProperty( prop, value ); + if (!ok) { + console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value ); + } + + switch (prop) + { + case "texmap": + this.setTextureMap(value); + break; + + case "diffusecolor": + this.setDiffuseColor( value ); + break; + + case "color": + break; + } + }; + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // save the world + if (world) this.setWorld( world ); + + // allocate a new uber material + var newMat = new CloudMaterial(); + + // copy over the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties( propNames, propValues, propTypes, propLabels); + var n = propNames.length; + for (var i=0; i 200.0) this._time = 0.0; + } + } + }; + + // JSON export + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]] + }; + + 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[0]] = jObj.texture; + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } + + + this.export = function() { + // every material needs the base type and instance name + var exportStr = "material: " + this.getShaderName() + "\n"; + exportStr += "name: " + this.getName() + "\n"; + + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var texMapName = this._propValues[this._propNames[0]]; + exportStr += "texture: " +texMapName + "\n"; + + // every material needs to terminate like this + 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 { + this._propValues[this._propNames[0]] = pu.nextValue( "texture: " ); + + 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; + } +}; + +/////////////////////////////////////////////////////////////////////////////////////// +// RDGE shader + +// shader spec (can also be loaded from a .JSON file, or constructed at runtime) +var cloudMaterialDef = +{'shaders': + { + 'defaultVShader':"assets/shaders/Cloud.vert.glsl", + 'defaultFShader':"assets/shaders/Cloud.frag.glsl" + }, + 'techniques': + { + 'default': + [ + { + 'vshader' : 'defaultVShader', + 'fshader' : 'defaultFShader', + // attributes + 'attributes' : + { + 'vert' : { 'type' : 'vec3' }, + 'normal' : { 'type' : 'vec3' }, + 'texcoord' : { 'type' : 'vec2' } + }, + // parameters + 'params' : + { + 'u_tex0': { 'type' : 'tex2d' }, + 'u_time' : { 'type' : 'float' }, + 'u_DiffuseColor' : { 'type' : 'vec4' } + }, + + // render states + 'states' : + { + 'depthEnable' : true, + 'offset':[1.0, 0.1] + } + } + ] + } +}; + + + + +CloudMaterial.prototype = new Material(); + +if (typeof exports === "object") { + exports.CloudMaterial = CloudMaterial; +} + diff --git a/js/lib/rdge/materials/plasma-material.js b/js/lib/rdge/materials/plasma-material.js index 316a5989..b04d8451 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -69,7 +69,6 @@ var PlasmaMaterial = function PlasmaMaterial() { this.exportJSON = function() { - var jObj = { 'material' : this.getShaderName(), diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index fd2cbe0b..e6be69b4 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -165,10 +165,6 @@ var PulseMaterial = function PulseMaterial() { // JSON export this.exportJSON = function() { - var world = this.getWorld(); - if (!world) - throw new Error( "no world in material.export, " + this.getName() ); - var jObj = { 'material' : this.getShaderName(), diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index d67a3d43..91eebcff 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -159,10 +159,6 @@ var RadialBlurMaterial = function RadialBlurMaterial() { this.exportJSON = function() { - var world = this.getWorld(); - if (!world) - throw new Error( "no world in material.export, " + this.getName() ); - var jObj = { 'material' : this.getShaderName(), diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 0868e3e9..c1d1913c 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -579,11 +579,6 @@ var UberMaterial = function UberMaterial() { this.exportJSON = function() { - // we will be needing the world. Make sure it is there - var world = this.getWorld(); - if (!world) - throw new Error( "no world in material.export, " + this.getName() ); - // every material needs the base type and instance name var caps = this._ubershaderCaps; var jObj = -- cgit v1.2.3 From 4cd4d29ae10b87f7b280d537b8980d207a22dd43 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 21 Mar 2012 16:51:05 -0700 Subject: Synchronized material animation speed for pulse material between Ninja and runtime. --- js/lib/rdge/materials/pulse-material.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index e6be69b4..2075d1ff 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -169,7 +169,8 @@ var PulseMaterial = function PulseMaterial() { { 'material' : this.getShaderName(), 'name' : this.getName(), - 'texture' : this._propValues[this._propNames[0]] + 'texture' : this._propValues[this._propNames[0]], + 'dTime' : this._dTime }; return jObj; @@ -183,6 +184,8 @@ var PulseMaterial = function PulseMaterial() { try { this._propValues[this._propNames[0]] = jObj.texture; this._texMap = jObj.texture; + if (jObj.dTime) + this._dTime = jObj.dTime; } catch (e) { -- cgit v1.2.3 From 31e924e1b8b8da8342b3ff2341c8284915486c0b Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 22 Mar 2012 15:32:19 -0700 Subject: Added Paris and Raiders materials --- js/lib/rdge/materials/radial-blur-material.js | 2 - js/lib/rdge/materials/water-material.js | 84 ++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 5 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/radial-blur-material.js b/js/lib/rdge/materials/radial-blur-material.js index 91eebcff..f4a4baa2 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -275,7 +275,6 @@ var radialBlurMaterialDef = }; -/* var RaidersMaterial = function RaidersMaterial() { // initialize the inherited members @@ -295,7 +294,6 @@ if (typeof exports === "object") { exports.RaidersMaterial = RaidersMaterial; } -*/ RadialBlurMaterial.prototype = new Material(); diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index 565055a1..b7413f55 100644 --- a/js/lib/rdge/materials/water-material.js +++ b/js/lib/rdge/materials/water-material.js @@ -117,7 +117,6 @@ var waterMaterialDef = } }; -/* var ParisMaterial = function ParisMaterial() { // initialize the inherited members @@ -125,19 +124,98 @@ var ParisMaterial = function ParisMaterial() this.inheritedFrom(); this._name = "ParisMaterial"; - this._shaderName = "water"; + this._shaderName = "paris"; this._texMap = 'assets/images/paris.png'; this._propValues[ this._propNames[0] ] = this._texMap.slice(0); this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); + + // duplcate method requirde + this.dup = function( world ) { + // allocate a new uber material + var newMat = new ParisMaterial(); + + // copy over the current values; + var propNames = [], propValues = [], propTypes = [], propLabels = []; + this.getAllProperties( propNames, propValues, propTypes, propLabels); + var n = propNames.length; + for (var i=0; i