Search in sources :

Example 1 with SkeletonDebugger

use of com.jme3.scene.debug.SkeletonDebugger in project jmonkeyengine by jMonkeyEngine.

the class TestOgreComplexAnim method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
    Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    control = model.getControl(AnimControl.class);
    AnimChannel feet = control.createChannel();
    AnimChannel leftHand = control.createChannel();
    AnimChannel rightHand = control.createChannel();
    // feet will dodge
    feet.addFromRootBone("hip.right");
    feet.addFromRootBone("hip.left");
    feet.setAnim("Dodge");
    feet.setSpeed(2);
    feet.setLoopMode(LoopMode.Cycle);
    // will blend over 15 seconds to stand
    feet.setAnim("Walk", 15);
    feet.setSpeed(0.25f);
    feet.setLoopMode(LoopMode.Cycle);
    // left hand will pull
    leftHand.addFromRootBone("uparm.right");
    leftHand.setAnim("pull");
    leftHand.setSpeed(.5f);
    // will blend over 15 seconds to stand
    leftHand.setAnim("stand", 15);
    // right hand will push
    rightHand.addBone("spinehigh");
    rightHand.addFromRootBone("uparm.left");
    rightHand.setAnim("push");
    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat.getAdditionalRenderState().setDepthTest(false);
    skeletonDebug.setMaterial(mat);
    model.attachChild(skeletonDebug);
    rootNode.attachChild(model);
}
Also used : SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) AnimChannel(com.jme3.animation.AnimChannel) Material(com.jme3.material.Material) AnimControl(com.jme3.animation.AnimControl)

Example 2 with SkeletonDebugger

use of com.jme3.scene.debug.SkeletonDebugger in project jmonkeyengine by jMonkeyEngine.

the class TestAnimBlendBug method simpleInitApp.

@Override
public void simpleInitApp() {
    inputManager.addMapping("One", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addListener(this, "One");
    flyCam.setMoveSpeed(100f);
    cam.setLocation(new Vector3f(0f, 150f, -325f));
    cam.lookAt(new Vector3f(0f, 100f, 0f), Vector3f.UNIT_Y);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
    Node model1 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    Node model2 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    //        Node model2 = model1.clone();
    model1.setLocalTranslation(-60, 0, 0);
    model2.setLocalTranslation(60, 0, 0);
    AnimControl control1 = model1.getControl(AnimControl.class);
    animNames = control1.getAnimationNames().toArray(new String[0]);
    channel1 = control1.createChannel();
    AnimControl control2 = model2.getControl(AnimControl.class);
    channel2 = control2.createChannel();
    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton1", control1.getSkeleton());
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat.getAdditionalRenderState().setDepthTest(false);
    skeletonDebug.setMaterial(mat);
    model1.attachChild(skeletonDebug);
    skeletonDebug = new SkeletonDebugger("skeleton2", control2.getSkeleton());
    skeletonDebug.setMaterial(mat);
    model2.attachChild(skeletonDebug);
    rootNode.attachChild(model1);
    rootNode.attachChild(model2);
}
Also used : SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) ColorRGBA(com.jme3.math.ColorRGBA) KeyTrigger(com.jme3.input.controls.KeyTrigger) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) AnimControl(com.jme3.animation.AnimControl)

Example 3 with SkeletonDebugger

use of com.jme3.scene.debug.SkeletonDebugger in project jmonkeyengine by jMonkeyEngine.

the class TestBoneRagdoll method simpleInitApp.

public void simpleInitApp() {
    initCrossHairs();
    initMaterial();
    cam.setLocation(new Vector3f(0.26924422f, 6.646658f, 22.265987f));
    cam.setRotation(new Quaternion(-2.302544E-4f, 0.99302495f, -0.117888905f, -0.0019395084f));
    bulletAppState = new BulletAppState();
    bulletAppState.setEnabled(true);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 1.0f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(1.0f);
    //        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    setupLight();
    model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    //  model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
    //debug view
    AnimControl control = model.getControl(AnimControl.class);
    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
    Material mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Green);
    mat2.getAdditionalRenderState().setDepthTest(false);
    skeletonDebug.setMaterial(mat2);
    skeletonDebug.setLocalTranslation(model.getLocalTranslation());
    //Note: PhysicsRagdollControl is still TODO, constructor will change
    ragdoll = new KinematicRagdollControl(0.5f);
    setupSinbad(ragdoll);
    ragdoll.addCollisionListener(this);
    model.addControl(ragdoll);
    float eighth_pi = FastMath.PI * 0.125f;
    ragdoll.setJointLimit("Waist", eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi);
    ragdoll.setJointLimit("Chest", eighth_pi, eighth_pi, 0, 0, eighth_pi, eighth_pi);
    //Oto's head is almost rigid
    //    ragdoll.setJointLimit("head", 0, 0, eighth_pi, -eighth_pi, 0, 0);
    getPhysicsSpace().add(ragdoll);
    speed = 1.3f;
    rootNode.attachChild(model);
    // rootNode.attachChild(skeletonDebug);
    flyCam.setMoveSpeed(50);
    animChannel = control.createChannel();
    animChannel.setAnim("Dance");
    control.addListener(this);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggle") && isPressed) {
                Vector3f v = new Vector3f();
                v.set(model.getLocalTranslation());
                v.y = 0;
                model.setLocalTranslation(v);
                Quaternion q = new Quaternion();
                float[] angles = new float[3];
                model.getLocalRotation().toAngles(angles);
                q.fromAngleAxis(angles[1], Vector3f.UNIT_Y);
                model.setLocalRotation(q);
                if (angles[0] < 0) {
                    animChannel.setAnim("StandUpBack");
                    ragdoll.blendToKinematicMode(0.5f);
                } else {
                    animChannel.setAnim("StandUpFront");
                    ragdoll.blendToKinematicMode(0.5f);
                }
            }
            if (name.equals("bullet+") && isPressed) {
                bulletSize += 0.1f;
            }
            if (name.equals("bullet-") && isPressed) {
                bulletSize -= 0.1f;
            }
            if (name.equals("stop") && isPressed) {
                ragdoll.setEnabled(!ragdoll.isEnabled());
                ragdoll.setRagdollMode();
            }
            if (name.equals("shoot") && !isPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(matBullet);
                bulletg.setLocalTranslation(cam.getLocation());
                bulletg.setLocalScale(bulletSize);
                bulletCollisionShape = new SphereCollisionShape(bulletSize);
                RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, bulletSize * 10);
                bulletNode.setCcdMotionThreshold(0.001f);
                bulletNode.setLinearVelocity(cam.getDirection().mult(80));
                bulletg.addControl(bulletNode);
                rootNode.attachChild(bulletg);
                getPhysicsSpace().add(bulletNode);
            }
            if (name.equals("boom") && !isPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(matBullet);
                bulletg.setLocalTranslation(cam.getLocation());
                bulletg.setLocalScale(bulletSize);
                bulletCollisionShape = new SphereCollisionShape(bulletSize);
                BombControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
                bulletNode.setForceFactor(8);
                bulletNode.setExplosionRadius(20);
                bulletNode.setCcdMotionThreshold(0.001f);
                bulletNode.setLinearVelocity(cam.getDirection().mult(180));
                bulletg.addControl(bulletNode);
                rootNode.attachChild(bulletg);
                getPhysicsSpace().add(bulletNode);
            }
        }
    }, "toggle", "shoot", "stop", "bullet+", "bullet-", "boom");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("boom", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("bullet-", new KeyTrigger(KeyInput.KEY_COMMA));
    inputManager.addMapping("bullet+", new KeyTrigger(KeyInput.KEY_PERIOD));
}
Also used : SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) KinematicRagdollControl(com.jme3.bullet.control.KinematicRagdollControl) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) ActionListener(com.jme3.input.controls.ActionListener) Vector3f(com.jme3.math.Vector3f) BulletAppState(com.jme3.bullet.BulletAppState) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 4 with SkeletonDebugger

use of com.jme3.scene.debug.SkeletonDebugger in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method createScene.

public static Spatial createScene(FbxNode fbxNode) {
    Spatial jmeSpatial = fbxNode.getJmeObject();
    if (jmeSpatial instanceof Node) {
        // Attach children to Node
        Node jmeNode = (Node) jmeSpatial;
        for (FbxNode fbxChild : fbxNode.children) {
            if (!(fbxChild instanceof FbxLimbNode)) {
                createScene(fbxChild);
                FbxNode preferredParent = fbxChild.getPreferredParent();
                Spatial jmeChild = fbxChild.getJmeObject();
                if (preferredParent != null) {
                    System.out.println("Preferred parent for " + fbxChild + " is " + preferredParent);
                    Node jmePreferredParent = (Node) preferredParent.getJmeObject();
                    relocateSpatial(jmeChild, fbxChild.jmeWorldNodeTransform, preferredParent.jmeWorldNodeTransform);
                    jmePreferredParent.attachChild(jmeChild);
                } else {
                    jmeNode.attachChild(jmeChild);
                }
            }
        }
    }
    if (fbxNode.skeleton != null) {
        jmeSpatial.addControl(new AnimControl(fbxNode.skeleton));
        jmeSpatial.addControl(new SkeletonControl(fbxNode.skeleton));
        SkeletonDebugger sd = new SkeletonDebugger("debug", fbxNode.skeleton);
        Material mat = new Material(fbxNode.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.getAdditionalRenderState().setWireframe(true);
        mat.getAdditionalRenderState().setDepthTest(false);
        mat.setColor("Color", ColorRGBA.Green);
        sd.setMaterial(mat);
        ((Node) jmeSpatial).attachChild(sd);
    }
    return jmeSpatial;
}
Also used : SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) Spatial(com.jme3.scene.Spatial) FbxLimbNode(com.jme3.scene.plugins.fbx.anim.FbxLimbNode) Node(com.jme3.scene.Node) FbxAnimCurveNode(com.jme3.scene.plugins.fbx.anim.FbxAnimCurveNode) SkeletonControl(com.jme3.animation.SkeletonControl) Material(com.jme3.material.Material) FbxMaterial(com.jme3.scene.plugins.fbx.material.FbxMaterial) FbxLimbNode(com.jme3.scene.plugins.fbx.anim.FbxLimbNode) AnimControl(com.jme3.animation.AnimControl)

Aggregations

Material (com.jme3.material.Material)4 SkeletonDebugger (com.jme3.scene.debug.SkeletonDebugger)4 AnimControl (com.jme3.animation.AnimControl)3 Vector3f (com.jme3.math.Vector3f)3 Node (com.jme3.scene.Node)3 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 DirectionalLight (com.jme3.light.DirectionalLight)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Quaternion (com.jme3.math.Quaternion)2 AnimChannel (com.jme3.animation.AnimChannel)1 SkeletonControl (com.jme3.animation.SkeletonControl)1 BulletAppState (com.jme3.bullet.BulletAppState)1 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)1 KinematicRagdollControl (com.jme3.bullet.control.KinematicRagdollControl)1 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)1 ActionListener (com.jme3.input.controls.ActionListener)1 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)1 Geometry (com.jme3.scene.Geometry)1 Spatial (com.jme3.scene.Spatial)1 FbxAnimCurveNode (com.jme3.scene.plugins.fbx.anim.FbxAnimCurveNode)1