aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLRectangle.js
diff options
context:
space:
mode:
authorEric Guzman2012-02-27 11:13:35 -0800
committerEric Guzman2012-02-27 11:13:35 -0800
commit1a6604a50f6cfbbf0cd6f45ab94b63a001d02162 (patch)
treebbfc75d1be1ff98d22042dbbed4ca93b4a845e0c /js/helper-classes/RDGE/GLRectangle.js
parent9e8cd4448a6d0f809a55c3bdea8b45ed75339794 (diff)
parent8125c8c6c9431067840d81c46624b6a2dd5eb4a7 (diff)
downloadninja-1a6604a50f6cfbbf0cd6f45ab94b63a001d02162.tar.gz
Merge branch 'refs/heads/master' into CSSPanelUpdates
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rwxr-xr-xjs/helper-classes/RDGE/GLRectangle.js117
1 files changed, 10 insertions, 107 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index 4216fe53..5b6ff94f 100755
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -404,12 +404,18 @@ function GLRectangle()
404 ctx.beginPath(); 404 ctx.beginPath();
405 ctx.fillStyle = "#990000"; 405 ctx.fillStyle = "#990000";
406 if (this._fillColor) 406 if (this._fillColor)
407 ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); 407 {
408 var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")";
409 ctx.fillStyle = c;
410 }
408 411
409 // set the stroke 412 // set the stroke
410 ctx.strokeStyle = "#0000ff"; 413 ctx.strokeStyle = "#0000ff";
411 if (this._strokeColor) 414 if (this._strokeColor)
412 ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); 415 {
416 var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")";
417 ctx.strokeStyle = c;
418 }
413 419
414 ctx.lineWidth = lw; 420 ctx.lineWidth = lw;
415 var inset = Math.ceil( 0.5*lw ) + 0.5; 421 var inset = Math.ceil( 0.5*lw ) + 0.5;
@@ -1051,13 +1057,12 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1051 { 1057 {
1052 var paramRange = material.getVertexDeformationRange(); 1058 var paramRange = material.getVertexDeformationRange();
1053 var tolerance = material.getVertexDeformationTolerance(); 1059 var tolerance = material.getVertexDeformationTolerance();
1054 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1060 //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1055 } 1061 }
1056 } 1062 }
1057 1063
1058 // create the RDGE primitive 1064 // create the RDGE primitive
1059 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1065 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1060 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1061 return prim; 1066 return prim;
1062} 1067}
1063 1068
@@ -1145,7 +1150,7 @@ RectangleGeometry.create = function( ctr, width, height, material )
1145 { 1150 {
1146 var paramRange = material.getVertexDeformationRange(); 1151 var paramRange = material.getVertexDeformationRange();
1147 var tolerance = material.getVertexDeformationTolerance(); 1152 var tolerance = material.getVertexDeformationTolerance();
1148 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1153 //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1149 } 1154 }
1150 } 1155 }
1151 1156
@@ -1223,108 +1228,6 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver
1223} 1228}
1224 1229
1225 1230
1226ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance )
1227{
1228 // get the param range
1229 var pUMin = paramRange[0], pVMin = paramRange[1],
1230 pUMax = paramRange[2], pVMax = paramRange[3];
1231 var iTriangle = 0;
1232 var nTriangles = indices.length/3;
1233 var index = 0;
1234 while (iTriangle < nTriangles)
1235 {
1236 // get the indices of the 3 vertices
1237 var i0 = indices[index],
1238 i1 = indices[index+1],
1239 i2 = indices[index+2];
1240
1241 // get the uv values
1242 //var vrtIndex = 3*iTriangle;
1243 var iuv0 = 2 * i0,
1244 iuv1 = 2 * i1,
1245 iuv2 = 2 * i2;
1246 var u0 = uvs[iuv0], v0 = uvs[iuv0+1],
1247 u1 = uvs[iuv1], v1 = uvs[iuv1+1],
1248 u2 = uvs[iuv2], v2 = uvs[iuv2+1];
1249
1250 // find the u and v range
1251 var uMin = u0, vMin = v0;
1252 if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1;
1253 if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2;
1254 var uMax = u0, vMax = v0;
1255 if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1;
1256 if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2;
1257
1258 // if the parameter range of the triangle is outside the
1259 // desired parameter range, advance to the next polygon and continue
1260 if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin))
1261 {
1262 // go to the next triangle
1263 iTriangle++;
1264 index += 3;
1265 }
1266 else
1267 {
1268 // check thesize of the triangle in uv space. If small enough, advance
1269 // to the next triangle. If not small enough, split the triangle into 3;
1270 var du = uMax - uMin, dv = vMax - vMin;
1271 if ((du < tolerance) && (dv < tolerance))
1272 {
1273 iTriangle++;
1274 index += 3;
1275 }
1276 else // split the triangle into 4 parts
1277 {
1278 //calculate the position of the new vertex
1279 var iPt0 = 3 * i0,
1280 iPt1 = 3 * i1,
1281 iPt2 = 3 * i2;
1282 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2],
1283 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2],
1284 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2];
1285
1286 // calculate the midpoints of the edges
1287 var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0,
1288 xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0,
1289 xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0;
1290
1291 // calculate the uv values of the new coordinates
1292 var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0,
1293 uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0,
1294 uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0;
1295
1296 // calculate the normals for the new points
1297 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2],
1298 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2],
1299 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2];
1300 var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ),
1301 nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ),
1302 nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 );
1303
1304 // push everything
1305 verts.push(xA); verts.push(yA); verts.push(zA);
1306 verts.push(xB); verts.push(yB); verts.push(zB);
1307 verts.push(xC); verts.push(yC); verts.push(zC);
1308 uvs.push(uA), uvs.push(vA);
1309 uvs.push(uB), uvs.push(vB);
1310 uvs.push(uC), uvs.push(vC);
1311 norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]);
1312 norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]);
1313 norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]);
1314
1315 // split the current triangle into 4
1316 indices[index+1] = nVertices; indices[index+2] = nVertices+2;
1317 indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++;
1318 indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++;
1319 indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++;
1320 nVertices += 3;
1321
1322 // by not advancing 'index', we examine the first of the 3 triangles generated above
1323 }
1324 }
1325 }
1326 return nVertices;
1327}
1328 1231
1329 1232
1330 1233