Import libtess.js

This commit is contained in:
Brendan Kenny
2013-09-03 11:23:27 +02:00
committed by Tom Payne
parent 221a56a411
commit 31f3e92494
21 changed files with 6420 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
/**
* Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
* Copyright 2012, Google Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Original Code. The Original Code is: OpenGL Sample Implementation,
* Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
* Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
* Copyright in any portions created by third parties is as indicated
* elsewhere herein. All Rights Reserved.
*/
/**
* @author Eric Veach, July 1994
* @author Brendan Kenny
*/
// require libtess
// requre libtess.GluHalfEdge
/*global libtess */
/**
* Each face has a pointer to the next and previous faces in the
* circular list, and a pointer to a half-edge with this face as
* the left face (null if this is the dummy header). There is also
* a field "data" for client data.
*
* @param {libtess.GluFace=} opt_nextFace [description]
* @param {libtess.GluFace=} opt_prevFace [description]
* @constructor
*/
libtess.GluFace = function(opt_nextFace, opt_prevFace) {
// TODO(bckenny): reverse order of params?
/**
* next face (never null)
* @type {!libtess.GluFace}
*/
this.next = opt_nextFace || this;
/**
* previous face (never NULL)
* @type {!libtess.GluFace}
*/
this.prev = opt_prevFace || this;
/**
* A half edge with this left face.
* @type {libtess.GluHalfEdge}
*/
this.anEdge = null;
/**
* room for client's data
* @type {Object}
*/
this.data = null;
/**
* "stack" for conversion to strips
* @type {libtess.GluFace}
*/
this.trail = null;
/**
* Flag for conversion to strips.
* @type {boolean}
*/
this.marked = false;
/**
* This face is in the polygon interior.
* @type {boolean}
*/
this.inside = false;
};

View File

@@ -0,0 +1,191 @@
/**
* Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
* Copyright 2012, Google Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Original Code. The Original Code is: OpenGL Sample Implementation,
* Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
* Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
* Copyright in any portions created by third parties is as indicated
* elsewhere herein. All Rights Reserved.
*/
/**
* @author Eric Veach, July 1994
* @author Brendan Kenny
*/
// require libtess
// require libtess.GluFace
// require libtess.GluVertex
// require libtess.ActiveRegion
/*global libtess */
/**
* The fundamental data structure is the "half-edge". Two half-edges
* go together to make an edge, but they point in opposite directions.
* Each half-edge has a pointer to its mate (the "symmetric" half-edge sym),
* its origin vertex (org), the face on its left side (lFace), and the
* adjacent half-edges in the CCW direction around the origin vertex
* (oNext) and around the left face (lNext). There is also a "next"
* pointer for the global edge list (see below).
*
* The notation used for mesh navigation:
* sym = the mate of a half-edge (same edge, but opposite direction)
* oNext = edge CCW around origin vertex (keep same origin)
* dNext = edge CCW around destination vertex (keep same dest)
* lNext = edge CCW around left face (dest becomes new origin)
* rNext = edge CCW around right face (origin becomes new dest)
*
* "prev" means to substitute CW for CCW in the definitions above.
*
* The circular edge list is special; since half-edges always occur
* in pairs (e and e.sym), each half-edge stores a pointer in only
* one direction. Starting at eHead and following the e.next pointers
* will visit each *edge* once (ie. e or e.sym, but not both).
* e.sym stores a pointer in the opposite direction, thus it is
* always true that e.sym.next.sym.next === e.
*
* @param {libtess.GluHalfEdge=} opt_nextEdge [description]
* @constructor
*/
libtess.GluHalfEdge = function(opt_nextEdge) {
// TODO(bckenny): are these the right defaults? (from gl_meshNewMesh requirements)
/**
* doubly-linked list (prev==sym->next)
* @type {!libtess.GluHalfEdge}
*/
this.next = opt_nextEdge || this;
// TODO(bckenny): how can this be required if created in pairs? move to factory creation only?
/**
* same edge, opposite direction
* @type {libtess.GluHalfEdge}
*/
this.sym = null;
/**
* next edge CCW around origin
* @type {libtess.GluHalfEdge}
*/
this.oNext = null;
/**
* next edge CCW around left face
* @type {libtess.GluHalfEdge}
*/
this.lNext = null;
/**
* origin vertex (oVertex too long)
* @type {libtess.GluVertex}
*/
this.org = null;
/**
* left face
* @type {libtess.GluFace}
*/
this.lFace = null;
// Internal data (keep hidden)
// NOTE(bckenny): can't be private, though...
/**
* a region with this upper edge (see sweep.js)
* @type {libtess.ActiveRegion}
*/
this.activeRegion = null;
/**
* change in winding number when crossing from the right face to the left face
* @type {number}
*/
this.winding = 0;
};
// NOTE(bckenny): the following came from macros in mesh
// TODO(bckenny): using methods as aliases for sym connections for now.
// not sure about this approach. getters? renames?
/**
* [rFace description]
* @return {libtess.GluFace} [description]
*/
libtess.GluHalfEdge.prototype.rFace = function() {
return this.sym.lFace;
};
/**
* [dst description]
* @return {libtess.GluVertex} [description]
*/
libtess.GluHalfEdge.prototype.dst = function() {
return this.sym.org;
};
/**
* [oPrev description]
* @return {libtess.GluHalfEdge} [description]
*/
libtess.GluHalfEdge.prototype.oPrev = function() {
return this.sym.lNext;
};
/**
* [lPrev description]
* @return {libtess.GluHalfEdge} [description]
*/
libtess.GluHalfEdge.prototype.lPrev = function() {
return this.oNext.sym;
};
/**
* [dPrev description]
* @return {libtess.GluHalfEdge} [description]
*/
libtess.GluHalfEdge.prototype.dPrev = function() {
return this.lNext.sym;
};
/**
* [rPrev description]
* @return {libtess.GluHalfEdge} [description]
*/
libtess.GluHalfEdge.prototype.rPrev = function() {
return this.sym.oNext;
};
/**
* [dNext description]
* @return {libtess.GluHalfEdge} [description]
*/
libtess.GluHalfEdge.prototype.dNext = function() {
return this.rPrev().sym;
};
/**
* [rNext description]
* @return {libtess.GluHalfEdge} [description]
*/
libtess.GluHalfEdge.prototype.rNext = function() {
return this.oPrev().sym;
};

View File

@@ -0,0 +1,141 @@
/**
* Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
* Copyright 2012, Google Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Original Code. The Original Code is: OpenGL Sample Implementation,
* Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
* Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
* Copyright in any portions created by third parties is as indicated
* elsewhere herein. All Rights Reserved.
*/
/**
* @author Eric Veach, July 1994
* @author Brendan Kenny
*/
// require libtess.GluFace
// require libtess.GluHalfEdge
// require libtess.GluVertex
/*global libtess */
/**
* Creates a new mesh with no edges, no vertices,
* and no loops (what we usually call a "face").
*
* @constructor
*/
libtess.GluMesh = function() {
/**
* dummy header for vertex list
* @type {libtess.GluVertex}
*/
this.vHead = new libtess.GluVertex();
/**
* dummy header for face list
* @type {libtess.GluFace}
*/
this.fHead = new libtess.GluFace();
/**
* dummy header for edge list
* @type {libtess.GluHalfEdge}
*/
this.eHead = new libtess.GluHalfEdge();
/**
* and its symmetric counterpart
* @type {libtess.GluHalfEdge}
*/
this.eHeadSym = new libtess.GluHalfEdge();
// TODO(bckenny): better way to pair these?
this.eHead.sym = this.eHeadSym;
this.eHeadSym.sym = this.eHead;
};
// TODO(bckenny): #ifndef NDEBUG
/**
* Checks mesh for self-consistency.
*/
libtess.GluMesh.prototype.checkMesh = function() {
if (!libtess.DEBUG) {
return;
}
var fHead = this.fHead;
var vHead = this.vHead;
var eHead = this.eHead;
var e;
// faces
var f;
var fPrev = fHead;
for (fPrev = fHead; (f = fPrev.next) !== fHead; fPrev = f) {
libtess.assert(f.prev === fPrev);
e = f.anEdge;
do {
libtess.assert(e.sym !== e);
libtess.assert(e.sym.sym === e);
libtess.assert(e.lNext.oNext.sym === e);
libtess.assert(e.oNext.sym.lNext === e);
libtess.assert(e.lFace === f);
e = e.lNext;
} while(e !== f.anEdge);
}
libtess.assert(f.prev === fPrev && f.anEdge === null && f.data === null);
// vertices
var v;
var vPrev = vHead;
for (vPrev = vHead; (v = vPrev.next) !== vHead; vPrev = v) {
libtess.assert(v.prev === vPrev);
e = v.anEdge;
do {
libtess.assert(e.sym !== e);
libtess.assert(e.sym.sym === e);
libtess.assert(e.lNext.oNext.sym === e);
libtess.assert(e.oNext.sym.lNext === e);
libtess.assert(e.org === v);
e = e.oNext;
} while(e !== v.anEdge);
}
libtess.assert(v.prev === vPrev && v.anEdge === null && v.data === null);
// edges
var ePrev = eHead;
for (ePrev = eHead; (e = ePrev.next) !== eHead; ePrev = e) {
libtess.assert(e.sym.next === ePrev.sym);
libtess.assert(e.sym !== e);
libtess.assert(e.sym.sym === e);
libtess.assert(e.org !== null);
libtess.assert(e.dst() !== null);
libtess.assert(e.lNext.oNext.sym === e);
libtess.assert(e.oNext.sym.lNext === e);
}
libtess.assert(e.sym.next === ePrev.sym &&
e.sym === this.eHeadSym &&
e.sym.sym === e &&
e.org === null && e.dst() === null &&
e.lFace === null && e.rFace() === null);
};

View File

@@ -0,0 +1,102 @@
/**
* Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
* Copyright 2012, Google Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Original Code. The Original Code is: OpenGL Sample Implementation,
* Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
* Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
* Copyright in any portions created by third parties is as indicated
* elsewhere herein. All Rights Reserved.
*/
/**
* @author Eric Veach, July 1994
* @author Brendan Kenny
*/
// requre libtess.GluHalfEdge
/*global libtess */
/**
* Each vertex has a pointer to next and previous vertices in the
* circular list, and a pointer to a half-edge with this vertex as
* the origin (null if this is the dummy header). There is also a
* field "data" for client data.
*
* @param {libtess.GluVertex=} opt_nextVertex [description]
* @param {libtess.GluVertex=} opt_prevVertex [description]
* @constructor
*/
libtess.GluVertex = function(opt_nextVertex, opt_prevVertex) {
// TODO(bckenny): reverse order of params?
/**
* Next vertex (never null).
* @type {!libtess.GluVertex}
*/
this.next = opt_nextVertex || this;
/**
* Previous vertex (never null).
* @type {!libtess.GluVertex}
*/
this.prev = opt_prevVertex || this;
/**
* A half-edge with this origin.
* @type {libtess.GluHalfEdge}
*/
this.anEdge = null;
/**
* The client's data.
* @type {Object}
*/
this.data = null;
/**
* The vertex location in 3D.
* @type {Array.<number>}
*/
this.coords = [0, 0, 0];
// TODO(bckenny): we may want to rethink coords, either eliminate (using s
// and t and user data) or index into contiguous storage?
/**
* Component of projection onto the sweep plane.
* @type {number}
*/
this.s = 0;
/**
* Component of projection onto the sweep plane.
* @type {number}
*/
this.t = 0;
/**
* To allow deletion from priority queue.
* @type {?libtess.PQHandle}
*/
this.pqHandle = null;
// NOTE(bckenny): pqHandle inited in sweep
// TODO(bckenny): can we have a numeric default value? null may do bad things
};