diff options
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 83 |
1 files changed, 59 insertions, 24 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index fcd1c1bd..51db0dd0 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -12,7 +12,11 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; | |||
12 | // GL representation of a rectangle. | 12 | // GL representation of a rectangle. |
13 | // Derived from class GeomObj | 13 | // Derived from class GeomObj |
14 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
15 | var Rectangle = function GLRectangle() { | 15 | var Rectangle = function GLRectangle() |
16 | { | ||
17 | if (!MaterialsModel) | ||
18 | MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
19 | |||
16 | // CONSTANTS | 20 | // CONSTANTS |
17 | this.N_TRIANGLES = 15; | 21 | this.N_TRIANGLES = 15; |
18 | 22 | ||
@@ -856,13 +860,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
856 | } | 860 | } |
857 | 861 | ||
858 | //refine the mesh for vertex deformations | 862 | //refine the mesh for vertex deformations |
859 | // if (material) { | 863 | if (material) { |
860 | // if (material.hasVertexDeformation()) { | 864 | if (material.hasVertexDeformation()) { |
861 | // var paramRange = material.getVertexDeformationRange(); | 865 | var paramRange = material.getVertexDeformationRange(); |
862 | // var tolerance = material.getVertexDeformationTolerance(); | 866 | var tolerance = material.getVertexDeformationTolerance(); |
863 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 867 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
864 | // } | 868 | } |
865 | // } | 869 | } |
866 | 870 | ||
867 | // create the RDGE primitive | 871 | // create the RDGE primitive |
868 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 872 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1088,13 +1092,13 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1088 | } | 1092 | } |
1089 | 1093 | ||
1090 | //refine the mesh for vertex deformations | 1094 | //refine the mesh for vertex deformations |
1091 | // if (material) { | 1095 | if (material) { |
1092 | // if (material.hasVertexDeformation()) { | 1096 | if (material.hasVertexDeformation()) { |
1093 | // var paramRange = material.getVertexDeformationRange(); | 1097 | var paramRange = material.getVertexDeformationRange(); |
1094 | // var tolerance = material.getVertexDeformationTolerance(); | 1098 | var tolerance = material.getVertexDeformationTolerance(); |
1095 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1099 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1096 | // } | 1100 | } |
1097 | // } | 1101 | } |
1098 | 1102 | ||
1099 | // create the RDGE primitive | 1103 | // create the RDGE primitive |
1100 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1104 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1172,15 +1176,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) { | |||
1172 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1176 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1173 | 1177 | ||
1174 | //refine the mesh for vertex deformations | 1178 | //refine the mesh for vertex deformations |
1175 | // if (material) | 1179 | if (material) |
1176 | // { | 1180 | { |
1177 | // if (material.hasVertexDeformation()) | 1181 | if (material.hasVertexDeformation()) |
1178 | // { | 1182 | { |
1179 | // var paramRange = material.getVertexDeformationRange(); | 1183 | var paramRange = material.getVertexDeformationRange(); |
1180 | // var tolerance = material.getVertexDeformationTolerance(); | 1184 | var tolerance = material.getVertexDeformationTolerance(); |
1181 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1185 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1182 | // } | 1186 | } |
1183 | // } | 1187 | } |
1184 | 1188 | ||
1185 | // create the RDGE primitive | 1189 | // create the RDGE primitive |
1186 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1190 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1193,11 +1197,42 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices; | |||
1193 | RectangleGeometry.getVertex = RectangleFill.getVertex; | 1197 | RectangleGeometry.getVertex = RectangleFill.getVertex; |
1194 | RectangleGeometry.getUV = RectangleFill.getUV; | 1198 | RectangleGeometry.getUV = RectangleFill.getUV; |
1195 | 1199 | ||
1200 | RectangleGeometry.init = function() | ||
1201 | { | ||
1202 | this.vertices = []; | ||
1203 | this.normals = []; | ||
1204 | this.uvs = []; | ||
1205 | this.indices = []; | ||
1206 | } | ||
1207 | |||
1208 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | ||
1209 | { | ||
1210 | var offset = this.vertices.length/3; | ||
1211 | for (var i=0; i<4; i++) | ||
1212 | { | ||
1213 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); | ||
1214 | RectangleGeometry.pushNormal( normals[i] ); | ||
1215 | RectangleGeometry.pushUV( uvs[i] ); | ||
1216 | } | ||
1217 | |||
1218 | RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset ); | ||
1219 | RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset ); | ||
1220 | } | ||
1221 | |||
1222 | RectangleGeometry.buildPrimitive = function() | ||
1223 | { | ||
1224 | var nVertices = this.vertices.length/3; | ||
1225 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | ||
1226 | } | ||
1227 | |||
1228 | |||
1229 | |||
1196 | 1230 | ||
1197 | Rectangle.prototype = new GeomObj(); | 1231 | Rectangle.prototype = new GeomObj(); |
1198 | 1232 | ||
1199 | if (typeof exports === "object") { | 1233 | if (typeof exports === "object") { |
1200 | exports.Rectangle = Rectangle; | 1234 | exports.Rectangle = Rectangle; |
1235 | exports.RectangleGeometry = RectangleGeometry; | ||
1201 | } | 1236 | } |
1202 | 1237 | ||
1203 | 1238 | ||