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.js171
1 files changed, 159 insertions, 12 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index b88ecc71..e34532d2 100644
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -72,13 +72,14 @@ function GLRectangle()
72 this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; 72 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
73 73
74 if(strokeMaterial) 74 if(strokeMaterial)
75 {
76 this._strokeMaterial = strokeMaterial; 75 this._strokeMaterial = strokeMaterial;
77 } 76 else
77 this._strokeMaterial = new FlatMaterial();
78
78 if(fillMaterial) 79 if(fillMaterial)
79 {
80 this._fillMaterial = fillMaterial; 80 this._fillMaterial = fillMaterial;
81 } 81 else
82 this._fillMaterial = new FlatMaterial();
82 } 83 }
83 84
84 /////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////
@@ -209,8 +210,11 @@ function GLRectangle()
209 // get the world 210 // get the world
210 var world = this.getWorld(); 211 var world = this.getWorld();
211 if (!world) throw( "null world in buildBuffers" ); 212 if (!world) throw( "null world in buildBuffers" );
212 213 //console.log( "GLRectangle.buildBuffers " + world._worldCount );
213 if (!world._useWebGL) return; 214 if (!world._useWebGL) return;
215
216 // make sure RDGE has the correct context
217 g_Engine.setContext( world.getCanvas().uuid );
214 218
215 // create the gl buffer 219 // create the gl buffer
216 var gl = world.getGLContext(); 220 var gl = world.getGLContext();
@@ -283,6 +287,7 @@ function GLRectangle()
283 xFill -= strokeSize; 287 xFill -= strokeSize;
284 yFill -= strokeSize; 288 yFill -= strokeSize;
285 var fillMaterial = this.makeFillMaterial(); 289 var fillMaterial = this.makeFillMaterial();
290 //console.log( "fillMaterial: " + fillMaterial.getName() );
286 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 291 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
287 this._primArray.push( fillPrim ); 292 this._primArray.push( fillPrim );
288 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 293 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
@@ -430,7 +435,7 @@ function GLRectangle()
430 this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) 435 this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
431 { 436 {
432 // create the geometry 437 // create the geometry
433 var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) 438 var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
434 return prim; 439 return prim;
435 } 440 }
436 441
@@ -440,9 +445,9 @@ function GLRectangle()
440 // special the (common) case of no rounded corners 445 // special the (common) case of no rounded corners
441 var prim 446 var prim
442 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) 447 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0))
443 prim = RectangleGeometry.create( ctr, width, height ); 448 prim = RectangleGeometry.create( ctr, width, height, material );
444 else 449 else
445 prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); 450 prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material);
446 451
447 return prim; 452 return prim;
448 } 453 }
@@ -691,7 +696,7 @@ function GLRectangle()
691 } 696 }
692 697
693RectangleFill = {}; 698RectangleFill = {};
694RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) 699RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material)
695{ 700{
696 var x = rectCtr[0], y = rectCtr[1], z = 0.0; 701 var x = rectCtr[0], y = rectCtr[1], z = 0.0;
697 var hw = 0.5*width, hh = 0.5*height; 702 var hw = 0.5*width, hh = 0.5*height;
@@ -778,6 +783,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad,
778 j++; 783 j++;
779 } 784 }
780 785
786 //refine the mesh for vertex deformations
787 if (material)
788 {
789 if (material.hasVertexDeformation())
790 {
791 var paramRange = material.getVertexDeformationRange();
792 var tolerance = material.getVertexDeformationTolerance();
793 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
794 }
795 }
796
781 // create the RDGE primitive 797 // create the RDGE primitive
782 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 798 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
783 return prim; 799 return prim;
@@ -850,7 +866,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices)
850 866
851 867
852RectangleStroke = {}; 868RectangleStroke = {};
853RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) 869RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
854{ 870{
855 var x = rectCtr[0], y = rectCtr[1], z = 0.0; 871 var x = rectCtr[0], y = rectCtr[1], z = 0.0;
856 var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; 872 var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth;
@@ -1041,8 +1057,20 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1041 k++; 1057 k++;
1042 } 1058 }
1043 1059
1060 //refine the mesh for vertex deformations
1061 if (material)
1062 {
1063 if (material.hasVertexDeformation())
1064 {
1065 var paramRange = material.getVertexDeformationRange();
1066 var tolerance = material.getVertexDeformationTolerance();
1067 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1068 }
1069 }
1070
1044 // create the RDGE primitive 1071 // create the RDGE primitive
1045 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1072 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1073 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1046 return prim; 1074 return prim;
1047} 1075}
1048 1076
@@ -1085,7 +1113,7 @@ RectangleStroke.getUV = RectangleFill.getUV;
1085 1113
1086// Helper function for generating Three.js geometry 1114// Helper function for generating Three.js geometry
1087RectangleGeometry = {}; 1115RectangleGeometry = {};
1088RectangleGeometry.create = function( ctr, width, height ) 1116RectangleGeometry.create = function( ctr, width, height, material )
1089{ 1117{
1090 var x = ctr[0], y = ctr[1], z = 0.0; 1118 var x = ctr[0], y = ctr[1], z = 0.0;
1091 var hw = 0.5*width, hh = 0.5*height; 1119 var hw = 0.5*width, hh = 0.5*height;
@@ -1123,8 +1151,20 @@ RectangleGeometry.create = function( ctr, width, height )
1123 RectangleGeometry.pushIndices( 2, 1, 0 ); 1151 RectangleGeometry.pushIndices( 2, 1, 0 );
1124 RectangleGeometry.pushIndices( 0, 3, 2 ); 1152 RectangleGeometry.pushIndices( 0, 3, 2 );
1125 1153
1154 //refine the mesh for vertex deformations
1155 if (material)
1156 {
1157 if (material.hasVertexDeformation())
1158 {
1159 var paramRange = material.getVertexDeformationRange();
1160 var tolerance = material.getVertexDeformationTolerance();
1161 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1162 }
1163 }
1164
1126 // create the RDGE primitive 1165 // create the RDGE primitive
1127 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1166 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1167 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1128 return prim; 1168 return prim;
1129} 1169}
1130 1170
@@ -1193,4 +1233,111 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver
1193 renderer.createPrimitive(prim, vertexCount); 1233 renderer.createPrimitive(prim, vertexCount);
1194 1234
1195 return prim; 1235 return prim;
1196} \ No newline at end of file 1236}
1237
1238
1239ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance )
1240{
1241 // get the param range
1242 var pUMin = paramRange[0], pVMin = paramRange[1],
1243 pUMax = paramRange[2], pVMax = paramRange[3];
1244 var iTriangle = 0;
1245 var nTriangles = indices.length/3;
1246 var index = 0;
1247 while (iTriangle < nTriangles)
1248 {
1249 // get the indices of the 3 vertices
1250 var i0 = indices[index],
1251 i1 = indices[index+1],
1252 i2 = indices[index+2];
1253
1254 // get the uv values
1255 //var vrtIndex = 3*iTriangle;
1256 var iuv0 = 2 * i0,
1257 iuv1 = 2 * i1,
1258 iuv2 = 2 * i2;
1259 var u0 = uvs[iuv0], v0 = uvs[iuv0+1],
1260 u1 = uvs[iuv1], v1 = uvs[iuv1+1],
1261 u2 = uvs[iuv2], v2 = uvs[iuv2+1];
1262
1263 // find the u and v range
1264 var uMin = u0, vMin = v0;
1265 if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1;
1266 if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2;
1267 var uMax = u0, vMax = v0;
1268 if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1;
1269 if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2;
1270
1271 // if the parameter range of the triangle is outside the