diff options
author | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
---|---|---|
committer | Pushkar Joshi | 2012-02-24 12:08:49 -0800 |
commit | 03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch) | |
tree | c51112223ceb9121cd595a60335eb2795215590f /js/helper-classes/RDGE/GLRectangle.js | |
parent | fcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff) | |
parent | 053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff) | |
download | ninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz |
Merge branch 'pentool' into brushtool
Conflicts:
imports/codemirror/mode/scheme/scheme.js
js/tools/BrushTool.js
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rwxr-xr-x[-rw-r--r--] | js/helper-classes/RDGE/GLRectangle.js | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 2899e476..5b6ff94f 100644..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() ); |
@@ -400,12 +404,18 @@ function GLRectangle() | |||
400 | ctx.beginPath(); | 404 | ctx.beginPath(); |
401 | ctx.fillStyle = "#990000"; | 405 | ctx.fillStyle = "#990000"; |
402 | if (this._fillColor) | 406 | if (this._fillColor) |
403 | ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); | 407 | { |
408 | var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; | ||
409 | ctx.fillStyle = c; | ||
410 | } | ||
404 | 411 | ||
405 | // set the stroke | 412 | // set the stroke |
406 | ctx.strokeStyle = "#0000ff"; | 413 | ctx.strokeStyle = "#0000ff"; |
407 | if (this._strokeColor) | 414 | if (this._strokeColor) |
408 | ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); | 415 | { |
416 | var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; | ||
417 | ctx.strokeStyle = c; | ||
418 | } | ||
409 | 419 | ||
410 | ctx.lineWidth = lw; | 420 | ctx.lineWidth = lw; |
411 | var inset = Math.ceil( 0.5*lw ) + 0.5; | 421 | var inset = Math.ceil( 0.5*lw ) + 0.5; |
@@ -418,7 +428,7 @@ function GLRectangle() | |||
418 | this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) | 428 | this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
419 | { | 429 | { |
420 | // create the geometry | 430 | // create the geometry |
421 | var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) | 431 | var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
422 | return prim; | 432 | return prim; |
423 | } | 433 | } |
424 | 434 | ||
@@ -428,9 +438,9 @@ function GLRectangle() | |||
428 | // special the (common) case of no rounded corners | 438 | // special the (common) case of no rounded corners |
429 | var prim | 439 | var prim |
430 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) | 440 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) |
431 | prim = RectangleGeometry.create( ctr, width, height ); | 441 | prim = RectangleGeometry.create( ctr, width, height, material ); |
432 | else | 442 | else |
433 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); | 443 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); |
434 | 444 | ||
435 | return prim; | 445 | return prim; |
436 | } | 446 | } |
@@ -679,7 +689,7 @@ function GLRectangle() | |||
679 | } | 689 | } |
680 | 690 | ||
681 | RectangleFill = {}; | 691 | RectangleFill = {}; |
682 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) | 692 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material) |
683 | { | 693 | { |
684 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 694 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
685 | var hw = 0.5*width, hh = 0.5*height; | 695 | var hw = 0.5*width, hh = 0.5*height; |
@@ -766,6 +776,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
766 | j++; | 776 | j++; |
767 | } | 777 | } |
768 | 778 | ||
779 | //refine the mesh for vertex deformations | ||
780 | if (material) | ||
781 | { | ||
782 | if (material.hasVertexDeformation()) | ||
783 | { | ||
784 | var paramRange = material.getVertexDeformationRange(); | ||
785 | var tolerance = material.getVertexDeformationTolerance(); | ||
786 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | ||
787 | } | ||
788 | } | ||
789 | |||
769 | // create the RDGE primitive | 790 | // create the RDGE primitive |
770 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 791 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |
771 | return prim; | 792 | return prim; |
@@ -838,7 +859,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices) | |||
838 | 859 | ||
839 | 860 | ||
840 | RectangleStroke = {}; | 861 | RectangleStroke = {}; |
841 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) | 862 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
842 | { | 863 | { |
843 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 864 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
844 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; | 865 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; |
@@ -1029,6 +1050,17 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1029 | k++; | 1050 | k++; |
1030 | } | 1051 | } |
1031 | 1052 | ||
1053 | //refine the mesh for vertex deformations | ||
1054 | if (material) | ||
1055 | { | ||
1056 | if (material.hasVertexDeformation()) | ||
1057 | { | ||
1058 | var paramRange = material.getVertexDeformationRange(); | ||
1059 | var tolerance = material.getVertexDeformationTolerance(); | ||
1060 | //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | ||
1061 | } | ||
1062 | } | ||
1063 | |||
1032 | // create the RDGE primitive | 1064 | // create the RDGE primitive |
1033 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 1065 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |
1034 | return prim; | 1066 | return prim; |
@@ -1073,7 +1105,7 @@ RectangleStroke.getUV = RectangleFill.getUV; | |||
1073 | 1105 | ||
1074 | // Helper function for generating Three.js geometry | 1106 | // Helper function for generating Three.js geometry |
1075 | RectangleGeometry = {}; | 1107 | RectangleGeometry = {}; |
1076 | RectangleGeometry.create = function( ctr, width, height ) | 1108 | RectangleGeometry.create = function( ctr, width, height, material ) |
1077 | { | 1109 | { |
1078 | var x = ctr[0], y = ctr[1], z = 0.0; | 1110 | var x = ctr[0], y = ctr[1], z = 0.0; |
1079 | var hw = 0.5*width, hh = 0.5*height; | 1111 | var hw = 0.5*width, hh = 0.5*height; |
@@ -1111,8 +1143,20 @@ RectangleGeometry.create = function( ctr, width, height ) | |||
1111 | RectangleGeometry.pushIndices( 2, 1, 0 ); | 1143 | RectangleGeometry.pushIndices( 2, 1, 0 ); |
1112 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1144 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1113 | 1145 | ||
1146 | //refine the mesh for vertex deformations | ||
1147 | if (material) | ||
1148 | { | ||
1149 | if (material.hasVertexDeformation()) | ||
1150 | { | ||
1151 | var paramRange = material.getVertexDeformationRange(); | ||
1152 | var tolerance = material.getVertexDeformationTolerance(); | ||
1153 | //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | ||
1154 | } | ||
1155 | } | ||
1156 | |||
1114 | // create the RDGE primitive | 1157 | // create the RDGE primitive |
1115 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 1158 | var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |
1159 | //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); | ||
1116 | return prim; | 1160 | return prim; |
1117 | } | 1161 | } |
1118 | 1162 | ||
@@ -1182,3 +1226,8 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver | |||
1182 | 1226 | ||
1183 | return prim; | 1227 | return prim; |
1184 | } | 1228 | } |
1229 | |||
1230 | |||
1231 | |||
1232 | |||
1233 | |||