Search in sources :

Example 36 with BoundingBox

use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.

the class UVProjectionGenerator method flatProjection.

/**
     * Flat projection for 2D textures.
     * 
     * @param mesh
     *            mesh that is to be projected
     * @param bb
     *            the bounding box for projecting
     * @return UV coordinates after the projection
     */
public static float[] flatProjection(float[] positions, BoundingBox bb) {
    Vector3f min = bb.getMin(null);
    float[] ext = new float[] { bb.getXExtent() * 2.0f, bb.getZExtent() * 2.0f };
    float[] uvCoordinates = new float[positions.length / 3 * 2];
    for (int i = 0, j = 0; i < positions.length; i += 3, j += 2) {
        uvCoordinates[j] = (positions[i] - min.x) / ext[0];
        // skip the Y-coordinate
        uvCoordinates[j + 1] = (positions[i + 2] - min.z) / ext[1];
    }
    return uvCoordinates;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 37 with BoundingBox

use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.

the class BIHTree method createBox.

private BoundingBox createBox(int l, int r) {
    TempVars vars = TempVars.get();
    Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
    Vector3f v1 = vars.vect3, v2 = vars.vect4, v3 = vars.vect5;
    for (int i = l; i <= r; i++) {
        getTriangle(i, v1, v2, v3);
        BoundingBox.checkMinMax(min, max, v1);
        BoundingBox.checkMinMax(min, max, v2);
        BoundingBox.checkMinMax(min, max, v3);
    }
    BoundingBox bbox = new BoundingBox(min, max);
    vars.release();
    return bbox;
}
Also used : Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) TempVars(com.jme3.util.TempVars)

Example 38 with BoundingBox

use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.

the class BIHTree method createNode.

//    private BIHNode createNode2(int l, int r, BoundingBox nodeBbox, int depth){
//        if ((r - l) < maxTrisPerNode || depth > 100)
//            return createLeaf(l, r);
//
//        BoundingBox currentBox = createBox(l, r);
//        int axis = depth % 3;
//        float split = currentBox.getCenter().get(axis);
//
//        TriangleAxisComparator comparator = comparators[axis];
//        Arrays.sort(tris, l, r, comparator);
//        int splitIndex = -1;
//
//        float leftPlane, rightPlane = Float.POSITIVE_INFINITY;
//        leftPlane = tris[l].getExtreme(axis, false);
//        for (int i = l; i <= r; i++){
//            BIHTriangle tri = tris[i];
//            if (splitIndex == -1){
//                float v = tri.getCenter().get(axis);
//                if (v > split){
//                    if (i == 0){
//                        // no left plane
//                        splitIndex = -2;
//                    }else{
//                        splitIndex = i;
//                        // first triangle assigned to right
//                        rightPlane = tri.getExtreme(axis, true);
//                    }
//                }else{
//                    // triangle assigned to left
//                    float ex = tri.getExtreme(axis, false);
//                    if (ex > leftPlane)
//                        leftPlane = ex;
//                }
//            }else{
//                float ex = tri.getExtreme(axis, true);
//                if (ex < rightPlane)
//                    rightPlane = ex;
//            }
//        }
//
//        if (splitIndex < 0){
//            splitIndex = (r - l) / 2;
//
//            leftPlane = Float.NEGATIVE_INFINITY;
//            rightPlane = Float.POSITIVE_INFINITY;
//
//            for (int i = l; i < splitIndex; i++){
//                float ex = tris[i].getExtreme(axis, false);
//                if (ex > leftPlane){
//                    leftPlane = ex;
//                }
//            }
//            for (int i = splitIndex; i <= r; i++){
//                float ex = tris[i].getExtreme(axis, true);
//                if (ex < rightPlane){
//                    rightPlane = ex;
//                }
//            }
//        }
//
//        BIHNode node = new BIHNode(axis);
//        node.leftPlane = leftPlane;
//        node.rightPlane = rightPlane;
//
//        node.leftIndex = l;
//        node.rightIndex = r;
//
//        BoundingBox leftBbox = new BoundingBox(currentBox);
//        setMinMax(leftBbox, false, axis, split);
//        node.left = createNode2(l, splitIndex-1, leftBbox, depth+1);
//
//        BoundingBox rightBbox = new BoundingBox(currentBox);
//        setMinMax(rightBbox, true, axis, split);
//        node.right = createNode2(splitIndex, r, rightBbox, depth+1);
//
//        return node;
//    }
private BIHNode createNode(int l, int r, BoundingBox nodeBbox, int depth) {
    if ((r - l) < maxTrisPerNode || depth > MAX_TREE_DEPTH) {
        return new BIHNode(l, r);
    }
    BoundingBox currentBox = createBox(l, r);
    Vector3f exteriorExt = nodeBbox.getExtent(null);
    Vector3f interiorExt = currentBox.getExtent(null);
    exteriorExt.subtractLocal(interiorExt);
    int axis = 0;
    if (exteriorExt.x > exteriorExt.y) {
        if (exteriorExt.x > exteriorExt.z) {
            axis = 0;
        } else {
            axis = 2;
        }
    } else {
        if (exteriorExt.y > exteriorExt.z) {
            axis = 1;
        } else {
            axis = 2;
        }
    }
    if (exteriorExt.equals(Vector3f.ZERO)) {
        axis = 0;
    }
    //        Arrays.sort(tris, l, r, comparators[axis]);
    float split = currentBox.getCenter().get(axis);
    int pivot = sortTriangles(l, r, split, axis);
    if (pivot == l || pivot == r) {
        pivot = (r + l) / 2;
    }
    //If one of the partitions is empty, continue with recursion: same level but different bbox
    if (pivot < l) {
        //Only right
        BoundingBox rbbox = new BoundingBox(currentBox);
        setMinMax(rbbox, true, axis, split);
        return createNode(l, r, rbbox, depth + 1);
    } else if (pivot > r) {
        //Only left
        BoundingBox lbbox = new BoundingBox(currentBox);
        setMinMax(lbbox, false, axis, split);
        return createNode(l, r, lbbox, depth + 1);
    } else {
        //Build the node
        BIHNode node = new BIHNode(axis);
        //Left child
        BoundingBox lbbox = new BoundingBox(currentBox);
        setMinMax(lbbox, false, axis, split);
        //The left node right border is the plane most right
        node.setLeftPlane(getMinMax(createBox(l, max(l, pivot - 1)), false, axis));
        //Recursive call
        node.setLeftChild(createNode(l, max(l, pivot - 1), lbbox, depth + 1));
        //Right Child
        BoundingBox rbbox = new BoundingBox(currentBox);
        setMinMax(rbbox, true, axis, split);
        //The right node left border is the plane most left
        node.setRightPlane(getMinMax(createBox(pivot, r), true, axis));
        //Recursive call
        node.setRightChild(createNode(pivot, r, rbbox, depth + 1));
        return node;
    }
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f)

Example 39 with BoundingBox

use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method emitParticles.

/**
     * Instantly emits available particles, up to num.
     */
public void emitParticles(int num) {
    // Force world transform to update
    this.getWorldTransform();
    TempVars vars = TempVars.get();
    BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
    Vector3f min = vars.vect1;
    Vector3f max = vars.vect2;
    bbox.getMin(min);
    bbox.getMax(max);
    if (!Vector3f.isValidVector(min)) {
        min.set(Vector3f.POSITIVE_INFINITY);
    }
    if (!Vector3f.isValidVector(max)) {
        max.set(Vector3f.NEGATIVE_INFINITY);
    }
    for (int i = 0; i < num; i++) {
        if (emitParticle(min, max) == null)
            break;
    }
    bbox.setMinMax(min, max);
    this.setBoundRefresh();
    vars.release();
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 40 with BoundingBox

use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.

the class PoiLightProbeLightFilter method filterLights.

@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {
    TempVars vars = TempVars.get();
    try {
        LightList worldLights = geometry.getWorldLightList();
        for (int i = 0; i < worldLights.size(); i++) {
            Light light = worldLights.get(i);
            if (light.getType() == Light.Type.Probe) {
                continue;
            }
            if (light.frustumCheckNeeded) {
                processedLights.add(light);
                light.frustumCheckNeeded = false;
                light.intersectsFrustum = light.intersectsFrustum(camera, vars);
            }
            if (!light.intersectsFrustum) {
                continue;
            }
            BoundingVolume bv = geometry.getWorldBound();
            if (bv instanceof BoundingBox) {
                if (!light.intersectsBox((BoundingBox) bv, vars)) {
                    continue;
                }
            } else if (bv instanceof BoundingSphere) {
                if (!Float.isInfinite(((BoundingSphere) bv).getRadius())) {
                    if (!light.intersectsSphere((BoundingSphere) bv, vars)) {
                        continue;
                    }
                }
            }
            filteredLightList.add(light);
        }
        processor.populateProbe(filteredLightList);
    } finally {
        vars.release();
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Aggregations

BoundingBox (com.jme3.bounding.BoundingBox)42 Vector3f (com.jme3.math.Vector3f)35 Geometry (com.jme3.scene.Geometry)14 TempVars (com.jme3.util.TempVars)14 BoundingVolume (com.jme3.bounding.BoundingVolume)10 BoundingSphere (com.jme3.bounding.BoundingSphere)8 Material (com.jme3.material.Material)7 Vector2f (com.jme3.math.Vector2f)4 Texture (com.jme3.texture.Texture)4 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 Matrix4f (com.jme3.math.Matrix4f)3 Ray (com.jme3.math.Ray)3 Node (com.jme3.scene.Node)3 Spatial (com.jme3.scene.Spatial)3 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)3 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)3 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)3 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)3 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)3