diff options
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rw-r--r-- | js/helper-classes/RDGE/GLRectangle.js | 148 |
1 files changed, 140 insertions, 8 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 1bb4bcac..e72b4488 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js | |||
@@ -280,7 +280,7 @@ function GLRectangle() | |||
280 | 280 | ||
281 | // stroke | 281 | // stroke |
282 | var strokeMaterial = this.makeStrokeMaterial(); | 282 | var strokeMaterial = this.makeStrokeMaterial(); |
283 | prim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial) | 283 | prim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius); |
284 | this._primArray.push( prim ); | 284 | this._primArray.push( prim ); |
285 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 285 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
286 | 286 | ||
@@ -486,7 +486,7 @@ function GLRectangle() | |||
486 | this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) | 486 | this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
487 | { | 487 | { |
488 | // create the geometry | 488 | // create the geometry |
489 | var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) | 489 | var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
490 | return prim; | 490 | return prim; |
491 | } | 491 | } |
492 | 492 | ||
@@ -496,9 +496,9 @@ function GLRectangle() | |||
496 | // special the (common) case of no rounded corners | 496 | // special the (common) case of no rounded corners |
497 | var prim | 497 | var prim |
498 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) | 498 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) |
499 | prim = RectangleGeometry.create( ctr, width, height ); | 499 | prim = RectangleGeometry.create( ctr, width, height, material ); |
500 | else | 500 | else |
501 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); | 501 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); |
502 | 502 | ||
503 | return prim; | 503 | return prim; |
504 | } | 504 | } |
@@ -747,7 +747,7 @@ function GLRectangle() | |||
747 | } | 747 | } |
748 | 748 | ||
749 | RectangleFill = {}; | 749 | RectangleFill = {}; |
750 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) | 750 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material) |
751 | { | 751 | { |
752 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 752 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
753 | var hw = 0.5*width, hh = 0.5*height; | 753 | var hw = 0.5*width, hh = 0.5*height; |
@@ -834,6 +834,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
834 | j++; | 834 | j++; |
835 | } | 835 | } |
836 | 836 | ||
837 | //refine the mesh for vertex deformations | ||
838 | if (material) | ||
839 | { | ||
840 | if (material.hasVertexDeformation()) | ||
841 | { | ||
842 | var paramRange = material.getVertexDeformationRange(); | ||
843 | var tolerance = material.getVertexDeformationTolerance(); | ||
844 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | ||
845 | } | ||
846 | } | ||
847 | |||
837 | // create the RDGE primitive | 848 | // create the RDGE primitive |
838 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 849 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |
839 | return prim; | 850 | return prim; |
@@ -906,7 +917,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices) | |||
906 | 917 | ||
907 | 918 | ||
908 | RectangleStroke = {}; | 919 | RectangleStroke = {}; |
909 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) | 920 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
910 | { | 921 | { |
911 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 922 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
912 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; | 923 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; |
@@ -1097,6 +1108,17 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1097 | k++; | 1108 | k++; |
1098 | } | 1109 | } |
1099 | 1110 | ||
1111 | //refine the mesh for vertex deformations | ||
1112 | if (material) | ||
1113 | { | ||
1114 | if (material.hasVertexDeformation()) | ||
1115 | { | ||
1116 | var paramRange = material.getVertexDeformationRange(); | ||
1117 | var tolerance = material.getVertexDeformationTolerance(); | ||
1118 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | ||
1119 | } | ||
1120 | } | ||
1121 | |||
1100 | // create the RDGE primitive | 1122 | // create the RDGE primitive |
1101 | 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); |
1102 | return prim; | 1124 | return prim; |
@@ -1141,7 +1163,7 @@ RectangleStroke.getUV = RectangleFill.getUV; | |||
1141 | 1163 | ||
1142 | // Helper function for generating Three.js geometry | 1164 | // Helper function for generating Three.js geometry |
1143 | RectangleGeometry = {}; | 1165 | RectangleGeometry = {}; |
1144 | RectangleGeometry.create = function( ctr, width, height ) | 1166 | RectangleGeometry.create = function( ctr, width, height, material ) |
1145 | { | 1167 | { |
1146 | var x = ctr[0], y = ctr[1], z = 0.0; | 1168 | var x = ctr[0], y = ctr[1], z = 0.0; |
1147 | var hw = 0.5*width, hh = 0.5*height; | 1169 | var hw = 0.5*width, hh = 0.5*height; |
@@ -1179,6 +1201,17 @@ RectangleGeometry.create = function( ctr, width, height ) | |||
1179 | RectangleGeometry.pushIndices( 2, 1, 0 ); | 1201 | RectangleGeometry.pushIndices( 2, 1, 0 ); |
1180 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1202 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1181 | 1203 | ||
1204 | //refine the mesh for vertex deformations | ||
1205 | if (material) | ||
1206 | { | ||
1207 | if (material.hasVertexDeformation()) | ||
1208 | { | ||
1209 | var paramRange = material.getVertexDeformationRange(); | ||
1210 | var tolerance = material.getVertexDeformationTolerance(); | ||
1211 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1182 | // create the RDGE primitive | 1215 | // create the RDGE primitive |
1183 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 1216 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |
1184 | return prim; | 1217 | return prim; |
@@ -1249,4 +1282,103 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver | |||
1249 | renderer.createPrimitive(prim, vertexCount); | 1282 | renderer.createPrimitive(prim, vertexCount); |
1250 | 1283 | ||
1251 | return prim; | 1284 | return prim; |
1252 | } \ No newline at end of file | 1285 | } |
1286 | |||
1287 | |||
1288 | ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) | ||
1289 | { | ||
1290 | // get the param range | ||
1291 | var pUMin = paramRange[0], pVMin = paramRange[1], | ||
1292 | pUMax = paramRange[2], pVMax = paramRange[3]; | ||
1293 | var iTriangle = 0; | ||
1294 | var nTriangles = indices.length/3; | ||
1295 | var index = 0; | ||
1296 | while (iTriangle < nTriangles) | ||
1297 | { | ||
1298 | // get the indices of the 3 vertices | ||
1299 | var i0 = indices[index], | ||
1300 | i1 = indices[index+1], | ||
1301 | i2 = indices[index+2]; | ||
1302 | |||
1303 | // get the uv values | ||
1304 | var vrtIndex = 3*iTriangle; | ||
1305 | var iuv0 = 2 * i0, | ||
1306 | iuv1 = 2 * i1, | ||
1307 | iuv2 = 2 * i2; | ||
1308 | var u0 = uvs[iuv0], v0 = uvs[iuv0+1], | ||
1309 | u1 = uvs[iuv1], v1 = uvs[iuv1+1], | ||
1310 | u2 = uvs[iuv2], v2 = uvs[iuv2+1]; | ||
1311 | |||
1312 | // find the u and v range | ||
1313 | var uMin = u0, vMin = v0; | ||
1314 | if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1; | ||
1315 | if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2; | ||
1316 | var uMax = u0, vMax = v0; | ||
1317 | if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1; | ||
1318 | if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2; | ||
1319 | |||
1320 | // if the parameter range of the triangle is outside the | ||
1321 | // desired parameter range, advance to the next polygon and continue | ||
1322 | if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin)) | ||
1323 | { | ||
1324 | // go to the next triangle | ||
1325 | iTriangle++; | ||
1326 | index += 3; | ||
1327 | } | ||
1328 | else | ||
1329 | { | ||
1330 | // check thesize of the triangle in uv space. If small enough, advance | ||
1331 | // to the next triangle. If not small enough, split the triangle into 3; | ||
1332 | var du = uMax - uMin, dv = vMax - vMin; | ||
1333 | if ((du < tolerance) && (dv < tolerance)) | ||
1334 | { | ||
1335 | iTriangle++; | ||
1336 | index += 3; | ||
1337 | } | ||
1338 | else // split the triangle | ||
1339 | { | ||
1340 | //calculate the position of the new vertex | ||
1341 | var iPt0 = 3 * i0, | ||
1342 | iPt1 = 3 * i1, | ||
1343 | iPt2 = 3 * i2; | ||
1344 | var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], | ||
1345 | x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], | ||
1346 | x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; | ||
1347 | var xMid = (x0 + x1 + x2)/3.0, | ||
1348 | yMid = (y0 + y1 + y2)/3.0, | ||
1349 | zMid = (z0 + z1 + z2)/3.0; | ||
1350 | |||
1351 | // calculate the uv value of the new coordinate | ||
1352 | var uMid = (u0 + u1 + u2)/3.0, | ||
1353 | vMid = (v0 + v1 + v2)/3.0; | ||
1354 | |||
1355 | // calculate the normal for the new coordinate | ||
1356 | var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], | ||
1357 | nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], | ||
1358 | nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; | ||
1359 | var nxMid = (nx0 + nx1 + nx2), | ||
1360 | nyMid = (ny0 + ny1 + ny2), | ||
1361 | nzMid = (nz0 + nz1 + nz2); | ||