Well… When I run TestMultiViewsFilter, things seem to work great. No contest. But it’s not in my game.
But I do things very differently.
For starters, TestMultiViewsFilter clone the main camera and apply a filter to it. I don’t do that. I make a new camera and I think that’s why I’m having a totally different result.
I do things this way because the object in the viewports is NOT in the main view. All objects in the main game view are only colored dots representing stars and that wouldn’t work with a cloned camera. So I build a scene with a sphere with some material and stick a camera close to it and apply this to a viewport.
Here’s the complete class. This should be easier to understand than my ramblings.
[java]
package com.madjack.games.sc.scenes;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.post.filters.FogFilter;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.texture.Texture;
import com.madjack.games.sc.Base;
import com.madjack.games.sc.GameLogic;
import com.madjack.games.sc.galaxy.Galaxy;
import com.madjack.games.sc.galaxy.spacebodies.SolarSystem;
import com.madjack.games.sc.galaxy.spacebodies.Star;
import com.madjack.games.sc.utils.GameManagers;
import com.madjack.games.sc.utils.GameNode;
/**
*
-
@author MadJack
/
public class PreviewScene extends Base {
private ViewPort panelViewPort;
private Camera panelCam;
private GameNode panelNode;
private static GameLogic gProc;
private static GameManagers gMgrs;
private String viewportName;
private ObjectPreviewScene objectPreviewScene;
private boolean isRotatable = true;
private PointLight pointLight;
Object objectInView;
/
- Constructor
-
@param gProcessor, GameProcessor used to load assets
/
public PreviewScene(GameLogic gProc, GameManagers gMgrs) {
if (gProc == null || gMgrs == null) {
throw new IllegalStateException("GameProcessor and/or GameManagers not initialized.");
}
initPreviewScene();
this.gProc = gProc;
this.gMgrs = gMgrs;
}
/
- PreviewScene
*
-
@param gProc GameProcessor
-
@param gMgrs GameManagers
-
@param viewportName Name of the viewport to create
-
@param pickedObject Object we want a preview of
*
/
public PreviewScene(GameLogic gProc, GameManagers gMgrs, String viewportName, Object pickedObject) {
this(gProc, gMgrs);
initPreviewScene();
makePreviewScene(viewportName, pickedObject);
}
/
- PreviewScene
*
-
@param viewportName Name of the viewport to create
-
@param pickedObject Object we want a preview of
*
- NOTE: if either GameProcessor or GameManagers haven’t been set before
- the method will throw an IllegalStateException.
*
/
public PreviewScene(String viewportName, Object pickedObject) {
if (gProc == null || gMgrs == null) {
throw new IllegalStateException("GameProcessor and/or GameManagers not initialized.");
}
initPreviewScene();
makePreviewScene(viewportName, pickedObject);
}
private void initPreviewScene() {
objectPreviewScene = new ObjectPreviewScene(gMgrs);
}
/
- makePreviewScene
-
@param viewportName Name of the ViewPort
-
@param pickedObject Object selected to make a preview of
*
- makePreviewScene will setup the PreviewScene with the main selected object
- and all subobjects if applicable (moons for a planet).
/
final public void makePreviewScene(String viewportName, Object pickedObject) {
System.out.println("…Making viewport named: " + viewportName);
this.objectInView = pickedObject;
this.viewportName = viewportName;
setPanelCamera(viewportName);
panelNode = objectPreviewScene.getScene(objectInView);
if (objectInView instanceof Star) {
panelCam.setLocation(new Vector3f(10, 0, 0));
panelCam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
isRotatable = true;
pointLight = new PointLight();
pointLight.setColor(((Star) objectInView).getColor());
pointLight.setPosition(panelCam.getLocation());
pointLight.setRadius(50f);
} else if (objectInView instanceof Galaxy) {
isRotatable = false;
} else if (objectInView instanceof SolarSystem) {
isRotatable = false;
}
setViewPort(viewportName);
attachNewSceneToViewport(panelNode);
setViewPortEnabled(true);
setPostProcess();
}
/
- Deletes named viewport
-
@param viewPortName Name of the viewport to remove.
/
public void deleteViewPort(String viewPortName) {
System.out.println("…Destroyed viewport: " + viewPortName);
gMgrs.getRenderManager().removeMainView(viewPortName);
panelViewPort = null;
}
/
- Removes all children from preview node.
/
public void deleteAll() {
panelNode.detachAllChildren();
isRotatable = false;
}
/
- Deletes default (rightPanel) viewport
/
void deleteViewPort() {
deleteViewPort(panelViewPort.getName());
}
/
- updatePreviewScene
- updates the preview scene.
-
@param pickedObject Object selected.
*/
final void updatePreviewScene(Object pickedObject) {
// don’t process if same object
if (objectInView == pickedObject) {
return;
}
objectInView = pickedObject;
changeObjectParams();
}
private void changeObjectParams() {
System.out.println("…Updating viewport named: " + viewportName);
if (viewportName.equals(“listPreview”)) {
// System.out.println("…Object to change to -> " + objectInView);
panelNode = objectPreviewScene.getScene(objectInView);
isRotatable = true;
attachNewSceneToViewport(panelNode);
} else if (viewportName.equals(“rightPreview”)) {
// we’re in the right preview viewport; update star there
if (objectInView instanceof Star) {
retextureStar((Star) objectInView);
}
}
// System.out.println(“Fully updated viewport.n”);
}
private void retextureStar(Star star) {
Texture texture = gMgrs.getAssetManager().loadTexture(
“Textures/Stars/Class”
- star.getSpectralClass()
- ".png");
Material material = gMgrs.getAssetManager().loadMaterial(
"Materials/Stars/Class"
- star.getSpectralClass()
- "Star.j3m");
ColorRGBA color = star.getColor();
objectPreviewScene.retextureBody(texture, material, color);
}
/*
- getPanelNode returns the GameNode that is attached to the viewport
-
@return GameNode
/
GameNode getPanelNode() {
return panelNode;
}
/
- setViewPort
-
@param previewName String, name of the preview
*
- Sets basic viewport properties.
/
private void setViewPort(String viewportName) {
panelViewPort = gMgrs.getRenderManager().createMainView(viewportName, panelCam);
panelViewPort.setBackgroundColor(ColorRGBA.DarkGray);
if (viewportName.equals("listPreview")) {
setListPreviewSceneParams();
} else if (viewportName.equals("rightPreview")) {
setRightPreviewSceneParams();
}
}
private void setListPreviewSceneParams() {
// set viewport params
setViewPortAreas(2.46f, 3.46f, 2.76f, 3.76f);
setViewPortCamSize(165, 165);
setCameraLocation(new Vector3f(10, 0, 0));
setCameraLookAt(Vector3f.ZERO);
}
private void setRightPreviewSceneParams() {
setViewPortAreas(5.23f, 6.33f, 0.56f, 1.66f);
setViewPortCamSize(200, 200);
setCameraLocation(new Vector3f(10, 0, 0));
setCameraLookAt(Vector3f.ZERO);
}
/
- attachNewSceneToViewport
-
@param noteToAttach
-
new node to attach to viewport<br />
/
private void attachNewSceneToViewport(GameNode nodeToAttach) {
panelViewPort.clearScenes();
panelViewPort.attachScene(nodeToAttach);
System.out.println("…Attached scene on: " + panelViewPort);
}
private void setPostProcess() {
FilterPostProcessor fpp = new FilterPostProcessor(globalAssetManager);
FogFilter ff = new FogFilter(ColorRGBA.Magenta, .25f, .75f);
BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
bf.setExposurePower(10f);
// fpp.addFilter(bf);
fpp.addFilter(ff);
panelViewPort.addProcessor(fpp);
System.out.println("…PostProcess set on: " + panelViewPort);
}
/
- setViewPortEnabled
-
@param state, boolean state to set the viewport at.
/
public void setViewPortEnabled(boolean state) {
if (panelViewPort.getScenes().isEmpty()) {
throw new IllegalStateException("Viewport does not have a scene attached.");
}
panelViewPort.setEnabled(state);
}
/
- isViewPortExist()
-
@return Returns viewport’s state
/
public boolean isViewPortExist() {
if (panelViewPort == null) {
return false;
} else {
return true;
}
}
private void setPanelCamera(String viewportName) {
panelCam = new Camera(165, 165);
panelCam.setName(viewportName);
panelCam.setFrustumPerspective(90.0f, 1f, 1f, 75f);
}
protected void setCameraLocation(Vector3f location) {
panelCam.setLocation(location);
}
protected void setCameraLookAt(Vector3f lookAt) {
panelCam.lookAt(lookAt, Vector3f.UNIT_Y);
}
/
- setViewPortAreas
-
@param float left
-
@param float right
-
@param float bottom
-
@param float top
*
- Used to set the viewport areas
/
private void setViewPortAreas(float left, float right, float bottom, float top) {
panelCam.setViewPort(left, right, bottom, top);
}
/
- setViewPortCamSize
-
@param int width
-
@param int height
*
- Height and width of the viewport camera.
/
private void setViewPortCamSize(int width, int height) {
panelCam.resize(width, height, true);
}
/
- getPreviewName
-
@return String PreviewName
/
String getPreviewName() {
return viewportName;
}
/
- isRotatable
-
@return true if the preview is stand-alone and not an image.
*/
boolean isRotating() {
return isRotatable;
}
}
[/java]
If you have suggestions or fixes I’ll gladly take them.