Rendering Order Question [Solved]

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 :confused:

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();
        }
    }
    
}
1 Like

Bump:
Anyone know whats wrong here? I really wanna get this problem worked out :thumbsup:

How do you know that what you are viewing can be seen by this camera?

You may want to clone the regular camera so that you at least have the same setup… then you probably want to tweak the frustum near/far planes so that your near objects aren’t clipped and so on.

Essentially, experiment with placing things in your post scene until you can see them. I’d pick a blue box personally… as it’s easy to verify that it works.

I tested the code pasted above (using Jaime in place of humanTestModel) on JME 3.1. It ran without any unusual diagnostics, and the red figure was rendered in front of the blue cube. I assume that’s what you want.

Perhaps the issue has to do with your test model. Try using Jaime in its place, as I did.

Finally got it guys.

First off sorry sgold about the second main file I commented out the wrong line :sweat_smile:
You would not have been able to see it other wise.

Pspeed it was indeed the camera’s fault. I just tried to make a totally new camera with just the width and height arguments thinking I totally knew what I was doing when I didn’t. :wink: Simply cloning the camera off the start to copy all the default settings and then moving the clone around/ changing the near/far frustum made things show up as expected. Before when I didn’t clone the camera I could sometimes notice things super super super zoomed in and only for very precise locations/rotations. That’s when I knew what I messed up. I also had to turn on setClearDepth().

Anyways guys thanks for being patient with me and helping me get this cool feature implemented. :slight_smile:

2 Likes