diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/helper-classes/RDGE/GLMaterial.js | 11 | ||||
-rw-r--r-- | js/helper-classes/RDGE/GLRectangle.js | 148 | ||||
-rw-r--r-- | js/helper-classes/RDGE/GLWorld.js | 25 | ||||
-rw-r--r-- | js/helper-classes/RDGE/Materials/FlatMaterial.js | 1 | ||||
-rw-r--r-- | js/helper-classes/RDGE/Materials/LinearGradientMaterial.js | 4 | ||||
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/renderer.js | 13 |
6 files changed, 178 insertions, 24 deletions
diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js index c633f679..07a98ab5 100644 --- a/js/helper-classes/RDGE/GLMaterial.js +++ b/js/helper-classes/RDGE/GLMaterial.js | |||
@@ -31,6 +31,11 @@ function GLMaterial( world ) | |||
31 | 31 | ||
32 | this._texture; | 32 | this._texture; |
33 | 33 | ||
34 | // vertex deformation variables | ||
35 | this._hasVertexDeformation = false; | ||
36 | this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) | ||
37 | this._vertexDeformationTolerance = 0.05; | ||
38 | |||
34 | // RDGE variables | 39 | // RDGE variables |
35 | this._shader; | 40 | this._shader; |
36 | this._materialNode; | 41 | this._materialNode; |
@@ -66,6 +71,12 @@ function GLMaterial( world ) | |||
66 | // Any material needing continuous rendering should override this method | 71 | // Any material needing continuous rendering should override this method |
67 | this.isAnimated = function() { return false; } | 72 | this.isAnimated = function() { return false; } |
68 | 73 | ||
74 | // the vertex shader can apply deformations requiring refinement in | ||
75 | // certain areas. | ||
76 | this.hasVertexDeformation = function() { return this._hasVertexDeformation; } | ||
77 | this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); } | ||
78 | this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; } | ||
79 | |||
69 | 80 | ||
70 | /////////////////////////////////////////////////////////////////////// | 81 | /////////////////////////////////////////////////////////////////////// |
71 | // Common Material Methods | 82 | // Common Material Methods |
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 1bb4bcac..e72b4488 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js | |||
@@ -280,7 +280,7 @@ function GLRectangle() | |||
280 | 280 | ||
281 | // stroke | 281 | // stroke |
282 | var strokeMaterial = this.makeStrokeMaterial(); | 282 | var strokeMaterial = this.makeStrokeMaterial(); |
283 | 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); |
284 | this._primArray.push( prim ); | 284 | this._primArray.push( prim ); |
285 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 285 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
286 | 286 | ||
@@ -486,7 +486,7 @@ function GLRectangle() | |||
486 | 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) |
487 | { | 487 | { |
488 | // create the geometry | 488 | // create the geometry |
489 | 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) |
490 | return prim; | 490 | return prim; |
491 | } | 491 | } |
492 | 492 | ||
@@ -496,9 +496,9 @@ function GLRectangle() | |||
496 | // special the (common) case of no rounded corners | 496 | // special the (common) case of no rounded corners |
497 | var prim | 497 | var prim |
498 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) | 498 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) |
499 | prim = RectangleGeometry.create( ctr, width, height ); | 499 | prim = RectangleGeometry.create( ctr, width, height, material ); |
500 | else | 500 | else |
501 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); | 501 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); |
502 | 502 | ||
503 | return prim; | 503 | return prim; |
504 | } | 504 | } |
@@ -747,7 +747,7 @@ function GLRectangle() | |||
747 | } | 747 | } |
748 | 748 | ||
749 | RectangleFill = {}; | 749 | RectangleFill = {}; |
750 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) | 750 | RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material) |
751 | { | 751 | { |
752 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 752 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
753 | var hw = 0.5*width, hh = 0.5*height; | 753 | var hw = 0.5*width, hh = 0.5*height; |
@@ -834,6 +834,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
834 | j++; | 834 | j++; |
835 | } | 835 | } |
836 | 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 | |||
837 | // create the RDGE primitive | 848 | // create the RDGE primitive |
838 | 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); |
839 | return prim; | 850 | return prim; |
@@ -906,7 +917,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices) | |||
906 | 917 | ||
907 | 918 | ||
908 | RectangleStroke = {}; | 919 | RectangleStroke = {}; |
909 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) | 920 | RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) |
910 | { | 921 | { |
911 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; | 922 | var x = rectCtr[0], y = rectCtr[1], z = 0.0; |
912 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; | 923 | var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; |
@@ -1097,6 +1108,17 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1097 | k++; | 1108 | k++; |
1098 | } | 1109 | } |
1099 | 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 | |||
1100 | // create the RDGE primitive | 1122 | // create the RDGE primitive |
1101 | 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); |
1102 | return prim; | 1124 | return prim; |
@@ -1141,7 +1163,7 @@ RectangleStroke.getUV = RectangleFill.getUV; | |||
1141 | 1163 | ||
1142 | // Helper function for generating Three.js geometry | 1164 | // Helper function for generating Three.js geometry |
1143 | RectangleGeometry = {}; | 1165 | RectangleGeometry = {}; |
1144 | RectangleGeometry.create = function( ctr, width, height ) | 1166 | RectangleGeometry.create = function( ctr, width, height, material ) |
1145 | { | 1167 | { |
1146 | var x = ctr[0], y = ctr[1], z = 0.0; | 1168 | var x = ctr[0], y = ctr[1], z = 0.0; |
1147 | var hw = 0.5*width, hh = 0.5*height; | 1169 | var hw = 0.5*width, hh = 0.5*height; |
@@ -1179,6 +1201,17 @@ RectangleGeometry.create = function( ctr, width, height ) | |||
1179 | RectangleGeometry.pushIndices( 2, 1, 0 ); | 1201 | RectangleGeometry.pushIndices( 2, 1, 0 ); |
1180 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1202 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1181 | 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 | |||
1182 | // create the RDGE primitive | 1215 | // create the RDGE primitive |
1183 | 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); |
1184 | return prim; | 1217 | return prim; |
@@ -1249,4 +1282,103 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver | |||
1249 | renderer.createPrimitive(prim, vertexCount); | 1282 | renderer.createPrimitive(prim, vertexCount); |
1250 | 1283 | ||
1251 | return prim; | 1284 | return prim; |
1252 | } \ 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 | } | ||