Search in sources :

Example 41 with Node

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

the class TestShadowBug method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(100f);
    rootNode.attachChild(makeFloor());
    Node characters = new Node("Characters");
    characters.setShadowMode(ShadowMode.Cast);
    rootNode.attachChild(characters);
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(200.0f, -6f, 200f);
    golem.setShadowMode(ShadowMode.CastAndReceive);
    characters.attachChild(golem);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-1f, -1f, 1f));
    sun.setColor(ColorRGBA.White.mult(1.3f));
    rootNode.addLight(sun);
    characters.addLight(sun);
    SpotLight spot = new SpotLight();
    // distance
    spot.setSpotRange(13f);
    // inner light cone (central beam)
    spot.setSpotInnerAngle(15f * FastMath.DEG_TO_RAD);
    // outer light cone (edge of the light)
    spot.setSpotOuterAngle(20f * FastMath.DEG_TO_RAD);
    // light color
    spot.setColor(ColorRGBA.White.mult(1.3f));
    spot.setPosition(new Vector3f(192.0f, -1f, 192f));
    spot.setDirection(new Vector3f(1, -0.5f, 1));
    rootNode.addLight(spot);
    PointLight lamp_light = new PointLight();
    lamp_light.setColor(ColorRGBA.Yellow);
    lamp_light.setRadius(20f);
    lamp_light.setPosition(new Vector3f(210.0f, 0f, 210f));
    rootNode.addLight(lamp_light);
    SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
    slsr.setLight(spot);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
    slsr.setShadowIntensity(0.6f);
    slsr.setFlushQueues(false);
    viewPort.addProcessor(slsr);
    PointLightShadowRenderer plsr = new PointLightShadowRenderer(assetManager, 512);
    plsr.setLight(lamp_light);
    plsr.setShadowIntensity(0.6f);
    plsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
    plsr.setFlushQueues(false);
    viewPort.addProcessor(plsr);
    viewPort.getCamera().setLocation(new Vector3f(192.0f, 10f, 192f));
    float[] angles = new float[] { 3.14f / 2, 3.14f / 2, 0 };
    viewPort.getCamera().setRotation(new Quaternion(angles));
}
Also used : Spatial(com.jme3.scene.Spatial) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLightShadowRenderer(com.jme3.shadow.PointLightShadowRenderer) PointLight(com.jme3.light.PointLight) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight)

Example 42 with Node

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

the class TestCameraNode method simpleInitApp.

public void simpleInitApp() {
    // load a teapot model 
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat);
    //create a node to attach the geometry and the camera node
    teaNode = new Node("teaNode");
    teaNode.attachChild(teaGeom);
    rootNode.attachChild(teaNode);
    // create a floor
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat);
    rootNode.attachChild(ground);
    //creating the camera Node
    camNode = new CameraNode("CamNode", cam);
    //Setting the direction to Spatial to camera, this means the camera will copy the movements of the Node
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    //attaching the camNode to the teaNode
    teaNode.attachChild(camNode);
    //setting the local translation of the cam node to move it away from the teanNode a bit
    camNode.setLocalTranslation(new Vector3f(-10, 0, 0));
    //setting the camNode to look at the teaNode
    camNode.lookAt(teaNode.getLocalTranslation(), Vector3f.UNIT_Y);
    //disable the default 1st-person flyCam (don't forget this!!)
    flyCam.setEnabled(false);
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) CameraNode(com.jme3.scene.CameraNode) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material)

Example 43 with Node

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

the class TestManyLightsSingle method reloadScene.

protected void reloadScene(Geometry g, Geometry boxGeo, Node cubeNodes) {
    MaterialDebugAppState debug = stateManager.getState(MaterialDebugAppState.class);
    Material m = debug.reloadMaterial(g.getMaterial());
    if (m != null) {
        g.setMaterial(m);
    }
    m = debug.reloadMaterial(boxGeo.getMaterial());
    if (m != null) {
        cubeNodes.setMaterial(m);
    }
}
Also used : MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) Material(com.jme3.material.Material)

Example 44 with Node

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

the class TestPointLightShadows method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f));
    cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f));
    al = new AmbientLight(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o");
    scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(scene);
    rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive);
    lightNode = (Node) rootNode.getChild("Lamp");
    Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setShadowMode(RenderQueue.ShadowMode.Off);
    lightNode.attachChild(lightMdl);
    //lightMdl.setLocalTranslation(lightNode.getLocalTranslation());
    Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(box);
    box.setLocalTranslation(-1f, 0.5f, -2);
    plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    plsr.setLight((PointLight) scene.getLocalLightList().get(0));
    plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsr.setShadowZExtend(15);
    plsr.setShadowZFadeLength(5);
    plsr.setShadowIntensity(0.9f);
    // plsr.setFlushQueues(false);
    //plsr.displayFrustum();
    plsr.displayDebug();
    viewPort.addProcessor(plsr);
    plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    plsf.setLight((PointLight) scene.getLocalLightList().get(0));
    plsf.setShadowZExtend(15);
    plsf.setShadowZFadeLength(5);
    plsf.setShadowIntensity(0.8f);
    plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(plsf);
    viewPort.addProcessor(fpp);
    inputManager.addListener(this, "ShadowUp", "ShadowDown");
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) PointLightShadowFilter(com.jme3.shadow.PointLightShadowFilter) Box(com.jme3.scene.shape.Box) PointLightShadowRenderer(com.jme3.shadow.PointLightShadowRenderer) FilterPostProcessor(com.jme3.post.FilterPostProcessor) AmbientLight(com.jme3.light.AmbientLight)

Example 45 with Node

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

the class HelloCollision method simpleInitApp.

public void simpleInitApp() {
    /** Set up Physics */
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    // We re-use the flyby camera for rotation, while positioning is handled by physics
    viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
    flyCam.setMoveSpeed(100);
    setUpKeys();
    setUpLight();
    // We load the scene from the zip file and adjust its size.
    assetManager.registerLocator("town.zip", ZipLocator.class);
    sceneModel = assetManager.loadModel("main.scene");
    sceneModel.setLocalScale(2f);
    // We set up collision detection for the scene by creating a
    // compound collision shape and a static RigidBodyControl with mass zero.
    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
    landscape = new RigidBodyControl(sceneShape, 0);
    sceneModel.addControl(landscape);
    // We set up collision detection for the player by creating
    // a capsule collision shape and a CharacterControl.
    // The CharacterControl offers extra settings for
    // size, stepheight, jumping, falling, and gravity.
    // We also put the player in its starting position.
    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
    player = new CharacterControl(capsuleShape, 0.05f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);
    player.setPhysicsLocation(new Vector3f(0, 10, 0));
    // We attach the scene and the player to the rootnode and the physics space,
    // to make them appear in the game world.
    rootNode.attachChild(sceneModel);
    bulletAppState.getPhysicsSpace().add(landscape);
    bulletAppState.getPhysicsSpace().add(player);
}
Also used : CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) ColorRGBA(com.jme3.math.ColorRGBA) CharacterControl(com.jme3.bullet.control.CharacterControl) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

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