Search in sources :

Example 41 with Spatial

use of com.jme3.scene.Spatial 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 42 with Spatial

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

the class TestTangentSpace method simpleInitApp.

@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);
}
Also used : Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) KeyTrigger(com.jme3.input.controls.KeyTrigger) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 43 with Spatial

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

the class VRAppState method update.

@Override
public void update(float tpf) {
    // update VR pose & cameras
    if (environment.getVRViewManager() != null) {
        environment.getVRViewManager().update(tpf);
    } else if (environment.getObserver() != null) {
        environment.getCamera().setFrame(((Spatial) environment.getObserver()).getWorldTranslation(), ((Spatial) environment.getObserver()).getWorldRotation());
    }
    //FIXME: check if this code is necessary.
    // Updates scene and gui states.
    Iterator<Spatial> spatialIter = application.getViewPort().getScenes().iterator();
    Spatial spatial = null;
    while (spatialIter.hasNext()) {
        spatial = spatialIter.next();
        spatial.updateLogicalState(tpf);
        spatial.updateGeometricState();
    }
    if (environment.isInVR() == false || environment.getVRGUIManager().getPositioningMode() == VRGUIPositioningMode.MANUAL) {
        // only update geometric state here if GUI is in manual mode, or not in VR
        // it will get updated automatically in the viewmanager update otherwise
        spatialIter = application.getGuiViewPort().getScenes().iterator();
        spatial = null;
        while (spatialIter.hasNext()) {
            spatial = spatialIter.next();
            spatial.updateGeometricState();
        }
    }
    // use the analog control on the first tracked controller to push around the mouse
    environment.getVRMouseManager().updateAnalogAsMouse(0, null, null, null, tpf);
}
Also used : Spatial(com.jme3.scene.Spatial)

Example 44 with Spatial

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

the class OSVRInput method getFinalObserverPosition.

@Override
public Vector3f getFinalObserverPosition(int index) {
    VRViewManagerOSVR vrvm = (VRViewManagerOSVR) environment.getVRViewManager();
    if (vrvm == null || isInputDeviceTracking(index) == false)
        return null;
    Object obs = environment.getObserver();
    Vector3f pos = getPosition(index);
    if (obs instanceof Camera) {
        ((Camera) obs).getRotation().mult(pos, pos);
        return pos.addLocal(((Camera) obs).getLocation());
    } else {
        ((Spatial) obs).getWorldRotation().mult(pos, pos);
        return pos.addLocal(((Spatial) obs).getWorldTranslation());
    }
}
Also used : VRViewManagerOSVR(com.jme3.util.VRViewManagerOSVR) Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera)

Example 45 with Spatial

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

the class OpenVRInput method getFinalObserverPosition.

@Override
public Vector3f getFinalObserverPosition(int index) {
    if (environment != null) {
        VRViewManagerOpenVR vrvm = (VRViewManagerOpenVR) environment.getVRViewManager();
        if (vrvm != null) {
            if (isInputDeviceTracking(index) == false) {
                return null;
            }
            Object obs = environment.getObserver();
            Vector3f pos = getPosition(index);
            if (obs instanceof Camera) {
                ((Camera) obs).getRotation().mult(pos, pos);
                return pos.addLocal(((Camera) obs).getLocation());
            } else {
                ((Spatial) obs).getWorldRotation().mult(pos, pos);
                return pos.addLocal(((Spatial) obs).getWorldTranslation());
            }
        } else {
            throw new IllegalStateException("VR environment has no valid view manager.");
        }
    } else {
        throw new IllegalStateException("VR input is not attached to a VR environment.");
    }
}
Also used : VRViewManagerOpenVR(com.jme3.util.VRViewManagerOpenVR) Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera)

Aggregations

Spatial (com.jme3.scene.Spatial)123 Vector3f (com.jme3.math.Vector3f)74 Node (com.jme3.scene.Node)56 Geometry (com.jme3.scene.Geometry)50 DirectionalLight (com.jme3.light.DirectionalLight)46 Material (com.jme3.material.Material)39 Quaternion (com.jme3.math.Quaternion)34 FilterPostProcessor (com.jme3.post.FilterPostProcessor)17 Box (com.jme3.scene.shape.Box)17 KeyTrigger (com.jme3.input.controls.KeyTrigger)15 AmbientLight (com.jme3.light.AmbientLight)14 ColorRGBA (com.jme3.math.ColorRGBA)14 Camera (com.jme3.renderer.Camera)13 Sphere (com.jme3.scene.shape.Sphere)13 Texture (com.jme3.texture.Texture)12 TempVars (com.jme3.util.TempVars)12 InputCapsule (com.jme3.export.InputCapsule)11 ActionListener (com.jme3.input.controls.ActionListener)11 AnimControl (com.jme3.animation.AnimControl)10 OutputCapsule (com.jme3.export.OutputCapsule)9