Java Code Examples for com.jme3.scene.Geometry#move()

The following examples show how to use com.jme3.scene.Geometry#move() . 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: TestTriangleCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    // Create two boxes
    Mesh mesh1 = new Box(0.5f, 0.5f, 0.5f);
    geom1 = new Geometry("Box", mesh1);
    geom1.move(2, 2, -.5f);
    Material m1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m1.setColor("Color", ColorRGBA.Blue);
    geom1.setMaterial(m1);
    rootNode.attachChild(geom1);

    // load a character from jme3test-test-data
    golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    rootNode.attachChild(golem);

    // Create input
    inputManager.addMapping("MoveRight", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("MoveLeft", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("MoveUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("MoveDown", new KeyTrigger(KeyInput.KEY_K));

    inputManager.addListener(analogListener, new String[]{
                "MoveRight", "MoveLeft", "MoveUp", "MoveDown"
            });
}
 
Example 2
Source File: TestShaderNodesStress.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {

    Quad q = new Quad(1, 1);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(-500, -500, 0);
    g.setLocalScale(1000);

    rootNode.attachChild(g);
    cam.setLocation(new Vector3f(0.0f, 0.0f, 0.40647888f));
    cam.setRotation(new Quaternion(0.0f, 1.0f, 0.0f, 0.0f));

    Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
  //Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setColor("Color", ColorRGBA.Yellow);
    mat.setTexture("ColorMap", tex);
    g.setMaterial(mat);
    //place the geoms in the transparent bucket so that they are rendered back to front for maximum overdraw
    g.setQueueBucket(RenderQueue.Bucket.Transparent);

    for (int i = 0; i < 1000; i++) {
        Geometry cl = g.clone(false);
        cl.move(0, 0, -(i + 1));
        rootNode.attachChild(cl);
    }

    flyCam.setMoveSpeed(20);
    Logger.getLogger("com.jme3").setLevel(Level.WARNING);

    this.setAppProfiler(new Profiler());

}
 
Example 3
Source File: TestSkeletonControlRefresh.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupFloor() {
    Quad q = new Quad(20, 20);
   q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(10));
   Geometry geom = new Geometry("floor", q);
   Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat.setColor("Color", ColorRGBA.White);       
   geom.setMaterial(mat);

   geom.rotate(-FastMath.HALF_PI, 0, 0);
   geom.center();
   geom.move(0, -0.3f, 0);
   geom.setShadowMode(RenderQueue.ShadowMode.Receive);
   rootNode.attachChild(geom);
}
 
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: TestMatParamOverride.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createBox(float location, ColorRGBA color) {
    Geometry geom = new Geometry("Box", box);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", color);
    geom.setMaterial(mat);
    geom.move(location, 0, 0);
    rootNode.attachChild(geom);
}
 
Example 7
Source File: TestTriangleCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    // Create two boxes
    Mesh mesh1 = new Box(0.5f, 0.5f, 0.5f);
    geom1 = new Geometry("Box", mesh1);
    geom1.move(2, 2, -.5f);
    Material m1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m1.setColor("Color", ColorRGBA.Blue);
    geom1.setMaterial(m1);
    rootNode.attachChild(geom1);

    // load a character from jme3test-test-data
    golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    rootNode.attachChild(golem);

    // Create input
    inputManager.addMapping("MoveRight", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("MoveLeft", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("MoveUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("MoveDown", new KeyTrigger(KeyInput.KEY_K));

    inputManager.addListener(analogListener, new String[]{
                "MoveRight", "MoveLeft", "MoveUp", "MoveDown"
            });
}
 
Example 8
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 9
Source File: TestDepthFuncChange.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setMoveSpeed(20);
    
   
    //top of the screen
    //default depth func (less or equal) rendering.
    //2 cubes, a blue and a red. the red cube is offset by 0.2 WU to the right   
    //the red cube is put in the transparent bucket to be sure it's rendered after the blue one (but there is no transparency involved).
    //You should see a small part of the blue cube on the left and the whole red cube
    Box boxshape1 = new Box(1f, 1f, 1f);
    Geometry cube1 = new Geometry("box", boxshape1);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    
    cube1.setMaterial(mat);
    rootNode.attachChild(cube1);
    cube1.move(0, 1.5f, 0);      
    
    Geometry cube2 = cube1.clone(true);
    cube2.move(0.2f, 0 , 0);    
    cube2.setQueueBucket(RenderQueue.Bucket.Transparent);
    cube2.getMaterial().setColor("Color",  ColorRGBA.Red);
    rootNode.attachChild(cube2);
    
    //Bottom of the screen
    //here the 2 cubes are clonned and the depthFunc for the red cube's material is set to Less
    //You should see the whole bleu cube and a small part of the red cube on the right
    Geometry cube3 = cube1.clone();
    Geometry cube4 = cube2.clone(true);
    cube4.getMaterial().getAdditionalRenderState().setDepthFunc(RenderState.TestFunction.Less);       
    cube3.move(0,-3,0);
    cube4.move(0,-3,0);
    rootNode.attachChild(cube3);
    rootNode.attachChild(cube4);
    
    //Note that if you move the camera z fighting will occur but that's expected.
            
    
}
 
Example 10
Source File: TestTangentSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    renderManager.setSinglePassLightBatchSize(2);
    renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
    initView();
    
    Spatial s = assetManager.loadModel("Models/Test/BasicCubeLow.obj");
    rootNode.attachChild(s);

    Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    m.setTexture("NormalMap", assetManager.loadTexture("Models/Test/Normal_pixel.png"));

    Geometry g = (Geometry)s;
    Geometry g2 = (Geometry) g.deepClone();
    g2.move(5, 0, 0);
    g.getParent().attachChild(g2);

    g.setMaterial(m);
    g2.setMaterial(m);

    //Regular tangent generation (left geom)
    TangentBinormalGenerator.generate(g2.getMesh(), true);

    //MikkTSPace Tangent generation (right geom)        

    MikktspaceTangentGenerator.generate(g);
    
    createDebugTangents(g2);
    createDebugTangents(g);
    
    inputManager.addListener(new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggleDebug") && isPressed) {
                if (debugNode.getParent() == null) {
                    rootNode.attachChild(debugNode);
                } else {
                    debugNode.removeFromParent();
                }
            }
        }
    }, "toggleDebug");

    inputManager.addMapping("toggleDebug", new KeyTrigger(KeyInput.KEY_SPACE));
    
    
    DirectionalLight dl = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
}
 
Example 11
Source File: TestTwoSideLighting.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // Two-sided lighting requires single pass.
    renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
    renderManager.setSinglePassLightBatchSize(4);
    
    cam.setLocation(new Vector3f(5.936224f, 3.3759952f, -3.3202777f));
    cam.setRotation(new Quaternion(0.16265652f, -0.4811838f, 0.09137692f, 0.8565368f));
    
    Geometry quadGeom = new Geometry("quad", new Quad(1, 1));
    quadGeom.move(1, 0, 0);
    Material mat1 = assetManager.loadMaterial("Textures/BumpMapTest/SimpleBump.j3m");
    
    // Display both front and back faces.
    mat1.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
    
    quadGeom.setMaterial(mat1);
    // SimpleBump material requires tangents.
    TangentBinormalGenerator.generate(quadGeom);
    rootNode.attachChild(quadGeom);
    
    Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.move(-1, 0, 0);
    teapot.setLocalScale(2f);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat2.setFloat("Shininess", 25);
    mat2.setBoolean("UseMaterialColors", true);
    mat2.setColor("Ambient",  ColorRGBA.Black);
    mat2.setColor("Diffuse",  ColorRGBA.Gray);
    mat2.setColor("Specular", ColorRGBA.Gray);
    
    // Only display backfaces.
    mat2.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front);
    
    teapot.setMaterial(mat2);
    rootNode.attachChild(teapot);

    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);

    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    pl.setRadius(4f);
    rootNode.addLight(pl);
}
 
Example 12
Source File: TestColorApp.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        // Lights
        DirectionalLight sun = new DirectionalLight();
        Vector3f sunPosition = new Vector3f(1, -1, 1);
        sun.setDirection(sunPosition);
        sun.setColor(new ColorRGBA(1f,1f,1f,1f));
        rootNode.addLight(sun);
 
        //DirectionalLightShadowFilter sun_renderer = new DirectionalLightShadowFilter(assetManager, 2048, 4);
        DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1);
        sun_renderer.setLight(sun);
        viewPort.addProcessor(sun_renderer);
        
//        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
//        fpp.addFilter(sun_renderer);
//        viewPort.addProcessor(fpp);
        
        rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
 
        // Camera
        viewPort.setBackgroundColor(new ColorRGBA(.6f, .6f, .6f, 1f));
        ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
 
 
        // Objects
        // Ground Object
        final Geometry groundBoxWhite = new Geometry("Box", new Box(7.5f, 7.5f, .25f));
        float[] f = {-FastMath.PI / 2, 3 * FastMath.PI / 2, 0f};
        groundBoxWhite.setLocalRotation(new Quaternion(f));
        groundBoxWhite.move(7.5f, -.75f, 7.5f);
        final Material groundMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        groundMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f));
        groundBoxWhite.setMaterial(groundMaterial);
        groundBoxWhite.addControl(chaseCam);
        rootNode.attachChild(groundBoxWhite);
 
        // Planter
        Geometry planterBox = new Geometry("Box", new Box(.5f, .5f, .5f));
        final Material planterMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        planterMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
        planterBox.setMaterial(groundMaterial);
        planterBox.setLocalTranslation(10, 0, 9);
        rootNode.attachChild(planterBox);
 
        // Action!
        inputManager.addMapping("on", new KeyTrigger(KeyInput.KEY_Z));
        inputManager.addMapping("off", new KeyTrigger(KeyInput.KEY_X));
 
        inputManager.addListener(new AnalogListener() {
            @Override
            public void onAnalog(String s, float v, float v1) {
                if (s.equals("on")) {
                    groundBoxWhite.setMaterial(planterMaterial);
                }
                if (s.equals("off")) {
                    groundBoxWhite.setMaterial(groundMaterial);
                }
            }
        }, "on", "off");
 
        inputEnabled = true;
    }