From 6321075d93044c6747682a8e7280b5996da7ec52 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 2 Feb 2012 11:57:58 -0800 Subject: added some additional shaders --- js/helper-classes/RDGE/Materials/DeformMaterial.js | 133 +++++++++++++++++++++ js/helper-classes/RDGE/Materials/FlyMaterial.js | 133 +++++++++++++++++++++ .../RDGE/Materials/ReliefTunnelMaterial.js | 133 +++++++++++++++++++++ .../RDGE/Materials/SquareTunnelMaterial.js | 133 +++++++++++++++++++++ js/helper-classes/RDGE/Materials/StarMaterial.js | 133 +++++++++++++++++++++ js/helper-classes/RDGE/Materials/WaterMaterial.js | 133 +++++++++++++++++++++ .../RDGE/Materials/ZInvertMaterial.js | 133 +++++++++++++++++++++ js/helper-classes/RDGE/MaterialsLibrary.js | 21 ++++ 8 files changed, 952 insertions(+) create mode 100644 js/helper-classes/RDGE/Materials/DeformMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/FlyMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/ReliefTunnelMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/SquareTunnelMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/StarMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/WaterMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/ZInvertMaterial.js (limited to 'js/helper-classes/RDGE') diff --git a/js/helper-classes/RDGE/Materials/DeformMaterial.js b/js/helper-classes/RDGE/Materials/DeformMaterial.js new file mode 100644 index 00000000..ddc97383 --- /dev/null +++ b/js/helper-classes/RDGE/Materials/DeformMaterial.js @@ -0,0 +1,133 @@ +/* + 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. +
*/ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function DeformMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "DeformMaterial"; + this._shaderName = "deform"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new DeformMaterial(); + + // 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 + 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. + */ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function FlyMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "FlyMaterial"; + this._shaderName = "tunnel"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new FlyMaterial(); + + // 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 + 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. + */ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function ReliefTunnelMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "ReliefTunnelMaterial"; + this._shaderName = "tunnel"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new ReliefTunnelMaterial(); + + // 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 + 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. + */ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function SquareTunnelMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "SquareTunnelMaterial"; + this._shaderName = "tunnel"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new SquareTunnelMaterial(); + + // 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 + 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. + */ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function StarMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "StarMaterial"; + this._shaderName = "star"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new StarMaterial(); + + // 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 + 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. + */ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function WaterMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "WaterMaterial"; + this._shaderName = "water"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new WaterMaterial(); + + // 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 + 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. + */ + + + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// RDGE representation of a material. +/////////////////////////////////////////////////////////////////////// +function ZInvertMaterial() +{ + // initialize the inherited members + this.inheritedFrom = PulseMaterial; + this.inheritedFrom(); + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._name = "ZInvertMaterial"; + this._shaderName = "zinvert"; + + this._texMap = 'assets/images/rocky-normal.jpg'; + + this._time = 0.0; + this._dTime = 0.01; + + /////////////////////////////////////////////////////////////////////// + // Properties + /////////////////////////////////////////////////////////////////////// + // all defined in parent PulseMaterial.js + // load the local default value + this._propValues[ this._propNames[0] ] = this._texMap.slice(0); + + /////////////////////////////////////////////////////////////////////// + // Material Property Accessors + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + // duplcate method requirde + this.dup = function( world ) + { + // allocate a new uber material + var newMat = new ZInvertMaterial(); + + // 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 uMax) uMax = u1; if (v1 > vMax) vMax = v1; + if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2; + + // if the parameter range of the triangle is outside the + // desired parameter range, advance to the next polygon and continue + if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin)) + { + // go to the next triangle + iTriangle++; + index += 3; + } + else + { + // check thesize of the triangle in uv space. If small enough, advance + // to the next triangle. If not small enough, split the triangle into 3; + var du = uMax - uMin, dv = vMax - vMin; + if ((du < tolerance) && (dv < tolerance)) + { + iTriangle++; + index += 3; + } + else // split the triangle + { + //calculate the position of the new vertex + var iPt0 = 3 * i0, + iPt1 = 3 * i1, + iPt2 = 3 * i2; + var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], + x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], + x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; + var xMid = (x0 + x1 + x2)/3.0, + yMid = (y0 + y1 + y2)/3.0, + zMid = (z0 + z1 + z2)/3.0; + + // calculate the uv value of the new coordinate + var uMid = (u0 + u1 + u2)/3.0, + vMid = (v0 + v1 + v2)/3.0; + + // calculate the normal for the new coordinate + var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], + nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], + nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; + var nxMid = (nx0 + nx1 + nx2), + nyMid = (ny0 + ny1 + ny2), + nzMid = (nz0 + nz1 + nz2); + var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); + + // push the new vertex + verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); + uvs.push(uMid), uvs.push(vMid); + norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); + var iMidVrt = nVertices; + nVertices++; + + // split the current triangle into 3 + indices[index+2] = iMidVrt; + indices.push(i1); indices.push(i2); indices.push(iMidVrt); nTriangles++; + indices.push(i2); indices.push(i0); indices.push(iMidVrt); nTriangles++; + + // by not advancing 'index', we examine the first of the 3 triangles generated above + } + } + } + return nVertices; +} + + + diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index 819f89db..c97e29d4 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -225,19 +225,15 @@ function GLWorld( canvas, use3D ) { if (this._useWebGL) { - if (this._allMapsLoaded) + var ctx = g_Engine.getContext(); + var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle); + if (ctx1 != ctx) console.log( "***** different contexts (2) *****" ); + var aRenderer = ctx1.renderer; + var renderer = ctx.renderer; + if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); + + if (renderer.unloadedTextureCount <= 0) { - var ctx = g_Engine.getContext(); - //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name); - - ///////////////////////////// - var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle); - if (ctx1 != ctx) console.log( "***** different contexts (2) *****" ); - var aRenderer = ctx1.renderer; - ////////////////////////////////////////// - - var renderer = ctx.renderer; - if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); renderer.disableCulling(); this.myScene.render(); //console.log( "render" ); @@ -249,8 +245,8 @@ function GLWorld( canvas, use3D ) if (!this.hasAnimatedMaterials()) { //this.myScene.render(); - //this._canvas.task.stop(); - this._renderCount = 10; + this._canvas.task.stop(); + //this._renderCount = 10; } } else if (this._renderCount >= 0) @@ -259,7 +255,6 @@ function GLWorld( canvas, use3D ) if (this._renderCount <= 0) this._canvas.task.stop(); } - } } else diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index 3e3ae25e..c8eb3b6c 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -121,6 +121,7 @@ function FlatMaterial() flatShaderDef = { 'shaders': { // shader files + //'defaultVShader':"assets/shaders/Taper.vert.glsl", 'defaultVShader':"assets/shaders/Basic.vert.glsl", 'defaultFShader':"assets/shaders/Basic.frag.glsl", }, diff --git a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js index ce965296..8b23d77e 100644 --- a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js @@ -135,8 +135,10 @@ function LinearGradientMaterial() // duplcate method requirde this.dup = function() { return new LinearGradientMaterial(); } - this.init = function() + this.init = function( world ) { + this.setWorld( world ); + // set up the shader this._shader = new jshader(); this._shader.def = linearGradientMaterialDef; diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js index 517947df..04cb36a7 100644 --- a/js/helper-classes/RDGE/src/core/script/renderer.js +++ b/js/helper-classes/RDGE/src/core/script/renderer.js @@ -359,9 +359,11 @@ _renderer = function(canvas) { * @param wrap - optional "CLAMP or "REPEAT", default is clamp * @param mips - optional true/false value to create mipmaps, the default is true */ + this.unloadedTextureCount = 0; _texparams = function(wrap, mips) { this.wrap = wrap, this.mips = mips }; this.createTexture = function(url, wrap, mips) { var texture = this.ctx.createTexture(); + this.unloadedTextureCount++; if (wrap === undefined) wrap = "CLAMP"; @@ -379,7 +381,18 @@ _renderer = function(canvas) { stateMan.RDGEInitState.loadTexture(texture); //console.log( "loaded texture: " + texture.lookUpName ); if (texture.callback) texture.callback( texture ); + this.context.renderer.unloadedTextureCount--; + if (this.context.renderer.unloadedTextureCount < 0) + console.log( "more textures loaded then created..." ); }; + texture.image.onerror = function() { + this.context.renderer.unloadedTextureCount--; + if (texture.callback) texture.callback( texture ); + console.log( "Error loading texture: " + texture.image.src ); + if (this.context.renderer.unloadedTextureCount < 0) + console.log( "more textures loaded then created..." ); + } + } return texture; } -- cgit v1.2.3 From 2d4da18a778471b02e188ad668752e331ee76127 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 7 Feb 2012 14:35:55 -0800 Subject: test code for deformation shader --- js/helper-classes/RDGE/GLMaterial.js | 4 +- js/helper-classes/RDGE/GLRectangle.js | 64 ++++++++++++++---------- js/helper-classes/RDGE/GLWorld.js | 6 ++- js/helper-classes/RDGE/Materials/FlatMaterial.js | 11 ++-- 4 files changed, 52 insertions(+), 33 deletions(-) (limited to 'js/helper-classes/RDGE') diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js index 07a98ab5..a74a74e4 100644 --- a/js/helper-classes/RDGE/GLMaterial.js +++ b/js/helper-classes/RDGE/GLMaterial.js @@ -34,7 +34,7 @@ function GLMaterial( world ) // vertex deformation variables this._hasVertexDeformation = false; this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) - this._vertexDeformationTolerance = 0.05; + this._vertexDeformationTolerance = 0.1; // RDGE variables this._shader; @@ -74,7 +74,7 @@ function GLMaterial( world ) // the vertex shader can apply deformations requiring refinement in // certain areas. this.hasVertexDeformation = function() { return this._hasVertexDeformation; } - this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); } + this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); } this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; } diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index e72b4488..7fe03022 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -1121,6 +1121,7 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); + //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1214,6 +1215,7 @@ RectangleGeometry.create = function( ctr, width, height, material ) // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); + //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1301,7 +1303,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa i2 = indices[index+2]; // get the uv values - var vrtIndex = 3*iTriangle; + //var vrtIndex = 3*iTriangle; var iuv0 = 2 * i0, iuv1 = 2 * i1, iuv2 = 2 * i2; @@ -1335,7 +1337,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa iTriangle++; index += 3; } - else // split the triangle + else // split the triangle into 4 parts { //calculate the position of the new vertex var iPt0 = 3 * i0, @@ -1344,34 +1346,42 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; - var xMid = (x0 + x1 + x2)/3.0, - yMid = (y0 + y1 + y2)/3.0, - zMid = (z0 + z1 + z2)/3.0; - - // calculate the uv value of the new coordinate - var uMid = (u0 + u1 + u2)/3.0, - vMid = (v0 + v1 + v2)/3.0; - - // calculate the normal for the new coordinate + + // calculate the midpoints of the edges + var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0, + xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0, + xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0; + + // calculate the uv values of the new coordinates + var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0, + uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0, + uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0; + + // calculate the normals for the new points var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; - var nxMid = (nx0 + nx1 + nx2), - nyMid = (ny0 + ny1 + ny2), - nzMid = (nz0 + nz1 + nz2); - var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); - - // push the new vertex - verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); - uvs.push(uMid), uvs.push(vMid); - norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); - var iMidVrt = nVertices; - nVertices++; - - // split the current triangle into 3 - indices[index+2] = iMidVrt; - indices.push(i1); indices.push(i2); indices.push(iMidVrt); nTriangles++; - indices.push(i2); indices.push(i0); indices.push(iMidVrt); nTriangles++; + var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ), + nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ), + nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 ); + + // push everything + verts.push(xA); verts.push(yA); verts.push(zA); + verts.push(xB); verts.push(yB); verts.push(zB); + verts.push(xC); verts.push(yC); verts.push(zC); + uvs.push(uA), uvs.push(vA); + uvs.push(uB), uvs.push(vB); + uvs.push(uC), uvs.push(vC); + norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]); + norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]); + norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]); + + // split the current triangle into 4 + indices[index+1] = nVertices; indices[index+2] = nVertices+2; + indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++; + indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++; + indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++; + nVertices += 3; // by not advancing 'index', we examine the first of the 3 triangles generated above } diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index c97e29d4..83ed717d 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -14,6 +14,7 @@ var fragmentShaderSource = ""; var rdgeStarted = false; var nodeCounter = 0; +var worldCounter = 0; /////////////////////////////////////////////////////////////////////// @@ -70,6 +71,9 @@ function GLWorld( canvas, use3D ) // no animated materials this._firstRender = true; + this._worldCount = worldCounter; + worldCounter++; + /////////////////////////////////////////////////////////////////////// // Property accessors /////////////////////////////////////////////////////////////////////// @@ -236,7 +240,7 @@ function GLWorld( canvas, use3D ) { renderer.disableCulling(); this.myScene.render(); - //console.log( "render" ); + console.log( "render" ); if (this._firstRender) { diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index c8eb3b6c..de039231 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js @@ -26,10 +26,13 @@ function FlatMaterial() /////////////////////////////////////////////////////////////////////// // Property Accessors /////////////////////////////////////////////////////////////////////// - this.getColor = function() { return this._color; } - this.getShaderName = function() { return this._shaderName; } + this.getColor = function() { return this._color; } + this.getShaderName = function() { return this._shaderName; } - this.isAnimated = function() { return false; } + this.isAnimated = function() { return false; } + this.hasVertexDeformation = function() { return true; } + this._hasVertexDeformation = true; + this._vertexDeformationTolerance = 0.2; //////////////////////////////////s///////////////////////////////////// // Methods @@ -55,6 +58,7 @@ function FlatMaterial() // this._shader.colorMe.u_limit1.set( [0.25] ); // this._shader.colorMe.u_limit2.set( [0.5] ); // this._shader.colorMe.u_limit3.set( [0.75] ); +// this._shader.colorMe.u_center.set( [0.0] ); // this._shader.colorMe.u_taperAmount.set( [0.5] ); } @@ -146,6 +150,7 @@ flatShaderDef = //'u_limit1': { 'type': 'float' }, //'u_limit2': { 'type': 'float' }, //'u_limit3': { 'type': 'float' }, + //'u_center': { 'type': 'float' }, //'u_taperAmount': { 'type': 'float' } }, }, -- cgit v1.2.3 From 064d74fb2694318615f513c83772276cec34bb86 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 8 Feb 2012 13:41:52 -0800 Subject: Fixed context switching problems in rdge --- js/helper-classes/RDGE/GLCircle.js | 3 + js/helper-classes/RDGE/GLLine.js | 3 + js/helper-classes/RDGE/GLRectangle.js | 6 +- js/helper-classes/RDGE/GLWorld.js | 27 +- .../RDGE/Materials/RadialGradientMaterial.js | 1 - js/helper-classes/RDGE/src/core/script/renderer.js | 13 +- .../RDGE/src/tools/compile-rdge-core.bat | 4 + .../RDGE/src/tools/compile-rdge-core.sh | 3 + js/helper-classes/RDGE/src/tools/compiler.jar | Bin 0 -> 4927265 bytes js/helper-classes/RDGE/src/tools/rdge-compiled.js | 461 +++++++++++++++++++++ 10 files changed, 507 insertions(+), 14 deletions(-) create mode 100644 js/helper-classes/RDGE/src/tools/compile-rdge-core.bat create mode 100644 js/helper-classes/RDGE/src/tools/compile-rdge-core.sh create mode 100644 js/helper-classes/RDGE/src/tools/compiler.jar create mode 100644 js/helper-classes/RDGE/src/tools/rdge-compiled.js (limited to 'js/helper-classes/RDGE') diff --git a/js/helper-classes/RDGE/GLCircle.js b/js/helper-classes/RDGE/GLCircle.js index 942eb528..08057778 100644 --- a/js/helper-classes/RDGE/GLCircle.js +++ b/js/helper-classes/RDGE/GLCircle.js @@ -133,6 +133,9 @@ function GLCircle() if (!world) throw( "null world in buildBuffers" ); if (!world._useWebGL) return; + + // make sure RDGE has the correct context + g_Engine.setContext( world.getCanvas().uuid ); // create the gl buffer var gl = world.getGLContext(); diff --git a/js/helper-classes/RDGE/GLLine.js b/js/helper-classes/RDGE/GLLine.js index bd3cbc26..f01e1610 100644 --- a/js/helper-classes/RDGE/GLLine.js +++ b/js/helper-classes/RDGE/GLLine.js @@ -109,6 +109,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro var world = this.getWorld(); if (!world) throw( "null world in buildBuffers" ); if (!world._useWebGL) return; + + // make sure RDGE has the correct context + g_Engine.setContext( world.getCanvas().uuid ); // create the gl buffer var gl = world.getGLContext(); diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index f6f5a899..595a5b48 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -210,8 +210,11 @@ function GLRectangle() // get the world var world = this.getWorld(); if (!world) throw( "null world in buildBuffers" ); - + //console.log( "GLRectangle.buildBuffers " + world._worldCount ); if (!world._useWebGL) return; + + // make sure RDGE has the correct context + g_Engine.setContext( world.getCanvas().uuid ); // create the gl buffer var gl = world.getGLContext(); @@ -284,6 +287,7 @@ function GLRectangle() xFill -= strokeSize; yFill -= strokeSize; var fillMaterial = this.makeFillMaterial(); + //console.log( "fillMaterial: " + fillMaterial.getName() ); var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); this._primArray.push( fillPrim ); this._materialNodeArray.push( fillMaterial.getMaterialNode() ); diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index afd61c8a..e6e7f466 100644 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js @@ -151,6 +151,7 @@ function GLWorld( canvas, use3D ) ctx2 = g_Engine.getContext(); if (ctx1 != ctx2) console.log( "***** different contexts *****" ); this.renderer = ctx1.renderer; + this.renderer._world = this; // create a camera, set its perspective, and then point it at the origin var cam = new camera(); @@ -229,18 +230,24 @@ function GLWorld( canvas, use3D ) { if (this._useWebGL) { + g_Engine.setContext( this._canvas.uuid ); var ctx = g_Engine.getContext(); var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle); - if (ctx1 != ctx) console.log( "***** different contexts (2) *****" ); + if (ctx1 != ctx) + console.log( "***** different contexts (2) *****" ); var aRenderer = ctx1.renderer; var renderer = ctx.renderer; - if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" ); + if (renderer != aRenderer) + { + console.log( "***** DIFFERENT RENDERERS *****" ); + renderer = aRenderer; + } if (renderer.unloadedTextureCount <= 0) { renderer.disableCulling(); + //console.log( "GLWorld.draw " + renderer._world._worldCount ); this.myScene.render(); - console.log( "render" ); if (this._firstRender) { @@ -389,7 +396,6 @@ function GLWorld( canvas, use3D ) rdgeStarted = true; this._canvas.rdgeid = this._canvas.uuid; - this._canvas.id = this._canvas.uuid; g_Engine.registerCanvas(this._canvas, this); RDGEStart( this._canvas ); @@ -508,16 +514,22 @@ GLWorld.prototype.addObject = function( obj ) GLWorld.prototype.restartRenderLoop = function() { - console.log( "restartRenderLoop" ); + //console.log( "restartRenderLoop" ); this._firstRender = true; this._renderCount = -1; if (this._canvas.task) { if (this._allMapsLoaded) + { + //console.log( "starting task" ); this._canvas.task.start(); + } else + { + //console.log( "stopping task" ); this._canvas.task.stop(); + } } } @@ -757,7 +769,10 @@ GLWorld.prototype.render = function() } else { - this.draw(); + console.log( "GLWorld.render, " + this._worldCount ); + g_Engine.setContext( this._canvas.uuid ); + //this.draw(); + this.restartRenderLoop(); } } diff --git a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js index cf91f1aa..50833f4f 100644 --- a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js @@ -264,7 +264,6 @@ var radialGradientMaterialDef = 'u_colorStop2': { 'type' : 'float' }, 'u_colorStop3': { 'type' : 'float' }, 'u_colorStop4': { 'type' : 'float' }, - 'u_cos_sin_angle' : { 'type' : 'vec2' } //'u_colorCount': {'type' : 'int' } }, diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js index 04cb36a7..a50b8a68 100644 --- a/js/helper-classes/RDGE/src/core/script/renderer.js +++ b/js/helper-classes/RDGE/src/core/script/renderer.js @@ -371,7 +371,6 @@ _renderer = function(canvas) { mips = true; if (texture) { - //console.log( "createTexture: " + url ); texture.image = new Image(); texture.image.src = url; texture.image.context = g_Engine.getContext(); @@ -379,16 +378,16 @@ _renderer = function(canvas) { texture.image.onload = function() { var stateMan = this.context.ctxStateManager; stateMan.RDGEInitState.loadTexture(texture); - //console.log( "loaded texture: " + texture.lookUpName ); - if (texture.callback) texture.callback( texture ); this.context.renderer.unloadedTextureCount--; + //console.log( "loaded texture: " + texture.lookUpNam