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 91b1d426..ef91d158 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 | ||
@@ -848,13 +852,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
848 | } | 852 | } |
849 | 853 | ||
850 | //refine the mesh for vertex deformations | 854 | //refine the mesh for vertex deformations |
851 | // if (material) { | 855 | if (material) { |
852 | // if (material.hasVertexDeformation()) { | 856 | if (material.hasVertexDeformation()) { |
853 | // var paramRange = material.getVertexDeformationRange(); | 857 | var paramRange = material.getVertexDeformationRange(); |
854 | // var tolerance = material.getVertexDeformationTolerance(); | 858 | var tolerance = material.getVertexDeformationTolerance(); |
855 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 859 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
856 | // } | 860 | } |
857 | // } | 861 | } |
858 | 862 | ||
859 | // create the RDGE primitive | 863 | // create the RDGE primitive |
860 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 864 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1080,13 +1084,13 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1080 | } | 1084 | } |
1081 | 1085 | ||
1082 | //refine the mesh for vertex deformations | 1086 | //refine the mesh for vertex deformations |
1083 | // if (material) { | 1087 | if (material) { |
1084 | // if (material.hasVertexDeformation()) { | 1088 | if (material.hasVertexDeformation()) { |
1085 | // var paramRange = material.getVertexDeformationRange(); | 1089 | var paramRange = material.getVertexDeformationRange(); |
1086 | // var tolerance = material.getVertexDeformationTolerance(); | 1090 | var tolerance = material.getVertexDeformationTolerance(); |
1087 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1091 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1088 | // } | 1092 | } |
1089 | // } | 1093 | } |
1090 | 1094 | ||
1091 | // create the RDGE primitive | 1095 | // create the RDGE primitive |
1092 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1096 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1164,15 +1168,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) { | |||
1164 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1168 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1165 | 1169 | ||
1166 | //refine the mesh for vertex deformations | 1170 | //refine the mesh for vertex deformations |
1167 | // if (material) | 1171 | if (material) |
1168 | // { | 1172 | { |
1169 | // if (material.hasVertexDeformation()) | 1173 | if (material.hasVertexDeformation()) |
1170 | // { | 1174 | { |
1171 | // var paramRange = material.getVertexDeformationRange(); | 1175 | var paramRange = material.getVertexDeformationRange(); |
1172 | // var tolerance = material.getVertexDeformationTolerance(); | 1176 | var tolerance = material.getVertexDeformationTolerance(); |
1173 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1177 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1174 | // } | 1178 | } |
1175 | // } | 1179 | } |
1176 | 1180 | ||
1177 | // create the RDGE primitive | 1181 | // create the RDGE primitive |
1178 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1182 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1185,11 +1189,42 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices; | |||
1185 | RectangleGeometry.getVertex = RectangleFill.getVertex; | 1189 | RectangleGeometry.getVertex = RectangleFill.getVertex; |
1186 | RectangleGeometry.getUV = RectangleFill.getUV; | 1190 | RectangleGeometry.getUV = RectangleFill.getUV; |
1187 | 1191 | ||
1192 | RectangleGeometry.init = function() | ||
1193 | { | ||
1194 | this.vertices = []; | ||
1195 | this.normals = []; | ||
1196 | this.uvs = []; | ||
1197 | this.indices = []; | ||
1198 | } | ||
1199 | |||
1200 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | ||
1201 | { | ||
1202 | var offset = this.vertices.length/3; | ||
1203 | for (var i=0; i<4; i++) | ||
1204 | { | ||
1205 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); | ||
1206 | RectangleGeometry.pushNormal( normals[i] ); | ||
1207 | RectangleGeometry.pushUV( uvs[i] ); | ||
1208 | } | ||
1209 | |||
1210 | RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset ); | ||
1211 | RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset ); | ||
1212 | } | ||
1213 | |||
1214 | RectangleGeometry.buildPrimitive = function() | ||
1215 | { | ||
1216 | var nVertices = this.vertices.length/3; | ||
1217 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | ||
1218 | } | ||
1219 | |||
1220 | |||
1221 | |||
1188 | 1222 | ||
1189 | Rectangle.prototype = new GeomObj(); | 1223 | Rectangle.prototype = new GeomObj(); |
1190 | 1224 | ||
1191 | if (typeof exports === "object") { | 1225 | if (typeof exports === "object") { |
1192 | exports.Rectangle = Rectangle; | 1226 | exports.Rectangle = Rectangle; |
1227 | exports.RectangleGeometry = RectangleGeometry; | ||
1193 | } | 1228 | } |
1194 | 1229 | ||
1195 | 1230 | ||