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

The following examples show how to use com.jme3.scene.Geometry#clone() . 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: 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 2
Source File: TestBatchLod.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
//        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);

        // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        flyCam.setMoveSpeed(5);
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                Geometry clonePot = teapot.clone();

                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                clonePot.setMaterial(mat);
                rootNode.attachChild(clonePot);
            }
        }
        GeometryBatchFactory.optimize(rootNode, true);
        LodControl control = new LodControl();
        rootNode.getChild(0).addControl(control);
        cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
        cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));

    }
 
Example 3
Source File: TestLodStress.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);
        
//        Sphere sph = new Sphere(16, 16, 4);
//        Geometry teapot = new Geometry("teapot", sph);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);
        
       // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        for (int y = -10; y < 10; y++){
            for (int x = -10; x < 10; x++){
                Geometry clonePot = teapot.clone();
                
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                
                LodControl control = new LodControl();
                clonePot.addControl(control);
                rootNode.attachChild(clonePot);
            }
        }

        cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
        cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    }
 
Example 4
Source File: TestBatchLod.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
//        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);

        // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        flyCam.setMoveSpeed(5);
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                Geometry clonePot = teapot.clone();

                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                clonePot.setMaterial(mat);
                rootNode.attachChild(clonePot);
            }
        }
        GeometryBatchFactory.optimize(rootNode, true);
        LodControl control = new LodControl();
        rootNode.getChild(0).addControl(control);
        cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
        cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));

    }
 
Example 5
Source File: TestLodStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);
        
//        Sphere sph = new Sphere(16, 16, 4);
//        Geometry teapot = new Geometry("teapot", sph);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);
        
       // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        for (int y = -10; y < 10; y++){
            for (int x = -10; x < 10; x++){
                Geometry clonePot = teapot.clone();
                
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                
                LodControl control = new LodControl();
                clonePot.addControl(control);
                rootNode.attachChild(clonePot);
            }
        }

        cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
        cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    }
 
Example 6
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 7
Source File: TestBitmapFontAlignment.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    int width = getCamera().getWidth();
    int height = getCamera().getHeight();

    // VAlign.Top
    BitmapText labelAlignTop = guiFont.createLabel("This text has VAlign.Top.");
    Rectangle textboxAlignTop = new Rectangle(width * 0.2f, height * 0.7f, 120, 120);
    labelAlignTop.setBox(textboxAlignTop);
    labelAlignTop.setVerticalAlignment(BitmapFont.VAlign.Top);
    getGuiNode().attachChild(labelAlignTop);

    Geometry backgroundBoxAlignTop = new Geometry("", new Quad(textboxAlignTop.width, -textboxAlignTop.height));
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor("Color", ColorRGBA.Blue);
    backgroundBoxAlignTop.setMaterial(material);
    backgroundBoxAlignTop.setLocalTranslation(textboxAlignTop.x, textboxAlignTop.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignTop);

    // VAlign.Center
    BitmapText labelAlignCenter = guiFont.createLabel("This text has VAlign.Center");
    Rectangle textboxAlignCenter = new Rectangle(width * 0.4f, height * 0.7f, 120, 120);
    labelAlignCenter.setBox(textboxAlignCenter);
    labelAlignCenter.setVerticalAlignment(BitmapFont.VAlign.Center);
    getGuiNode().attachChild(labelAlignCenter);

    Geometry backgroundBoxAlignCenter = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignCenter.setLocalTranslation(textboxAlignCenter.x, textboxAlignCenter.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignCenter);

    // VAlign.Bottom
    BitmapText labelAlignBottom = guiFont.createLabel("This text has VAlign.Bottom");
    Rectangle textboxAlignBottom = new Rectangle(width * 0.6f, height * 0.7f, 120, 120);
    labelAlignBottom.setBox(textboxAlignBottom);
    labelAlignBottom.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    getGuiNode().attachChild(labelAlignBottom);

    Geometry backgroundBoxAlignBottom = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignBottom.setLocalTranslation(textboxAlignBottom.x, textboxAlignBottom.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignBottom);

    // VAlign.Top + Align.Right
    BitmapText labelAlignTopRight = guiFont.createLabel("This text has VAlign.Top and Align.Right");
    Rectangle textboxAlignTopRight = new Rectangle(width * 0.2f, height * 0.3f, 120, 120);
    labelAlignTopRight.setBox(textboxAlignTopRight);
    labelAlignTopRight.setVerticalAlignment(BitmapFont.VAlign.Top);
    labelAlignTopRight.setAlignment(BitmapFont.Align.Right);
    getGuiNode().attachChild(labelAlignTopRight);

    Geometry backgroundBoxAlignTopRight = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignTopRight.setLocalTranslation(textboxAlignTopRight.x, textboxAlignTopRight.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignTopRight);

    // VAlign.Center + Align.Center
    BitmapText labelAlignCenterCenter = guiFont.createLabel("This text has VAlign.Center and Align.Center");
    Rectangle textboxAlignCenterCenter = new Rectangle(width * 0.4f, height * 0.3f, 120, 120);
    labelAlignCenterCenter.setBox(textboxAlignCenterCenter);
    labelAlignCenterCenter.setVerticalAlignment(BitmapFont.VAlign.Center);
    labelAlignCenterCenter.setAlignment(BitmapFont.Align.Center);
    getGuiNode().attachChild(labelAlignCenterCenter);

    Geometry backgroundBoxAlignCenterCenter = backgroundBoxAlignCenter.clone(false);
    backgroundBoxAlignCenterCenter.setLocalTranslation(textboxAlignCenterCenter.x, textboxAlignCenterCenter.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignCenterCenter);

    // VAlign.Bottom + Align.Left
    BitmapText labelAlignBottomLeft = guiFont.createLabel("This text has VAlign.Bottom and Align.Left");
    Rectangle textboxAlignBottomLeft = new Rectangle(width * 0.6f, height * 0.3f, 120, 120);
    labelAlignBottomLeft.setBox(textboxAlignBottomLeft);
    labelAlignBottomLeft.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    labelAlignBottomLeft.setAlignment(BitmapFont.Align.Left);
    getGuiNode().attachChild(labelAlignBottomLeft);

    Geometry backgroundBoxAlignBottomLeft = backgroundBoxAlignBottom.clone(false);
    backgroundBoxAlignBottomLeft.setLocalTranslation(textboxAlignBottomLeft.x, textboxAlignBottomLeft.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignBottomLeft);

    // Large quad with VAlign.Center and Align.Center
    BitmapText label = guiFont.createLabel("This text is centered, both horizontally and vertically.");
    Rectangle box = new Rectangle(width * 0.05f, height * 0.95f, width * 0.9f, height * 0.1f);
    label.setBox(box);
    label.setAlignment(BitmapFont.Align.Center);
    label.setVerticalAlignment(BitmapFont.VAlign.Center);
    getGuiNode().attachChild(label);

    Geometry background = new Geometry("background", new Quad(box.width, -box.height));
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Green);
    background.setMaterial(mat);
    background.setLocalTranslation(box.x, box.y, -1);
    getGuiNode().attachChild(background);
}