aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLRectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rw-r--r--js/helper-classes/RDGE/GLRectangle.js64
1 files changed, 37 insertions, 27 deletions
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,
1121 1121
1122 // create the RDGE primitive 1122 // create the RDGE primitive
1123 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1123 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1124 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1124 return prim; 1125 return prim;
1125} 1126}
1126 1127
@@ -1214,6 +1215,7 @@ RectangleGeometry.create = function( ctr, width, height, material )
1214 1215
1215 // create the RDGE primitive 1216 // create the RDGE primitive
1216 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1217 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1218 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1217 return prim; 1219 return prim;
1218} 1220}
1219 1221
@@ -1301,7 +1303,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1301 i2 = indices[index+2]; 1303 i2 = indices[index+2];
1302 1304
1303 // get the uv values 1305 // get the uv values
1304 var vrtIndex = 3*iTriangle; 1306 //var vrtIndex = 3*iTriangle;
1305 var iuv0 = 2 * i0, 1307 var iuv0 = 2 * i0,
1306 iuv1 = 2 * i1, 1308 iuv1 = 2 * i1,
1307 iuv2 = 2 * i2; 1309 iuv2 = 2 * i2;
@@ -1335,7 +1337,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1335 iTriangle++; 1337 iTriangle++;
1336 index += 3; 1338 index += 3;
1337 } 1339 }
1338 else // split the triangle 1340 else // split the triangle into 4 parts
1339 { 1341 {
1340 //calculate the position of the new vertex 1342 //calculate the position of the new vertex
1341 var iPt0 = 3 * i0, 1343 var iPt0 = 3 * i0,
@@ -1344,34 +1346,42 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1344 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], 1346 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2],
1345 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], 1347 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2],
1346 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; 1348 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2];
1347 var xMid = (x0 + x1 + x2)/3.0, 1349
1348 yMid = (y0 + y1 + y2)/3.0, 1350 // calculate the midpoints of the edges
1349 zMid = (z0 + z1 + z2)/3.0; 1351 var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0,
1350 1352 xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0,
1351 // calculate the uv value of the new coordinate 1353 xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0;
1352 var uMid = (u0 + u1 + u2)/3.0, 1354
1353 vMid = (v0 + v1 + v2)/3.0; 1355 // calculate the uv values of the new coordinates
1354 1356 var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0,
1355 // calculate the normal for the new coordinate 1357 uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0,
1358 uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0;
1359
1360 // calculate the normals for the new points
1356 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], 1361 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2],
1357 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], 1362 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2],
1358 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; 1363 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2];
1359 var nxMid = (nx0 + nx1 + nx2), 1364 var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ),
1360 nyMid = (ny0 + ny1 + ny2), 1365 nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ),
1361 nzMid = (nz0 + nz1 + nz2); 1366 nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 );
1362 var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); 1367
1363 1368 // push everything
1364 // push the new vertex 1369 verts.push(xA); verts.push(yA); verts.push(zA);
1365 verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); 1370 verts.push(xB); verts.push(yB); verts.push(zB);
1366 uvs.push(uMid), uvs.push(vMid); 1371 verts.push(xC); verts.push(yC); verts.push(zC);
1367 norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); 1372 uvs.push(uA), uvs.push(vA);
1368 var iMidVrt = nVertices; 1373 uvs.push(uB), uvs.push(vB);
1369 nVertices++; 1374 uvs.push(uC), uvs.push(vC);
1370 1375 norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]);
1371 // split the current triangle into 3 1376 norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]);
1372 indices[index+2] = iMidVrt; 1377 norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]);
1373 indices.push(i1); indices.push(i2); indices.push(iMidVrt); nTriangles++; 1378
1374 indices.push(i2); indices.push(i0); indices.push(iMidVrt); nTriangles++; 1379 // split the current triangle into 4
1380 indices[index+1] = nVertices; indices[index+2] = nVertices+2;
1381 indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++;
1382 indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++;
1383 indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++;
1384 nVertices += 3;
1375 1385
1376 // by not advancing 'index', we examine the first of the 3 triangles generated above 1386 // by not advancing 'index', we examine the first of the 3 triangles generated above
1377 } 1387 }