From fdeed8051c3af538d28ca3bc599121cea483c22c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 22 Mar 2012 15:47:56 -0700 Subject: Squashed commit of the following GL integration Signed-off-by: Valerio Virgillito --- js/lib/rdge/materials/bump-metal-material.js | 40 +++ js/lib/rdge/materials/cloud-material.js | 300 ++++++++++++++++++++++ js/lib/rdge/materials/flat-material.js | 21 ++ js/lib/rdge/materials/julia-material.js | 6 +- js/lib/rdge/materials/linear-gradient-material.js | 53 ++++ js/lib/rdge/materials/mandel-material.js | 6 +- js/lib/rdge/materials/plasma-material.js | 18 ++ js/lib/rdge/materials/pulse-material.js | 44 +++- js/lib/rdge/materials/radial-blur-material.js | 57 +++- 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 | 180 ++++++++++++- js/lib/rdge/materials/water-material.js | 103 ++++++++ 14 files changed, 908 insertions(+), 29 deletions(-) create mode 100644 js/lib/rdge/materials/cloud-material.js (limited to 'js/lib/rdge') diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index fa6f5300..2ef83227 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -152,6 +152,46 @@ var BumpMetalMaterial = function BumpMetalMaterial() { } }; + this.exportJSON = function() + { + 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/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/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/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/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/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..b04d8451 100644 --- a/js/lib/rdge/materials/plasma-material.js +++ b/js/lib/rdge/materials/plasma-material.js @@ -67,6 +67,24 @@ 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 81db36c6..2075d1ff 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 ); @@ -174,6 +162,38 @@ var PulseMaterial = function PulseMaterial() { } }; + // JSON export + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]], + 'dTime' : this._dTime + }; + + 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; + this._texMap = jObj.texture; + if (jObj.dTime) + this._dTime = jObj.dTime; + } + 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..f4a4baa2 100644 --- a/js/lib/rdge/materials/radial-blur-material.js +++ b/js/lib/rdge/materials/radial-blur-material.js @@ -157,6 +157,38 @@ var RadialBlurMaterial = function RadialBlurMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'color' : this._propValues["color"], + '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 ); + + 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"; @@ -242,10 +274,31 @@ 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/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..c1d1913c 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -483,6 +483,182 @@ 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() + { + // 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 +715,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() ); diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index cac5a249..b7413f55 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,107 @@ var waterMaterialDef = } }; +var ParisMaterial = function ParisMaterial() +{ + // initialize the inherited members + this.inheritedFrom = WaterMaterial; + this.inheritedFrom(); + + this._name = "ParisMaterial"; + 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