use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class SoundEvent method initEvent.
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
audioNode = new AudioNode(app.getAssetManager(), path, stream);
audioNode.setPositional(false);
setLoopMode(loopMode);
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class AppletHarness method createCanvas.
private void createCanvas() {
AppSettings settings = new AppSettings(true);
// load app cfg
if (appCfg != null) {
InputStream in = null;
try {
in = appCfg.openStream();
settings.load(in);
in.close();
} catch (IOException ex) {
// Called before application has been created ....
// Display error message through AWT
JOptionPane.showMessageDialog(this, "An error has occured while " + "loading applet configuration" + ex.getMessage(), "jME3 Applet", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} finally {
if (in != null)
try {
in.close();
} catch (IOException ex) {
}
}
}
if (assetCfg != null) {
settings.putString("AssetConfigURL", assetCfg.toString());
}
settings.setWidth(getWidth());
settings.setHeight(getHeight());
JmeSystem.setLowPermissions(true);
try {
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}
appToApplet.put(app, this);
app.setSettings(settings);
app.createCanvas();
context = (JmeCanvasContext) app.getContext();
canvas = context.getCanvas();
canvas.setSize(getWidth(), getHeight());
add(canvas);
app.startCanvas();
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method syncScreenProcessing.
/**
* Sets the two views to use the list of {@link SceneProcessor processors}.
* @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
*/
public void syncScreenProcessing(ViewPort sourceViewport) {
if (rightViewport == null) {
return;
}
if (environment != null) {
if (environment.getApplication() != null) {
// setup post processing filters
if (rightPostProcessor == null) {
rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
}
// clear out all filters & processors, to start from scratch
rightPostProcessor.removeAllFilters();
leftPostProcessor.removeAllFilters();
leftViewport.clearProcessors();
rightViewport.clearProcessors();
// if we have no processors to sync, don't add the FilterPostProcessor
if (sourceViewport.getProcessors().isEmpty())
return;
// add post processors we just made, which are empty
leftViewport.addProcessor(leftPostProcessor);
rightViewport.addProcessor(rightPostProcessor);
// add them to the left viewport processor & clone them to the right
for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
if (sceneProcessor instanceof FilterPostProcessor) {
for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
if (f instanceof TranslucentBucketFilter) {
// just remove this filter, we will add it at the end manually
((FilterPostProcessor) sceneProcessor).removeFilter(f);
} else {
leftPostProcessor.addFilter(f);
// clone to the right
Filter f2;
if (f instanceof FogFilter) {
f2 = FilterUtil.cloneFogFilter((FogFilter) f);
} else if (f instanceof CartoonSSAO) {
f2 = new CartoonSSAO((CartoonSSAO) f);
} else if (f instanceof SSAOFilter) {
f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
} else if (f instanceof DirectionalLightShadowFilter) {
f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
} else {
// dof, bloom, lightscattering etc.
f2 = f;
}
rightPostProcessor.addFilter(f2);
}
}
} else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
// shadow processing
// TODO: make right shadow processor use same left shadow maps for performance
VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
dlsrRight.setLight(dlsr.getLight());
rightViewport.getProcessors().add(0, dlsrRight);
leftViewport.getProcessors().add(0, sceneProcessor);
}
}
// make sure each has a translucent filter renderer
leftPostProcessor.addFilter(new TranslucentBucketFilter());
rightPostProcessor.addFilter(new TranslucentBucketFilter());
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method setupVRScene.
/**
* Replaces rootNode as the main cameras scene with the distortion mesh
*/
private void setupVRScene() {
if (environment != null) {
if (environment.getApplication() != null) {
// no special scene to setup if we are doing instancing
if (environment.isInstanceRendering()) {
// distortion has to be done with compositor here... we want only one pass on our end!
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
setupMirrorBuffers(environment.getCamera(), dualEyeTex, true);
}
return;
}
leftEyeTexture = (Texture2D) leftViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
rightEyeTexture = (Texture2D) rightViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
leftEyeDepth = (Texture2D) leftViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
rightEyeDepth = (Texture2D) rightViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
// main viewport is either going to be a distortion scene or nothing
// mirroring is handled by copying framebuffers
Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
environment.getApplication().getViewPort().detachScene(spatialIter.next());
}
spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
environment.getApplication().getGuiViewPort().detachScene(spatialIter.next());
}
// only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
if (environment.getVRHardware().getCompositor() == null) {
Node distortionScene = new Node();
Material leftMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
leftMat.setTexture("Texture", leftEyeTexture);
Geometry leftEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, environment.getVRHardware()));
leftEye.setMaterial(leftMat);
distortionScene.attachChild(leftEye);
Material rightMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
rightMat.setTexture("Texture", rightEyeTexture);
Geometry rightEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, environment.getVRHardware()));
rightEye.setMaterial(rightMat);
distortionScene.attachChild(rightEye);
distortionScene.updateGeometricState();
environment.getApplication().getViewPort().attachScene(distortionScene);
//if( useCustomDistortion ) setupFinalFullTexture(app.getViewPort().getCamera());
}
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method setupCamerasAndViews.
private void setupCamerasAndViews() {
if (environment != null) {
if (environment.getApplication() != null) {
// get desired frustrum from original camera
Camera origCam = environment.getCamera();
float fFar = origCam.getFrustumFar();
float fNear = origCam.getFrustumNear();
// if we are using OSVR get the eye info here
if (environment.getVRHardware() instanceof OSVR) {
((OSVR) environment.getVRHardware()).getEyeInfo();
}
// restore frustrum on distortion scene cam, if needed
if (environment.isInstanceRendering()) {
leftCamera = origCam;
} else if (environment.compositorAllowed() == false) {
origCam.setFrustumFar(100f);
origCam.setFrustumNear(1f);
leftCamera = origCam.clone();
prepareCameraSize(origCam, 2f);
} else {
leftCamera = origCam.clone();
}
leftCamera.setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar);
prepareCameraSize(leftCamera, 1f);
if (environment.getVRHardware() != null)
leftCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(leftCamera));
if (!environment.isInstanceRendering()) {
leftViewport = setupViewBuffers(leftCamera, LEFT_VIEW_NAME);
rightCamera = leftCamera.clone();
if (environment.getVRHardware() != null) {
rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
}
rightViewport = setupViewBuffers(rightCamera, RIGHT_VIEW_NAME);
} else {
System.err.println("[VRViewManager] THIS CODE NEED CHANGES !!!");
leftViewport = environment.getApplication().getViewPort();
//leftViewport.attachScene(app.getRootNode());
rightCamera = leftCamera.clone();
if (environment.getVRHardware() != null) {
rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
}
org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0);
//FIXME: [jme-vr] Fix with JMonkey next release
//RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix();
setupFinalFullTexture(environment.getApplication().getViewPort().getCamera());
}
// setup gui
environment.getVRGUIManager().setupGui(leftCamera, rightCamera, leftViewport, rightViewport);
if (environment.getVRHardware() != null) {
// call these to cache the results internally
environment.getVRHardware().getHMDMatrixPoseLeftEye();
environment.getVRHardware().getHMDMatrixPoseRightEye();
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
Aggregations