aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/geom-obj.js11
-rwxr-xr-xjs/lib/geom/rectangle.js82
-rw-r--r--js/lib/geom/shape-primitive.js128
3 files changed, 197 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 b85433a0..42d51e74 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 ///////////////////////////////////////////////////////////////////////
@@ -942,13 +945,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad,
942 } 945 }
943 946
944 //refine the mesh for vertex deformations 947 //refine the mesh for vertex deformations
945// if (material) { 948 if (material) {
946// if (material.hasVertexDeformation()) { 949 if (material.hasVertexDeformation()) {
947// var paramRange = material.getVertexDeformationRange(); 950 var paramRange = material.getVertexDeformationRange();
948// var tolerance = material.getVertexDeformationTolerance(); 951 var tolerance = material.getVertexDeformationTolerance();
949// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 952 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
950// } 953 }
951// } 954 }
952 955
953 // create the RDGE primitive 956 // create the RDGE primitive
954 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); 957 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices);
@@ -1174,13 +1177,15 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1174 } 1177 }
1175 1178
1176 //refine the mesh for vertex deformations 1179 //refine the mesh for vertex deformations
1177// if (material) { 1180 if (material)
1178// if (material.hasVertexDeformation()) { 1181 {
1179// var paramRange = material.getVertexDeformationRange(); 1182 if (material.hasVertexDeformation())
1180// var tolerance = material.getVertexDeformationTolerance(); 1183 {
1181// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1184 var paramRange = material.getVertexDeformationRange();
1182// } 1185 var tolerance = material.getVertexDeformationTolerance();
1183// } 1186 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1187 }
1188 }
1184 1189
1185 // create the RDGE primitive 1190 // create the RDGE primitive
1186 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); 1191 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices);
@@ -1258,15 +1263,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) {
1258 RectangleGeometry.pushIndices( 0, 3, 2 ); 1263 RectangleGeometry.pushIndices( 0, 3, 2 );
1259 1264
1260 //refine the mesh for vertex deformations 1265 //refine the mesh for vertex deformations
1261// if (material) 1266 if (material)
1262// { 1267 {
1263// if (material.hasVertexDeformation()) 1268 if (material.hasVertexDeformation())
1264// { 1269 {
1265// var paramRange = material.getVertexDeformationRange(); 1270 var paramRange = material.getVertexDeformationRange();
1266// var tolerance = material.getVertexDeformationTolerance(); 1271 var tolerance = material.getVertexDeformationTolerance();
1267// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1272 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1268// } 1273 }
1269// } 1274 }
1270 1275
1271 // create the RDGE primitive 1276 // create the RDGE primitive
1272 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); 1277 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices);
@@ -1279,5 +1284,36 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices;
1279RectangleGeometry.getVertex = RectangleFill.getVertex; 1284RectangleGeometry.getVertex = RectangleFill.getVertex;
1280RectangleGeometry.getUV = RectangleFill.getUV; 1285RectangleGeometry.getUV = RectangleFill.getUV;
1281 1286
1287RectangleGeometry.init = function()
1288{
1289 this.vertices = [];
1290 this.normals = [];
1291 this.uvs = [];
1292 this.indices = [];
1293}
1294
1295RectangleGeometry.addQuad = function( verts, normals, uvs )
1296{
1297 var offset = this.vertices.length/3;
1298 for (var i=0; i<4; i++)
1299 {
1300 RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]);
1301 RectangleGeometry.pushNormal( normals[i] );
1302 RectangleGeometry.pushUV( uvs[i] );
1303 }
1304
1305 RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset );
1306 RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset );
1307}
1308
1309RectangleGeometry.buildPrimitive = function()
1310{
1311 var nVertices = this.vertices.length/3;
1312 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices);
1313}
1314
1315
1316
1317 exports.RectangleGeometry = RectangleGeometry;
1282 1318
1283 1319
diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js
index 9864a8e9..858f38c8 100644
--- a/js/lib/geom/shape-primitive.js
+++ b/js/lib/geom/shape-primitive.js
@@ -51,6 +51,31 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver
51 51
52ShapePrimitive.getBounds = function( prim ) 52ShapePrimitive.getBounds = function( prim )
53{ 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
74ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance )
75{
76 var oldVrtCount = nVertices;
77
78 // get the param range
54 var verts = prim.bufferStreams[0]; 79 var verts = prim.bufferStreams[0];
55 var nVerts = verts.length; 80 var nVerts = verts.length;
56 var xMin = verts[0], xMax = verts[0], 81 var xMin = verts[0], xMax = verts[0],
@@ -76,6 +101,109 @@ ShapePrimitive.getBounds = function( prim )
76 return [xMin, yMin, zMin, xMax, yMax, zMax]; 101 return [xMin, yMin, zMin, xMax, yMax, zMax];
77}; 102};
78 103