aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/circle.js44
-rwxr-xr-xjs/lib/geom/geom-obj.js12
-rwxr-xr-xjs/lib/geom/rectangle.js82
-rw-r--r--js/lib/geom/shape-primitive.js130
4 files changed, 232 insertions, 36 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 4a369844..b2709ce4 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -295,39 +295,39 @@ exports.Circle = Object.create(GeomObj, {
295 if(this._strokeWidth > 0) { 295 if(this._strokeWidth > 0) {
296 var numStrokes = 1; 296 var numStrokes = 1;
297 if(this._innerRadius !== 0) { 297 if(this._innerRadius !== 0) {
298 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles); 298 strokeMaterial0 = this.makeStrokeMaterial();
299 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0);
299 } 300 }
300 301
301 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles); 302 strokeMaterial2 = this.makeStrokeMaterial();
303 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2);
302 } 304 }
303 305
304 ///////////////////////////////////////////////////////////// 306 /////////////////////////////////////////////////////////////
305 // Fill 307 // Fill
308 fillMaterial = this.makeFillMaterial();
306 if(this._innerRadius === 0) { 309 if(this._innerRadius === 0) {
307 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles); 310 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial);
308 } else { 311 } else {
309 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles); 312 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial);
310 } 313 }
311 314
312 if (fillPrim) { 315 if (fillPrim) {
313 fillMaterial = this.makeFillMaterial(); 316 fillMaterial.fitToPrimitive( fillPrim );
314 fillMaterial.fitToPrimitive( fillPrim );
315 317
316 this._primArray.push( fillPrim ); 318 this._primArray.push( fillPrim );
317 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 319 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
318 } 320 }
319 321
320 if (strokePrim0) { 322 if (strokePrim0) {
321 strokeMaterial0 = this.makeStrokeMaterial(); 323 strokeMaterial0.fitToPrimitive( strokePrim0 );
322 strokeMaterial0.fitToPrimitive( strokePrim0 );
323 324
324 this._primArray.push( strokePrim0 ); 325 this._primArray.push( strokePrim0 );
325 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); 326 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() );
326 } 327 }
327 328
328 if (strokePrim1) { 329 if (strokePrim1) {
329 strokeMaterial2 = this.makeStrokeMaterial(); 330 strokeMaterial2.fitToPrimitive( strokePrim1 );
330 strokeMaterial2.fitToPrimitive( strokePrim1 );
331 331
332 this._primArray.push( strokePrim1 ); 332 this._primArray.push( strokePrim1 );
333 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); 333 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() );
@@ -338,7 +338,7 @@ exports.Circle = Object.create(GeomObj, {
338 }, 338 },
339 339
340 generateOval: { 340 generateOval: {
341 value: function(xOff, yOff, rotationMat, scaleMat, nTriangles) { 341 value: function(xOff, yOff, rotationMat, scaleMat, nTriangles, material) {
342 var pt = [1.0, 0.0, 0.0]; 342 var pt = [1.0, 0.0, 0.0];
343 //var pts = scaleMat.multiply(pt); 343 //var pts = scaleMat.multiply(pt);
344 var pts = glmat4.multiplyVec3( scaleMat, pt, []); 344 var pts = glmat4.multiplyVec3( scaleMat, pt, []);
@@ -392,12 +392,21 @@ exports.Circle = Object.create(GeomObj, {
392 392
393 this.recalcTexMapCoords( vrts, uvs ); 393 this.recalcTexMapCoords( vrts, uvs );
394 394
395 //refine the mesh for vertex deformations
396 if (material) {
397 if (material.hasVertexDeformation()) {
398 var paramRange = material.getVertexDeformationRange();
399 var tolerance = material.getVertexDeformationTolerance();
400 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance );
401 }
402 }
403
395 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); 404 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index);
396 } 405 }
397 }, 406 },
398 407
399 generateOvalRing: { 408 generateOvalRing: {
400 value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { 409 value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles, material) {
401 var pt = [1.0, 0.0, 0.0]; 410 var pt = [1.0, 0.0, 0.0];
402 411
403 var z = 0; 412 var z = 0;
@@ -451,6 +460,17 @@ exports.Circle = Object.create(GeomObj, {
451 460
452 this.recalcTexMapCoords( vrts, uvs ); 461 this.recalcTexMapCoords( vrts, uvs );
453 462
463 /*
464 //refine the mesh for vertex deformations
465 if (material) {
466 if (material.hasVertexDeformation()) {
467 var paramRange = material.getVertexDeformationRange();
468 var tolerance = material.getVertexDeformationTolerance();
469 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance );
470 }
471 }
472 */
473
454 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); 474 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length);
455 } 475 }
456 }, 476 },
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 4cb21a25..417c8731 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":
@@ -379,6 +388,7 @@ exports.GeomObj = Object.create(Object.prototype, {
379 case "keleidoscope": 388 case "keleidoscope":
380 case "radialBlur": 389 case "radialBlur":
381 case "pulse": 390 case "pulse":
391 case "twistVert":
382 mat = MaterialsModel.getMaterialByShader(shaderName); 392 mat = MaterialsModel.getMaterialByShader(shaderName);
383 if (mat) mat = mat.dup(); 393 if (mat) mat = mat.dup();
384 break; 394 break;
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// }