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.js146
1 files changed, 96 insertions, 50 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index a44026eb..c0322f46 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -45,7 +46,7 @@ exports.Line = Object.create(GeomObj, {
45 _xOffset: { value : 0, writable: true }, 46 _xOffset: { value : 0, writable: true },
46 _yOffset: { value : 0, writable: true }, 47 _yOffset: { value : 0, writable: true },
47 48
48 // If line doesn't fit in canvas world, we had to grow the canvas by this much on either side 49 // 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 }, 50 _xAdj: { value : 0, writable: true },
50 _yAdj: { value : 0, writable: true }, 51 _yAdj: { value : 0, writable: true },
51 52
@@ -87,13 +88,22 @@ exports.Line = Object.create(GeomObj, {
87 this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; 88 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
88 89
89 if(strokeMaterial) { 90 if(strokeMaterial) {
90 this._strokeMaterial = strokeMaterial; 91 this._strokeMaterial = strokeMaterial.dup();
91 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); 92 } else {
93 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
94 }
95
96 if(strokeColor) {
97 if(this._strokeMaterial.hasProperty("color")) {
98 this._strokeMaterial.setProperty( "color", this._strokeColor );
99 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
100 this._strokeMaterial.setGradientData(this._strokeColor.color);
101 }
92 } 102 }
93 } 103 }
94 }, 104 },
95 105
96 //////////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////////
97 // Property Accessors 107 // Property Accessors
98 /////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////
99 // TODO - Use getters/setters in the future 109 // TODO - Use getters/setters in the future
@@ -217,26 +227,26 @@ exports.Line = Object.create(GeomObj, {
217 } 227 }
218 }, 228 },
219 229
220 /////////////////////////////////////////////////////////////////////// 230 ///////////////////////////////////////////////////////////////////////
221 // Methods 231 // Methods
222 /////////////////////////////////////////////////////////////////////// 232 ///////////////////////////////////////////////////////////////////////
223 exportJSON: { 233 exportJSON: {
224 value: function() { 234 value: function() {
225 var jObj = 235 var jObj =
226 { 236 {
227 'type' : this.geomType(), 237 'type' : this.geomType(),
228 'xoff' : this._xOffset, 238 'xoff' : this._xOffset,
229 'yoff' : this._yOffset, 239 'yoff' : this._yOffset,
230 'width' : this._width, 240 'width' : this._width,
231 'height' : this._height, 241 'height' : this._height,
232 'xAdj' : this._xAdj, 242 'xAdj' : this._xAdj,
233 'yAdj' : this._yAdj, 243 'yAdj' : this._yAdj,
234 'slope' : this._slope, 244 'slope' : this._slope,
235 'strokeWidth' : this._strokeWidth, 245 'strokeWidth' : this._strokeWidth,
236 'strokeColor' : this._strokeColor, 246 'strokeColor' : this._strokeColor,
237 'strokeStyle' : this._strokeStyle, 247 'strokeStyle' : this._strokeStyle,
238 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 248 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
239 'materials' : this.exportMaterialsJSON() 249 'materials' : this.exportMaterialsJSON()
240 }; 250 };
241 251
242 return jObj; 252 return jObj;
@@ -245,17 +255,17 @@ exports.Line = Object.create(GeomObj, {
245 255
246 importJSON: { 256 importJSON: {
247 value: function(jObj) { 257 value: function(jObj) {
248 this._xOffset = jObj.xoff; 258 this._xOffset = jObj.xoff;
249 this._yOffset = jObj.yoff; 259 this._yOffset = jObj.yoff;
250 this._width = jObj.width; 260 this._width = jObj.width;
251 this._height = jObj.height; 261 this._height = jObj.height;
252 this._xAdj = jObj.xAdj; 262 this._xAdj = jObj.xAdj;
253 this._yAdj = jObj.yAdj; 263 this._yAdj = jObj.yAdj;
254 this._strokeWidth = jObj.strokeWidth; 264 this._strokeWidth = jObj.strokeWidth;
255 this._slope = jObj.slope; 265 this._slope = jObj.slope;
256 this._strokeStyle = jObj.strokeStyle; 266 this._strokeStyle = jObj.strokeStyle;
257 this._strokeColor = jObj.strokeColor; 267 this._strokeColor = jObj.strokeColor;
258 var strokeMaterialName = jObj.strokeMat; 268 var strokeMaterialName = jObj.strokeMat;
259 269
260 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 270 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
261 if (!strokeMat) { 271 if (!strokeMat) {
@@ -295,15 +305,15 @@ exports.Line = Object.create(GeomObj, {
295 305
296 // get the normalized device coordinates (NDC) for 306 // get the normalized device coordinates (NDC) for
297 // all position and dimensions. 307 // all position and dimensions.
298 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 308 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
299 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, 309 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph,
300 xFillNDC = this._width/vpw, yFillNDC = this._height/vph, 310 xFillNDC = this._width/vpw, yFillNDC = this._height/vph,
301 xAdjNDC = this._xAdj/vpw, yAdjNDC = this._yAdj/vph, 311 xAdjNDC = this._xAdj/vpw, yAdjNDC = this._yAdj/vph,
302 xStrokeNDC = this._strokeWidth/vpw, yStrokeNDC = this._strokeWidth/vph; 312 xStrokeNDC = this._strokeWidth/vpw, yStrokeNDC = this._strokeWidth/vph;
303 313
304 var aspect = world.getAspect(); 314 var aspect = world.getAspect();
305 var zn = world.getZNear(), zf = world.getZFar(); 315 var zn = world.getZNear(), zf = world.getZFar();
306 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 316 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
307 b = -t, 317 b = -t,
308 r = aspect*t, 318 r = aspect*t,
309 l = -r; 319 l = -r;
@@ -437,12 +447,48 @@ exports.Line = Object.create(GeomObj, {
437 indices.push( index ); index++; 447 indices.push( index ); index++;
438 } 448 }
439 449
440 var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length);
441
442 var strokeMaterial = this.makeStrokeMaterial(); 450 var strokeMaterial = this.makeStrokeMaterial();
443 451// var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length);
444 this._primArray.push( prim ); 452// this._primArray.push( prim );
453// this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
454
455 // refine the mesh for vertex deformations
456 if (strokeMaterial)
457 {
458 var primArray;
459 if (strokeMaterial.hasVertexDeformation())
460 {
461 var paramRange = strokeMaterial.getVertexDeformationRange();
462 var tolerance = strokeMaterial.getVertexDeformationTolerance();
463 var nVertices = indices.length;
464 nVertices = ShapePrimitive.refineMesh( strokeVertices, strokeNormals, strokeTextures, indices, nVertices, paramRange, tolerance );
465 var subdividedParts = ShapePrimitive.subdivideOversizedMesh( strokeVertices, strokeNormals, strokeTextures, indices );
466
467 primArray = [];
468 if (subdividedParts)
469 {
470 for (var i=0; i<subdividedParts.length; i++)
471 {
472 var obj = subdividedParts[i];
473 primArray.push( ShapePrimitive.create(obj.vertices, obj.normals, obj.uvs, obj.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, obj.vertices.length/3) );
474 }
475 }
476 else
477 primArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
478 }
479 else
480 {
481 // create the RDGE primitive
482 primArray = [ ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, indices.length) ];
483 }
484
485 var nPrims = primArray.length;
486 for (var i=0; i<nPrims; i++)
487 {
488 this._primArray.push( primArray[i] );
445 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 489 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
490 }
491 }
446 492
447 world.updateObject(this); 493 world.updateObject(this);
448 } 494 }
@@ -472,7 +518,7 @@ exports.Line = Object.create(GeomObj, {
472 cs; 518 cs;
473 519
474 ctx.beginPath(); 520 ctx.beginPath();
475 ctx.lineWidth = lineWidth;