Is the process to render to texture done in another thread ?
I am trying to move the camera from an rendered texture, from another control, it simple dont move…
If I try to do the updateGeometricState or updateLogicalState it gets syncronized error or stackoverflow or do nothing as in the code / test case above :
TestRenderToTexture :
package mygame;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
public class TestRenderToTexture extends SimpleApplication {
public Spatial offBox;
private ViewPort offView;
TestRenderToTextureMoveCam test;
public static void main(String[] args){
TestRenderToTexture app = new TestRenderToTexture();
app.start();
}
public Texture setupOffscreenView(){
Camera offCamera = new Camera(512, 512);
offView = renderManager.createPreView("Offscreen View", offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.DarkGray);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
//setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer's texture
Texture2D offTex = new Texture2D(512, 512, Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.Trilinear);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorTexture(offTex);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
offBox = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.j3o");
offBox.scale(0.3f);
//Box boxMesh = new Box(Vector3f.ZERO, 1,1,1);
//Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//offBox = new Geometry("box", boxMesh);
//offBox.setMaterial(material);
// attach the scene to the viewport to be rendered
offView.attachScene(offBox);
return offTex;
}
@Override public void simpleInitApp() {
cam.setLocation(new Vector3f(3, 3, 3));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
//setup main scene
Geometry quad = new Geometry("box", new Box(Vector3f.ZERO, 1,1,1));
Texture offTex = setupOffscreenView();
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", offTex);
quad.setMaterial(mat);
rootNode.attachChild(quad);
}
public void moveCamera(float x, float y, float z) {
offView.getCamera().getLocation().addLocal(new Vector3f(x,y,z));
}
@Override public void simpleUpdate(float tpf){
if (offView.isEnabled()) {
//offView.getCamera().setLocation(new Vector3f(offView.getCamera().getLocation().x+0.1f*tpf,offView.getCamera().getLocation().y,offView.getCamera().getLocation().z));
offBox.updateLogicalState(tpf);
offBox.updateGeometricState();
if(test==null) test = new TestRenderToTextureMoveCam(this);
}
}
}
TestRenderToTextureMoveCam
package mygame;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import java.io.IOException;
public class TestRenderToTextureMoveCam extends AbstractControl {
TestRenderToTexture test;
public TestRenderToTextureMoveCam(TestRenderToTexture test) {
this.test = test;
spatial = new Node();
spatial.addControl(this);
}
@Override protected void controlUpdate(float tpf) {
test.moveCamera(0.5f*tpf, 0, 0);
test.offBox.updateGeometricState();
test.offBox.updateLogicalState(tpf);
}
@Override protected void controlRender(RenderManager rm, ViewPort vp) { }
}
How to make the camera movement to work ?