Java Code Examples for com.jme3.scene.Spatial#center()

The following examples show how to use com.jme3.scene.Spatial#center() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBlenderObjectAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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);

    BlenderKey blenderKey = new BlenderKey("Blender/2.4x/animtest.blend");
    
    Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
    rootNode.attachChild(scene);
    
    Spatial model = this.findNode(rootNode, "TestAnim");
    model.center();
    
    control = model.getControl(AnimControl.class);
    channel = control.createChannel();

    channel.setAnim("TestAnim");
}
 
Example 2
Source File: TestBlenderAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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);

    BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
    
    Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
    rootNode.attachChild(scene);
    
    Spatial model = this.findNode(rootNode, "BaseMesh_01");
    model.center();
    
    control = model.getControl(AnimControl.class);
    channel = control.createChannel();

    channel.setAnim("run_01");
}
 
Example 3
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void doCenterSelected(final Spatial selected) {
    final Vector3f location = new Vector3f(selected.getLocalTranslation());
    selected.center();
    Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, new AbstractUndoableSceneEdit() {

        @Override
        public void sceneUndo() {
            //undo stuff here
            selected.setLocalTranslation(location);
        }

        @Override
        public void sceneRedo() {
            //redo stuff here
            selected.center();
        }

        @Override
        public void awtRedo() {
        }

        @Override
        public void awtUndo() {
        }
    });
}
 
Example 4
Source File: TestAttachmentsNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4f, 7.5f, 12.8f));
    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(ColorRGBA.White);
    rootNode.addLight(dl);

    Spatial model = assetManager.loadModel("Models/Jaime/Jaime.j3o");
    control = model.getControl(AnimControl.class);
    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    model.center();
    model.setLocalScale(5f);

    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim("Idle");

    Box box = new Box(0.3f, 0.02f, 0.02f);
    Geometry saber = new Geometry("saber", box);
    saber.move(0.4f, 0.05f, 0.01f);
    Material red = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    saber.setMaterial(red);
    Node n = skeletonControl.getAttachmentsNode("hand.R");
    n.attachChild(saber);
    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example 5
Source File: TestOgreAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);

    Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();

    animComposer = model.getControl(AnimComposer.class);
    animComposer.actionBlended("Attack", new LinearBlendSpace(0f, 0.5f), "Dodge");
    for (AnimClip animClip : animComposer.getAnimClips()) {
        Action action = animComposer.action(animClip.getName());
        if(!"stand".equals(animClip.getName())) {
            action = new BaseAction(Tweens.sequence(action, Tweens.callMethod(this, "backToStand", animComposer)));
        }
        animComposer.addAction(animClip.getName(), action);
    }
    currentAction = animComposer.setCurrentAction("stand"); // Walk, pull, Dodge, stand, push

    SkinningControl skinningControl = model.getControl(SkinningControl.class);
    skinningControl.setHardwareSkinningPreferred(false);

    Box b = new Box(.25f, 3f, .25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skinningControl.getAttachmentsNode("hand.right");
    n.attachChild(item);

    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example 6
Source File: TestOgreAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);

    Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();

    control = model.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();

    for (String anim : control.getAnimationNames())
        System.out.println(anim);

    channel.setAnim("stand");

    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    Box b = new Box(.25f,3f,.25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skeletonControl.getAttachmentsNode("hand.right");
    n.attachChild(item);

    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example 7
Source File: TestCinematic.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createScene() {

        model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
        model.center();
        model.setShadowMode(ShadowMode.CastAndReceive);
        rootNode.attachChild(model);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Cyan);

        teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
        teapot.setLocalTranslation(10, 0, 10);
        teapot.setMaterial(mat);
        teapot.setShadowMode(ShadowMode.CastAndReceive);
        rootNode.attachChild(teapot);

        Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        matSoil.setBoolean("UseMaterialColors", true);
        matSoil.setColor("Ambient", ColorRGBA.Gray);
        matSoil.setColor("Diffuse", ColorRGBA.Green);
        matSoil.setColor("Specular", ColorRGBA.Black);

        Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -6.0f, 0), 50, 1, 50));
        soil.setMaterial(matSoil);
        soil.setShadowMode(ShadowMode.Receive);
        rootNode.attachChild(soil);
        DirectionalLight light = new DirectionalLight();
        light.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
        light.setColor(ColorRGBA.White.mult(1.5f));
        rootNode.addLight(light);

        fpp = new FilterPostProcessor(assetManager);
        fade = new FadeFilter();
        fpp.addFilter(fade);
        
        if (renderer.getCaps().contains(Caps.GLSL100)){
            PssmShadowRenderer pssm = new PssmShadowRenderer(assetManager, 512, 1);
            pssm.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
            pssm.setShadowIntensity(0.4f);
            viewPort.addProcessor(pssm);
            viewPort.addProcessor(fpp);
        }
    }