use of javax.vecmath.Vector3f in project bdx by GoranM.
the class CylinderShapeX method localGetSupportingVertexWithoutMargin.
@Override
public Vector3f localGetSupportingVertexWithoutMargin(Vector3f vec, Vector3f out) {
Stack stack = Stack.enter();
Vector3f result = cylinderLocalSupportX(getHalfExtentsWithoutMargin(stack.allocVector3f()), vec, out);
stack.leave();
return result;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method reportRayOverlappingNodex.
public void reportRayOverlappingNodex(NodeOverlapCallback nodeCallback, Vector3f raySource, Vector3f rayTarget) {
boolean fast_path = useQuantization && traversalMode == TraversalMode.STACKLESS;
Stack stack = Stack.enter();
if (fast_path) {
Vector3f tmp = stack.allocVector3f();
tmp.set(0f, 0f, 0f);
walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, tmp, tmp, 0, curNodeIndex);
} else {
/* Otherwise fallback to AABB overlap test */
Vector3f aabbMin = stack.alloc(raySource);
Vector3f aabbMax = stack.alloc(raySource);
VectorUtil.setMin(aabbMin, rayTarget);
VectorUtil.setMax(aabbMax, rayTarget);
reportAabbOverlappingNodex(nodeCallback, aabbMin, aabbMax);
}
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method buildTree.
protected void buildTree(int startIndex, int endIndex) {
//#ifdef DEBUG_TREE_BUILDING
if (DEBUG_TREE_BUILDING) {
gStackDepth++;
if (gStackDepth > gMaxStackDepth) {
gMaxStackDepth = gStackDepth;
}
}
//#endif //DEBUG_TREE_BUILDING
int splitAxis, splitIndex, i;
int numIndices = endIndex - startIndex;
int curIndex = curNodeIndex;
assert (numIndices > 0);
if (numIndices == 1) {
//#ifdef DEBUG_TREE_BUILDING
if (DEBUG_TREE_BUILDING) {
gStackDepth--;
}
//#endif //DEBUG_TREE_BUILDING
assignInternalNodeFromLeafNode(curNodeIndex, startIndex);
curNodeIndex++;
return;
}
// calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
splitAxis = calcSplittingAxis(startIndex, endIndex);
splitIndex = sortAndCalcSplittingIndex(startIndex, endIndex, splitAxis);
int internalNodeIndex = curNodeIndex;
Stack stack = Stack.enter();
Vector3f tmp1 = stack.allocVector3f();
tmp1.set(-1e30f, -1e30f, -1e30f);
setInternalNodeAabbMax(curNodeIndex, tmp1);
Vector3f tmp2 = stack.allocVector3f();
tmp2.set(1e30f, 1e30f, 1e30f);
setInternalNodeAabbMin(curNodeIndex, tmp2);
for (i = startIndex; i < endIndex; i++) {
mergeInternalNodeAabb(curNodeIndex, getAabbMin(i), getAabbMax(i));
}
curNodeIndex++;
//internalNode->m_escapeIndex;
int leftChildNodexIndex = curNodeIndex;
//build left child tree
buildTree(startIndex, splitIndex);
int rightChildNodexIndex = curNodeIndex;
// build right child tree
buildTree(splitIndex, endIndex);
//#ifdef DEBUG_TREE_BUILDING
if (DEBUG_TREE_BUILDING) {
gStackDepth--;
}
//#endif //DEBUG_TREE_BUILDING
int escapeIndex = curNodeIndex - curIndex;
if (useQuantization) {
// escapeIndex is the number of nodes of this subtree
int sizeQuantizedNode = QuantizedBvhNodes.getNodeSize();
int treeSizeInBytes = escapeIndex * sizeQuantizedNode;
if (treeSizeInBytes > MAX_SUBTREE_SIZE_IN_BYTES) {
updateSubtreeHeaders(leftChildNodexIndex, rightChildNodexIndex);
}
}
setInternalNodeEscapeIndex(internalNodeIndex, escapeIndex);
stack.leave();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method build.
public void build(StridingMeshInterface triangles, boolean useQuantizedAabbCompression, Vector3f _aabbMin, Vector3f _aabbMax) {
this.useQuantization = useQuantizedAabbCompression;
// NodeArray triangleNodes;
int numLeafNodes = 0;
if (useQuantization) {
// initialize quantization values
setQuantizationValues(_aabbMin, _aabbMax);
QuantizedNodeTriangleCallback callback = new QuantizedNodeTriangleCallback(quantizedLeafNodes, this);
triangles.internalProcessAllTriangles(callback, bvhAabbMin, bvhAabbMax);
// now we have an array of leafnodes in m_leafNodes
numLeafNodes = quantizedLeafNodes.size();
quantizedContiguousNodes.resize(2 * numLeafNodes);
} else {
Stack stack = Stack.enter();
NodeTriangleCallback callback = new NodeTriangleCallback(leafNodes);
Vector3f aabbMin = stack.allocVector3f();
aabbMin.set(-1e30f, -1e30f, -1e30f);
Vector3f aabbMax = stack.allocVector3f();
aabbMax.set(1e30f, 1e30f, 1e30f);
triangles.internalProcessAllTriangles(callback, aabbMin, aabbMax);
// now we have an array of leafnodes in m_leafNodes
numLeafNodes = leafNodes.size();
// TODO: check
//contiguousNodes.resize(2*numLeafNodes);
MiscUtil.resize(contiguousNodes, 2 * numLeafNodes, NEW_OPTIMIZED_BVH_NODE_SUPPLIER);
stack.leave();
}
curNodeIndex = 0;
buildTree(0, numLeafNodes);
// if the entire tree is small then subtree size, we need to create a header info for the tree
if (useQuantization && SubtreeHeaders.size() == 0) {
BvhSubtreeInfo subtree = new BvhSubtreeInfo();
SubtreeHeaders.add(subtree);
subtree.setAabbFromQuantizeNode(quantizedContiguousNodes, 0);
subtree.rootNodeIndex = 0;
subtree.subtreeSize = quantizedContiguousNodes.isLeafNode(0) ? 1 : quantizedContiguousNodes.getEscapeIndex(0);
}
// PCK: update the copy of the size
subtreeHeaderCount = SubtreeHeaders.size();
// PCK: clear m_quantizedLeafNodes and m_leafNodes, they are temporary
quantizedLeafNodes.clear();
leafNodes.clear();
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class OptimizedBvh method reportBoxCastOverlappingNodex.
public void reportBoxCastOverlappingNodex(NodeOverlapCallback nodeCallback, Vector3f raySource, Vector3f rayTarget, Vector3f aabbMin, Vector3f aabbMax) {
boolean fast_path = useQuantization && traversalMode == TraversalMode.STACKLESS;
if (fast_path) {
walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, curNodeIndex);
} else {
Stack stack = Stack.enter();
/* Slow path:
Construct the bounding box for the entire box cast and send that down the tree */
Vector3f qaabbMin = stack.alloc(raySource);
Vector3f qaabbMax = stack.alloc(raySource);
VectorUtil.setMin(qaabbMin, rayTarget);
VectorUtil.setMax(qaabbMax, rayTarget);
qaabbMin.add(aabbMin);
qaabbMax.add(aabbMax);
reportAabbOverlappingNodex(nodeCallback, qaabbMin, qaabbMax);
stack.leave();
}
}
Aggregations