slice method
dynamic
slice()
Implementation
slice() {
this._points = [];
this._texCoords = [];
this._indexes = [];
var i;
var cornerDistance0 = this._posCorners[ 0 ].dot(this._viewVector);
// print('nnn'+cornerDistance0.toString());
var cornerDistance = [ cornerDistance0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
var maxCorner = 0;
var minDistance = cornerDistance0;
var maxDistance = cornerDistance0;
for (i = 1; i < 8; i = (i + 1) | 0) {
//print('xxx'+i.toString()+" "+cornerDistance.toString()+" "+this._posCorners.toString()+" "+this._viewVector.toString());
cornerDistance[ i ] = this._posCorners[ i ].dot(this._viewVector);
if (cornerDistance[ i ] > maxDistance) {
maxCorner = i;
maxDistance = cornerDistance[ i ];
}
if (cornerDistance[ i ] < minDistance) {
minDistance = cornerDistance[ i ];
}
//print("iii"+i.toString());
}
// Aligning slices
// print("ooo"+maxDistance.toString()+" "+this._sliceSpacing.toString());
var sliceDistance = (maxDistance / this._sliceSpacing).floor() *
this._sliceSpacing;
var activeEdges = [];
var firstEdge = 0;
var nextEdge = 0;
var expirations = new PriorityQueue();
createEdge(startIndex, endIndex) {
if (nextEdge >= 12) {
return null;
}
var activeEdge = {
'expired': false,
'startIndex': startIndex,
'endIndex': endIndex,
'deltaPos': new THREE.Vector3(),
'deltaTex': new THREE.Vector3(),
'pos': new THREE.Vector3(),
'tex': new THREE.Vector3(),
'cur': nextEdge
};
var range = cornerDistance[ startIndex ] - cornerDistance[ endIndex ];
if (range != 0.0) {
var irange = 1.0 / range;
activeEdge['deltaPos'].subVectors(
this._posCorners[ endIndex ],
this._posCorners[ startIndex ]
).multiplyScalar(irange);
activeEdge['deltaTex'].subVectors(
this._texCorners[ endIndex ],
this._texCorners[ startIndex ]
).multiplyScalar(irange);
var step = cornerDistance[ startIndex ] - sliceDistance;
activeEdge['pos'].addVectors(
activeEdge['deltaPos'].clone().multiplyScalar(step),
this._posCorners[ startIndex ]
);
activeEdge['tex'].addVectors(
activeEdge['deltaTex'].clone().multiplyScalar(step),
this._texCorners[ startIndex ]
);
activeEdge['deltaPos'].multiplyScalar(this._sliceSpacing);
activeEdge['deltaTex'].multiplyScalar(this._sliceSpacing);
}
expirations.push(activeEdge, cornerDistance[ endIndex ]);
nextEdge++;
if (nextEdge<activeEdges.length)
activeEdges[ nextEdge] = activeEdge;
else
activeEdges.add(activeEdge);
//activeEdges[ nextEdge++ ] = activeEdge;
return activeEdge;
};
for (i = 0; i < 3; i = (i + 1) | 0) {
var activeEdge = createEdge(
maxCorner, cornerNeighbors[ maxCorner ][ i ]);
if (activeEdge!=null) {//gl
activeEdge['prev'] = (i + 2) % 3;
activeEdge['next'] = (i + 1) % 3;
}
}
int nextIndex = 0;
while (sliceDistance > minDistance) {
//print("ooo"+expirations.contents.length.toString());
//print("nn"+sliceDistance.toString());
while (/*expirations.contents.length>0&&*/expirations //gl
.top()
['priority'] >= sliceDistance) {
var edge = expirations
.pop()
['object'];
if (edge['expired']) {
continue;
}
if (
edge['endIndex'] != activeEdges[ edge['prev'] ]['endIndex'] &&
edge['endIndex'] != activeEdges[ edge['next'] ]['endIndex']
) {
// split this edge.
edge['expired'] = true;
// create two new edges.
var activeEdge1 = createEdge(
edge['endIndex'],
incomingEdges[ edge['endIndex'] ][ edge['startIndex'] ]
);
if (activeEdge1!=null) { //gl
activeEdge1['prev'] = edge['prev'];
activeEdges[ edge['prev'] ]['next'] = nextEdge - 1;
activeEdge1['next'] = nextEdge;
var activeEdge2 = createEdge(
edge['endIndex'],
incomingEdges[ edge['endIndex'] ][ activeEdge1['endIndex'] ]
);
if (activeEdge2 != null) {
activeEdge2['prev'] = nextEdge - 2;
activeEdge2['next'] = edge['next'];
activeEdges[activeEdge2['next']]['prev'] = nextEdge - 1;
firstEdge = nextEdge - 1;
}
}
} else {
// merge edge.
var prev;
var next;
if (edge['endIndex'] == activeEdges[ edge['prev'] ]['endIndex']) {
prev = activeEdges[ edge['prev'] ];
next = edge;
} else {
prev = edge;
next = activeEdges[ edge['next'] ];
}
prev['expired'] = true;
next['expired'] = true;
// make new edge
var activeEdge = createEdge(
edge['endIndex'],
incomingEdges[ edge['endIndex'] ][ prev['startIndex'] ]
);
if (activeEdge!=null) {
activeEdge['prev'] = prev['prev'];
activeEdges[ activeEdge['prev'] ]['next'] = nextEdge - 1;
activeEdge['next'] = next['next'];
activeEdges[ activeEdge['next'] ]['prev'] = nextEdge - 1;
firstEdge = nextEdge - 1;
}
}
}
var cur = firstEdge;
var count = 0;
do {
++count;
var activeEdge = activeEdges[ cur ];
this._points.addAll(
[activeEdge['pos'].x,
activeEdge['pos'].y,
activeEdge['pos'].z]
);
this._texCoords.addAll(
[activeEdge['tex'].x,
activeEdge['tex'].y,
activeEdge['tex'].z]
);
activeEdge['pos'].add(activeEdge['deltaPos']);
activeEdge['tex'].add(activeEdge['deltaTex']);
cur = activeEdge['next'];
} while (cur != firstEdge);
for (int i = 2; i < count; i = (i + 1) | 0) {
// print("uuu"+this._indexes.toString()+" uu"+i.toString()+" mm"+nextIndex.toString());
/* this._indexes.add(nextIndex);
this._indexes.add((nextIndex+int(i)-1));
this._indexes.add(nextIndex);*/
this._indexes.addAll(
[nextIndex,
(nextIndex + i - 1),
nextIndex + i]
);
}
nextIndex += count;
sliceDistance -= this._sliceSpacing;
}
}