Package com.jme3.bounding

Examples of com.jme3.bounding.BoundingBox


     *            bounding box)
     * @return UV coordinates for the given mesh
     */
    public static List<Vector3f> generateUVCoordinatesFor3DTexture(Mesh mesh, UVCoordinatesType texco, int[] coordinatesSwappingIndexes, List<Geometry> geometries) {
        List<Vector3f> result = new ArrayList<Vector3f>();
        BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometries);
        float[] inputData = null;// positions, normals, reflection vectors, etc.

        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);
            float[] uvCoordsResults = new float[4];// used for coordinates swapping
            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;
                }
            }
View Full Code Here


     * @param geometries
     *            the list of geometries
     * @return bounding box of the given geometries
     */
    public static BoundingBox getBoundingBox(List<Geometry> geometries) {
        BoundingBox result = null;
        for (Geometry geometry : geometries) {
            BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometry.getMesh());
            if (result == null) {
                result = bb;
            } else {
                result.merge(bb);
            }
View Full Code Here

        if (bv instanceof BoundingBox) {
            return (BoundingBox) bv;
        } else if (bv instanceof BoundingSphere) {
            BoundingSphere bs = (BoundingSphere) bv;
            float r = bs.getRadius();
            return new BoundingBox(bs.getCenter(), r, r, r);
        } else {
            throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName());
        }
    }
View Full Code Here

     */
    /* package */static BoundingSphere getBoundingSphere(Mesh mesh) {
        mesh.updateBound();
        BoundingVolume bv = mesh.getBound();
        if (bv instanceof BoundingBox) {
            BoundingBox bb = (BoundingBox) bv;
            float r = Math.max(bb.getXExtent(), bb.getYExtent());
            r = Math.max(r, bb.getZExtent());
            return new BoundingSphere(r, bb.getCenter());
        } else if (bv instanceof BoundingSphere) {
            return (BoundingSphere) bv;
        } else {
            throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName());
        }
View Full Code Here

    private int collideWithBoundingVolume(BoundingVolume boundingVolume, CollisionResults results) {
        if (boundingVolume instanceof BoundingBox)
            return collideWithBoundingBox((BoundingBox)boundingVolume, results);
        else if(boundingVolume instanceof BoundingSphere) {
            BoundingSphere sphere = (BoundingSphere) boundingVolume;
            BoundingBox bbox = new BoundingBox(boundingVolume.getCenter().clone(), sphere.getRadius(),
                                                           sphere.getRadius(),
                                                           sphere.getRadius());
            return collideWithBoundingBox(bbox, results);
        }
        return 0;
View Full Code Here

*/
public class EntropyComputeUtil {

    public static float computeLodEntropy(Mesh terrainBlock, Buffer lodIndices){
        // Bounding box for the terrain block
        BoundingBox bbox = (BoundingBox) terrainBlock.getBound();

        // Vertex positions for the block
        FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);

        // Prepare to cast rays
        Vector3f pos = new Vector3f();
        Vector3f dir = new Vector3f(0, -1, 0);
        Ray ray = new Ray(pos, dir);

        // Prepare collision results
        CollisionResults results = new CollisionResults();

        // Set the LOD indices on the block
        VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);

        terrainBlock.clearBuffer(Type.Index);
        if (lodIndices instanceof IntBuffer)
            terrainBlock.setBuffer(Type.Index, 3, (IntBuffer)lodIndices);
        else if (lodIndices instanceof ShortBuffer) {
            terrainBlock.setBuffer(Type.Index, 3, (ShortBuffer) lodIndices);
        }

        // Recalculate collision mesh
        terrainBlock.createCollisionData();

        float entropy = 0;
        for (int i = 0; i < positions.limit() / 3; i++){
            BufferUtils.populateFromBuffer(pos, positions, i);

            float realHeight = pos.y;

            pos.addLocal(0, bbox.getYExtent(), 0);
            ray.setOrigin(pos);

            results.clear();
            terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);

View Full Code Here

    bv.getCenter(center);
    switch (bv.getType())
      {
      case OBB:
      case AABB:
        BoundingBox aabb = (BoundingBox)bv;
        aabb.getExtent(extend);
        break;
      case Sphere:
        BoundingSphere bs = (BoundingSphere)bv;
        float f = bs.getRadius();
        extend.set(f, f, f);
View Full Code Here

   * @return
   */
  public static BoundingBox getAABoundingBox(Geometry g)
    {
    VertexBuffer posBuffer = g.getMesh().getBuffer(Type.Position);
    BoundingBox bb = new BoundingBox();
    bb.computeFromPoints((FloatBuffer)posBuffer.getData());

    return bb;
    }
View Full Code Here

    public static Geometry buildBound(Geometry refGeom) {
        BoundingVolume boundVolume = refGeom.getModelBound();
        Geometry g;
        switch (boundVolume.getType()) {
            case AABB:
                BoundingBox bBox = (BoundingBox) boundVolume;
                g = Util.createBox(bBox.getMax(null).subtract(bBox.getMin(null)));
                g.setLocalTranslation(bBox.getMin(null));
                g.setName("Bound");
                g.setMaterial(DebugMaterials.boundMat);
                g.getMesh().setLineWidth(2f);
                return g;
            case Sphere:
View Full Code Here

        // CollisionResults results = new CollisionResults();
        // CollisionResult result;
        // Vector3f dir = new Vector3f();
        // Vector3f cp = new Vector3f();

        BoundingBox bm = (BoundingBox) refGeom.getWorldBound();
        bm.getMin(min);
        bm.getMax(max);

        // min.subtractLocal(1, 1, 1);
        // max.addLocal(1, 1, 1);

        min.x = (float) Math.floor(min.x);
View Full Code Here

TOP

Related Classes of com.jme3.bounding.BoundingBox

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.