aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/line.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/line.js')
-rwxr-xr-xjs/lib/geom/line.js123
1 files changed, 84 insertions, 39 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index a44026eb..26631a31 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -45,7 +45,7 @@ exports.Line = Object.create(GeomObj, {
45 _xOffset: { value : 0, writable: true }, 45 _xOffset: { value : 0, writable: true },
46 _yOffset: { value : 0, writable: true }, 46 _yOffset: { value : 0, writable: true },
47 47
48 // If line doesn't fit in canvas world, we had to grow the canvas by this much on either side 48 // If line doesn't fit in canvas world, we had to grow the canvas by this much on either side
49 _xAdj: { value : 0, writable: true }, 49 _xAdj: { value : 0, writable: true },
50 _yAdj: { value : 0, writable: true }, 50 _yAdj: { value : 0, writable: true },
51 51
@@ -87,13 +87,22 @@ exports.Line = Object.create(GeomObj, {
87 this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; 87 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
88 88
89 if(strokeMaterial) { 89 if(strokeMaterial) {
90 this._strokeMaterial = strokeMaterial; 90 this._strokeMaterial = strokeMaterial.dup();
91 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); 91 } else {
92 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
93 }
94
95 if(strokeColor) {
96 if(this._strokeMaterial.hasProperty("color")) {
97 this._strokeMaterial.setProperty( "color", this._strokeColor );
98 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
99 this._strokeMaterial.setGradientData(this._strokeColor.color);
100 }
92 } 101 }
93 } 102 }
94 }, 103 },
95 104
96 //////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////
97 // Property Accessors 106 // Property Accessors
98 /////////////////////////////////////////////////////////////////////// 107 ///////////////////////////////////////////////////////////////////////
99 // TODO - Use getters/setters in the future 108 // TODO - Use getters/setters in the future
@@ -217,26 +226,26 @@ exports.Line = Object.create(GeomObj, {
217 } 226 }
218 }, 227 },
219 228
220 /////////////////////////////////////////////////////////////////////// 229 ///////////////////////////////////////////////////////////////////////
221 // Methods 230 // Methods
222 /////////////////////////////////////////////////////////////////////// 231 ///////////////////////////////////////////////////////////////////////
223 exportJSON: { 232 exportJSON: {
224 value: function() { 233 value: function() {
225 var jObj = 234 var jObj =
226 { 235 {
227 'type' : this.geomType(), 236 'type' : this.geomType(),
228 'xoff' : this._xOffset, 237 'xoff' : this._xOffset,
229 'yoff' : this._yOffset, 238 'yoff' : this._yOffset,
230 'width' : this._width, 239 'width' : this._width,
231 'height' : this._height, 240 'height' : this._height,
232 'xAdj' : this._xAdj, 241 'xAdj' : this._xAdj,
233 'yAdj' : this._yAdj, 242 'yAdj' : this._yAdj,
234 'slope' : this._slope, 243 'slope' : this._slope,
235 'strokeWidth' : this._strokeWidth, 244 'strokeWidth' : this._strokeWidth,
236 'strokeColor' : this._strokeColor, 245 'strokeColor' : this._strokeColor,
237 'strokeStyle' : this._strokeStyle, 246 'strokeStyle' : this._strokeStyle,
238 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 247 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
239 'materials' : this.exportMaterialsJSON() 248 'materials' : this.exportMaterialsJSON()
240 }; 249 };
241 250
242 return jObj; 251 return jObj;
@@ -245,17 +254,17 @@ exports.Line = Object.create(GeomObj, {
245 254
246 importJSON: { 255 importJSON: {
247 value: function(jObj) { 256 value: function(jObj) {
248 this._xOffset = jObj.xoff; 257 this._xOffset = jObj.xoff;
249 this._yOffset = jObj.yoff; 258 this._yOffset = jObj.yoff;
250 this._width = jObj.width; 259 this._width = jObj.width;
251 this._height = jObj.height; 260 this._height = jObj.height;
252 this._xAdj = jObj.xAdj; 261 this._xAdj = jObj.xAdj;
253 this._yAdj = jObj.yAdj; 262 this._yAdj = jObj.yAdj;
254 this._strokeWidth = jObj.strokeWidth; 263 this._strokeWidth = jObj.strokeWidth;
255 this._slope = jObj.slope; 264 this._slope = jObj.slope;
256 this._strokeStyle = jObj.strokeStyle; 265 this._strokeStyle = jObj.strokeStyle;
257 this._strokeColor = jObj.strokeColor; 266 this._strokeColor = jObj.strokeColor;
258 var strokeMaterialName = jObj.strokeMat; 267 var strokeMaterialName = jObj.strokeMat;
259 268
260 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 269 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
261 if (!strokeMat) { 270 if (!strokeMat) {
@@ -295,15 +304,15 @@ exports.Line = Object.create(GeomObj, {
295 304
296 // get the normalized device coordinates (NDC) for 305 // get the normalized device coordinates (NDC) for
297 // all position and dimensions. 306 // all position and dimensions.
298 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 307 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
299 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, 308 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph,
300 xFillNDC = this._width/vpw, yFillNDC = this._height/vph, 309 xFillNDC = this._width/vpw, yFillNDC = this._height/vph,
301 xAdjNDC = this._xAdj/vpw, yAdjNDC = this._yAdj/vph, 310 xAdjNDC = this._xAdj/vpw, yAdjNDC = this._yAdj/vph,
302 xStrokeNDC = this._strokeWidth/vpw, yStrokeNDC = this._strokeWidth/vph; 311 xStrokeNDC = this._strokeWidth/vpw, yStrokeNDC = this._strokeWidth/vph;
303 312
304 var aspect = world.getAspect(); 313 var aspect = world.getAspect();
305 var zn = world.getZNear(), zf = world.getZFar(); 314 var zn = world.getZNear(), zf = world.getZFar();
306 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 315 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
307 b = -t, 316 b = -t,
308 r = aspect*t, 317 r = aspect*t,
309 l = -r; 318 l = -r;
@@ -437,12 +446,48 @@ exports.Line = Object.create(GeomObj, {
437 indices.push( index ); index++; 446 indices.push( index ); index++;
438 } 447 }
439 448
440 var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length);
441
442 var strokeMaterial = this.makeStrokeMaterial(); 449 var strokeMaterial = this.makeStrokeMaterial();
443 450// var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length);
444 this._primArray.push( prim ); 451// this._primArray.push( prim );
452// this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
453
454 // refine the mesh for vertex deformations
455 if (strokeMaterial)
456 {
457 var primArray;
458 if (strokeMaterial.hasVertexDeformation())
459 {
460 var paramRange = strokeMaterial.getVertexDeformationRange();
461 var tolerance = strokeMaterial.getVertexDeformationTolerance();
462 var nVertices = indices.length;
463 nVertices = ShapePrimitive.refineMesh( strokeVertices, strokeNormals, strokeTextures, indices, nVertices, paramRange, tolerance );
464 var subdividedParts = ShapePrimitive.subdivideOversizedMesh( strokeVertices, strokeNormals, strokeTextures, indices );
465
466 primArray = [];
467 if (subdividedParts)
468 {
469 for (var i=0; i<subdividedParts.length; i++)
470 {
471 var obj = subdividedParts[i];
472 primArray.push( ShapePrimitive.create(obj.vertices, obj.normals, obj.uvs, obj.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, obj.vertices.length/3) );
473 }
474 }
475 else
476 primArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
477 }
478 else
479 {
480 // create the RDGE primitive
481 primArray = [ ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length) ];
482 }
483
484 var nPrims = primArray.length;
485 for (var i=0; i<nPrims; i++)
486 {
487 this._primArray.push( primArray[i] );
445 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 488 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
489 }
490 }
446 491
447 world.updateObject(this); 492 world.updateObject(this);
448 } 493 }
@@ -472,7 +517,7 @@ exports.Line = Object.create(GeomObj, {
472 cs; 517 cs;
473 518
474 ctx.beginPath(); 519 ctx.beginPath();
475 ctx.lineWidth = lineWidth; 520 ctx.lineWidth = lineWidth;
476 if (this._strokeColor) { 521 if (this._strokeColor) {
477 if(this._strokeColor.gradientMode) { 522 if(this._strokeColor.gradientMode) {
478 if(this._strokeColor.gradientMode === "radial") { 523 if(this._strokeColor.gradientMode === "radial") {