Search in sources :

Example 51 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class CubeField method createPlayer.

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(100, 0, 100);
    Geometry floorMesh = new Geometry("Box", floor);
    Vector3f translation = Vector3f.ZERO.add(playerMesh.getLocalTranslation().getX(), playerMesh.getLocalTranslation().getY() - 1, 0);
    floorMesh.setLocalTranslation(translation);
    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;
}
Also used : Geometry(com.jme3.scene.Geometry) Dome(com.jme3.scene.shape.Dome) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Example 52 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class RollingTheMonkey method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);
    cam.setLocation(new Vector3f(0.0f, 12.0f, 21.0f));
    viewPort.setBackgroundColor(new ColorRGBA(0.2118f, 0.0824f, 0.6549f, 1.0f));
    // init physics
    BulletAppState bulletState = new BulletAppState();
    stateManager.attach(bulletState);
    space = bulletState.getPhysicsSpace();
    space.addCollisionListener(this);
    // create light
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection((new Vector3f(-0.7f, -0.3f, -0.5f)).normalizeLocal());
    System.out.println("Here We Go: " + sun.getDirection());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
    // create materials
    Material materialRed = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialRed.setBoolean("UseMaterialColors", true);
    materialRed.setBoolean("HardwareShadows", true);
    materialRed.setColor("Diffuse", new ColorRGBA(0.9451f, 0.0078f, 0.0314f, 1.0f));
    materialRed.setColor("Specular", ColorRGBA.White);
    materialRed.setFloat("Shininess", 64.0f);
    Material materialGreen = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialGreen.setBoolean("UseMaterialColors", true);
    materialGreen.setBoolean("HardwareShadows", true);
    materialGreen.setColor("Diffuse", new ColorRGBA(0.0431f, 0.7725f, 0.0078f, 1.0f));
    materialGreen.setColor("Specular", ColorRGBA.White);
    materialGreen.setFloat("Shininess", 64.0f);
    Material logoMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    logoMaterial.setBoolean("UseMaterialColors", true);
    logoMaterial.setBoolean("HardwareShadows", true);
    logoMaterial.setTexture("DiffuseMap", assetManager.loadTexture("com/jme3/app/Monkey.png"));
    logoMaterial.setColor("Diffuse", ColorRGBA.White);
    logoMaterial.setColor("Specular", ColorRGBA.White);
    logoMaterial.setFloat("Shininess", 32.0f);
    Material materialYellow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialYellow.setBoolean("UseMaterialColors", true);
    materialYellow.setBoolean("HardwareShadows", true);
    materialYellow.setColor("Diffuse", new ColorRGBA(0.9529f, 0.7843f, 0.0078f, 1.0f));
    materialYellow.setColor("Specular", ColorRGBA.White);
    materialYellow.setFloat("Shininess", 64.0f);
    // create level spatial
    // TODO: create your own level mesh
    Node level = new Node("level");
    level.setShadowMode(ShadowMode.CastAndReceive);
    Geometry floor = new Geometry("floor", new Box(22.0f, 0.5f, 22.0f));
    floor.setShadowMode(ShadowMode.Receive);
    floor.setLocalTranslation(0.0f, -0.5f, 0.0f);
    floor.setMaterial(materialGreen);
    Geometry wallNorth = new Geometry("wallNorth", new Box(22.0f, 2.0f, 0.5f));
    wallNorth.setLocalTranslation(0.0f, 2.0f, 21.5f);
    wallNorth.setMaterial(materialRed);
    Geometry wallSouth = new Geometry("wallSouth", new Box(22.0f, 2.0f, 0.5f));
    wallSouth.setLocalTranslation(0.0f, 2.0f, -21.5f);
    wallSouth.setMaterial(materialRed);
    Geometry wallEast = new Geometry("wallEast", new Box(0.5f, 2.0f, 21.0f));
    wallEast.setLocalTranslation(-21.5f, 2.0f, 0.0f);
    wallEast.setMaterial(materialRed);
    Geometry wallWest = new Geometry("wallWest", new Box(0.5f, 2.0f, 21.0f));
    wallWest.setLocalTranslation(21.5f, 2.0f, 0.0f);
    wallWest.setMaterial(materialRed);
    level.attachChild(floor);
    level.attachChild(wallNorth);
    level.attachChild(wallSouth);
    level.attachChild(wallEast);
    level.attachChild(wallWest);
    // The easy way: level.addControl(new RigidBodyControl(0));
    // create level Shape
    CompoundCollisionShape levelShape = new CompoundCollisionShape();
    BoxCollisionShape floorShape = new BoxCollisionShape(new Vector3f(22.0f, 0.5f, 22.0f));
    BoxCollisionShape wallNorthShape = new BoxCollisionShape(new Vector3f(22.0f, 2.0f, 0.5f));
    BoxCollisionShape wallSouthShape = new BoxCollisionShape(new Vector3f(22.0f, 2.0f, 0.5f));
    BoxCollisionShape wallEastShape = new BoxCollisionShape(new Vector3f(0.5f, 2.0f, 21.0f));
    BoxCollisionShape wallWestShape = new BoxCollisionShape(new Vector3f(0.5f, 2.0f, 21.0f));
    levelShape.addChildShape(floorShape, new Vector3f(0.0f, -0.5f, 0.0f));
    levelShape.addChildShape(wallNorthShape, new Vector3f(0.0f, 2.0f, -21.5f));
    levelShape.addChildShape(wallSouthShape, new Vector3f(0.0f, 2.0f, 21.5f));
    levelShape.addChildShape(wallEastShape, new Vector3f(-21.5f, 2.0f, 0.0f));
    levelShape.addChildShape(wallEastShape, new Vector3f(21.5f, 2.0f, 0.0f));
    level.addControl(new RigidBodyControl(levelShape, 0));
    rootNode.attachChild(level);
    space.addAll(level);
    // create Pickups
    // TODO: create your own pickUp mesh
    //       create single mesh for all pickups
    // HINT: think particles.
    pickUps = new Node("pickups");
    Quaternion rotation = new Quaternion();
    Vector3f translation = new Vector3f(0.0f, PICKUP_SIZE * 1.5f, -PICKUP_RADIUS);
    int index = 0;
    float ammount = FastMath.TWO_PI / PICKUP_COUNT;
    for (float angle = 0; angle < FastMath.TWO_PI; angle += ammount) {
        Geometry pickUp = new Geometry("pickUp" + (index++), new Box(PICKUP_SIZE, PICKUP_SIZE, PICKUP_SIZE));
        pickUp.setShadowMode(ShadowMode.CastAndReceive);
        pickUp.setMaterial(materialYellow);
        pickUp.setLocalRotation(rotation.fromAngles(FastMath.rand.nextFloat() * FastMath.TWO_PI, FastMath.rand.nextFloat() * FastMath.TWO_PI, FastMath.rand.nextFloat() * FastMath.TWO_PI));
        rotation.fromAngles(0.0f, angle, 0.0f);
        rotation.mult(translation, pickUp.getLocalTranslation());
        pickUps.attachChild(pickUp);
        pickUp.addControl(new GhostControl(new SphereCollisionShape(PICKUP_SIZE)));
        space.addAll(pickUp);
    //space.addCollisionListener(pickUpControl);
    }
    rootNode.attachChild(pickUps);
    // Create player
    // TODO: create your own player mesh
    Geometry playerGeometry = new Geometry("player", new Sphere(16, 32, PLAYER_RADIUS));
    playerGeometry.setShadowMode(ShadowMode.CastAndReceive);
    playerGeometry.setLocalTranslation(PLAYER_START.clone());
    playerGeometry.setMaterial(logoMaterial);
    // Store control for applying forces
    // TODO: create your own player control
    player = new RigidBodyControl(new SphereCollisionShape(PLAYER_RADIUS), PLAYER_MASS);
    player.setRestitution(PLAYER_REST);
    playerGeometry.addControl(player);
    rootNode.attachChild(playerGeometry);
    space.addAll(playerGeometry);
    inputManager.addMapping(INPUT_MAPPING_FORWARD, new KeyTrigger(KeyInput.KEY_UP), new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping(INPUT_MAPPING_BACKWARD, new KeyTrigger(KeyInput.KEY_DOWN), new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping(INPUT_MAPPING_LEFT, new KeyTrigger(KeyInput.KEY_LEFT), new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping(INPUT_MAPPING_RIGHT, new KeyTrigger(KeyInput.KEY_RIGHT), new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping(INPUT_MAPPING_RESET, new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(this, INPUT_MAPPING_FORWARD, INPUT_MAPPING_BACKWARD, INPUT_MAPPING_LEFT, INPUT_MAPPING_RIGHT, INPUT_MAPPING_RESET);
    // init UI
    infoText = new BitmapText(guiFont, false);
    infoText.setText(INFO_MESSAGE);
    guiNode.attachChild(infoText);
    scoreText = new BitmapText(guiFont, false);
    scoreText.setText("Score: 0");
    guiNode.attachChild(scoreText);
    messageText = new BitmapText(guiFont, false);
    messageText.setText(MESSAGE);
    messageText.setLocalScale(0.0f);
    guiNode.attachChild(messageText);
    infoText.setLocalTranslation(0.0f, cam.getHeight(), 0.0f);
    scoreText.setLocalTranslation((cam.getWidth() - scoreText.getLineWidth()) / 2.0f, scoreText.getLineHeight(), 0.0f);
    messageText.setLocalTranslation((cam.getWidth() - messageText.getLineWidth()) / 2.0f, (cam.getHeight() - messageText.getLineHeight()) / 2, 0.0f);
    // init shadows
    FilterPostProcessor processor = new FilterPostProcessor(assetManager);
    DirectionalLightShadowFilter filter = new DirectionalLightShadowFilter(assetManager, 2048, 1);
    filter.setLight(sun);
    processor.addFilter(filter);
    viewPort.addProcessor(processor);
}
Also used : CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) BitmapText(com.jme3.font.BitmapText) GhostControl(com.jme3.bullet.control.GhostControl) Vector3f(com.jme3.math.Vector3f) BulletAppState(com.jme3.bullet.BulletAppState) DirectionalLight(com.jme3.light.DirectionalLight)

Example 53 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestEverything method setupRobotGuy.

//    public void setupTerrain(){
//        Material mat = manager.loadMaterial("Textures/Terrain/Rock/Rock.j3m");
//        mat.getTextureParam("DiffuseMap").getValue().setWrap(WrapMode.Repeat);
//        mat.getTextureParam("NormalMap").getValue().setWrap(WrapMode.Repeat);
//        try{
//            Geomap map = GeomapLoader.fromImage(TestEverything.class.getResource("/textures/heightmap.png"));
//            Mesh m = map.createMesh(new Vector3f(0.35f, 0.0005f, 0.35f), new Vector2f(10, 10), true);
//            Logger.getLogger(TangentBinormalGenerator.class.getName()).setLevel(Level.SEVERE);
//            TangentBinormalGenerator.generate(m);
//            Geometry t = new Geometry("Terrain", m);
//            t.setLocalTranslation(85, -15, 0);
//            t.setMaterial(mat);
//            t.updateModelBound();
//            t.setShadowMode(ShadowMode.Receive);
//            rootNode.attachChild(t);
//        }catch (IOException ex){
//            ex.printStackTrace();
//        }
//
//    }
public void setupRobotGuy() {
    Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    Material mat = assetManager.loadMaterial("Models/Oto/Oto.j3m");
    model.getChild(0).setMaterial(mat);
    //        model.setAnimation("Walk");
    model.setLocalTranslation(30, 10.5f, 30);
    model.setLocalScale(2);
    model.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(model);
}
Also used : Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 54 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestOgreConvert method simpleInitApp.

@Override
public void simpleInitApp() {
    Spatial ogreModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryExporter exp = new BinaryExporter();
        exp.save(ogreModel, baos);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        BinaryImporter imp = new BinaryImporter();
        imp.setAssetManager(assetManager);
        Node ogreModelReloaded = (Node) imp.load(bais, null, null);
        AnimControl control = ogreModelReloaded.getControl(AnimControl.class);
        AnimChannel chan = control.createChannel();
        chan.setAnim("Walk");
        rootNode.attachChild(ogreModelReloaded);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : BinaryExporter(com.jme3.export.binary.BinaryExporter) BinaryImporter(com.jme3.export.binary.BinaryImporter) Spatial(com.jme3.scene.Spatial) ByteArrayInputStream(java.io.ByteArrayInputStream) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) AnimChannel(com.jme3.animation.AnimChannel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AnimControl(com.jme3.animation.AnimControl)

Example 55 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestRagDoll method createRagDoll.

private void createRagDoll() {
    shoulders = createLimb(0.2f, 1.0f, new Vector3f(0.00f, 1.5f, 0), true);
    Node uArmL = createLimb(0.2f, 0.5f, new Vector3f(-0.75f, 0.8f, 0), false);
    Node uArmR = createLimb(0.2f, 0.5f, new Vector3f(0.75f, 0.8f, 0), false);
    Node lArmL = createLimb(0.2f, 0.5f, new Vector3f(-0.75f, -0.2f, 0), false);
    Node lArmR = createLimb(0.2f, 0.5f, new Vector3f(0.75f, -0.2f, 0), false);
    Node body = createLimb(0.2f, 1.0f, new Vector3f(0.00f, 0.5f, 0), false);
    Node hips = createLimb(0.2f, 0.5f, new Vector3f(0.00f, -0.5f, 0), true);
    Node uLegL = createLimb(0.2f, 0.5f, new Vector3f(-0.25f, -1.2f, 0), false);
    Node uLegR = createLimb(0.2f, 0.5f, new Vector3f(0.25f, -1.2f, 0), false);
    Node lLegL = createLimb(0.2f, 0.5f, new Vector3f(-0.25f, -2.2f, 0), false);
    Node lLegR = createLimb(0.2f, 0.5f, new Vector3f(0.25f, -2.2f, 0), false);
    join(body, shoulders, new Vector3f(0f, 1.4f, 0));
    join(body, hips, new Vector3f(0f, -0.5f, 0));
    join(uArmL, shoulders, new Vector3f(-0.75f, 1.4f, 0));
    join(uArmR, shoulders, new Vector3f(0.75f, 1.4f, 0));
    join(uArmL, lArmL, new Vector3f(-0.75f, .4f, 0));
    join(uArmR, lArmR, new Vector3f(0.75f, .4f, 0));
    join(uLegL, hips, new Vector3f(-.25f, -0.5f, 0));
    join(uLegR, hips, new Vector3f(.25f, -0.5f, 0));
    join(uLegL, lLegL, new Vector3f(-.25f, -1.7f, 0));
    join(uLegR, lLegR, new Vector3f(.25f, -1.7f, 0));
    ragDoll.attachChild(shoulders);
    ragDoll.attachChild(body);
    ragDoll.attachChild(hips);
    ragDoll.attachChild(uArmL);
    ragDoll.attachChild(uArmR);
    ragDoll.attachChild(lArmL);
    ragDoll.attachChild(lArmR);
    ragDoll.attachChild(uLegL);
    ragDoll.attachChild(uLegR);
    ragDoll.attachChild(lLegL);
    ragDoll.attachChild(lLegR);
    rootNode.attachChild(ragDoll);
    bulletAppState.getPhysicsSpace().addAll(ragDoll);
}
Also used : Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node)

Aggregations

Node (com.jme3.scene.Node)135 Vector3f (com.jme3.math.Vector3f)81 Geometry (com.jme3.scene.Geometry)64 Spatial (com.jme3.scene.Spatial)53 Material (com.jme3.material.Material)51 DirectionalLight (com.jme3.light.DirectionalLight)35 Quaternion (com.jme3.math.Quaternion)32 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 Box (com.jme3.scene.shape.Box)24 Sphere (com.jme3.scene.shape.Sphere)19 AmbientLight (com.jme3.light.AmbientLight)17 BulletAppState (com.jme3.bullet.BulletAppState)16 ColorRGBA (com.jme3.math.ColorRGBA)15 AnimControl (com.jme3.animation.AnimControl)14 KeyTrigger (com.jme3.input.controls.KeyTrigger)14 FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 HashMap (java.util.HashMap)14 CameraNode (com.jme3.scene.CameraNode)13 ArrayList (java.util.ArrayList)13 ActionListener (com.jme3.input.controls.ActionListener)12