Search in sources :

Example 1 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class RigidBodyControl method createCollisionShape.

protected void createCollisionShape() {
    if (spatial == null) {
        return;
    }
    if (spatial instanceof Geometry) {
        Geometry geom = (Geometry) spatial;
        Mesh mesh = geom.getMesh();
        if (mesh instanceof Sphere) {
            collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
            return;
        } else if (mesh instanceof Box) {
            collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
            return;
        }
    }
    if (mass > 0) {
        collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
    } else {
        collisionShape = CollisionShapeFactory.createMeshShape(spatial);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 2 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class RagdollUtils method buildPointMap.

public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
    Map<Integer, List<Float>> map = new HashMap<Integer, List<Float>>();
    if (model instanceof Geometry) {
        Geometry g = (Geometry) model;
        buildPointMapForMesh(g.getMesh(), map);
    } else if (model instanceof Node) {
        Node node = (Node) model;
        for (Spatial s : node.getChildren()) {
            if (s instanceof Geometry) {
                Geometry g = (Geometry) s;
                buildPointMapForMesh(g.getMesh(), map);
            }
        }
    }
    return map;
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 3 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class BulletVehicleDebugControl method createVehicle.

private void createVehicle() {
    suspensionNode.detachAllChildren();
    for (int i = 0; i < body.getNumWheels(); i++) {
        VehicleWheel physicsVehicleWheel = body.getWheel(i);
        Vector3f location = physicsVehicleWheel.getLocation().clone();
        Vector3f direction = physicsVehicleWheel.getDirection().clone();
        Vector3f axle = physicsVehicleWheel.getAxle().clone();
        float restLength = physicsVehicleWheel.getRestLength();
        float radius = physicsVehicleWheel.getRadius();
        Arrow locArrow = new Arrow(location);
        Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f));
        Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius));
        Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength));
        Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow);
        Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow);
        Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow);
        Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow);
        dirGeom.setLocalTranslation(location);
        axleGeom.setLocalTranslation(location.add(direction));
        wheelGeom.setLocalTranslation(location.add(direction));
        locGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        suspensionNode.attachChild(locGeom);
        suspensionNode.attachChild(dirGeom);
        suspensionNode.attachChild(axleGeom);
        suspensionNode.attachChild(wheelGeom);
    }
}
Also used : Arrow(com.jme3.scene.debug.Arrow) Geometry(com.jme3.scene.Geometry) VehicleWheel(com.jme3.bullet.objects.VehicleWheel) Vector3f(com.jme3.math.Vector3f)

Example 4 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class CollisionShapeFactory method createSingleMeshShape.

/**
     * This type of collision shape is mesh-accurate and meant for immovable "world objects".
     * Examples include terrain, houses or whole shooter levels.<br>
     * Objects with "mesh" type collision shape will not collide with each other.
     */
private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) {
    Mesh mesh = geom.getMesh();
    Transform trans = getTransform(geom, parent);
    if (mesh != null && mesh.getMode() == Mesh.Mode.Triangles) {
        MeshCollisionShape mColl = new MeshCollisionShape(mesh);
        mColl.setScale(trans.getScale());
        return mColl;
    } else {
        return null;
    }
}
Also used : Transform(com.jme3.math.Transform)

Example 5 with Geometry

use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.

the class CollisionShapeFactory method createSingleDynamicMeshShape.

/**
     * This method creates a hull collision shape for the given mesh.<br>
     */
private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) {
    Mesh mesh = geom.getMesh();
    Transform trans = getTransform(geom, parent);
    if (mesh != null) {
        HullCollisionShape dynamicShape = new HullCollisionShape(mesh);
        dynamicShape.setScale(trans.getScale());
        return dynamicShape;
    } else {
        return null;
    }
}
Also used : Transform(com.jme3.math.Transform)

Aggregations

Geometry (com.jme3.scene.Geometry)283 Material (com.jme3.material.Material)197 Vector3f (com.jme3.math.Vector3f)135 Box (com.jme3.scene.shape.Box)94 Node (com.jme3.scene.Node)67 Spatial (com.jme3.scene.Spatial)64 DirectionalLight (com.jme3.light.DirectionalLight)57 Sphere (com.jme3.scene.shape.Sphere)50 Quaternion (com.jme3.math.Quaternion)41 Quad (com.jme3.scene.shape.Quad)34 Mesh (com.jme3.scene.Mesh)33 ColorRGBA (com.jme3.math.ColorRGBA)32 Texture (com.jme3.texture.Texture)31 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 KeyTrigger (com.jme3.input.controls.KeyTrigger)24 AmbientLight (com.jme3.light.AmbientLight)24 FilterPostProcessor (com.jme3.post.FilterPostProcessor)22 PointLight (com.jme3.light.PointLight)20 ArrayList (java.util.ArrayList)20 Vector2f (com.jme3.math.Vector2f)19