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/uber-material.js') 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 ); -