aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLRectangle.js
diff options
context:
space:
mode:
authorAnanya Sen2012-02-13 16:19:21 -0800
committerAnanya Sen2012-02-13 16:19:21 -0800
commitb58dafe332fb57210f3d059a518a3d183c222631 (patch)
tree09fd958b0f7f3f51dc88e613e7764bdfc642b742 /js/helper-classes/RDGE/GLRectangle.js
parentf3dc624fa464a79fd8e8cec1ddd16ed2109bda23 (diff)
parentf70701db069a10dc5195605fc378a022125b434f (diff)
downloadninja-b58dafe332fb57210f3d059a518a3d183c222631.tar.gz
Merge branch 'FileIO' of github.com:joseeight/ninja-internal into FileIO
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rwxr-xr-xjs/helper-classes/RDGE/GLRectangle.js162
1 files changed, 154 insertions, 8 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index 2899e476..4216fe53 100755
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -180,7 +180,7 @@ function GLRectangle()
180 this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); 180 this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) );
181 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); 181 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
182 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); 182 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
183 this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); 183 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
184 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); 184 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
185 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); 185 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
186 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); 186 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) );
@@ -210,8 +210,11 @@ function GLRectangle()
210 // get the world 210 // get the world
211 var world = this.getWorld(); 211 var world = this.getWorld();
212 if (!world) throw( "null world in buildBuffers" ); 212 if (!world) throw( "null world in buildBuffers" );
213 213 //console.log( "GLRectangle.buildBuffers " + world._worldCount );
214 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 );
215 218
216 // create the gl buffer 219 // create the gl buffer
217 var gl = world.getGLContext(); 220 var gl = world.getGLContext();
@@ -284,6 +287,7 @@ function GLRectangle()
284 xFill -= strokeSize; 287 xFill -= strokeSize;
285 yFill -= strokeSize; 288 yFill -= strokeSize;
286 var fillMaterial = this.makeFillMaterial(); 289 var fillMaterial = this.makeFillMaterial();
290 //console.log( "fillMaterial: " + fillMaterial.getName() );
287 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);
288 this._primArray.push( fillPrim ); 292 this._primArray.push( fillPrim );
289 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 293 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
@@ -418,7 +422,7 @@ function GLRectangle()
418 this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) 422 this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
419 { 423 {
420 // create the geometry 424 // create the geometry
421 var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) 425 var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
422 return prim; 426 return prim;
423 } 427 }
424 428
@@ -428,9 +432,9 @@ function GLRectangle()
428 // special the (common) case of no rounded corners 432 // special the (common) case of no rounded corners
429 var prim 433 var prim
430 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) 434 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0))
431 prim = RectangleGeometry.create( ctr, width, height ); 435 prim = RectangleGeometry.create( ctr, width, height, material );
432 else 436 else
433 prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); 437 prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material);
434 438
435 return prim; 439 return prim;
436 } 440 }
@@ -679,7 +683,7 @@ function GLRectangle()
679 } 683 }
680 684
681RectangleFill = {}; 685RectangleFill = {};
682RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) 686RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material)
683{ 687{
684 var x = rectCtr[0], y = rectCtr[1], z = 0.0; 688 var x = rectCtr[0], y = rectCtr[1], z = 0.0;
685 var hw = 0.5*width, hh = 0.5*height; 689 var hw = 0.5*width, hh = 0.5*height;
@@ -766,6 +770,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad,
766 j++; 770 j++;
767 } 771 }
768 772
773 //refine the mesh for vertex deformations
774 if (material)
775 {
776 if (material.hasVertexDeformation())
777 {
778 var paramRange = material.getVertexDeformationRange();
779 var tolerance = material.getVertexDeformationTolerance();
780 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
781 }
782 }
783
769 // create the RDGE primitive 784 // create the RDGE primitive
770 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 785 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
771 return prim; 786 return prim;
@@ -838,7 +853,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices)
838 853
839 854
840RectangleStroke = {}; 855RectangleStroke = {};
841RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) 856RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
842{ 857{
843 var x = rectCtr[0], y = rectCtr[1], z = 0.0; 858 var x = rectCtr[0], y = rectCtr[1], z = 0.0;
844 var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; 859 var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth;
@@ -1029,8 +1044,20 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1029 k++; 1044 k++;
1030 } 1045 }
1031 1046
1047 //refine the mesh for vertex deformations
1048 if (material)
1049 {
1050 if (material.hasVertexDeformation())
1051 {
1052 var paramRange = material.getVertexDeformationRange();
1053 var tolerance = material.getVertexDeformationTolerance();
1054 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1055 }
1056 }
1057
1032 // create the RDGE primitive 1058 // create the RDGE primitive
1033 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1059 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);
1034 return prim; 1061 return prim;
1035} 1062}
1036 1063
@@ -1073,7 +1100,7 @@ RectangleStroke.getUV = RectangleFill.getUV;
1073 1100
1074// Helper function for generating Three.js geometry 1101// Helper function for generating Three.js geometry
1075RectangleGeometry = {}; 1102RectangleGeometry = {};
1076RectangleGeometry.create = function( ctr, width, height ) 1103RectangleGeometry.create = function( ctr, width, height, material )
1077{ 1104{
1078 var x = ctr[0], y = ctr[1], z = 0.0; 1105 var x = ctr[0], y = ctr[1], z = 0.0;
1079 var hw = 0.5*width, hh = 0.5*height; 1106 var hw = 0.5*width, hh = 0.5*height;
@@ -1111,8 +1138,20 @@ RectangleGeometry.create = function( ctr, width, height )
1111 RectangleGeometry.pushIndices( 2, 1, 0 ); 1138 RectangleGeometry.pushIndices( 2, 1, 0 );
1112 RectangleGeometry.pushIndices( 0, 3, 2 ); 1139 RectangleGeometry.pushIndices( 0, 3, 2 );
1113 1140
1141 //refine the mesh for vertex deformations
1142 if (material)
1143 {
1144 if (material.hasVertexDeformation())
1145 {
1146 var paramRange = material.getVertexDeformationRange();
1147 var tolerance = material.getVertexDeformationTolerance();
1148 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1149 }
1150 }
1151
1114 // create the RDGE primitive 1152 // create the RDGE primitive
1115 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1153 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1154 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1116 return prim; 1155 return prim;
1117} 1156}
1118 1157
@@ -1182,3 +1221,110 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver
1182 1221
1183 return prim; 1222 return prim;
1184} 1223}
1224
1225
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