From 22cbc9644b79df60b3f6336f9563debd47fb3ea1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 28 Jun 2012 11:44:15 -0700 Subject: Added capability to split a mesh into multiiple parts to avoid buffer overflow situations. --- js/lib/rdge/materials/material.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'js/lib/rdge/materials/material.js') diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 65448c0c..34524097 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -32,16 +32,12 @@ var Material = function GLMaterial( world ) { // vertex deformation variables this._hasVertexDeformation = false; this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) - this._vertexDeformationTolerance = 0.1; + this._vertexDeformationTolerance = 0.02; // RDGE variables this._shader = null; this._materialNode = null; - // vertex deformation variables - this._hasVertexDeformation = false; - this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) - this._vertexDeformationTolerance = 0.02; /////////////////////////////////////////////////////////////////////// // Property Accessors @@ -366,6 +362,10 @@ var Material = function GLMaterial( world ) { throw new Error( "Material.init() must be overridden by subclass" ); }; + this.resetToDefault = function() { + // materials should override this functinon + }; + this.update = function( time ) { // animated materials should implement the update method }; @@ -374,6 +374,10 @@ var Material = function GLMaterial( world ) { // some materials need to preserve an aspect ratio - or someting else. }; + this.fitToPrimitiveArray = function( primArray ) { + // some materials need to preserve an aspect ratio - or someting else. + }; + this.registerTexture = function( texture ) { // the world needs to know about the texture map var world = this.getWorld(); -- cgit v1.2.3 From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/lib/rdge/materials/material.js | 574 +++++++++++++++++++------------------- 1 file changed, 287 insertions(+), 287 deletions(-) (limited to 'js/lib/rdge/materials/material.js') diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 34d3aa1f..c273611b 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -39,160 +39,160 @@ var Material = function GLMaterial( world ) { /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// - this._name = "GLMaterial"; - this._shaderName = "undefined"; + this._name = "GLMaterial"; + this._shaderName = "undefined"; - this._time = 0.0; - this._dTime = 0.01; + this._time = 0.0; + this._dTime = 0.01; - // keep a reference to the owning GLWorld - this._world = null; + // keep a reference to the owning GLWorld + this._world = null; if(world) { this._world = world; } - this._glTextures = []; // indexed by uniform name + this._glTextures = []; // indexed by uniform name - // vertex deformation variables - this._hasVertexDeformation = false; - this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) - this._vertexDeformationTolerance = 0.1; + // vertex deformation variables + this._hasVertexDeformation = false; + this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) + this._vertexDeformationTolerance = 0.1; - // RDGE variables - this._shader = null; - this._materialNode = null; + // RDGE variables + this._shader = null; + this._materialNode = null; - // vertex deformation variables - this._hasVertexDeformation = false; - this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) - this._vertexDeformationTolerance = 0.02; + // vertex deformation variables + this._hasVertexDeformation = false; + this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) + this._vertexDeformationTolerance = 0.02; /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// - this.setName = function(n) { + this.setName = function(n) { this._name = n; }; - this.getName = function() { + this.getName = function() { return this._name; }; - this.setShaderName = function(n) { + this.setShaderName = function(n) { this._shaderName = n; }; - this.getShaderName = function() { + this.getShaderName = function() { return this._shaderName; }; - this.setWorld = function(world) { + this.setWorld = function(world) { this._world = world; }; - this.getWorld = function() { + this.getWorld = function() { return this._world; }; - this.getShader = function() { + this.getShader = function() { return this._shader; }; - this.getMaterialNode = function() { + this.getMaterialNode = function() { return this._materialNode; }; - // a material can be animated or not. default is not. - // Any material needing continuous rendering should override this method - this.isAnimated = function() { + // a material can be animated or not. default is not. + // Any material needing continuous rendering should override this method + this.isAnimated = function() { return false; }; - this.getTechniqueName = function() { - return 'default' - }; + this.getTechniqueName = function() { + return 'default' + }; - // the vertex shader can apply deformations requiring refinement in - // certain areas. - this.hasVertexDeformation = function() { + // the vertex shader can apply deformations requiring refinement in + // certain areas. + this.hasVertexDeformation = function() { return this._hasVertexDeformation; }; - this.getVertexDeformationRange = function() { + this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); }; - this.getVertexDeformationTolerance = function() { + this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; }; /////////////////////////////////////////////////////////////////////// // Common Material Methods /////////////////////////////////////////////////////////////////////// - this.getProperty = function( propName ) { - return this._propValues[propName]; - }; - - this.getPropertyCount = function() { - return this._propNames.length; - }; - - this.getPropertyAtIndex = function( index ) { - var rtnArr = []; - if ((index < 0) || (index >= this.getPropertyCount())) { - throw new Error( "property index " + index + " is out of range for material" ); + this.getProperty = function( propName ) { + return this._propValues[propName]; + }; + + this.getPropertyCount = function() { + return this._propNames.length; + }; + + this.getPropertyAtIndex = function( index ) { + var rtnArr = []; + if ((index < 0) || (index >= this.getPropertyCount())) { + throw new Error( "property index " + index + " is out of range for material" ); + } + + return [ this._propNames[index], this._propLabels[index], this._propTypes[index], this._propValues[index] ]; + }; + + this.getAllProperties = function( propNames, propValues, propTypes, propLabels) { + // clear all the input arrays if there is junk in them + propNames.length = 0; + propValues.length = 0; + propTypes.length = 0; + propLabels.length = 0; + + var nProps = this._propNames.length; + for (var i=0; i= 4)); - break; - - case "vector2d": - rtnVal = ((valType == "object") && (value.length >= 2)); - break; - - case "vector3d": - rtnVal = ((valType == "object") && (value.length >= 3)); - break; - - case "angle": - case "float": - rtnVal = (valType == "number"); - break; - - case "file": - rtnVal = ((valType == "string") || !value); - break; - } - - break; - } - } - } - catch(e) { - console.log( "setting invalid material property: " + prop + ", value: " + value ); - } - -// if (!rtnVal && (prop != 'color')) { -// console.log( "invalid material property: " + prop + " : " + value ); + this.validateProperty = function( prop, value ) { + var rtnVal = false; + try + { + //if (!this._propValues[prop]) return false; + + // find the index of the property + var n = this._propNames.length; + var valType = typeof value; + for (var i=0; i= 4)); + break; + + case "vector2d": + rtnVal = ((valType == "object") && (value.length >= 2)); + break; + + case "vector3d": + rtnVal = ((valType == "object") && (value.length >= 3)); + break; + + case "angle": + case "float": + rtnVal = (valType == "number"); + break; + + case "file": + rtnVal = ((valType == "string") || !value); + break; + } + + break; + } + } + } + catch(e) { + console.log( "setting invalid material property: " + prop + ", value: " + value ); + } + +// if (!rtnVal && (prop != 'color')) { +// console.log( "invalid material property: " + prop + " : " + value ); // } - return rtnVal; - }; - - this.setProperty = function( prop, value ) - { - var ok = this.validateProperty( prop, value ); - if (!ok && (prop != 'color')) { - //console.log( "invalid property in Material:" + prop + " : " + value ); - return; - } - - // get the technique if the shader is instantiated - var technique; - var material = this._materialNode; - if (material) technique = material.shaderProgram[this.getTechniqueName()]; - - switch (this.getPropertyType(prop)) - { - case "angle": - case "float": - this._propValues[prop] = value; - if (technique) technique[prop].set( [value] ); - break; - - case "file": - this._propValues[prop] = value.slice(); - if (technique) - { - var glTex = new Texture( this.getWorld(), value ); - this._glTextures[prop] = glTex; - glTex.render(); - var tex = glTex.getTexture(); - if (tex) technique[prop].set( tex ); - } - break; - - case "color": - case "vector2d": - case "vector3d": - this._propValues[prop] = value.slice(); - if (technique) technique[prop].set( value ); - break; - } - }; - - this.setShaderValues = function() - { - var material = this._materialNode; - if (material) - { - var technique = material.shaderProgram[this.getTechniqueName()]; - if (technique) - { - var n = this.getPropertyCount(); - for (var i=0; i= 2)); break; - + case "vector3d": rtnVal = ((valType == "object") && (value.length >= 3)); break; @@ -243,7 +243,7 @@ var Material = function GLMaterial( world ) { catch(e) { console.log( "setting invalid material property: " + prop + ", value: " + value ); } - + // if (!rtnVal && (prop != 'color')) { // console.log( "invalid material property: " + prop + " : " + value ); // } @@ -360,7 +360,7 @@ var Material = function GLMaterial( world ) { return jObj; }; - + this.importJSON = function (jObj) { if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); this.setName(jObj.name); @@ -382,7 +382,7 @@ var Material = function GLMaterial( world ) { }; /////////////////////////////////////////////////////////////////////// - + /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From ac27d538af33ca8d67d3d88729f49c05793afda7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 9 Jul 2012 11:43:36 -0700 Subject: PI, drawing and editing fixes for shapes and materials. IKNinja-1841 - Cannot change webgl shape with LinearGradient and RadialGradient to solid color. IKNINJA-1851 - Cannot draw webgl shapes with Linear/RadialGradient material. IKNINJA-1864 - PI doesn't update the color of shape if WebGL material switches to Flat. IKNINJA-1886 - Gradient edits not applied to WebGL Stage object. Signed-off-by: Nivesh Rajbhandari --- js/lib/rdge/materials/material.js | 69 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'js/lib/rdge/materials/material.js') diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 65448c0c..1864b84e 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js @@ -177,6 +177,8 @@ var Material = function GLMaterial( world ) { }; this.validateProperty = function( prop, value ) { + if(prop === "gradient") return true; + var rtnVal = false; try { @@ -240,33 +242,37 @@ var Material = function GLMaterial( world ) { var material = this._materialNode; if (material) technique = material.shaderProgram[this.getTechniqueName()]; - switch (this.getPropertyType(prop)) - { - case "angle": - case "float": - this._propValues[prop] = value; - if (technique) technique[prop].set( [value] ); - break; - - case "file": - this._propValues[prop] = value.slice(); - if (technique) - { - var glTex = new Texture( this.getWorld(), value ); - this._glTextures[prop] = glTex; - glTex.render(); - var tex = glTex.getTexture(); - if (tex) technique[prop].set( tex ); - } - break; - - case "color": - case "vector2d": - case "vector3d": - this._propValues[prop] = value.slice(); - if (technique) technique[prop].set( value ); - break; - } + if(prop === "gradient") { + this.setGradientData(value); + } else { + switch (this.getPropertyType(prop)) + { + case "angle": + case "float": + this._propValues[prop] = value; + if (technique) technique[prop].set( [value] ); + break; + + case "file": + this._propValues[prop] = value.slice(); + if (technique) + { + var glTex = new Texture( this.getWorld(), value ); + this._glTextures[prop] = glTex; + glTex.render(); + var tex = glTex.getTexture(); + if (tex) technique[prop].set( tex ); + } + break; + + case "color": + case "vector2d": + case "vector3d": + this._propValues[prop] = value.slice(); + if (technique) technique[prop].set( value ); + break; + } + } }; this.setShaderValues = function() @@ -398,6 +404,15 @@ var Material = function GLMaterial( world ) { return tex; }; + this.gradientType = null; + + this.getGradientData = function() { + return null; + }; + + this.setGradientData = function() { + // override in linear-gradient-material and radial-gradient-material + }; }; if (typeof exports === "object") { -- cgit v1.2.3