From 679a0746bedab9c5871a83a5fea6a06ac6a4f41c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 2 Apr 2012 10:17:48 -0700 Subject: texture abstraction --- js/lib/geom/geom-obj.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index a87bdbf5..11b9303a 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -220,6 +220,8 @@ var GeomObj = function GLGeomObj() { this.setStrokeColor(this._strokeColor); } + this._strokeMaterial = strokeMaterial; + return strokeMaterial; }; @@ -242,6 +244,8 @@ var GeomObj = function GLGeomObj() { this.setFillColor(this._fillColor); } + this._fillMaterial = fillMaterial; + return fillMaterial; }; -- cgit v1.2.3 From 4b199cf04af83f59895d4d1e9a2d8443c1ec8e06 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 3 Apr 2012 09:36:14 -0700 Subject: started the flag material --- js/lib/geom/geom-obj.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 11b9303a..0c0d7c01 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -309,6 +309,7 @@ var GeomObj = function GLGeomObj() { case "tunnel": case "reliefTunnel": case "squareTunnel": + case "flag": case "twist": case "fly": case "julia": @@ -382,6 +383,7 @@ var GeomObj = function GLGeomObj() { case "tunnel": case "reliefTunnel": case "squareTunnel": + case "flag": case "twist": case "fly": case "julia": -- cgit v1.2.3 From 0f31002ca696c1ef303d2926a504afd27305e94f Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 4 Apr 2012 05:52:54 -0700 Subject: Added Flag material --- js/lib/geom/rectangle.js | 46 +++++++-------- js/lib/geom/shape-primitive.js | 130 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 23 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index e511d5f4..51947ff1 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -943,13 +943,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, } //refine the mesh for vertex deformations -// if (material) { -// if (material.hasVertexDeformation()) { -// var paramRange = material.getVertexDeformationRange(); -// var tolerance = material.getVertexDeformationTolerance(); -// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); -// } -// } + if (material) { + if (material.hasVertexDeformation()) { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + } + } // create the RDGE primitive return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); @@ -1175,13 +1175,13 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, } //refine the mesh for vertex deformations -// if (material) { -// if (material.hasVertexDeformation()) { -// var paramRange = material.getVertexDeformationRange(); -// var tolerance = material.getVertexDeformationTolerance(); -// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); -// } -// } + if (material) { + if (material.hasVertexDeformation()) { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + } + } // create the RDGE primitive return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); @@ -1259,15 +1259,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) { RectangleGeometry.pushIndices( 0, 3, 2 ); //refine the mesh for vertex deformations -// if (material) -// { -// if (material.hasVertexDeformation()) -// { -// var paramRange = material.getVertexDeformationRange(); -// var tolerance = material.getVertexDeformationTolerance(); -// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); -// } -// } + if (material) + { + if (material.hasVertexDeformation()) + { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + } + } // create the RDGE primitive return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js index bf0087b2..44a7aa52 100644 --- a/js/lib/geom/shape-primitive.js +++ b/js/lib/geom/shape-primitive.js @@ -49,6 +49,136 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver return prim; }; +ShapePrimitive.getMeshBounds = function( verts, nVerts ) +{ + if (!verts || (nVerts <= 0)) return null; + + var bounds = [verts[0], verts[1], verts[2], verts[0], verts[1], verts[2]]; + var index = 3; + for (var i=1; i bounds[3]) bounds[3] = x; + if (y < bounds[1]) bounds[1] = y; + else if (y > bounds[4]) bounds[4] = y; + if (z < bounds[2]) bounds[2] = z; + else if (z > bounds[5]) bounds[5] = z; + } + + return bounds; +}; + +ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) +{ + var oldVrtCount = nVertices; + + // get the param range + var pUMin = paramRange[0], pVMin = paramRange[1], + pUMax = paramRange[2], pVMax = paramRange[3]; + var iTriangle = 0; + var nTriangles = indices.length/3; + var index = 0; + while (iTriangle < nTriangles) + { + // get the indices of the 3 vertices + var i0 = indices[index], + i1 = indices[index+1], + i2 = indices[index+2]; + + // get the uv values + //var vrtIndex = 3*iTriangle; + var iuv0 = 2 * i0, + iuv1 = 2 * i1, + iuv2 = 2 * i2; + var u0 = uvs[iuv0], v0 = uvs[iuv0+1], + u1 = uvs[iuv1], v1 = uvs[iuv1+1], + u2 = uvs[iuv2], v2 = uvs[iuv2+1]; + + // find the u and v range + var uMin = u0, vMin = v0; + if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1; + if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2; + var uMax = u0, vMax = v0; + if (u1 > 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 into 4 parts + { + //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]; + + // 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 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 + } + } + } + + console.log( "refine mesh vertex count " + oldVrtCount + " => " + nVertices ); + return nVertices; +}; + + if (typeof exports === "object") { exports.ShapePrimitive = ShapePrimitive; } \ No newline at end of file -- cgit v1.2.3 From c1a6cacf364d79cbf23b41e7089a1a6d39afea85 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 10 Apr 2012 10:12:49 -0700 Subject: Cloud material --- js/lib/geom/rectangle.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 51947ff1..f41c27f6 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -1280,11 +1280,41 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices; RectangleGeometry.getVertex = RectangleFill.getVertex; RectangleGeometry.getUV = RectangleFill.getUV; +RectangleGeometry.init = function() +{ + this.vertices = []; + this.normals = []; + this.uvs = []; + this.indices = []; +} + +RectangleGeometry.addQuad = function( verts, normals, uvs ) +{ + for (var i=0; i<4; i++) + { + RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); + RectangleGeometry.pushNormal( normals[i] ); + RectangleGeometry.pushUV( uvs[i] ); + } + + RectangleGeometry.pushIndices( 0, 1, 2 ); + RectangleGeometry.pushIndices( 2, 3, 0 ); +} + +RectangleGeometry.buildPrimitive = function() +{ + var nVertices = this.vertices.length; + return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); +} + + + Rectangle.prototype = new GeomObj(); if (typeof exports === "object") { exports.Rectangle = Rectangle; + exports.RectangleGeometry = RectangleGeometry; } -- cgit v1.2.3 From 331b2ad4d602016f9bb3d03be759fd81fed50c10 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 13 Apr 2012 07:08:42 -0700 Subject: Cloud Material --- js/lib/geom/rectangle.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index f41c27f6..d4dd8033 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -12,7 +12,11 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; // GL representation of a rectangle. // Derived from class GeomObj /////////////////////////////////////////////////////////////////////// -var Rectangle = function GLRectangle() { +var Rectangle = function GLRectangle() +{ + if (!MaterialsModel) + MaterialsModel = require("js/models/materials-model").MaterialsModel; + // CONSTANTS this.N_TRIANGLES = 15; -- cgit v1.2.3 From 8992d9baf542135e910bb59328a592d9e330703a Mon Sep 17 00:00:00 2001 From: hwc487 Date: Sun, 15 Apr 2012 05:16:34 -0700 Subject: Cloud Material --- js/lib/geom/rectangle.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index d4dd8033..70f6b01b 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -1294,6 +1294,7 @@ RectangleGeometry.init = function() RectangleGeometry.addQuad = function( verts, normals, uvs ) { + var offset = this.vertices.length/3; for (var i=0; i<4; i++) { RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); @@ -1301,13 +1302,13 @@ RectangleGeometry.addQuad = function( verts, normals, uvs ) RectangleGeometry.pushUV( uvs[i] ); } - RectangleGeometry.pushIndices( 0, 1, 2 ); - RectangleGeometry.pushIndices( 2, 3, 0 ); + RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset ); + RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset ); } RectangleGeometry.buildPrimitive = function() { - var nVertices = this.vertices.length; + var nVertices = this.vertices.length/3; return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); } -- cgit v1.2.3 From f13d0f45f6b449764898e99db309c43b51a33476 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 19 Apr 2012 13:39:54 -0700 Subject: chaned textures --- js/lib/geom/rectangle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index ef91d158..304b9c19 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -1214,7 +1214,7 @@ RectangleGeometry.addQuad = function( verts, normals, uvs ) RectangleGeometry.buildPrimitive = function() { var nVertices = this.vertices.length/3; - return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); + return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); } -- cgit v1.2.3 From 5fcb96cae89007c684df3ce948831e2fcf9fd8b7 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 14 May 2012 10:00:52 -0700 Subject: Fixing merge issues --- js/lib/geom/geom-obj.js | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 803dbb53..6f37ad1c 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -11,7 +11,6 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; // Super class for all geometry classes /////////////////////////////////////////////////////////////////////// exports.GeomObj = Object.create(Object.prototype, { -{ /////////////////////////////////////////////////////////////////////// // Constants /////////////////////////////////////////////////////////////////////// @@ -181,14 +180,12 @@ exports.GeomObj = Object.create(Object.prototype, { /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// - setMaterialColor: { + setMaterialColor: { value: function(c, type) { var i = 0, nMats = 0; if (c) { if (c.gradientMode) { - if (c.gradientMode) - { // Gradient support if (this._materialArray && this._materialTypeArray) { nMats = this._materialArray.length; @@ -204,7 +201,6 @@ exports.GeomObj = Object.create(Object.prototype, { } for (var n = 0; n < len; n++) { - { var position = colors[n].position / 100; var cs = colors[n].value; var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a]; @@ -213,9 +209,6 @@ exports.GeomObj = Object.create(Object.prototype, { if (nMats === this._materialTypeArray.length) { for (i = 0; i < nMats; i++) { if (this._materialTypeArray[i] == type) { - { - if (this._materialTypeArray[i] == type) - { this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0)); this._materialArray[i].setProperty("colorStop" + (n + 1), position); } @@ -225,15 +218,12 @@ exports.GeomObj = Object.create(Object.prototype, { if (type === "fill") { this._fillColor = c; } else { - else { this._strokeColor = c; } } else { - else { if (type === "fill") { this._fillColor = c.slice(0); } else { - else { this._strokeColor = c.slice(0); } @@ -241,7 +231,6 @@ exports.GeomObj = Object.create(Object.prototype, { nMats = this._materialArray.length; if (nMats === this._materialTypeArray.length) { for (i = 0; i < nMats; i++) { - { if (this._materialTypeArray[i] == type) { this._materialArray[i].setProperty("color", c.slice(0)); } @@ -250,24 +239,17 @@ exports.GeomObj = Object.create(Object.prototype, { } } } else { - else - { if (type === "fill") { this._fillColor = null; } else { - else { this._strokeColor = null; } if (this._materialArray && this._materialTypeArray) { - { nMats = this._materialArray.length; if (nMats === this._materialTypeArray.length) { for (i = 0; i < nMats; i++) { if (this._materialTypeArray[i] == type) { - { - if (this._materialTypeArray[i] == type) - { // TODO - Not sure how to set color to null values in shaders this._materialArray[i].setProperty("color", [0, 0, 0, 0]); } @@ -289,7 +271,6 @@ exports.GeomObj = Object.create(Object.prototype, { if (this.getStrokeMaterial()) { strokeMaterial = this.getStrokeMaterial().dup(); } else { - else { strokeMaterial = MaterialsModel.exportFlatMaterial(); } @@ -304,7 +285,7 @@ exports.GeomObj = Object.create(Object.prototype, { this.setStrokeColor(this._strokeColor); } - this._strokeMaterial = strokeMaterial; + this._strokeMaterial = strokeMaterial; return strokeMaterial; } @@ -316,7 +297,6 @@ exports.GeomObj = Object.create(Object.prototype, { if (this.getFillMaterial()) { fillMaterial = this.getFillMaterial().dup(); } else { - else { fillMaterial = MaterialsModel.exportFlatMaterial(); } @@ -339,17 +319,17 @@ exports.GeomObj = Object.create(Object.prototype, { exportMaterialsJSON: { value: function() { - MaterialsModel = require("js/models/materials-model").MaterialsModel; + MaterialsModel = require("js/models/materials-model").MaterialsModel; var jObj; if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { var nMats = this._materialArray.length; if (nMats > 0) { - { + { var arr = []; for (var i = 0; i < nMats; i++) { - { + { var matObj = { 'materialNodeName':this._materialNodeArray[i].name, @@ -373,7 +353,7 @@ exports.GeomObj = Object.create(Object.prototype, { importMaterialsJSON: { value: function(jObj) { - MaterialsModel = require("js/models/materials-model").MaterialsModel; + MaterialsModel = require("js/models/materials-model").MaterialsModel; this._materialArray = []; this._materialTypeArray = []; @@ -383,12 +363,10 @@ exports.GeomObj = Object.create(Object.prototype, { var nMaterials = jObj.nMaterials; var matArray = jObj.materials; for (var i = 0; i < nMaterials; i++) { - { var mat; var matObj = matArray[i].material; var shaderName = matObj.material; switch (shaderName) { - { case "flat": case "radialGradient": case "linearGradient": @@ -402,7 +380,7 @@ exports.GeomObj = Object.create(Object.prototype, { case "tunnel": case "reliefTunnel": case "squareTunnel": - case "flag": + case "flag": case "twist": case "fly": case "julia": -- cgit v1.2.3 From 25a2e1c5eb21a18caccc7a9435d835a3f5e7f3a0 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 14 May 2012 10:37:03 -0700 Subject: More merge problems --- js/lib/geom/geom-obj.js | 2 -- js/lib/geom/rectangle.js | 13 +++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 6f37ad1c..6b73463f 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -325,11 +325,9 @@ exports.GeomObj = Object.create(Object.prototype, { if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { var nMats = this._materialArray.length; if (nMats > 0) { - { var arr = []; for (var i = 0; i < nMats; i++) { - { var matObj = { 'materialNodeName':this._materialNodeArray[i].name, diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 22cbb5d4..ab0d7022 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -14,13 +14,12 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; // Derived from class GeomObj /////////////////////////////////////////////////////////////////////// exports.Rectangle = Object.create(GeomObj, { -{ - if (!MaterialsModel) - MaterialsModel = require("js/models/materials-model").MaterialsModel; - // CONSTANTS N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? + //if (!MaterialsModel) + // MaterialsModel = require("js/models/materials-model").MaterialsModel; + /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// @@ -1180,8 +1179,10 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, } //refine the mesh for vertex deformations - if (material) { - if (material.hasVertexDeformation()) { + if (material) + { + if (material.hasVertexDeformation()) + { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); -- cgit v1.2.3 From 44a8ec171bedac6921d796501e654f856d716855 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 23 May 2012 10:19:39 -0700 Subject: Fixed merge problems --- js/lib/geom/shape-primitive.js | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js index 858f38c8..380cf334 100644 --- a/js/lib/geom/shape-primitive.js +++ b/js/lib/geom/shape-primitive.js @@ -49,7 +49,7 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver return prim; }; -ShapePrimitive.getBounds = function( prim ) +ShapePrimitive.getMeshBounds = function( verts, nVerts ) { if (!verts || (nVerts <= 0)) return null; @@ -76,31 +76,6 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa var oldVrtCount = nVertices; // get the param range - var verts = prim.bufferStreams[0]; - var nVerts = verts.length; - var xMin = verts[0], xMax = verts[0], - yMin = verts[1], yMax = verts[1], - zMin = verts[2], zMax = verts[2]; - - for (var index=3; index xMax) xMax = verts[index]; - - index++; - if (verts[index] < yMin) yMin = verts[index]; - else if (verts[index] > yMax) yMax = verts[index]; - - index++; - if (verts[index] < zMin) zMin = verts[index]; - else if (verts[index] > zMax) zMax = verts[index]; - - index++; - } - - return [xMin, yMin, zMin, xMax, yMax, zMax]; -}; - var pUMin = paramRange[0], pVMin = paramRange[1], pUMax = paramRange[2], pVMax = paramRange[3]; var iTriangle = 0; -- cgit v1.2.3 From bc1b0276a3947e10f914e83f9750add4fa8b6c00 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 25 May 2012 09:25:37 -0700 Subject: New functions on shape primitives. --- js/lib/geom/shape-primitive.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js index 380cf334..5a44deb3 100644 --- a/js/lib/geom/shape-primitive.js +++ b/js/lib/geom/shape-primitive.js @@ -71,6 +71,33 @@ ShapePrimitive.getMeshBounds = function( verts, nVerts ) return bounds; }; +ShapePrimitive.getBounds = function( prim ) +{ + var verts = prim.bufferStreams[0]; + var nVerts = verts.length; + var xMin = verts[0], xMax = verts[0], + yMin = verts[1], yMax = verts[1], + zMin = verts[2], zMax = verts[2]; + + for (var index=3; index xMax) xMax = verts[index]; + + index++; + if (verts[index] < yMin) yMin = verts[index]; + else if (verts[index] > yMax) yMax = verts[index]; + + index++; + if (verts[index] < zMin) zMin = verts[index]; + else if (verts[index] > zMax) zMax = verts[index]; + + index++; + } + + return [xMin, yMin, zMin, xMax, yMax, zMax]; +}; + ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) { var oldVrtCount = nVertices; -- cgit v1.2.3 From 08e9abf8db06f714a95f0490d65c7337bed648b8 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 25 May 2012 17:02:43 -0700 Subject: Added mesh refinement to circles. --- js/lib/geom/circle.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 4a369844..b2709ce4 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -295,39 +295,39 @@ exports.Circle = Object.create(GeomObj, { if(this._strokeWidth > 0) { var numStrokes = 1; if(this._innerRadius !== 0) { - strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles); + strokeMaterial0 = this.makeStrokeMaterial(); + strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); } - strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles); + strokeMaterial2 = this.makeStrokeMaterial(); + strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2); } ///////////////////////////////////////////////////////////// // Fill + fillMaterial = this.makeFillMaterial(); if(this._innerRadius === 0) { - fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles); + fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial); } else { - fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles); + fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial); } if (fillPrim) { - fillMaterial = this.makeFillMaterial(); - fillMaterial.fitToPrimitive( fillPrim ); + fillMaterial.fitToPrimitive( fillPrim ); this._primArray.push( fillPrim ); this._materialNodeArray.push( fillMaterial.getMaterialNode() ); } if (strokePrim0) { - strokeMaterial0 = this.makeStrokeMaterial(); - strokeMaterial0.fitToPrimitive( strokePrim0 ); + strokeMaterial0.fitToPrimitive( strokePrim0 ); this._primArray.push( strokePrim0 ); this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); } if (strokePrim1) { - strokeMaterial2 = this.makeStrokeMaterial(); - strokeMaterial2.fitToPrimitive( strokePrim1 ); + strokeMaterial2.fitToPrimitive( strokePrim1 ); this._primArray.push( strokePrim1 ); this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); @@ -338,7 +338,7 @@ exports.Circle = Object.create(GeomObj, { }, generateOval: { - value: function(xOff, yOff, rotationMat, scaleMat, nTriangles) { + value: function(xOff, yOff, rotationMat, scaleMat, nTriangles, material) { var pt = [1.0, 0.0, 0.0]; //var pts = scaleMat.multiply(pt); var pts = glmat4.multiplyVec3( scaleMat, pt, []); @@ -392,12 +392,21 @@ exports.Circle = Object.create(GeomObj, { this.recalcTexMapCoords( vrts, uvs ); + //refine the mesh for vertex deformations + if (material) { + if (material.hasVertexDeformation()) { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance ); + } + } + return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); } }, generateOvalRing: { - value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { + value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles, material) { var pt = [1.0, 0.0, 0.0]; var z = 0; @@ -451,6 +460,17 @@ exports.Circle = Object.create(GeomObj, { this.recalcTexMapCoords( vrts, uvs ); + /* + //refine the mesh for vertex deformations + if (material) { + if (material.hasVertexDeformation()) { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance ); + } + } + */ + return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); } }, -- cgit v1.2.3 From 129b5282ef35f320ea39d1878d2b5f77ae73a3e2 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 29 May 2012 14:36:59 -0700 Subject: Fixed authortime & runtime for twist vertex shader. --- js/lib/geom/geom-obj.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 6b73463f..417c8731 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -388,6 +388,7 @@ exports.GeomObj = Object.create(Object.prototype, { case "keleidoscope": case "radialBlur": case "pulse": + case "twistVert": mat = MaterialsModel.getMaterialByShader(shaderName); if (mat) mat = mat.dup(); break; -- cgit v1.2.3 From 6c994c4b90023cecf4fd0caafb404b859fe28f54 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 6 Jun 2012 16:34:41 -0700 Subject: material cleanup and rearchitecture --- js/lib/geom/circle.js | 22 ++++++++++++++-------- js/lib/geom/geom-obj.js | 21 +++++++++++++-------- js/lib/geom/rectangle.js | 23 +++++++++++++++-------- 3 files changed, 42 insertions(+), 24 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index b2709ce4..6627b4b7 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -57,16 +57,18 @@ exports.Circle = Object.create(GeomObj, { this.m_world = world; if(strokeMaterial) { - this._strokeMaterial = strokeMaterial; + this._strokeMaterial = strokeMaterial.dup(); } else { - this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); if(fillMaterial) { - this._fillMaterial = fillMaterial; + this._fillMaterial = fillMaterial.dup(); } else { - this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); } }, @@ -702,19 +704,23 @@ exports.Circle = Object.create(GeomObj, { var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); + var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); if (!strokeMat) { console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._strokeMaterial = strokeMat; + if (this._strokeMaterial.hasProperty( 'color' )) + this._strokeMaterial.setProperty( 'color', this._strokeColor ); - var fillMat = MaterialsModel.getMaterial( fillMaterialName ); + var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); if (!fillMat) { console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._fillMaterial = fillMat; + if (this._fillMaterial.hasProperty( 'color' )) + this._fillMaterial.setProperty( 'color', this._fillColor ); this.importMaterialsJSON( jObj.materials ); } diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 417c8731..3a7a5619 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -281,9 +281,11 @@ exports.GeomObj = Object.create(Object.prototype, { this._materialArray.push(strokeMaterial); this._materialTypeArray.push("stroke"); - if (this._strokeColor) { - this.setStrokeColor(this._strokeColor); - } + // don't set the value here. The material editor may set a color directly + // to the material without setting this value in the obj. The following + // lines of code will clobber the value in the material + //if (this._strokeColor) + // this.setStrokeColor(this._strokeColor); this._strokeMaterial = strokeMaterial; @@ -306,12 +308,14 @@ exports.GeomObj = Object.create(Object.prototype, { this._materialArray.push(fillMaterial); this._materialTypeArray.push("fill"); + + // don't set the value here. The material editor may set a color directly + // to the material without setting this value in the obj. The following + // lines of code will clobber the value in the material + //if (this._fillColor) + // this.setFillColor(this._fillColor); - if (this._fillColor) { - this.setFillColor(this._fillColor); - } - - this._fillMaterial = fillMaterial; + this._fillMaterial = fillMaterial; return fillMaterial; } @@ -389,6 +393,7 @@ exports.GeomObj = Object.create(Object.prototype, { case "radialBlur": case "pulse": case "twistVert": + case "taper": mat = MaterialsModel.getMaterialByShader(shaderName); if (mat) mat = mat.dup(); break; diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 42d51e74..81a8556d 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -73,16 +73,19 @@ exports.Rectangle = Object.create(GeomObj, { this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; if(strokeMaterial) { - this._strokeMaterial = strokeMaterial; + this._strokeMaterial = strokeMaterial.dup(); } else { - this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); + if(fillMaterial) { - this._fillMaterial = fillMaterial; + this._fillMaterial = fillMaterial.dup(); } else { - this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } + if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); } }, @@ -289,19 +292,23 @@ exports.Rectangle = Object.create(GeomObj, { var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; - var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); + var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); if (!strokeMat) { console.log( "object material not found in library: " + strokeMaterialName ); - strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._strokeMaterial = strokeMat; + if (this._strokeMaterial.hasProperty( 'color' )) + this._strokeMaterial.setProperty( 'color', this._strokeColor ); - var fillMat = MaterialsModel.getMaterial( fillMaterialName ); + var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); if (!fillMat) { console.log( "object material not found in library: " + fillMaterialName ); - fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); } this._fillMaterial = fillMat; + if (this._fillMaterial.hasProperty( 'color' )) + this._fillMaterial.setProperty( 'color', this._fillColor ); this.importMaterialsJSON( jObj.materials ); } -- cgit v1.2.3 From 250d84a79d9f72c6a98cbbecfe4e21f2c0d53a19 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 13 Jun 2012 10:55:21 -0700 Subject: fixes bug #1623: middle transform handle causes the brush stroke to have a zero width or height and brush stroke cannot be recovered --- js/lib/geom/brush-stroke.js | 69 ++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 0e0406dd..b69139b6 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js @@ -31,6 +31,8 @@ var BrushStroke = function GLBrushStroke() { //the HTML5 canvas that holds this brush stroke this._canvas = null; + //flag indicating whether or not to freeze the size and position of canvas + this._freezeCanvas = false; //stroke information this._strokeWidth = 1.0; @@ -174,11 +176,15 @@ BrushStroke.prototype.getStrokeWidth = function () { }; BrushStroke.prototype.setStrokeWidth = function (w) { - this._strokeWidth = w; - if (this._strokeWidth<1) { - this._strokeWidth = 1; + if (this._strokeWidth!==w) { + this._strokeWidth = w; + + if (this._strokeWidth<1) { + this._strokeWidth = 1; + } + this._isDirty=true; + this._freezeCanvas=false; } - this._isDirty=true; }; /* BrushStroke.prototype.getStrokeMaterial = function () { @@ -236,6 +242,7 @@ BrushStroke.prototype.setSmoothingAmount = function(a){ if (this._strokeAmountSmoothing!==a) { this._strokeAmountSmoothing = a; this._isDirty = true; + this._freezeCanvas=false; } }; @@ -274,27 +281,32 @@ BrushStroke.prototype.setStrokeStyle = function (s) { }; BrushStroke.prototype.setWidth = function (newW) { - if (newW<1) { - newW=1; //clamp minimum width to 1 + //get the old width from the canvas controller if the canvas is frozen, or from bbox if not frozen. + var oldCanvasWidth = parseInt(CanvasController.getProperty(this._canvas, "width")); + if (!this._freezeCanvas){ + oldCanvasWidth = Math.round(this._BBoxMax[0]-this._BBoxMin[0]); + } + var minWidth = 1+this._strokeWidth; + if (newW