Search in sources :

Example 51 with Stack

use of com.bulletphysics.util.Stack 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();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 52 with Stack

use of com.bulletphysics.util.Stack 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();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 53 with Stack

use of com.bulletphysics.util.Stack 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();
    }
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 54 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class OptimizedBvh method setQuantizationValues.

public void setQuantizationValues(Vector3f aabbMin, Vector3f aabbMax, float quantizationMargin) {
    // enlarge the AABB to avoid division by zero when initializing the quantization values
    Stack stack = Stack.enter();
    Vector3f clampValue = stack.allocVector3f();
    clampValue.set(quantizationMargin, quantizationMargin, quantizationMargin);
    bvhAabbMin.sub(aabbMin, clampValue);
    bvhAabbMax.add(aabbMax, clampValue);
    Vector3f aabbSize = stack.allocVector3f();
    aabbSize.sub(bvhAabbMax, bvhAabbMin);
    bvhQuantization.set(65535f, 65535f, 65535f);
    VectorUtil.div(bvhQuantization, bvhQuantization, aabbSize);
    stack.leave();
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 55 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class OptimizedBvh method refit.

public void refit(StridingMeshInterface meshInterface) {
    if (useQuantization) {
        // calculate new aabb
        Stack stack = Stack.enter();
        Vector3f aabbMin = stack.allocVector3f(), aabbMax = stack.allocVector3f();
        meshInterface.calculateAabbBruteForce(aabbMin, aabbMax);
        setQuantizationValues(aabbMin, aabbMax);
        updateBvhNodes(meshInterface, 0, curNodeIndex, 0);
        // now update all subtree headers
        int i;
        for (i = 0; i < SubtreeHeaders.size(); i++) {
            BvhSubtreeInfo subtree = SubtreeHeaders.getQuick(i);
            subtree.setAabbFromQuantizeNode(quantizedContiguousNodes, subtree.rootNodeIndex);
        }
        stack.leave();
    } else {
        // JAVA NOTE: added for testing, it's too slow for practical use
        build(meshInterface, false, null, null);
    }
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Aggregations

Stack (com.bulletphysics.util.Stack)252 Vector3f (javax.vecmath.Vector3f)197 Transform (com.bulletphysics.linearmath.Transform)65 Matrix3f (javax.vecmath.Matrix3f)23 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)15 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)15 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)10 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)10 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)10 Vector4f (javax.vecmath.Vector4f)8 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)6 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)5 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 RigidBody (com.bulletphysics.dynamics.RigidBody)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3