Search in sources :

Example 31 with BoundingBox

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

the class TemporalMesh method getWorldBound.

@Override
public BoundingVolume getWorldBound() {
    this.updateModelBound();
    Node parent = this.getParent();
    if (parent != null) {
        BoundingVolume bv = boundingBox.clone();
        bv.setCenter(parent.getWorldTranslation());
        return bv;
    } else {
        return boundingBox;
    }
}
Also used : Node(com.jme3.scene.Node) BoundingVolume(com.jme3.bounding.BoundingVolume)

Example 32 with BoundingBox

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

the class TemporalMesh method updateModelBound.

@Override
public void updateModelBound() {
    if (boundingBox == null) {
        boundingBox = new BoundingBox();
    }
    Vector3f min = new Vector3f(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
    Vector3f max = new Vector3f(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
    for (Vector3f v : vertices) {
        min.set(Math.min(min.x, v.x), Math.min(min.y, v.y), Math.min(min.z, v.z));
        max.set(Math.max(max.x, v.x), Math.max(max.y, v.y), Math.max(max.z, v.z));
    }
    boundingBox.setMinMax(min, max);
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f)

Example 33 with BoundingBox

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

the class UVCoordinatesGenerator method generateUVCoordinatesFor2DTexture.

/**
     * Generates a UV coordinates for 2D texture.
     * 
     * @param mesh
     *            the mesh we generate UV's for
     * @param texco
     *            UV coordinates type
     * @param projection
     *            projection type
     * @param geometries
     *            the geometris the given mesh belongs to (required to compute
     *            bounding box)
     * @return UV coordinates for the given mesh
     */
public static List<Vector2f> generateUVCoordinatesFor2DTexture(Mesh mesh, UVCoordinatesType texco, UVProjectionType projection, Geometry geometries) {
    List<Vector2f> result = new ArrayList<Vector2f>();
    BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometries);
    // positions, normals, reflection vectors, etc.
    float[] inputData = null;
    switch(texco) {
        case TEXCO_ORCO:
            inputData = BufferUtils.getFloatArray(mesh.getFloatBuffer(VertexBuffer.Type.Position));
            break;
        case // this should be used if not defined by user explicitly
        TEXCO_UV:
            Vector2f[] data = new Vector2f[] { new Vector2f(0, 1), new Vector2f(0, 0), new Vector2f(1, 0) };
            for (int i = 0; i < mesh.getVertexCount(); ++i) {
                result.add(data[i % 3]);
            }
            break;
        case TEXCO_NORM:
            inputData = BufferUtils.getFloatArray(mesh.getFloatBuffer(VertexBuffer.Type.Normal));
            break;
        case TEXCO_REFL:
        case TEXCO_GLOB:
        case TEXCO_TANGENT:
        case TEXCO_STRESS:
        case TEXCO_LAVECTOR:
        case TEXCO_OBJECT:
        case TEXCO_OSA:
        case TEXCO_PARTICLE_OR_STRAND:
        case TEXCO_SPEED:
        case TEXCO_STICKY:
        case TEXCO_VIEW:
        case TEXCO_WINDOW:
            LOGGER.warning("Texture coordinates type not currently supported: " + texco);
            break;
        default:
            throw new IllegalStateException("Unknown texture coordinates value: " + texco);
    }
    if (inputData != null) {
        // make projection calculations
        switch(projection) {
            case PROJECTION_FLAT:
                inputData = UVProjectionGenerator.flatProjection(inputData, bb);
                break;
            case PROJECTION_CUBE:
                inputData = UVProjectionGenerator.cubeProjection(inputData, bb);
                break;
            case PROJECTION_TUBE:
                BoundingTube bt = UVCoordinatesGenerator.getBoundingTube(geometries);
                inputData = UVProjectionGenerator.tubeProjection(inputData, bt);
                break;
            case PROJECTION_SPHERE:
                BoundingSphere bs = UVCoordinatesGenerator.getBoundingSphere(geometries);
                inputData = UVProjectionGenerator.sphereProjection(inputData, bs);
                break;
            default:
                throw new IllegalStateException("Unknown projection type: " + projection);
        }
        for (int i = 0; i < inputData.length; i += 2) {
            result.add(new Vector2f(inputData[i], inputData[i + 1]));
        }
    }
    return result;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Vector2f(com.jme3.math.Vector2f) BoundingBox(com.jme3.bounding.BoundingBox) ArrayList(java.util.ArrayList)

Example 34 with BoundingBox

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

the class UVCoordinatesGenerator method generateUVCoordinatesFor3DTexture.

/**
     * Generates a UV coordinates for 3D texture.
     * 
     * @param mesh
     *            the mesh we generate UV's for
     * @param texco
     *            UV coordinates type
     * @param coordinatesSwappingIndexes
     *            coordinates swapping indexes
     * @param geometries
     *            the geometris the given mesh belongs to (required to compute
     *            bounding box)
     * @return UV coordinates for the given mesh
     */
public static List<Vector3f> generateUVCoordinatesFor3DTexture(Mesh mesh, UVCoordinatesType texco, int[] coordinatesSwappingIndexes, Geometry... geometries) {
    List<Vector3f> result = new ArrayList<Vector3f>();
    BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometries);
    // positions, normals, reflection vectors, etc.
    float[] inputData = null;
    switch(texco) {
        case TEXCO_ORCO:
            inputData = BufferUtils.getFloatArray(mesh.getFloatBuffer(VertexBuffer.Type.Position));
            break;
        case TEXCO_UV:
            Vector2f[] data = new Vector2f[] { new Vector2f(0, 1), new Vector2f(0, 0), new Vector2f(1, 0) };
            for (int i = 0; i < mesh.getVertexCount(); ++i) {
                Vector2f uv = data[i % 3];
                result.add(new Vector3f(uv.x, uv.y, 0));
            }
            break;
        case TEXCO_NORM:
            inputData = BufferUtils.getFloatArray(mesh.getFloatBuffer(VertexBuffer.Type.Normal));
            break;
        case TEXCO_REFL:
        case TEXCO_GLOB:
        case TEXCO_TANGENT:
        case TEXCO_STRESS:
        case TEXCO_LAVECTOR:
        case TEXCO_OBJECT:
        case TEXCO_OSA:
        case TEXCO_PARTICLE_OR_STRAND:
        case TEXCO_SPEED:
        case TEXCO_STICKY:
        case TEXCO_VIEW:
        case TEXCO_WINDOW:
            LOGGER.warning("Texture coordinates type not currently supported: " + texco);
            break;
        default:
            throw new IllegalStateException("Unknown texture coordinates value: " + texco);
    }
    if (inputData != null) {
        // make calculations
        Vector3f min = bb.getMin(null);
        // used for coordinates swapping
        float[] uvCoordsResults = new float[4];
        float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
        for (int i = 0; i < ext.length; ++i) {
            if (ext[i] == 0) {
                ext[i] = 1;
            }
        }
        // <0; 1>
        for (int i = 0; i < inputData.length; i += 3) {
            uvCoordsResults[1] = (inputData[i] - min.x) / ext[0];
            uvCoordsResults[2] = (inputData[i + 1] - min.y) / ext[1];
            uvCoordsResults[3] = (inputData[i + 2] - min.z) / ext[2];
            result.add(new Vector3f(uvCoordsResults[coordinatesSwappingIndexes[0]], uvCoordsResults[coordinatesSwappingIndexes[1]], uvCoordsResults[coordinatesSwappingIndexes[2]]));
        }
    }
    return result;
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) ArrayList(java.util.ArrayList)

Example 35 with BoundingBox

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

the class UVCoordinatesGenerator method getBoundingTube.

/**
     * This method returns the bounding tube of the given geometries.
     * 
     * @param geometries
     *            the list of geometries
     * @return bounding tube of the given geometries
     */
/* package */
static BoundingTube getBoundingTube(Geometry... geometries) {
    BoundingTube result = null;
    for (Geometry geometry : geometries) {
        BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometry);
        Vector3f max = bb.getMax(null);
        Vector3f min = bb.getMin(null);
        float radius = Math.max(max.x - min.x, max.y - min.y) * 0.5f;
        BoundingTube bt = new BoundingTube(radius, max.z - min.z, bb.getCenter());
        if (result == null) {
            result = bt;
        } else {
            result.merge(bt);
        }
    }
    return result;
}
Also used : Geometry(com.jme3.scene.Geometry) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f)

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