From cc3b66f817c9d72ca247d5ff789a08ec5b57a2b5 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 22 May 2012 08:38:38 -0700 Subject: Editable material properties --- js/lib/drawing/world.js | 20 ++++---- js/lib/rdge/materials/bump-metal-material.js | 58 ++++++++++++---------- js/lib/rdge/materials/uber-material.js | 1 + .../materials-popup.reel/materials-popup.js | 12 ++++- 4 files changed, 54 insertions(+), 37 deletions(-) (limited to 'js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 14e63f4a..3c93b2b7 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -180,14 +180,14 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { // create some lights // light 1 - this.light = RDGE.createLightNode("myLight"); - this.light.setPosition([0,0,1.2]); - this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); +// this.light = RDGE.createLightNode("myLight"); +// this.light.setPosition([0,0,1.2]); +// this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); // light 2 - this.light2 = RDGE.createLightNode("myLight2"); - this.light2.setPosition([-0.5,0,1.2]); - this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); +// this.light2 = RDGE.createLightNode("myLight2"); +// this.light2.setPosition([-0.5,0,1.2]); +// this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); // create a light transform var lightTr = RDGE.createTransformNode("lightTr"); @@ -196,8 +196,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { lightTr.attachMaterial(RDGE.createMaterialNode("lights")); // enable light channels 1, 2 - channel 0 is used by the default shader - lightTr.materialNode.enableLightChannel(1, this.light); - lightTr.materialNode.enableLightChannel(2, this.light2); +// lightTr.materialNode.enableLightChannel(1, this.light); +// lightTr.materialNode.enableLightChannel(2, this.light2); // all added objects are parented to the light node this._rootNode = lightTr; @@ -225,8 +225,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { RDGE.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)]); +// 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)]); } this.updateMaterials( this.getGeomRoot(), this.elapsed ); diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js index 4bc5dfe8..4d19c9c1 100755 --- a/js/lib/rdge/materials/bump-metal-material.js +++ b/js/lib/rdge/materials/bump-metal-material.js @@ -28,6 +28,8 @@ var BumpMetalMaterial = function BumpMetalMaterial() { // keep the array of initialized textures this._textures = []; + this._speed = 1.0; + /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// @@ -67,15 +69,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { /////////////////////////////////////////////////////////////////////// // Material Property Accessors /////////////////////////////////////////////////////////////////////// - this._propNames = ["lightDiff", "diffuseTexture", "normalMap", "specularTexture"]; - this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map", "Specular Map"]; - this._propTypes = ["color", "file", "file", "file"]; + this._propNames = ["lightDiff", "diffuseTexture", "normalMap" ]; + this._propLabels = ["Diffuse Color", "Diffuse Map", "Bump Map" ]; + this._propTypes = ["color", "file", "file" ]; this._propValues = []; this._propValues[ this._propNames[0] ] = this._lightDiff.slice(0); this._propValues[ this._propNames[1] ] = this._diffuseTexture.slice(0); this._propValues[ this._propNames[2] ] = this._normalTexture.slice(0); - this._propValues[ this._propNames[3] ] = this._specularTexture.slice(0); // TODO - shader techniques are not all named the same, i.e., FlatMaterial uses "colorMe" and BrickMaterial uses "default" this.setProperty = function( prop, value ) @@ -127,7 +128,6 @@ var BumpMetalMaterial = function BumpMetalMaterial() { this._materialNode = RDGE.createMaterialNode( this.getShaderName() + "_" + world.generateUniqueNodeID() ); this._materialNode.setShader(this._shader); - // DEBUG CODE this.initTextures(); }; @@ -137,8 +137,14 @@ var BumpMetalMaterial = function BumpMetalMaterial() { if (dstWorld) { var texMapName = this._propValues[this._propNames[index]]; - var texture = new Texture( dstWorld, texMapName ); - this._textures[index] = texture; + if (texMapName) + { + var texture = new Texture( dstWorld, texMapName ); + this._textures[index] = texture; + } + else + this._textures[index] = null; + this.updateTexture( index ); } } @@ -165,24 +171,25 @@ var BumpMetalMaterial = function BumpMetalMaterial() { var renderer = RDGE.globals.engine.getContext().renderer; if (renderer && technique) { - var glTex = this._textures[ index ]; - if (glTex) - { - if (glTex.isAnimated()) - glTex.render(); - - 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 ); - } - } - } + var glTex = this._textures[ index ]; + var tex; + if (glTex) + { + if (glTex.isAnimated()) + glTex.render(); + + tex = glTex.getTexture(); + } + + { + 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 ); + } + } } } }; @@ -291,7 +298,6 @@ var bumpMetalMaterialDef = bumpMetalShaderDef = 'params' : { 'u_light0Diff' : { 'type' : 'vec4' }, - //'u_matDiffuse' : { 'type' : 'vec4' } 'u_colMap': { 'type' : 'tex2d' }, 'u_normalMap': { 'type' : 'tex2d' }, 'u_glowMap': { 'type' : 'tex2d' } diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 9d0cc564..6de74495 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js @@ -180,6 +180,7 @@ var UberMaterial = function UberMaterial() { this.updateAmbientColor = function () { this._ambientColor = this._propValues['ambientColor'].slice(0); var material = this._materialNode; + console.log( "ambient color: " + this._ambientColor ); if (material) { var technique = material.shaderProgram.defaultTechnique; technique.u_ambientColor.set(this._ambientColor); diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js index c54b311e..1e92e144 100755 --- a/js/panels/Materials/materials-popup.reel/materials-popup.js +++ b/js/panels/Materials/materials-popup.reel/materials-popup.js @@ -18,6 +18,8 @@ exports.MaterialsPopup = Montage.create(Component, { value: "" }, + _useSelection: { value: false, enumerable: true }, + captureAction: { value:function(event) { switch(event._currentTarget.label) @@ -134,6 +136,11 @@ exports.MaterialsPopup = Montage.create(Component, { var value = this.decodeValue( this._propTypes[index], propValue ); this._material.setProperty( this._propNames[index], value ); } + + if (this._useSelection) + { + console.log( "apply to selection" ); + } } } }, @@ -224,6 +231,7 @@ exports.MaterialsPopup = Montage.create(Component, { this._materialName = materialID; if (useSelection) { + this._useSelection = true; var selection = this.application.ninja.selectedElements; if (selection && (selection.length > 0)) { @@ -236,6 +244,8 @@ exports.MaterialsPopup = Montage.create(Component, { } else { + this._useSelection = false; + if( (materialID === "BumpMetalMaterial") || (materialID === "DeformMaterial") || @@ -342,7 +352,7 @@ exports.MaterialsPopup = Montage.create(Component, { { value: function( label, color ) { - var css = 'rgba(' + color[0]*255 + ',' + color[1]*255 + ',' + color[2]*255 + ',' + color[3] + ')'; + var css = 'rgba(' + Math.floor(color[0]*255) + ',' + Math.floor(color[1]*255) + ',' + Math.floor(color[2]*255) + ',' + color[3] + ')'; var colorObj = this.application.ninja.colorController.getColorObjFromCss(css) var obj = { -- cgit v1.2.3