aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js131
1 files changed, 109 insertions, 22 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index ec3e25b2..cfa6aae5 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -101,15 +101,28 @@ exports.Rectangle = Object.create(GeomObj, {
101 } else { 101 } else {
102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
103 } 103 }
104 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor );
105 104
105 if(strokeColor) {
106 if(this._strokeMaterial.hasProperty("color")) {
107 this._strokeMaterial.setProperty( "color", this._strokeColor );
108 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
109 this._strokeMaterial.setGradientData(this._strokeColor.color);
110 }
111 }
106 112
107 if(fillMaterial) { 113 if(fillMaterial) {
108 this._fillMaterial = fillMaterial.dup(); 114 this._fillMaterial = fillMaterial.dup();
109 } else { 115 } else {
110 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 116 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
111 } 117 }
112 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); 118
119 if(fillColor) {
120 if(this._fillMaterial.hasProperty("color")) {
121 this._fillMaterial.setProperty( "color", this._fillColor );
122 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) {
123 this._fillMaterial.setGradientData(this._fillColor.color);
124 }
125 }
113 } 126 }
114 }, 127 },
115 128
@@ -407,11 +420,15 @@ exports.Rectangle = Object.create(GeomObj, {
407 brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; 420 brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC;
408 421
409 // stroke 422 // stroke
423 var i;
410 var strokeMaterial = this.makeStrokeMaterial(); 424 var strokeMaterial = this.makeStrokeMaterial();
411 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); 425 var strokePrimArray = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial);
412 strokeMaterial.fitToPrimitive( strokePrim ); 426 strokeMaterial.fitToPrimitiveArray( strokePrimArray );
413 this._primArray.push( strokePrim ); 427 for (i=0; i<strokePrimArray.length; i++)
428 {
429 this._primArray.push( strokePrimArray[i] );
414 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 430 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
431 }
415 432
416 // fill 433 // fill
417 tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; 434 tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0;
@@ -422,10 +439,13 @@ exports.Rectangle = Object.create(GeomObj, {
422 yFill -= strokeSize; 439 yFill -= strokeSize;
423 var fillMaterial = this.makeFillMaterial(); 440 var fillMaterial = this.makeFillMaterial();
424 //console.log( "fillMaterial: " + fillMaterial.getName() ); 441 //console.log( "fillMaterial: " + fillMaterial.getName() );
425 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 442 var fillPrimArray = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
426 fillMaterial.fitToPrimitive( fillPrim ); 443 fillMaterial.fitToPrimitiveArray( fillPrimArray );
427 this._primArray.push( fillPrim ); 444 for (i=0; i<fillPrimArray.length; i++)
445 {
446 this._primArray.push( fillPrimArray[i] );
428 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 447 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
448 }
429 449
430 world.updateObject(this); 450 world.updateObject(this);
431 } 451 }
@@ -645,15 +665,17 @@ exports.Rectangle = Object.create(GeomObj, {
645 value: function(ctr, width, height, tlRad, blRad, brRad, trRad, material) { 665 value: function(ctr, width, height, tlRad, blRad, brRad, trRad, material) {
646 // create the geometry 666 // create the geometry
647 // special the (common) case of no rounded corners 667 // special the (common) case of no rounded corners
648 var prim; 668 var primArray;
649 669
650 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { 670 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) {
651 prim = RectangleGeometry.create( ctr, width, height, material ); 671 primArray = RectangleGeometry.create( ctr, width, height, material );
652 } else { 672 } else {
653 prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); 673 primArray = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material);
654 } 674 }
655 675
656 return prim; 676 console.log( "rectangle produced " + primArray.length + " fill primitives" );
677
678 return primArray;
657 } 679 }
658 }, 680 },
659 681
@@ -976,16 +998,43 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad,
976 } 998 }
977 999
978 //refine the mesh for vertex deformations 1000 //refine the mesh for vertex deformations
979 if (material) { 1001 var rtnArray;
980 if (material.hasVertexDeformation()) { 1002 if (material)
1003 {
1004 if (material.hasVertexDeformation())
1005 {
981 var paramRange = material.getVertexDeformationRange(); 1006 var paramRange = material.getVertexDeformationRange();
982 var tolerance = material.getVertexDeformationTolerance(); 1007 var tolerance = material.getVertexDeformationTolerance();
983 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1008 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1009
1010 var subdividedParts = ShapePrimitive.subdivideOversizedMesh( this.vertices, this.normals, this.uvs, this.indices );
1011
1012 rtnArray = [];
1013 if (subdividedParts)
1014 {
1015 for (var i=0; i<subdividedParts.length; i++)
1016 {
1017 var obj = subdividedParts[i];
1018 rtnArray.push( ShapePrimitive.create(obj.vertices, obj.normals, obj.uvs, obj.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, obj.vertices.length/3) );
984 } 1019 }
985 } 1020 }
1021 else
1022 rtnArray = [ ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
1023
1024// var vertsOut = [], normsOut = [], uvsOut = [], indicesOut = [];
1025// ShapePrimitive.convertTrianglesToLines( this.vertices, this.normals, this.uvs, this.indices, vertsOut, normsOut, uvsOut, indicesOut );
1026// nVertices = vertsOut.length;
1027// return ShapePrimitive.create(vertsOut, normsOut, uvsOut, indicesOut, RDGE.globals.engine.getContext().renderer.LINES, nVertices);
986 1028
1029 }
1030 else
1031 {
987 // create the RDGE primitive 1032 // create the RDGE primitive
988 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); 1033 rtnArray = [ ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
1034 }
1035 }
1036
1037 return rtnArray;
989}; 1038};
990 1039
991RectangleFill.pushVertex = function( x, y, z ) { 1040RectangleFill.pushVertex = function( x, y, z ) {
@@ -1018,7 +1067,7 @@ RectangleFill.getVertex = function( index ) {
1018 1067
1019RectangleFill.getUV = function( x, y, xMin, w, yMin, h) { 1068RectangleFill.getUV = function( x, y, xMin, w, yMin, h) {
1020 var u = (x - xMin)/w, 1069 var u = (x - xMin)/w,
1021 v = (y - yMin)/h; 1070 v = 1.0 - (y - yMin)/h;
1022 1071
1023 var uv = [ u, v ]; 1072 var uv = [ u, v ];
1024 return uv; 1073 return uv;
@@ -1208,6 +1257,7 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1208 } 1257 }
1209 1258
1210 //refine the mesh for vertex deformations 1259 //refine the mesh for vertex deformations
1260 var rtnArray;
1211 if (material) 1261 if (material)
1212 { 1262 {
1213 if (material.hasVertexDeformation()) 1263 if (material.hasVertexDeformation())
@@ -1215,11 +1265,29 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1215 var paramRange = material.getVertexDeformationRange(); 1265 var paramRange = material.getVertexDeformationRange();
1216 var tolerance = material.getVertexDeformationTolerance(); 1266 var tolerance = material.getVertexDeformationTolerance();
1217 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1267 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1268
1269 var subdividedParts = ShapePrimitive.subdivideOversizedMesh( this.vertices, this.normals, this.uvs, this.indices );
1270
1271 rtnArray = [];
1272 if (subdividedParts)
1273 {
1274 for (var i=0; i<subdividedParts.length; i++)
1275 {
1276 var obj = subdividedParts[i];
1277 rtnArray.push( ShapePrimitive.create(obj.vertices, obj.normals, obj.uvs, obj.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, obj.vertices.length/3) );
1218 } 1278 }
1219 } 1279 }
1220 1280 else
1221 // create the RDGE primitive 1281 rtnArray = [ ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
1222 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); 1282 }
1283 else
1284 {
1285 // create the RDGE primitive
1286 rtnArray = [ ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
1287 }
1288 }
1289
1290 return rtnArray;
1223}; 1291};
1224 1292
1225RectangleStroke.getRoundedCorner = function( ctr, insidePt, outsidePt ) { 1293RectangleStroke.getRoundedCorner = function( ctr, insidePt, outsidePt ) {
@@ -1294,6 +1362,7 @@ RectangleGeometry.create = function( ctr, width, height, material ) {
1294 RectangleGeometry.pushIndices( 0, 3, 2 ); 1362 RectangleGeometry.pushIndices( 0, 3, 2 );
1295 1363
1296 //refine the mesh for vertex deformations 1364 //refine the mesh for vertex deformations
1365 var rtnArray;
1297 if (material) 1366 if (material)
1298 { 1367 {
1299 if (material.hasVertexDeformation()) 1368 if (material.hasVertexDeformation())
@@ -1301,11 +1370,29 @@ RectangleGeometry.create = function( ctr, width, height, material ) {
1301 var paramRange = material.getVertexDeformationRange(); 1370 var paramRange = material.getVertexDeformationRange();
1302 var tolerance = material.getVertexDeformationTolerance(); 1371 var tolerance = material.getVertexDeformationTolerance();
1303 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1372 nVertices = ShapePrimiti