com.jme3.scene.shape.Box Java Examples

The following examples show how to use com.jme3.scene.shape.Box. 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: TestSpotLight.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
   // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess",3);
  //  mat.setBoolean("VertexLighting", true);
    
    
    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example #2
Source File: TestCollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void attachRandomGeometry(Node node, Material mat) {
    Box box = new Box(0.25f, 0.25f, 0.25f);
    Torus torus = new Torus(16, 16, 0.2f, 0.8f);
    Geometry[] boxes = new Geometry[]{
        new Geometry("box1", box),
        new Geometry("box2", box),
        new Geometry("box3", box),
        new Geometry("torus1", torus),
        new Geometry("torus2", torus),
        new Geometry("torus3", torus)
    };
    for (int i = 0; i < boxes.length; i++) {
        Geometry geometry = boxes[i];
        geometry.setLocalTranslation((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10);
        geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI));
        geometry.setLocalScale((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10);
        geometry.setMaterial(mat);
        node.attachChild(geometry);
    }
}
 
Example #3
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createWall() {
    float xOff = -144;
    float zOff = -40;
    float startpt = bLength / 4 - xOff;
    float height = 6.1f;
    brick = new Box(bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    for (int j = 0; j < 15; j++) {
        for (int i = 0; i < 4; i++) {
            Vector3f vt = new Vector3f(i * bLength * 2 + startpt, bHeight + height, zOff);
            addBrick(vt);
        }
        startpt = -startpt;
        height += 1.01f * bHeight;
    }
}
 
Example #4
Source File: TestWalkingChar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createWall() {
    float xOff = -144;
    float zOff = -40;
    float startpt = bLength / 4 - xOff;
    float height = 6.1f;
    brick = new Box(Vector3f.ZERO, bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    for (int j = 0; j < 15; j++) {
        for (int i = 0; i < 4; i++) {
            Vector3f vt = new Vector3f(i * bLength * 2 + startpt, bHeight + height, zOff);
            addBrick(vt);
        }
        startpt = -startpt;
        height += 1.01f * bHeight;
    }
}
 
Example #5
Source File: TestBrickTower.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
 //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);

    brick = new Box(brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
}
 
Example #6
Source File: TestPostWater.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createBox() {
        //creating a transluscent box
        box = new Geometry("box", new Box(50, 50, 50));
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", new ColorRGBA(1.0f, 0, 0, 0.3f));
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        //mat.getAdditionalRenderState().setDepthWrite(false);
        //mat.getAdditionalRenderState().setDepthTest(false);
        box.setMaterial(mat);
        box.setQueueBucket(Bucket.Translucent);


        //creating a post view port
//        ViewPort post=renderManager.createPostView("transpPost", cam);
//        post.setClearFlags(false, true, true);


        box.setLocalTranslation(-600, 0, 300);

        //attaching the box to the post viewport
        //Don't forget to updateGeometricState() the box in the simpleUpdate
        //  post.attachScene(box);

        rootNode.attachChild(box);
    }
 
Example #7
Source File: TestCollisionShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void attachRandomGeometry(Node node, Material mat) {
    Box box = new Box(0.25f, 0.25f, 0.25f);
    Torus torus = new Torus(16, 16, 0.2f, 0.8f);
    Geometry[] boxes = new Geometry[]{
        new Geometry("box1", box),
        new Geometry("box2", box),
        new Geometry("box3", box),
        new Geometry("torus1", torus),
        new Geometry("torus2", torus),
        new Geometry("torus3", torus)
    };
    for (int i = 0; i < boxes.length; i++) {
        Geometry geometry = boxes[i];
        geometry.setLocalTranslation((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10);
        geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI));
        geometry.setLocalScale((float) Math.random() * 10 -10, (float) Math.random() * 10 -10, (float) Math.random() * 10 -10);
        geometry.setMaterial(mat);
        node.attachChild(geometry);
    }
}
 
Example #8
Source File: CubeField.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Node createPlayer() {
    Dome b = new Dome(Vector3f.ZERO, 10, 100, 1);
    Geometry playerMesh = new Geometry("Box", b);

    playerMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    playerMaterial.setColor("Color", ColorRGBA.Red);
    playerMesh.setMaterial(playerMaterial);
    playerMesh.setName("player");

    Box floor = new Box(Vector3f.ZERO.add(playerMesh.getLocalTranslation().getX(),
            playerMesh.getLocalTranslation().getY() - 1, 0), 100, 0, 100);
    Geometry floorMesh = new Geometry("Box", floor);

    floorMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    floorMaterial.setColor("Color", ColorRGBA.LightGray);
    floorMesh.setMaterial(floorMaterial);
    floorMesh.setName("floor");

    Node playerNode = new Node();
    playerNode.attachChild(playerMesh);
    playerNode.attachChild(floorMesh);

    return playerNode;
}
 
Example #9
Source File: TestShaderNodes.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(20);
    Logger.getLogger("com.jme3").setLevel(Level.WARNING);
    Box boxshape1 = new Box(1f, 1f, 1f);
    Geometry cube_tex = new Geometry("A Textured Box", boxshape1);
    Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
    mat.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    Technique t = mat.getActiveTechnique();

    for (Shader.ShaderSource shaderSource : t.getDef().getShader(assetManager, renderer.getCaps(), t.getDynamicDefines()).getSources()) {
        System.out.println(shaderSource.getSource());
    }
    
    mat.setColor("Color", ColorRGBA.Yellow);
    mat.setTexture("ColorMap", tex);
    cube_tex.setMaterial(mat);
    rootNode.attachChild(cube_tex);
}
 
Example #10
Source File: TestIssue801.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1f));

    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);

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

    rootNode.attachChild(geom);
    inputManager.addMapping("changeBpp", new KeyTrigger(KeyInput.KEY_P));
    ActionListener listener = new ActionListener() {
        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("changeBpp") && keyPressed) {
                goWindowed();
            }
        }
    };
    inputManager.addListener(listener, "changeBpp");
}
 
Example #11
Source File: TestAndroidResources.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    // Create boxes with textures that are stored in the Android Resources Folders
    // Images are stored in multiple Drawable and Mipmap directories.  Android picks the ones that
    // match the device size and density.
    Box box1Mesh = new Box(1, 1, 1);
    Geometry box1 = new Geometry("Monkey Box 1", box1Mesh);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setTexture("ColorMap", assetManager.loadTexture("drawable_monkey.png"));
    box1.setMaterial(mat1);
    box1.setLocalTranslation(-2, 0, 0);
    rootNode.attachChild(box1);

    Box box2Mesh = new Box(1, 1, 1);
    Geometry box2 = new Geometry("Monkey Box 2", box2Mesh);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setTexture("ColorMap", assetManager.loadTexture("mipmap_monkey.png"));
    box2.setMaterial(mat2);
    box2.setLocalTranslation(2, 0, 0);
    rootNode.attachChild(box2);

}
 
Example #12
Source File: TestBatchNodeCluster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void randomGenerator() {
    for (int i = startAt; i < maxCubes - 1; i++) {
        randomize();
        Geometry box = new Geometry("Box" + i, new Box(1, 1, 1));
        box.setLocalTranslation(new Vector3f(xPosition.get(xPosition.size() - 1),
                yPosition.get(yPosition.size() - 1),
                zPosition.get(zPosition.size() - 1)));
        batchNode.attachChild(box);
        if (i < 500) {
            box.setMaterial(mat1);
        } else if (i < 1000) {

            box.setMaterial(mat2);
        } else if (i < 1500) {

            box.setMaterial(mat3);
        } else {

            box.setMaterial(mat4);
        }

    }
}
 
Example #13
Source File: MaterialPreviewWidget.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private  void initWidget() {
    SceneApplication.getApplication().addSceneListener(this);
    Sphere sphMesh = new Sphere(32, 32, 2.5f);
    sphMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphMesh.updateGeometry(32, 32, 2.5f, false, false);
    TangentBinormalGenerator.generate(sphMesh);
    sphere = new Geometry("previewSphere", sphMesh);
    sphere.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_X));

    Box boxMesh = new Box(new Vector3f(0, 0, 0), 1.75f, 1.75f, 1.75f);
    TangentBinormalGenerator.generate(boxMesh);
    box = new Geometry("previewBox", boxMesh);
    box.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.DEG_TO_RAD * 30, Vector3f.UNIT_X).multLocal(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Y)));

    Quad quadMesh = new Quad(4.5f, 4.5f);
    TangentBinormalGenerator.generate(quadMesh);
    quad = new Geometry("previewQuad", quadMesh);
    quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));

    currentGeom = sphere;
    sphereButton.setSelected(true);
    init=true;
}
 
Example #14
Source File: TestSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
   // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess",3);
  //  mat.setBoolean("VertexLighting", true);
    
    
    Box floor = new Box(Vector3f.ZERO, 50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example #15
Source File: HelloAudio.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
  flyCam.setMoveSpeed(40);
  
  /** just a blue box floating in space */
  Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
  player = new Geometry("Player", box1);
  Material mat1 = new Material(assetManager, 
          "Common/MatDefs/Misc/Unshaded.j3md");
  mat1.setColor("Color", ColorRGBA.Blue);
  player.setMaterial(mat1);
  rootNode.attachChild(player);

  /** custom init methods, see below */
  initKeys();
  initAudio();
}
 
Example #16
Source File: TestSimpleWater.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initScene() {
    //init cam location
    cam.setLocation(new Vector3f(0, 10, 10));
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
    //init scene
    sceneNode = new Node("Scene");
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    geom.setMaterial(mat);
    sceneNode.attachChild(geom);

    // load sky
    sceneNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    rootNode.attachChild(sceneNode);

    //add lightPos Geometry
    Sphere lite=new Sphere(8, 8, 3.0f);
    lightSphere=new Geometry("lightsphere", lite);
    lightSphere.setMaterial(mat);
    lightSphere.setLocalTranslation(lightPos);
    rootNode.attachChild(lightSphere);
}
 
Example #17
Source File: TestMotionPath.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createScene() {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 1f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Black);
    mat.setColor("Diffuse", ColorRGBA.DarkGray);
    mat.setColor("Specular", ColorRGBA.White.mult(0.6f));
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Black);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Black);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setName("Teapot");
    teapot.setLocalScale(3);
    teapot.setMaterial(mat);


    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -1.0f, 0), 50, 1, 50));
    soil.setMaterial(matSoil);

    rootNode.attachChild(soil);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
}
 
Example #18
Source File: HelloJME3.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin
    Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
    Material mat = new Material(assetManager,
      "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
    mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
    geom.setMaterial(mat);                   // set the cube's material
    rootNode.attachChild(geom);              // make the cube appear in the scene
}
 
Example #19
Source File: MapDrawer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void attachBuggedCliff(Cliff c) {
	Geometry g = new Geometry();
	g.setMesh(new Box(0.5f, 0.5f, 1));
	g.setMaterial(MaterialManager.redMaterial);
	g.setLocalTranslation((float)c.getTile().getCoord().x + 0.5f, (float)c.getTile().getCoord().y + 0.5f, (float) (c.level * Tile.STAGE_HEIGHT) + 1);

	Node n = new Node();
	n.attachChild(g);
	tilesSpatial.get(c.getTile()).add(n);
	castAndReceiveNode.attachChild(n);
}
 
Example #20
Source File: TestRagdollCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initWall(float bLength, float bWidth, float bHeight) {
    Box brick = new Box(bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, 0.5f));
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat2.setTexture("ColorMap", tex);

    float startpt = bLength / 4f;
    float height = -5f;
    for (int j = 0; j < 15; j++) {
        for (int i = 0; i < 4; i++) {
            Vector3f ori = new Vector3f(i * bLength * 2f + startpt, bHeight + height, -10f);
            Geometry reBoxg = new Geometry("brick", brick);
            reBoxg.setMaterial(mat2);
            reBoxg.setLocalTranslation(ori);
            //for geometry with sphere mesh the physics system automatically uses a sphere collision shape
            reBoxg.addControl(new RigidBodyControl(1.5f));
            reBoxg.setShadowMode(ShadowMode.CastAndReceive);
            reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f);
            this.rootNode.attachChild(reBoxg);
            physicsSpace.add(reBoxg);
        }
        startpt = -startpt;
        height += 2f * bHeight;
    }
}
 
Example #21
Source File: TestBox.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
 
Example #22
Source File: HelloLoop.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    /** this blue box is our player character */
    Box b = new Box(Vector3f.ZERO, 1, 1, 1);
    player = new Geometry("blue cube", b);
    Material mat = new Material(assetManager,
      "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    player.setMaterial(mat);
    rootNode.attachChild(player);
}
 
Example #23
Source File: TestAmbient.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
  float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
    1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f,
    0.00f, -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f,
    0.250f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f};
  Environment env = new Environment(eax);
  audioRenderer.setEnvironment(env);

  waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg",
          DataType.Buffer);
  waves.setPositional(true);
  waves.setLocalTranslation(new Vector3f(0, 0,0));
  waves.setMaxDistance(100);
  waves.setRefDistance(5);

  nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg",
          DataType.Stream);
  nature.setPositional(false);
  nature.setVolume(3);
  
  waves.playInstance();
  nature.play();
  
  // just a blue box to mark the spot
  Box box1 = new Box(.5f, .5f, .5f);
  Geometry player = new Geometry("Player", box1);
  Material mat1 = new Material(assetManager,
          "Common/MatDefs/Misc/Unshaded.j3md");
  mat1.setColor("Color", ColorRGBA.Blue);
  player.setMaterial(mat1);
  rootNode.attachChild(player);
}
 
Example #24
Source File: HelloAssets.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {

    /** Load a teapot model (OBJ file from test-data) */
    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_default = new Material( assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teapot.setMaterial(mat_default);
    rootNode.attachChild(teapot);

    /** Create a wall (Box with material and texture from test-data) */
    Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
    Spatial wall = new Geometry("Box", box );
    Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_brick.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    wall.setMaterial(mat_brick);
    wall.setLocalTranslation(2.0f,-2.5f,0.0f);
    rootNode.attachChild(wall);

    /** Display a line of text (default font from test-data) */
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("Hello World");
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);

    /** Load a Ninja model (OgreXML + material + texture from test_data) */
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    ninja.scale(0.05f, 0.05f, 0.05f);
    ninja.rotate(0.0f, -3.0f, 0.0f);
    ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
    rootNode.attachChild(ninja);
    /** You must add a light to make the model visible */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    rootNode.addLight(sun);
}
 
Example #25
Source File: TestLineWidthRenderState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    cam.setLocation(new Vector3f(5.5826545f, 3.6192513f, 8.016988f));
    cam.setRotation(new Quaternion(-0.04787097f, 0.9463123f, -0.16569641f, -0.27339742f));

    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    mat.getAdditionalRenderState().setWireframe(true);
    mat.getAdditionalRenderState().setLineWidth(2);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);

    inputManager.addListener(new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if(name.equals("up") && isPressed){
                mat.getAdditionalRenderState().setLineWidth(mat.getAdditionalRenderState().getLineWidth() + 1);
            }
            if(name.equals("down") && isPressed){
                mat.getAdditionalRenderState().setLineWidth(Math.max(mat.getAdditionalRenderState().getLineWidth() - 1, 1));
            }
        }
    }, "up", "down");
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_J));
}
 
Example #26
Source File: TestNiftyToMesh.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
   ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
   niftyView.setClearFlags(true, true, true);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                      inputManager,
                                                      audioRenderer,
                                                      niftyView);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("all/intro.xml", "start");
    niftyView.addProcessor(niftyDisplay);

    Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
    FrameBuffer fb = new FrameBuffer(1024, 768, 1);
    fb.setDepthTexture(depthTex);

    Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);

    fb.setColorTexture(tex);
    niftyView.setClearFlags(true, true, true);
    niftyView.setOutputFrameBuffer(fb);

    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
 
Example #27
Source File: HelloPicking.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** A cube object for target practice */
protected Geometry makeCube(String name, float x, float y, float z) {
  Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);
  Geometry cube = new Geometry(name, box);
  Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  mat1.setColor("Color", ColorRGBA.randomColor());
  cube.setMaterial(mat1);
  return cube;
}
 
Example #28
Source File: TestSafeCanvas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);

    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
 
Example #29
Source File: TestGhostObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);

    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));

    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);

    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);

    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);

    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);

    initGhostObject();
}
 
Example #30
Source File: TestBrickWall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);

    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(Vector3f.ZERO, bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));

    initMaterial();
    initWall();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 6f, 6f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(15);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
    inputManager.addListener(actionListener, "gc");

    rootNode.setShadowMode(ShadowMode.Off);
    bsr = new BasicShadowRenderer(assetManager, 256);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);
}