use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRGuiManager method setupGui.
/**
* Set up the GUI.
* @param leftcam the left eye camera.
* @param rightcam the right eye camera.
* @param left the left eye viewport.
* @param right the right eye viewport.
*/
protected void setupGui(Camera leftcam, Camera rightcam, ViewPort left, ViewPort right) {
if (environment != null) {
if (environment.hasTraditionalGUIOverlay()) {
camLeft = leftcam;
camRight = rightcam;
Spatial guiScene = getGuiQuad(camLeft);
left.attachScene(guiScene);
if (right != null)
right.attachScene(guiScene);
setPositioningMode(posMode);
}
} else {
throw new IllegalStateException("VR GUI manager is not attached to any environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRGuiManager method getGuiQuad.
/**
* Create a GUI quad for the given camera.
* @param sourceCam the camera
* @return a GUI quad for the given camera.
*/
private Spatial getGuiQuad(Camera sourceCam) {
if (environment != null) {
if (environment.getApplication() != null) {
if (guiQuadNode == null) {
Vector2f guiCanvasSize = getCanvasSize();
Camera offCamera = sourceCam.clone();
offCamera.setParallelProjection(true);
offCamera.setLocation(Vector3f.ZERO);
offCamera.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
offView = environment.getApplication().getRenderManager().createPreView("GUI View", offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.BlackNoAlpha);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer((int) guiCanvasSize.x, (int) guiCanvasSize.y, 1);
//setup framebuffer's texture
guiTexture = new Texture2D((int) guiCanvasSize.x, (int) guiCanvasSize.y, Format.RGBA8);
guiTexture.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
guiTexture.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorTexture(guiTexture);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
Iterator<Spatial> spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
offView.attachScene(spatialIter.next());
}
if (useCurvedSurface) {
guiQuad = (Geometry) environment.getApplication().getAssetManager().loadModel("Common/Util/gui_mesh.j3o");
} else {
guiQuad = new Geometry("guiQuad", new CenterQuad(1f, 1f));
}
Material mat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/GuiOverlay.j3md");
mat.getAdditionalRenderState().setDepthTest(!overdraw);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
mat.getAdditionalRenderState().setDepthWrite(false);
mat.setTexture("ColorMap", guiTexture);
guiQuad.setQueueBucket(Bucket.Translucent);
guiQuad.setMaterial(mat);
guiQuadNode = new Node("gui-quad-node");
guiQuadNode.setQueueBucket(Bucket.Translucent);
guiQuadNode.attachChild(guiQuad);
}
return guiQuadNode;
} else {
throw new IllegalStateException("VR GUI manager underlying environment is not attached to any application.");
}
} else {
throw new IllegalStateException("VR GUI manager is not attached to any environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method postRender.
@Override
public void postRender() {
if (environment != null) {
if (environment.isInVR()) {
VRAPI api = environment.getVRHardware();
if (api.getCompositor() != null) {
// using the compositor...
int errl = 0, errr = 0;
if (environment.isInstanceRendering()) {
if (leftTextureType.handle == -1 || leftTextureType.handle != getFullTexId()) {
leftTextureType.handle = getFullTexId();
if (leftTextureType.handle != -1) {
leftTextureType.write();
}
} else {
if (api instanceof OpenVR) {
int submitFlag = JOpenVRLibrary.EVRSubmitFlags.EVRSubmitFlags_Submit_Default;
errr = ((OpenVR) api).getCompositor().Submit.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Right, leftTextureType, rightTextureBounds, submitFlag);
errl = ((OpenVR) api).getCompositor().Submit.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Left, leftTextureType, leftTextureBounds, submitFlag);
}
}
} else if (leftTextureType.handle == -1 || rightTextureType.handle == -1 || leftTextureType.handle != getLeftTexId() || rightTextureType.handle != getRightTexId()) {
leftTextureType.handle = getLeftTexId();
if (leftTextureType.handle != -1) {
logger.fine("Writing Left texture to native memory at " + leftTextureType.getPointer());
leftTextureType.write();
}
rightTextureType.handle = getRightTexId();
if (rightTextureType.handle != -1) {
logger.fine("Writing Right texture to native memory at " + leftTextureType.getPointer());
rightTextureType.write();
}
} else {
if (api instanceof OpenVR) {
errl = ((OpenVR) api).getCompositor().Submit.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Left, leftTextureType, null, JOpenVRLibrary.EVRSubmitFlags.EVRSubmitFlags_Submit_Default);
errr = ((OpenVR) api).getCompositor().Submit.apply(JOpenVRLibrary.EVREye.EVREye_Eye_Right, rightTextureType, null, JOpenVRLibrary.EVRSubmitFlags.EVRSubmitFlags_Submit_Default);
} else {
}
}
if (errl != 0) {
logger.severe("Submit to left compositor error: " + OpenVRUtil.getEVRCompositorErrorString(errl) + " (" + Integer.toString(errl) + ")");
logger.severe(" Texture color space: " + OpenVRUtil.getEColorSpaceString(leftTextureType.eColorSpace));
logger.severe(" Texture type: " + OpenVRUtil.getETextureTypeString(leftTextureType.eType));
logger.severe(" Texture handle: " + leftTextureType.handle);
logger.severe(" Left eye texture " + leftEyeTexture.getName() + " (" + leftEyeTexture.getImage().getId() + ")");
logger.severe(" Type: " + leftEyeTexture.getType());
logger.severe(" Size: " + leftEyeTexture.getImage().getWidth() + "x" + leftEyeTexture.getImage().getHeight());
logger.severe(" Image depth: " + leftEyeTexture.getImage().getDepth());
logger.severe(" Image format: " + leftEyeTexture.getImage().getFormat());
logger.severe(" Image color space: " + leftEyeTexture.getImage().getColorSpace());
}
if (errr != 0) {
logger.severe("Submit to right compositor error: " + OpenVRUtil.getEVRCompositorErrorString(errl) + " (" + Integer.toString(errl) + ")");
logger.severe(" Texture color space: " + OpenVRUtil.getEColorSpaceString(rightTextureType.eColorSpace));
logger.severe(" Texture type: " + OpenVRUtil.getETextureTypeString(rightTextureType.eType));
logger.severe(" Texture handle: " + rightTextureType.handle);
logger.severe(" Right eye texture " + rightEyeTexture.getName() + " (" + rightEyeTexture.getImage().getId() + ")");
logger.severe(" Type: " + rightEyeTexture.getType());
logger.severe(" Size: " + rightEyeTexture.getImage().getWidth() + "x" + rightEyeTexture.getImage().getHeight());
logger.severe(" Image depth: " + rightEyeTexture.getImage().getDepth());
logger.severe(" Image format: " + rightEyeTexture.getImage().getFormat());
logger.severe(" Image color space: " + rightEyeTexture.getImage().getColorSpace());
}
}
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method setupFinalFullTexture.
private void setupFinalFullTexture(Camera cam) {
if (environment != null) {
if (environment.getApplication() != null) {
// create offscreen framebuffer
FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
//offBuffer.setSrgb(true);
//setup framebuffer's texture
dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);
logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")");
logger.config(" Type: " + dualEyeTex.getType());
logger.config(" Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight());
logger.config(" Image depth: " + dualEyeTex.getImage().getDepth());
logger.config(" Image format: " + dualEyeTex.getImage().getFormat());
logger.config(" Image color space: " + dualEyeTex.getImage().getColorSpace());
//setup framebuffer to use texture
out.setDepthBuffer(Image.Format.Depth);
out.setColorTexture(dualEyeTex);
ViewPort viewPort = environment.getApplication().getViewPort();
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
viewPort.setOutputFrameBuffer(out);
} 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