diff options
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/geom-obj.js | 11 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 82 | ||||
-rw-r--r-- | js/lib/geom/shape-primitive.js | 130 |
3 files changed, 199 insertions, 24 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 4cb21a25..6b73463f 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -180,7 +180,7 @@ exports.GeomObj = Object.create(Object.prototype, { | |||
180 | /////////////////////////////////////////////////////////////////////// | 180 | /////////////////////////////////////////////////////////////////////// |
181 | // Methods | 181 | // Methods |
182 | /////////////////////////////////////////////////////////////////////// | 182 | /////////////////////////////////////////////////////////////////////// |
183 | setMaterialColor: { | 183 | setMaterialColor: { |
184 | value: function(c, type) { | 184 | value: function(c, type) { |
185 | var i = 0, | 185 | var i = 0, |
186 | nMats = 0; | 186 | nMats = 0; |
@@ -285,6 +285,8 @@ exports.GeomObj = Object.create(Object.prototype, { | |||
285 | this.setStrokeColor(this._strokeColor); | 285 | this.setStrokeColor(this._strokeColor); |
286 | } | 286 | } |
287 | 287 | ||
288 | this._strokeMaterial = strokeMaterial; | ||
289 | |||
288 | return strokeMaterial; | 290 | return strokeMaterial; |
289 | } | 291 | } |
290 | }, | 292 | }, |
@@ -309,12 +311,16 @@ exports.GeomObj = Object.create(Object.prototype, { | |||
309 | this.setFillColor(this._fillColor); | 311 | this.setFillColor(this._fillColor); |
310 | } | 312 | } |
311 | 313 | ||
314 | this._fillMaterial = fillMaterial; | ||
315 | |||
312 | return fillMaterial; | 316 | return fillMaterial; |
313 | } | 317 | } |
314 | }, | 318 | }, |
315 | 319 | ||
316 | exportMaterialsJSON: { | 320 | exportMaterialsJSON: { |
317 | value: function() { | 321 | value: function() { |
322 | MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
323 | |||
318 | var jObj; | 324 | var jObj; |
319 | if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { | 325 | if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { |
320 | var nMats = this._materialArray.length; | 326 | var nMats = this._materialArray.length; |
@@ -345,6 +351,8 @@ exports.GeomObj = Object.create(Object.prototype, { | |||
345 | 351 | ||
346 | importMaterialsJSON: { | 352 | importMaterialsJSON: { |
347 | value: function(jObj) { | 353 | value: function(jObj) { |
354 | MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
355 | |||
348 | this._materialArray = []; | 356 | this._materialArray = []; |
349 | this._materialTypeArray = []; | 357 | this._materialTypeArray = []; |
350 | 358 | ||
@@ -370,6 +378,7 @@ exports.GeomObj = Object.create(Object.prototype, { | |||
370 | case "tunnel": | 378 | case "tunnel": |
371 | case "reliefTunnel": | 379 | case "reliefTunnel": |
372 | case "squareTunnel": | 380 | case "squareTunnel": |
381 | case "flag": | ||
373 | case "twist": | 382 | case "twist": |
374 | case "fly": | 383 | case "fly": |
375 | case "julia": | 384 | case "julia": |
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index d75abb05..ab0d7022 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -17,6 +17,9 @@ exports.Rectangle = Object.create(GeomObj, { | |||
17 | // CONSTANTS | 17 | // CONSTANTS |
18 | N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? | 18 | N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? |
19 | 19 | ||
20 | //if (!MaterialsModel) | ||
21 | // MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
22 | |||
20 | /////////////////////////////////////////////////////////////////////// | 23 | /////////////////////////////////////////////////////////////////////// |
21 | // Instance variables | 24 | // Instance variables |
22 | /////////////////////////////////////////////////////////////////////// | 25 | /////////////////////////////////////////////////////////////////////// |
@@ -944,13 +947,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
944 | } | 947 | } |
945 | 948 | ||
946 | //refine the mesh for vertex deformations | 949 | //refine the mesh for vertex deformations |
947 | // if (material) { | 950 | if (material) { |
948 | // if (material.hasVertexDeformation()) { | 951 | if (material.hasVertexDeformation()) { |
949 | // var paramRange = material.getVertexDeformationRange(); | 952 | var paramRange = material.getVertexDeformationRange(); |
950 | // var tolerance = material.getVertexDeformationTolerance(); | 953 | var tolerance = material.getVertexDeformationTolerance(); |
951 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 954 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
952 | // } | 955 | } |
953 | // } | 956 | } |
954 | 957 | ||
955 | // create the RDGE primitive | 958 | // create the RDGE primitive |
956 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 959 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1176,13 +1179,15 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1176 | } | 1179 | } |
1177 | 1180 | ||
1178 | //refine the mesh for vertex deformations | 1181 | //refine the mesh for vertex deformations |
1179 | // if (material) { | 1182 | if (material) |
1180 | // if (material.hasVertexDeformation()) { | 1183 | { |
1181 | // var paramRange = material.getVertexDeformationRange(); | 1184 | if (material.hasVertexDeformation()) |
1182 | // var tolerance = material.getVertexDeformationTolerance(); | 1185 | { |
1183 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1186 | var paramRange = material.getVertexDeformationRange(); |
1184 | // } | 1187 | var tolerance = material.getVertexDeformationTolerance(); |
1185 | // } | 1188 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1189 | } | ||
1190 | } | ||
1186 | 1191 | ||
1187 | // create the RDGE primitive | 1192 | // create the RDGE primitive |
1188 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1193 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1260,15 +1265,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) { | |||
1260 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1265 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1261 | 1266 | ||
1262 | //refine the mesh for vertex deformations | 1267 | //refine the mesh for vertex deformations |
1263 | // if (material) | 1268 | if (material) |
1264 | // { | 1269 | { |
1265 | // if (material.hasVertexDeformation()) | 1270 | if (material.hasVertexDeformation()) |
1266 | // { | 1271 | { |
1267 | // var paramRange = material.getVertexDeformationRange(); | 1272 | var paramRange = material.getVertexDeformationRange(); |
1268 | // var tolerance = material.getVertexDeformationTolerance(); | 1273 | var tolerance = material.getVertexDeformationTolerance(); |
1269 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1274 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1270 | // } | 1275 | } |
1271 | // } | 1276 | } |
1272 | 1277 | ||
1273 | // create the RDGE primitive | 1278 | // create the RDGE primitive |
1274 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1279 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1281,5 +1286,36 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices; | |||
1281 | RectangleGeometry.getVertex = RectangleFill.getVertex; | 1286 | RectangleGeometry.getVertex = RectangleFill.getVertex; |
1282 | RectangleGeometry.getUV = RectangleFill.getUV; | 1287 | RectangleGeometry.getUV = RectangleFill.getUV; |
1283 | 1288 | ||
1289 | RectangleGeometry.init = function() | ||
1290 | { | ||
1291 | this.vertices = []; | ||
1292 | this.normals = []; | ||
1293 | this.uvs = []; | ||
1294 | this.indices = []; | ||
1295 | } | ||
1296 | |||
1297 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | ||
1298 | { | ||
1299 | var offset = this.vertices.length/3; | ||
1300 | for (var i=0; i<4; i++) | ||
1301 | { | ||
1302 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); | ||
1303 | RectangleGeometry.pushNormal( normals[i] ); | ||
1304 | RectangleGeometry.pushUV( uvs[i] ); | ||
1305 | } | ||
1306 | |||
1307 | RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset ); | ||
1308 | RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset ); | ||
1309 | } | ||
1310 | |||
1311 | RectangleGeometry.buildPrimitive = function() | ||
1312 | { | ||
1313 | var nVertices = this.vertices.length/3; | ||
1314 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | ||
1315 | } | ||
1316 | |||
1317 | |||
1318 | |||
1319 | exports.RectangleGeometry = RectangleGeometry; | ||
1284 | 1320 | ||
1285 | 1321 | ||
diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js index 97873d32..380cf334 100644 --- a/js/lib/geom/shape-primitive.js +++ b/js/lib/geom/shape-primitive.js | |||
@@ -49,6 +49,136 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver | |||
49 | return prim; | 49 | return prim; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | ShapePrimitive.getMeshBounds = function( verts, nVerts ) | ||
53 | { | ||
54 | if (!verts || (nVerts <= 0)) return null; | ||
55 | |||
56 | var bounds = [verts[0], verts[1], verts[2], verts[0], verts[1], verts[2]]; | ||
57 | var index = 3; | ||
58 | for (var i=1; i<nVerts; i++) | ||
59 | { | ||
60 | var x = verts[index], y = verts[index+1], z = verts[index+2]; | ||
61 | index += 3; | ||
62 | |||
63 | if (x < bounds[0]) bounds[0] = x; | ||
64 | else if (x > bounds[3]) bounds[3] = x; | ||
65 | if (y < bounds[1]) bounds[1] = y; | ||
66 | else if (y > bounds[4]) bounds[4] = y; | ||
67 | if (z < bounds[2]) bounds[2] = z; | ||
68 | else if (z > bounds[5]) bounds[5] = z; | ||
69 | } | ||
70 | |||
71 | return bounds; | ||
72 | }; | ||
73 | |||
74 | ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) | ||
75 | { | ||
76 | var oldVrtCount = nVertices; | ||
77 | |||
78 | // get the param range | ||
79 | var pUMin = paramRange[0], pVMin = paramRange[1], | ||
80 | pUMax = paramRange[2], pVMax = paramRange[3]; | ||
81 | var iTriangle = 0; | ||
82 | var nTriangles = indices.length/3; | ||
83 | var index = 0; | ||
84 | while (iTriangle < nTriangles) | ||
85 | { | ||
86 |