Search in sources :

Example 86 with Spatial

use of com.jme3.scene.Spatial 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 87 with Spatial

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

the class AbstractPhysicsDebugControl method applyPhysicsTransform.

protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) {
    if (spatial != null) {
        Vector3f localLocation = spatial.getLocalTranslation();
        Quaternion localRotationQuat = spatial.getLocalRotation();
        if (spatial.getParent() != null) {
            localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
            localLocation.divideLocal(spatial.getParent().getWorldScale());
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
            localRotationQuat.set(worldRotation);
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
            spatial.setLocalTranslation(localLocation);
            spatial.setLocalRotation(localRotationQuat);
        } else {
            spatial.setLocalTranslation(worldLocation);
            spatial.setLocalRotation(worldRotation);
        }
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 88 with Spatial

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

the class BulletCharacterDebugControl method setSpatial.

@Override
public void setSpatial(Spatial spatial) {
    if (spatial != null && spatial instanceof Node) {
        Node node = (Node) spatial;
        node.attachChild(geom);
    } else if (spatial == null && this.spatial != null) {
        Node node = (Node) this.spatial;
        node.detachChild(geom);
    }
    super.setSpatial(spatial);
}
Also used : Node(com.jme3.scene.Node)

Example 89 with Spatial

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

the class BulletDebugAppState method updateCharacters.

private void updateCharacters() {
    HashMap<PhysicsCharacter, Spatial> oldObjects = characters;
    characters = new HashMap<PhysicsCharacter, Spatial>();
    Collection<PhysicsCharacter> current = space.getCharacterList();
    //create new map
    for (Iterator<PhysicsCharacter> it = current.iterator(); it.hasNext(); ) {
        PhysicsCharacter physicsObject = it.next();
        //copy existing spatials
        if (oldObjects.containsKey(physicsObject)) {
            Spatial spat = oldObjects.get(physicsObject);
            characters.put(physicsObject, spat);
            oldObjects.remove(physicsObject);
        } else {
            if (filter == null || filter.displayObject(physicsObject)) {
                logger.log(Level.FINE, "Create new debug Character");
                //create new spatial
                Node node = new Node(physicsObject.toString());
                node.addControl(new BulletCharacterDebugControl(this, physicsObject));
                characters.put(physicsObject, node);
                physicsDebugRootNode.attachChild(node);
            }
        }
    }
    //remove leftover spatials
    for (Map.Entry<PhysicsCharacter, Spatial> entry : oldObjects.entrySet()) {
        PhysicsCharacter object = entry.getKey();
        Spatial spatial = entry.getValue();
        spatial.removeFromParent();
    }
}
Also used : PhysicsCharacter(com.jme3.bullet.objects.PhysicsCharacter) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) HashMap(java.util.HashMap) Map(java.util.Map)

Example 90 with Spatial

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

the class BulletGhostObjectDebugControl method setSpatial.

@Override
public void setSpatial(Spatial spatial) {
    if (spatial != null && spatial instanceof Node) {
        Node node = (Node) spatial;
        node.attachChild(geom);
    } else if (spatial == null && this.spatial != null) {
        Node node = (Node) this.spatial;
        node.detachChild(geom);
    }
    super.setSpatial(spatial);
}
Also used : Node(com.jme3.scene.Node)

Aggregations

Spatial (com.jme3.scene.Spatial)123 Vector3f (com.jme3.math.Vector3f)74 Node (com.jme3.scene.Node)56 Geometry (com.jme3.scene.Geometry)50 DirectionalLight (com.jme3.light.DirectionalLight)46 Material (com.jme3.material.Material)39 Quaternion (com.jme3.math.Quaternion)34 FilterPostProcessor (com.jme3.post.FilterPostProcessor)17 Box (com.jme3.scene.shape.Box)17 KeyTrigger (com.jme3.input.controls.KeyTrigger)15 AmbientLight (com.jme3.light.AmbientLight)14 ColorRGBA (com.jme3.math.ColorRGBA)14 Camera (com.jme3.renderer.Camera)13 Sphere (com.jme3.scene.shape.Sphere)13 Texture (com.jme3.texture.Texture)12 TempVars (com.jme3.util.TempVars)12 InputCapsule (com.jme3.export.InputCapsule)11 ActionListener (com.jme3.input.controls.ActionListener)11 AnimControl (com.jme3.animation.AnimControl)10 OutputCapsule (com.jme3.export.OutputCapsule)9