I am not getting an error anymore about updating. I had the spatial.updateGeometricState() in the wrong spot due to a misunderstanding. I have taken your advice and moved the spatial updateGeometricState() inside the render method. However, unfortunatly nothing is showing up still
Here are the two classes with the AppState one updated. It only renders a blue cube. I also know that its not a mesh/object problem because when I attach it to the root node the object appears fine.
Main class:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
public static PostViewAppState postViewAppState = new PostViewAppState();
public static Camera postViewCamera;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
//Camera direction 0 0 -1
geom.setLocalTranslation(0, 0, -10);
stateManager.attach(postViewAppState);
postViewCamera = new Camera(getCamera().getWidth(),getCamera().getHeight());
ViewPort viewPortArm = renderManager.createPostView("viewPortArm", postViewCamera);
Material playerMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
playerMat.setColor("Color", ColorRGBA.Red);
Spatial playerModel = getAssetManager().loadModel(
"Models/humanTestModel.j3o");
playerModel.setMaterial(playerMat);
//Camera direction 0 0 -1
playerModel.setLocalTranslation(0, 0, -5);
viewPortArm.setBackgroundColor(new ColorRGBA(0,0,0,0));
viewPortArm.attachScene(playerModel);
playerModel.setLocalTranslation(0, 0, 0);
postViewAppState.addSpatial(playerModel);
//Doing this makes the human appear in front of the blue cube. I know because of that it does not have anything to do with the object itself or the material.
//viewPortArm.attachScene(playerModel);
rootNode.attachChild(geom);
rootNode.attachChild(playerModel);
System.err.println(getCamera().getDirection().toString());
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
}
}
PostViewAppState class (updated)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mygame;
import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
import java.util.ArrayList;
/**
*
* @author Cats
*/
public class PostViewAppState extends AbstractAppState {
private final static ArrayList<Spatial> addedSpatials = new ArrayList<>();
public ArrayList<Spatial> getSpatials() {
return addedSpatials;
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
}
@Override
public void update(float tpf) {
for (Spatial spatial : addedSpatials) {
spatial.updateLogicalState(tpf);
}
}
@Override
public void cleanup() {
super.cleanup();
//TODO: clean up what you initialized in the initialize method,
//e.g. remove all spatials from rootNode
//this is called on the OpenGL thread after the AppState has been detached
}
public void addSpatial(Spatial spatial) {
addedSpatials.add(spatial);
}
@Override
public void render(RenderManager rm) {
super.render(rm);
for (Spatial spatial : addedSpatials) {
spatial.updateGeometricState();
}
}
}