From 00cd98e49c959906d7c44bb6adcdef1f3d5148ae Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 22 Mar 2012 13:52:09 -0700 Subject: Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Texture Conflicts: assets/shaders/plasma.frag.glsl js/helper-classes/RDGE/GLLine.js js/helper-classes/RDGE/MaterialsLibrary.js js/lib/drawing/world.js js/lib/geom/circle.js js/lib/geom/rectangle.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/material.js js/panels/Materials/Materials.xml js/panels/Materials/materials-popup.reel/materials-popup.js js/preloader/Preloader.js --- js/lib/rdge/materials/bump-metal-material.js | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (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..fe8a9dd5 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -6,6 +6,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot 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. @@ -18,7 +20,9 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._shaderName = "bumpMetal"; this._lightDiff = [0.3, 0.3, 0.3, 1.0]; - this._diffuseTexture = "assets/images/metal.png"; + //this._diffuseTexture = "assets/images/metal.png"; + this._diffuseTexture = "texture"; + this._diffuseWorld = null; // the world that the texture is derived from (if there is one). this._specularTexture = "assets/images/silver.png"; this._normalTexture = "assets/images/normalMap.png"; @@ -119,12 +123,46 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._materialNode = createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); this._materialNode.setShader(this._shader); + // DEBUG CODE + this.initWorldTextures(); + // set some image maps this.updateTexture(1); this.updateTexture(2); this.updateTexture(3); }; + this.initWorldTextures = function() + { + // find the world with the given id + var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; + var root = viewUtils.application.ninja.currentDocument.documentRoot; + this._diffuseWorld = this.findWorld( this._diffuseTexture, root ); + } + + this.findWorld = function( id, elt ) + { + if (elt.id && elt.id === id) + { + if (elt.eltModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) + { + var world = elt.elementModel.shapeModel.GLWorld; + return world; + } + } + + if (elt.children) + { + var nKids = elt.children.length; + for (var i=0; i */ var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; +var Texture = require("js/lib/rdge/texture").Texture; var Material = require("js/lib/rdge/materials/material").Material; /////////////////////////////////////////////////////////////////////// // Class GLMaterial // RDGE representation of a material. /////////////////////////////////////////////////////////////////////// -var PulseMaterial = function PulseMaterial() { +var PulseMaterial = function PulseMaterial() +{ + var MaterialLibrary = require("js/models/materials-model").MaterialsModel; + + // initialize the inherited members + this.inheritedFrom = Material; + this.inheritedFrom(); + /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// this._name = "PulseMaterial"; this._shaderName = "pulse"; - this._texMap = 'assets/images/cubelight.png'; + //this._texMap = 'assets/images/cubelight.png'; + this._texMap = 'texture'; this._time = 0.0; this._dTime = 0.01; @@ -109,6 +118,16 @@ var PulseMaterial = function PulseMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // check if the texture uses a canvas as the source + var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; + var root = viewUtils.application.ninja.currentDocument.documentRoot; + var texMapName = this._propValues[this._propNames[0]]; + var texWorld = this.findWorld( texMapName, root ); + if (texWorld) + { + this._glTex = new Texture( this.getWorld() ); + this._glTex.loadFromCanvas( texWorld.getCanvas() ); + } // set the shader values in the shader this.updateTexture(); @@ -122,9 +141,18 @@ var PulseMaterial = function PulseMaterial() { var technique = material.shaderProgram['default']; var renderer = g_Engine.getContext().renderer; if (renderer && technique) { - var texMapName = this._propValues[this._propNames[0]]; var wrap = 'REPEAT', mips = true; - var tex = this.loadTexture( texMapName, wrap, mips ); + var tex; + if (this._glTex) + { + this._glTex.rerender(); + tex = this._glTex.getTexture(); + } + else + { + var texMapName = this._propValues[this._propNames[0]]; + tex = this.loadTexture( texMapName, wrap, mips ); + } if (tex) { technique.u_tex0.set( tex ); @@ -138,6 +166,9 @@ var PulseMaterial = function PulseMaterial() { var material = this._materialNode; if (material) { + if (this._glTex && this._glTex.isAnimated()) + this.updateTexture(); + var technique = material.shaderProgram['default']; var renderer = g_Engine.getContext().renderer; if (renderer && technique) { @@ -279,7 +310,8 @@ var pulseMaterialDef = } }; -PulseMaterial.prototype = new Material(); +// doing the inheritance here introtudes bugs. Local instance variables are overwritten in the base class +//PulseMaterial.prototype = new Material(); if (typeof exports === "object") { exports.PulseMaterial = PulseMaterial; -- cgit v1.2.3 From d7269673dc1f5caf6df3765c6b669d3d1a93bdb1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 27 Mar 2012 04:53:27 -0700 Subject: Integrated texture wrapper into pulse and bump-metal materials. --- js/lib/rdge/materials/bump-metal-material.js | 89 ++++++++++++++------------ js/lib/rdge/materials/material.js | 95 ---------------------------- js/lib/rdge/materials/pulse-material.js | 38 +++++------ 3 files changed, 64 insertions(+), 158 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 a3ef9d37..0570e8ed 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -21,14 +21,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._lightDiff = [0.3, 0.3, 0.3, 1.0]; - //this._diffuseTexture = "assets/images/metal.png"; - this._diffuseTexture = "texture"; - this._diffuseWorld = null; // the world that the texture is derived from (if there is one). - this._diffuseTextureObj = null; - + this._diffuseTexture = "assets/images/metal.png"; + //this._diffuseTexture = "texture"; this._specularTexture = "assets/images/silver.png"; this._normalTexture = "assets/images/normalMap.png"; + // keep the array of initialized textures + this._textures = []; + /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// @@ -55,13 +55,13 @@ var BumpMetalMaterial = function BumpMetalMaterial() { }; this.getDiffuseTexture = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null }; - this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.updateTexture(1); }; + this.setDiffuseTexture = function(m) { this._propValues[this._propNames[1]] = m ? m.slice(0) : null; this.initTexture(1); }; this.getNormalTexture = function() { return this._propValues[this._propNames[2]] ? this._propValues[this._propNames[2]].slice() : null }; - this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.updateTexture(2); }; + this.setNormalTexture = function(m) { this._propValues[this._propNames[2]] = m ? m.slice(0) : null; this.initTexture(2); }; this.getSpecularTexture = function() { return this._propValues[this._propNames[3]] ? this._propValues[this._propNames[3]].slice() : null }; - this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.updateTexture(3); }; + this.setSpecularTexture = function(m) { this._propValues[this._propNames[3]] = m ? m.slice(0) : null; this.initTexture(3); }; this.isAnimated = function() { return true; }; @@ -127,29 +127,34 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._materialNode.setShader(this._shader); // DEBUG CODE - this.initWorldTextures(); - - // set some image maps - this.updateTexture(1); - this.updateTexture(2); - this.updateTexture(3); + this.initTextures(); }; - this.initWorldTextures = function() + this.initTexture = function( index ) { - // find the world with the given id - var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; - var root = viewUtils.application.ninja.currentDocument.documentRoot; - this._diffuseWorld = this.findWorld( this._diffuseTexture, root ); - if (this._diffuseWorld) + var dstWorld = this.getWorld(); + if (dstWorld) { - var world = this.getWorld(); - var tex = new Texture( world ); - this._diffuseTextureObj = tex; - tex.loadFromCanvas( this._diffuseWorld.getCanvas() ); + var texMapName = this._propValues[this._propNames[index]]; + var texture = new Texture( dstWorld, texMapName ); + this._textures[index] = texture; + this.updateTexture( index ); } } + this.initTextures = function() + { + var dstWorld = this.getWorld(); + if (dstWorld) + { + // find the world with the given id + for (var i=1; i<=3; i++) + { + this.initTexture( i ); + } + } + } + this.updateTexture = function( index ) { var material = this._materialNode; @@ -159,24 +164,24 @@ var BumpMetalMaterial = function BumpMetalMaterial() { var renderer = g_Engine.getContext().renderer; if (renderer && technique) { - var texMapName = this._propValues[this._propNames[index]]; - var wrap = 'REPEAT', mips = true; - var tex; - if ((index === 1) && this._diffuseTextureObj) - tex = this._diffuseTextureObj.getTexture(); - else - tex = this.loadTexture( texMapName, wrap, mips ); - - if (tex) - { - switch (index) - { - case 1: technique.u_colMap.set( tex ); break; - case 2: technique.u_normalMap.set( tex ); break; - case 3: technique.u_glowMap.set( tex ); break; - default: console.log( "invalid map index in BumpMetalMaterial, " + index ); - } - } + var glTex = this._textures[ index ]; + if (glTex) + { + if (glTex.isAnimated()) + glTex.rerender(); + + var tex = glTex.getTexture(); + if (tex) + { + switch (index) + { + case 1: technique.u_colMap.set( tex ); break; + case 2: technique.u_normalMap.set( tex ); break; + case 3: technique.u_glowMap.set( tex ); break; + default: console.log( "invalid map index in BumpMetalMaterial, " + index ); + } + } + } } } }; diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 157fa7db..13251ce8 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -252,29 +252,6 @@ var Material = function GLMaterial( world ) { return tex; }; - this.findWorld = function( id, elt ) - { - if (elt.id && elt.id === id) - { - if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) - { - var world = elt.elementModel.shapeModel.GLWorld; - return world; - } - } - - if (elt.children) - { - var nKids = elt.children.length; - for (var i=0; i */ -var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; var Texture = require("js/lib/rdge/texture").Texture; var Material = require("js/lib/rdge/materials/material").Material; /////////////////////////////////////////////////////////////////////// @@ -220,7 +219,7 @@ var PulseMaterial = function PulseMaterial() } } - + /* this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; @@ -261,6 +260,7 @@ var PulseMaterial = function PulseMaterial() return rtnStr; } + */ }; /////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/lib/rdge/materials/relief-tunnel-material.js b/js/lib/rdge/materials/relief-tunnel-material.js index 52c40543..24fc885f 100644 --- a/js/lib/rdge/materials/relief-tunnel-material.js +++ b/js/lib/rdge/materials/relief-tunnel-material.js @@ -6,8 +6,10 @@ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; -var ReliefTunnelMaterial = function ReliefTunnelMaterial() { +var ReliefTunnelMaterial = function ReliefTunnelMaterial() +{ /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// @@ -62,6 +64,9 @@ var ReliefTunnelMaterial = function ReliefTunnelMaterial() { this._shader['default'].u_time.set( [this._time] ); } + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); -- cgit v1.2.3 From 947bad893335e1023bcbe177ff8db454c27c4bf8 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 30 Mar 2012 06:23:53 -0700 Subject: converted materials to new texture structure --- js/lib/rdge/materials/deform-material.js | 5 +++++ js/lib/rdge/materials/fly-material.js | 5 +++++ js/lib/rdge/materials/julia-material.js | 5 +++++ js/lib/rdge/materials/keleidoscope-material.js | 5 +++++ js/lib/rdge/materials/mandel-material.js | 5 +++++ js/lib/rdge/materials/pulse-material.js | 8 +++++--- js/lib/rdge/materials/square-tunnel-material.js | 5 +++++ js/lib/rdge/materials/star-material.js | 5 +++++ js/lib/rdge/materials/tunnel-material.js | 5 +++++ js/lib/rdge/materials/twist-material.js | 5 +++++ js/lib/rdge/materials/water-material.js | 4 ++++ js/lib/rdge/materials/z-invert-material.js | 5 +++++ 12 files changed, 59 insertions(+), 3 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/deform-material.js b/js/lib/rdge/materials/deform-material.js index dfd89d12..c7bfe67a 100644 --- a/js/lib/rdge/materials/deform-material.js +++ b/js/lib/rdge/materials/deform-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var DeformMaterial = function DeformMaterial() { /////////////////////////////////////////////////////////////////////// @@ -68,6 +69,10 @@ var DeformMaterial = function DeformMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index bd92ecd8..81cd1522 100644 --- a/js/lib/rdge/materials/fly-material.js +++ b/js/lib/rdge/materials/fly-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var FlyMaterial = function FlyMaterial() { /////////////////////////////////////////////////////////////////////// @@ -61,6 +62,10 @@ var FlyMaterial = function FlyMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/julia-material.js b/js/lib/rdge/materials/julia-material.js index a85bd6f7..c1eb2b6d 100644 --- a/js/lib/rdge/materials/julia-material.js +++ b/js/lib/rdge/materials/julia-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var JuliaMaterial = function JuliaMaterial() { /////////////////////////////////////////////////////////////////////// @@ -59,6 +60,10 @@ var JuliaMaterial = function JuliaMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); this.update( 0 ); diff --git a/js/lib/rdge/materials/keleidoscope-material.js b/js/lib/rdge/materials/keleidoscope-material.js index 16d1ccfa..a687bd59 100644 --- a/js/lib/rdge/materials/keleidoscope-material.js +++ b/js/lib/rdge/materials/keleidoscope-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var KeleidoscopeMaterial = function KeleidoscopeMaterial() { /////////////////////////////////////////////////////////////////////// @@ -68,6 +69,10 @@ var KeleidoscopeMaterial = function KeleidoscopeMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/mandel-material.js b/js/lib/rdge/materials/mandel-material.js index e7b105e1..4babe239 100644 --- a/js/lib/rdge/materials/mandel-material.js +++ b/js/lib/rdge/materials/mandel-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var MandelMaterial = function MandelMaterial() { /////////////////////////////////////////////////////////////////////// @@ -70,6 +71,10 @@ var MandelMaterial = function MandelMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); this.update( 0 ); diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index b12e9dd5..f7f6c7ae 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -4,8 +4,9 @@ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var Texture = require("js/lib/rdge/texture").Texture; var Material = require("js/lib/rdge/materials/material").Material; +var Texture = require("js/lib/rdge/texture").Texture; + /////////////////////////////////////////////////////////////////////// // Class GLMaterial // RDGE representation of a material. @@ -24,8 +25,8 @@ var PulseMaterial = function PulseMaterial() this._name = "PulseMaterial"; this._shaderName = "pulse"; - this._texMap = 'assets/images/cubelight.png'; - //this._texMap = 'texture'; + //this._texMap = 'assets/images/cubelight.png'; + this._texMap = 'texture'; this._time = 0.0; this._dTime = 0.01; @@ -117,6 +118,7 @@ var PulseMaterial = function PulseMaterial() this._shader['default'].u_time.set( [this._time] ); } + // set up the texture var texMapName = this._propValues[this._propNames[0]]; this._glTex = new Texture( world, texMapName ); diff --git a/js/lib/rdge/materials/square-tunnel-material.js b/js/lib/rdge/materials/square-tunnel-material.js index 9264872f..6e987fdc 100644 --- a/js/lib/rdge/materials/square-tunnel-material.js +++ b/js/lib/rdge/materials/square-tunnel-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var SquareTunnelMaterial = function SquareTunnelMaterial() { /////////////////////////////////////////////////////////////////////// @@ -63,6 +64,10 @@ var SquareTunnelMaterial = function SquareTunnelMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/star-material.js b/js/lib/rdge/materials/star-material.js index d7d797e4..1506927b 100644 --- a/js/lib/rdge/materials/star-material.js +++ b/js/lib/rdge/materials/star-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var StarMaterial = function StarMaterial() { /////////////////////////////////////////////////////////////////////// @@ -63,6 +64,10 @@ var StarMaterial = function StarMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/tunnel-material.js b/js/lib/rdge/materials/tunnel-material.js index fe0fbd51..aa93d5ba 100644 --- a/js/lib/rdge/materials/tunnel-material.js +++ b/js/lib/rdge/materials/tunnel-material.js @@ -6,6 +6,7 @@ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var TunnelMaterial = function TunnelMaterial() { /////////////////////////////////////////////////////////////////////// @@ -64,6 +65,10 @@ var TunnelMaterial = function TunnelMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/twist-material.js b/js/lib/rdge/materials/twist-material.js index 163c8a77..d0a2d8c4 100644 --- a/js/lib/rdge/materials/twist-material.js +++ b/js/lib/rdge/materials/twist-material.js @@ -6,6 +6,7 @@ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; /////////////////////////////////////////////////////////////////////// var TwistMaterial = function TwistMaterial() { @@ -64,6 +65,10 @@ var TwistMaterial = function TwistMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/water-material.js b/js/lib/rdge/materials/water-material.js index b7413f55..2512e5be 100644 --- a/js/lib/rdge/materials/water-material.js +++ b/js/lib/rdge/materials/water-material.js @@ -5,6 +5,7 @@ */ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; /////////////////////////////////////////////////////////////////////// // Class GLMaterial @@ -67,6 +68,9 @@ var WaterMaterial = function WaterMaterial() { this._shader['default'].u_time.set( [this._time] ); } + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); diff --git a/js/lib/rdge/materials/z-invert-material.js b/js/lib/rdge/materials/z-invert-material.js index a0d20de5..0d62d1b0 100644 --- a/js/lib/rdge/materials/z-invert-material.js +++ b/js/lib/rdge/materials/z-invert-material.js @@ -6,6 +6,7 @@ var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; var ZInvertMaterial = function ZInvertMaterial() { /////////////////////////////////////////////////////////////////////// @@ -63,6 +64,10 @@ var ZInvertMaterial = function ZInvertMaterial() { this._shader['default'].u_time.set( [this._time] ); } + // set up the texture + var texMapName = this._propValues[this._propNames[0]]; + this._glTex = new Texture( world, texMapName ); + // set the shader values in the shader this.updateTexture(); this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); -- cgit v1.2.3 From 19c975cfb16f1cccc9e9f86255575499315d421e Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 10:23:28 -0700 Subject: texture abstraction --- js/lib/rdge/materials/uber-material.js | 232 +++++---------------------------- 1 file changed, 34 insertions(+), 198 deletions(-) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index c1d1913c..ca244629 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -6,6 +6,7 @@ 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; var UberMaterial = function UberMaterial() { /////////////////////////////////////////////////////////////////////// @@ -23,7 +24,8 @@ var UberMaterial = function UberMaterial() { this._environmentAmount = 0.2; // 0 .. 1 // set the default maps - this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; + //this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' }; + this._diffuseMapOb = { 'texture' : 'texture', '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 }; @@ -34,6 +36,9 @@ var UberMaterial = function UberMaterial() { this._useEnvironmentMap = true; this._useLights = [true, true, true, true]; + // these are the abstracted texture objects - defined where they are set + this._diffuseTexture; + this._MAX_LIGHTS = 4; /////////////////////////////////////////////////////////////////////// @@ -189,6 +194,7 @@ var UberMaterial = function UberMaterial() { if (material) { var technique = material.shaderProgram.defaultTechnique; technique.u_diffuseColor.set(this._diffuseColor); + this.getWorld().restartRenderLoop(); } }; @@ -258,6 +264,7 @@ var UberMaterial = function UberMaterial() { if ((value == null) || (value.length == 0)) { if (this._useDiffuseMap) { this._useDiffuseMap = false; + this._diffuseTexture = undefined; this.rebuildShader(); } } else { @@ -270,8 +277,8 @@ var UberMaterial = function UberMaterial() { var technique = material.shaderProgram.defaultTechnique; var renderer = g_Engine.getContext().renderer; if (renderer && technique) { - var tex = renderer.getTextureByName(value, caps.diffuseMap.wrap); - this.registerTexture( tex ); + this._diffuseTexture = new Texture( this.getWorld(), value, caps.diffuseMap.wrap ); + var tex = this._diffuseTexture.getTexture(); technique.s_diffuseMap.set( tex ); } } @@ -370,118 +377,29 @@ var UberMaterial = function UberMaterial() { this._materialNode.setShader(this._shader); }; - this.import = function( importStr ) - { - // limit the key searches to this material - var endKey = "endMaterial\n"; - var index = importStr.indexOf( endKey ); - index += endKey.length; - importStr = importStr.slice( 0, index ); - var pu = new MaterialParser( importStr ); - - var matProps = pu.nextValue( "materialProps: " ); - if (matProps) - { - var ambientColor = eval( "[" + pu.nextValue("ambientColor: ") + ']' ); this.setProperty( "ambientColor", ambientColor ); - var diffuseColor = eval( "[" + pu.nextValue( "diffuseColor: ") + ']' ); this.setProperty( "diffuseColor", diffuseColor ); - var specularColor = eval( "[" + pu.nextValue( "specularColor: ") + ']' ); this.setProperty( "specularColor", specularColor ); - var specularPower = eval( "[" + pu.nextValue( "specularPower: ") + ']' ); this.setProperty( "specularPower", specularPower ); - } - - var lightProps = pu.nextValue( "lightProps: " ); - if (lightProps) - { - this._lights = []; - var lightStr; - 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 = pu.nextValue( "diffuseMap: " ) - if(diffuseMap) - this.setProperty( "diffuseMap", diffuseMap ); - - var normalMap = pu.nextValue( "normalMap: " ); - if(normalMap) - this.setProperty( "normalMap", normalMap ); - - var specularMap = pu.nextValue( "specularMap: " ); - if(specularMap) - this.setProperty( "specularMap", specularMap ); - - var environmentMap = pu.nextValue( "environmentMap: " ); - if(environmentMap) - { - this.setProperty( "environmentMap", environmentMap ); - this.setProperty( "environmentAmount", Number( pu.nextValue( "environmentAmount" ) ) ); - } + this.update = function() + { + var material = this._materialNode; + if (material) + { + var technique = material.shaderProgram.defaultTechnique; + var renderer = g_Engine.getContext().renderer; + if (renderer && technique) + { + if (this._diffuseTexture && this._diffuseTexture.isAnimated()) + { + this._diffuseTexture.rerender(); + technique.s_diffuseMap.set( this._diffuseTexture.getTexture() ); + } + } + } + } - this.rebuildShader(); - } + this.isAnimated = function() + { + var anim = (this._diffuseTexture && this._diffuseTexture.isAnimated()); + return anim; + } this.importJSON = function( jObj ) { @@ -658,88 +576,6 @@ var UberMaterial = function UberMaterial() { return 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 caps = this._ubershaderCaps; - - // export the material properties - if (typeof caps.material != 'undefined') - { - exportStr += "materialProps: true\n"; - exportStr += "ambientColor: " + this._ambientColor + "\n"; - exportStr += "diffuseColor: " + this._diffuseColor + "\n"; - exportStr += "specularColor: " + this._specularColor + "\n"; - exportStr += "specularPower: " + this._specularPower + "\n"; - } - - if (typeof caps.lighting != 'undefined') - { - exportStr += "lightProps: true\n"; - - var light = caps.lighting['light' + i]; - for (var i=0; i + 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 PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var Texture = require("js/lib/rdge/texture").Texture; + +var FlagMaterial = function FlagMaterial() { + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "FlagMaterial"; + this._shaderName = "flag"; + + this._texMap = 'assets/images/us_flag.png'; + + this._time = 0.0; + this._dTime = 0.1; + + this._defaultWaveWidth = 1.0; + this._defaultWaveHeight = 1.0; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propNames = ["texmap", "wavewidth", "waveheight" ]; + this._propLabels = ["Texture map", "Wave Width", "Wave Height" ]; + this._propTypes = ["file", "float", "float" ]; + this._propValues = []; + + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + this._propValues[ this._propNames[1] ] = this._defaultWaveWidth; + this._propValues[ this._propNames[2] ] = this._defaultWaveHeight; + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) { + // allocate a new uber material + var newMat = new FlagMaterial(); + + // 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 */ -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 TaperMaterial() +var TaperMaterial = function TaperMaterial() { // initialize the inherited members - this.inheritedFrom = GLMaterial; + this.inheritedFrom = Material; this.inheritedFrom(); /////////////////////////////////////////////////////////////////////// @@ -250,3 +252,7 @@ taperShaderDef = } }; + +if (typeof exports === "object") { + exports.TaperMaterial = TaperMaterial; +} 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 416ce9d4954e0a7f4ee7b9afe43bf691fdb276f4 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 6 Apr 2012 05:18:48 -0700 Subject: texture notifications --- js/lib/rdge/materials/material.js | 7 +++++++ js/lib/rdge/materials/pulse-material.js | 14 ++++++++++++++ js/lib/rdge/materials/uber-material.js | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+) (limited to 'js/lib/rdge/materials') diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index a81ca18f..bc4c8e6b 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -257,6 +257,13 @@ var Material = function GLMaterial( world ) { return tex; }; + this.updateTextures = function() + { + // this function is called whenever a world that generates textuers for + // the current world changes in some way. Sub-classes with textures + // should override this function. + } + this.export = function() { // this function should be overridden by subclasses var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n"; diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 276f7de6..0a7a5dd8 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -150,6 +150,20 @@ var PulseMaterial = func