Loading a .obj model into a DebugGameState

Hi folks,



I've been trying to load a .obj file (along with its .mtl) into jME.

Its seems as if the model loads (due to the output),

however there is "nothing displaying" on the screen.

I think I might be missing something in my code (I haven't used jME in a while)



here is the code -


public class ModelTest {
   public static void main(String[] args) throws Exception {
      // Instantiate StandardGame
      StandardGame game = new StandardGame("A Simple Test");
      // Show settings screen
      if (GameSettingsPanel.prompt(game.getSettings())) {
         // Start StandardGame, it will block until it has initialized successfully, then return
         game.start();

         // Create a DebugGameState - has all the built-in features that SimpleGame provides
         // NOTE: for a distributable game implementation you'll want to use something like
         // BasicGameState instead and provide control features yourself.
         DebugGameState state = new DebugGameState();
         // Put our box in it
         Node r = new Node("node");
         ObjToJme converter=new ObjToJme();
         try {
            URL objFile=ModelTest.class.getClassLoader().getResource("jmetest/data/model/baseship.obj");
            if(objFile == null) System.out.println("NULL!");
            converter.setProperty("mtllib", objFile);
            ByteArrayOutputStream BO=new ByteArrayOutputStream();
            converter.convert(objFile.openStream(), BO);
            r=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            r.setLocalScale(1.0f);
         } catch (IOException e) {
            e.printStackTrace();
         }
         r.setModelBound(new BoundingSphere());
         r.updateModelBound();
         r.updateRenderState();
         GameStateManager.getInstance().attachChild(state);
         // Activate the game state
         state.setActive(true);
      }
   }
}



the output is :

Mar 18, 2009 7:56:41 PM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
Mar 18, 2009 7:56:42 PM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Mar 18, 2009 7:56:45 PM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  1024H: 768
Mar 18, 2009 7:56:48 PM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
Mar 18, 2009 7:56:49 PM com.jmex.audio.openal.OpenALSystem setupSourcePool
INFO: max source channels: 64
Mar 18, 2009 7:56:49 PM com.jmex.game.state.GameStateManager create
INFO: Created GameStateManager
Mar 18, 2009 7:56:49 PM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
Mar 18, 2009 7:56:49 PM com.jme.scene.Node <init>
INFO: Node created.
Mar 18, 2009 7:56:50 PM com.jme.scene.Node <init>
INFO: Node created.
Mar 18, 2009 7:56:50 PM com.jme.scene.Node attachChild
INFO: Child (Text) attached to this node (TextNode)
Mar 18, 2009 7:56:50 PM com.jme.scene.Node <init>
INFO: Node created.
Mar 18, 2009 7:56:51 PM com.jme.scene.Node <init>
INFO: Node created.
Mar 18, 2009 7:56:51 PM com.jmex.model.converters.ObjToJme processLine
INFO: Object:dodecahedron1
Mar 18, 2009 7:56:52 PM com.jme.scene.Node <init>
INFO: Node created.
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 862 new: 862
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 647 new: 647
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 75 new: 75
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 903 new: 903
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 140 new: 140
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 530 new: 530
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 900 new: 900
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:52 PM com.jme.util.geom.GeometryTool minimizeVerts
INFO: batch: dodecahedron1: Batch 0 old: 485 new: 485
Mar 18, 2009 7:56:52 PM com.jme.scene.Node attachChild
INFO: Child (dodecahedron1) attached to this node (obj file)
Mar 18, 2009 7:56:53 PM com.jme.scene.Node <init>
INFO: Node created.

its not enough to just create a Node, you need to attach it to the Scene's RootNode so it gets rendered :slight_smile:



try: state.getRootNode().attachChild®;

You may also look into lighting your scene after you actually get the object attached to the scenegraph. I know I am new too but this was a mistake that I made first time around when loading a model.  8)