From 46defc9bd11bf077efd672c72787a3b67da1a178 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 12 Mar 2012 14:59:08 -0700 Subject: Uber material changes for IO --- .../RDGE/src/core/script/MeshManager.js | 2 +- .../RDGE/src/core/script/run_state.js | 16 +-- js/lib/geom/geom-obj.js | 6 +- js/lib/rdge/materials/flat-material.js | 6 - js/lib/rdge/materials/uber-material.js | 122 ++++++++++++++++++--- 5 files changed, 121 insertions(+), 31 deletions(-) diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js index 43813078..7dfc79d4 100755 --- a/js/helper-classes/RDGE/src/core/script/MeshManager.js +++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js @@ -69,7 +69,7 @@ MeshManager.prototype.deleteMesh = function (name) if (model) { g_Engine.ctxMan.forEach(function(context) - { + { context.renderer.deletePrimitive(model.primitive); }); diff --git a/js/helper-classes/RDGE/src/core/script/run_state.js b/js/helper-classes/RDGE/src/core/script/run_state.js index acdb6797..a5981caa 100755 --- a/js/helper-classes/RDGE/src/core/script/run_state.js +++ b/js/helper-classes/RDGE/src/core/script/run_state.js @@ -30,9 +30,9 @@ RunState.prototype.Init = function() this.userRunState.init(); } - if (this.hasUserState && this.userRunState && this.userRunState.onRunState) - this.userRunState.onRunState(); - + if (this.hasUserState && this.userRunState && this.userRunState.onRunState) + this.userRunState.onRunState(); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -97,11 +97,11 @@ RunState.prototype.ReInit = function() if(!this.initialized) { this.Init(); - } - else - { - if (this.hasUserState && this.userRunState && this.userRunState.onRunState) - this.userRunState.onRunState(); + } + else + { + if (this.hasUserState && this.userRunState && this.userRunState.onRunState) + this.userRunState.onRunState(); } } diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 1a197832..35ebadb9 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -285,9 +285,11 @@ var GeomObj = function GLGeomObj() { if (mat) mat.import( importStr ); - var endIndex = importStr.indexOf( "endMaterial\n" ); + // pull off the end of the material + var endMat = "endMaterial\n"; + var endIndex = importStr.indexOf( endMat ); if (endIndex < 0) break; - importStr = importStr.substr( endIndex ); + importStr = importStr.substr( endIndex + endMat.length ); } } diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index 97e4f646..fff0e68e 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js @@ -102,13 +102,7 @@ var FlatMaterial = function FlatMaterial() { 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) { diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 655d8e2a..8ec5b05c 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -4,6 +4,7 @@ (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 UberMaterial = function UberMaterial() { @@ -375,19 +376,111 @@ var UberMaterial = function UberMaterial() { var endKey = "endMaterial\n"; var index = importStr.indexOf( endKey ); index += endKey.length; - importStr = importStr.substr( index ); + importStr = importStr.slice( 0, index ); var pu = new MaterialParser( importStr ); var matProps = pu.nextValue( "materialProps: " ); if (matProps) { - var ambientColor = Number( pu.nextValue( "ambientColor: " )); this.setProperty( "ambientColor", ambientColor ); - var diffuseColor = Number( pu.nextValue( "diffuseColor: " )); this.setProperty( "diffuseColor", diffuseColor ); - var specularColor = Number( pu.nextValue( "specularColor: " )); this.setProperty( "specularColor", specularColor ); - var specularPower = Number( pu.nextValue( "specularPower: " )); this.setProperty( "specularPower", specularPower ); + 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( "theLights" ); + 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( "envReflection" ) ) ); + } + + this.rebuildShader(); } this.export = function() @@ -428,20 +521,18 @@ var UberMaterial = function UberMaterial() { else if (light.type === 'spot') { exportStr += 'light' + i + 'Pos: ' + light['position'] + '\n'; - - var deg2Rad = Math.PI / 180; - exportStr += 'light' + i + 'Spot: ' + [ Math.cos( ( light['spotInnerCutoff'] || 45.0 ) * deg2Rad ), - Math.cos( ( light['spotOuterCutoff'] || 90.0 ) * deg2Rad )] + '\n'; + exportStr += 'light' + i + 'SpotInnerCutoff: ' + light['spotInnerCutoff'] + '\n'; + exportStr += 'light' + i + 'SpotOuterCutoff: ' + light['spotOuterCutoff'] + '\n'; } else // light.type === 'point' { - exportStr += 'light' + i + 'Pos: ' + (light['position'] || [ 0, 0, 0 ]) ; - exportStr += 'light' + i + 'Attenuation: ' + (light['attenuation'] || [ 1, 0, 0 ]) ; + exportStr += 'light' + i + 'Pos: ' + (light['position'] || [ 0, 0, 0 ]) + '\n'; + exportStr += 'light' + i + 'Attenuation: ' + (light['attenuation'] || [ 1, 0, 0 ]) + '\n'; } // common to all lights - exportStr += 'light' + i + 'Color: ' + light['diffuseColor'] || [ 1,1,1,1 ] + '\n'; - exportStr += 'light' + i + 'SpecularColor: ' + light['specularColor'] || [ 1, 1, 1, 1 ] + '\n'; + exportStr += 'light' + i + 'Color: ' + (light['diffuseColor'] || [ 1,1,1,1 ]) + '\n'; + exportStr += 'light' + i + 'SpecularColor: ' + (light['specularColor'] || [ 1, 1, 1, 1 ]) + '\n'; exportStr += "endlight\n"; } @@ -466,7 +557,10 @@ var UberMaterial = function UberMaterial() { exportStr += "specularMap: " + caps.specularMap.texture + "\n"; if(typeof caps.environmentMap != 'undefined') + { exportStr += "environmentMap: " + caps.environmentMap.texture + "\n"; + exportStr += "envReflection: " + caps.environmentMap.envReflection + "\n"; + } // every material needs to terminate like this exportStr += "endMaterial\n"; -- cgit v1.2.3 From 9b40878fcc82d3ec08361e30d2029de261f0f80e Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 13 Mar 2012 16:32:46 -0700 Subject: Fixed BumpMetal material --- assets/canvas-runtime.js | 58 ++++++++++++++++++++++++++------ js/document/html-document.js | 12 +++++-- js/helper-classes/3D/vec-utils.js | 71 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 127 insertions(+), 14 deletions(-) diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index 655e52fa..51c1de1f 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -4,6 +4,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ + + /////////////////////////////////////////////////////////////////////// //Loading webGL/canvas data function initWebGl (rootElement, directory) { @@ -27,7 +29,8 @@ function CanvasDataManager() { this.loadGLData = function(root, valueArray, assetPath ) { - this._assetPath = assetPath.slice(); + if (assetPath) + this._assetPath = assetPath.slice(); var value = valueArray; var nWorlds = value.length; @@ -118,17 +121,22 @@ function GLRuntime( canvas, importStr, assetPath ) this._zFar = 100.0; this._viewDist = 5.0; + this.elapsed = 0; + this._aspect = canvas.width/canvas.height; - this._geomRoot; + this._geomRoot = null; // all "live" materials this._materials = []; // provide the mapping for the asset directory - this._assetPath = assetPath.slice(); - if (this._assetPath[this._assetPath.length-1] != '/') - this._assetPath += '/'; + if (assetPath) + { + this._assetPath = assetPath.slice(); + if (this._assetPath[this._assetPath.length-1] != '/') + this._assetPath += '/'; + } /////////////////////////////////////////////////////////////////////// // accessors @@ -166,6 +174,7 @@ function GLRuntime( canvas, importStr, assetPath ) this.importObjects( importStr ); this.linkMaterials( this._geomRoot ); this.initMaterials(); + this.linkLights(); } else { @@ -221,8 +230,8 @@ function GLRuntime( canvas, importStr, assetPath ) rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); // orbit the light nodes around the boxes - //this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); - //this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); + if (this.light ) this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); + if (this.light2) this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); this.updateMaterials(); @@ -344,6 +353,16 @@ function GLRuntime( canvas, importStr, assetPath ) parent.addChild( obj ); } + this.linkLights = function() + { + var matNode = this.findMaterialNode( "lights", this.myScene.scene ); + if (matNode) + { + this.light = matNode.lightChannel[1]; + this.light2 = matNode.lightChannel[2]; + } + } + this.linkMaterials = function( obj ) { if (!obj) return; @@ -377,6 +396,7 @@ function GLRuntime( canvas, importStr, assetPath ) this.remapAssetFolder = function( url ) { + /* var searchStr = "assets/"; var index = url.indexOf( searchStr ); var rtnPath = url; @@ -386,6 +406,8 @@ function GLRuntime( canvas, importStr, assetPath ) rtnPath = this._assetPath + rtnPath; } return rtnPath; + */ + return url; } this.findMaterialNode = function( nodeName, node ) @@ -1080,7 +1102,7 @@ function RuntimeMaterial( world ) /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - this.init = function() + this.init = function( world ) { } @@ -1127,7 +1149,7 @@ function RuntimeFlatMaterial() }; - this.init = function() + this.init = function( world ) { if (this._shader) { @@ -1302,7 +1324,7 @@ function RuntimeBumpMetalMaterial() this._normalTexture = this.getPropertyFromString( "normalMap: ", importStr ); } - this.init = function() + this.init = function( world ) { var material = this._materialNode; if (material) @@ -1322,7 +1344,6 @@ function RuntimeBumpMetalMaterial() this._diffuseTexture = world.remapAssetFolder( this._diffuseTexture ); tex = renderer.getTextureByName(this._diffuseTexture, wrap, mips ); if (tex) technique.u_colMap.set( tex ); - } if (this._normalTexture) { @@ -1344,6 +1365,21 @@ function RuntimeBumpMetalMaterial() function RuntimeUberMaterial() { + // inherit the members of RuntimeMaterial + this.inheritedFrom = RuntimeMaterial; + this.inheritedFrom(); + + this.init = function( ) + { + } + + this.update = function( time ) + { + } + + this.import = function( importStr ) + { + } } function RuntimePlasmaMaterial() diff --git a/js/document/html-document.js b/js/document/html-document.js index 051490f5..f4ec3184 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -207,9 +207,17 @@ exports.HTMLDocument = Montage.create(TextDocument, { }, set: function(value) { var elt = this.documentRoot; - if (elt) { + if (elt) + { var nWorlds= value.length; - for (var i=0; i= 0) { diff --git a/js/helper-classes/3D/vec-utils.js b/js/helper-classes/3D/vec-utils.js index 3db95ab7..e6db4a8d 100755 --- a/js/helper-classes/3D/vec-utils.js +++ b/js/helper-classes/3D/vec-utils.js @@ -191,5 +191,74 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype, return vec; } - } + }, + + matI : + { + value: function(dimen) + { + var mat = []; + for (var i=0; i= 0) { @@ -244,6 +245,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } } + // */ } } } diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 8ec5b05c..91f43754 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -477,7 +477,7 @@ var UberMaterial = function UberMaterial() { if(environmentMap) { this.setProperty( "environmentMap", environmentMap ); - this.setProperty( "environmentAmount", Number( pu.nextValue( "envReflection" ) ) ); + this.setProperty( "environmentAmount", Number( pu.nextValue( "environmentAmount" ) ) ); } this.rebuildShader(); @@ -495,10 +495,10 @@ var UberMaterial = function UberMaterial() { if (typeof caps.material != 'undefined') { exportStr += "materialProps: true\n"; - exportStr += "ambientColor: " + caps.material.ambientColor + "\n"; - exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n"; - exportStr += "specularColor: " + caps.material.specularColor + "\n"; - exportStr += "specularPower: " + caps.material.specularPower + "\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') @@ -559,7 +559,7 @@ var UberMaterial = function UberMaterial() { if(typeof caps.environmentMap != 'undefined') { exportStr += "environmentMap: " + caps.environmentMap.texture + "\n"; - exportStr += "envReflection: " + caps.environmentMap.envReflection + "\n"; + exportStr += "environmentAmount: " + caps.environmentMap.envReflection + "\n"; } // every material needs to terminate like this -- cgit v1.2.3