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();
}
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);
}
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);
}
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());
}
}
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.");
}
}
Aggregations