diff options
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rw-r--r-- | js/helper-classes/RDGE/GLRectangle.js | 157 |
1 files changed, 145 insertions, 12 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 1334d7e6..e72b4488 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js | |||
@@ -80,13 +80,14 @@ function GLRectangle() | |||
80 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; | 80 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; |
81 | 81 | ||
82 | if(strokeMaterial) | 82 | if(strokeMaterial) |
83 | { | ||
84 | this._strokeMaterial = strokeMaterial; | 83 | this._strokeMaterial = strokeMaterial; |
85 | } | 84 | else |
85 | this._strokeMaterial = new FlatMaterial(); | ||
86 | |||
86 | if(fillMaterial) | 87 | if(fillMaterial) |
87 | { | ||
88 | this._fillMaterial = fillMaterial; | 88 | this._fillMaterial = fillMaterial; |
89 | } | 89 | else |
90 | this._fillMaterial = new FlatMaterial(); | ||
90 | } | 91 | } |
91 | 92 | ||
92 | /////////////////////////////////////////////////////////////////////// | 93 | /////////////////////////////////////////////////////////////////////// |
@@ -279,7 +280,7 @@ function GLRectangle() | |||
279 | 280 | ||
280 | // stroke | 281 | // stroke |
281 | var strokeMaterial = this.makeStrokeMaterial(); | 282 | var strokeMaterial = this.makeStrokeMaterial(); |
282 | 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); |
283 | this._primArray.push( prim ); | 284 | this._primArray.push( prim ); |
284 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 285 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
285 | 286 | ||
@@ -485,7 +486,7 @@ function GLRectangle() | |||
485 | 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) |
486 | { | 487 | { |
487 | // create the geometry | 488 | // create the geometry |
488 | 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) |
489 | return prim; | 490 | return prim; |
490 | } | 491 | } |
491 | 492 | ||
@@ -495,9 +496,9 @@ function GLRectangle() | |||
495 | // special the (common) case of no rounded corners | 496 | // special the (common) case of no rounded corners |
496 | var prim | 497 | var prim |
497 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) | 498 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) |
498 | prim = RectangleGeometry.create( ctr, width, height ); | 499 | prim = RectangleGeometry.create( ctr, width, height, material ); |
499 | else | 500 | else |
500 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); | 501 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); |
501 | 502 | ||
502 | return prim; | 503 | return prim; |
503 | } | 504 | } |
@@ -746,7 +747,7 @@ function GLRectangle() | |||
746 | } | 747 | } |
747 | 748 | ||
748 | RectangleFill = {}; | 749 | RectangleFill = {}; |
749 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) | 750 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material) |
750 | { | 751 | { |
751 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 752 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
752 | var hw = 0.5*width, hh = 0.5*height; | 753 | var hw = 0.5*width, hh = 0.5*height; |
@@ -833,6 +834,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
833 | j++; | 834 | j++; |
834 | } | 835 | } |
835 | 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 | |||
836 | // create the RDGE primitive | 848 | // create the RDGE primitive |
837 | 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); |
838 | return prim; | 850 | return prim; |
@@ -905,7 +917,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices) | |||
905 | 917 | ||
906 | 918 | ||
907 | RectangleStroke = {}; | 919 | RectangleStroke = {}; |
908 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) | 920 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
909 | { | 921 | { |
910 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 922 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
911 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; | 923 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; |
@@ -1096,6 +1108,17 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1096 | k++; | 1108 | k++; |
1097 | } | 1109 | } |
1098 | 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 | |||
1099 | // create the RDGE primitive | 1122 | // create the RDGE primitive |
1100 | 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); |
1101 | return prim; | 1124 | return prim; |
@@ -1140,7 +1163,7 @@ RectangleStroke.getUV = RectangleFill.getUV; | |||
1140 | 1163 | ||
1141 | // Helper function for generating Three.js geometry | 1164 | // Helper function for generating Three.js geometry |
1142 | RectangleGeometry = {}; | 1165 | RectangleGeometry = {}; |
1143 | RectangleGeometry.create = function( ctr, width, height ) | 1166 | RectangleGeometry.create = function( ctr, width, height, material ) |
1144 | { | 1167 | { |
1145 | var x = ctr[0], y = ctr[1], z = 0.0; | 1168 | var x = ctr[0], y = ctr[1], z = 0.0; |
1146 | var hw = 0.5*width, hh = 0.5*height; | 1169 | var hw = 0.5*width, hh = 0.5*height; |
@@ -1178,6 +1201,17 @@ RectangleGeometry.create = function( ctr, width, height ) | |||
1178 | RectangleGeometry.pushIndices( 2, 1, 0 ); | 1201 | RectangleGeometry.pushIndices( 2, 1, 0 ); |
1179 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1202 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1180 | 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 | |||
1181 | // create the RDGE primitive | 1215 | // create the RDGE primitive |
1182 | 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); |
1183 | return prim; | 1217 | return prim; |
@@ -1248,4 +1282,103 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver | |||
1248 | renderer.createPrimitive(prim, vertexCount); | 1282 | renderer.createPrimitive(prim, vertexCount); |
1249 | 1283 | ||
1250 | return prim; | 1284 | return prim; |
1251 | } \ 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 |