Jme model not showing + problems with obj file

hello





I used ModelLoader.java for converting from a .obj file to a .jme file

this is the code I'm using to let it show, probably I'm forgetting more then one thing  :roll:



I just get a black screen and thats it , no errors except this one and the file path is valid I think, as you can see in my code I do a printout and it seems right



INFO: Node created.

8-mei-2008 15:22:31 com.jme.scene.Node attachChild

INFO: Child (obj file) attached to this node (null)




package be.khleuven.dhondtjim;


import com.jme.app.*;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;
import com.jme.util.*;
import com.jmex.game.*;
import com.jmex.game.state.*;
import com.jmex.editors.swing.settings.*;
import com.jmex.physics.*;
import com.jmex.physics.util.states.*;
import com.jmex.physics.impl.ode.OdePhysicsSpace;

import java.util.concurrent.*;
public class StartRaceGame extends Node {
   
   StandardGame game;
   
   
      
      
   

   public StartRaceGame() {
      game = new StandardGame("VGO racing");
      
      
      game.getSettings().setStencilBits(8);
      try {
         GameSettingsPanel.prompt(game.getSettings());
      } catch (Exception e) {
         System.exit(-1);
      }
      game.start();
   }
   

   public static void main(String[] args) {
      Util util=new Util();
      
      util.loadModel("SpeedyCar.jme");
      new StartRaceGame();
   }
}



this is the code for my util class

/*
 * Copyright (c) 2005-2007 jME Physics 2
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 *  * Neither the name of 'jME Physics 2' nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package be.khleuven.dhondtjim;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import com.jme.bounding.BoundingBox;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;

/**
 * Helper class for loading models and other stuff. Currently only loads JME
 * binary models, but it's easily customizable for loading other types.
 *
 * @author Erick B Passos
 */
public class Util {

    // So JME can find the model textures easily.
    private static URL resourceSearchPath;

    static {
        resourceSearchPath = Util.class.getResource( "/be/khleuven/dhondtjim/SpeedyCar/" );
        System.out.println(resourceSearchPath);
        try {
            ResourceLocatorTool.addResourceLocator( ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator( resourceSearchPath ) );
        } catch ( URISyntaxException e1 ) {
            e1.printStackTrace();
        }
    }

    /**
     * Loads a jme binary model from file, creating a bounding box for it.
     *
     * @param path to jme file
     * @return loaded model, null on error
     */
    public static Node loadModel( String path ) {
        try {
            URL modelURL = new URL( resourceSearchPath, path );
            BufferedInputStream stream = new BufferedInputStream( modelURL.openStream() );
            Node node = new Node();
            node.attachChild( (Spatial) BinaryImporter.getInstance().load( stream ) );
            node.setModelBound( new BoundingBox() );
            node.updateModelBound();
            return node;
        } catch ( IOException e ) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * Helper method to apply a ZBufferState to a node.
     *
     * @param node where to apply to
     */
    public static void applyZBuffer( Node node ) {
        ZBufferState zbuf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        zbuf.setWritable( false );
        zbuf.setEnabled( true );
        zbuf.setFunction( ZBufferState.CF_LEQUAL );
        node.setRenderState(zbuf);
   }
}



anyone can help me with this?

also have another problem, when I use the hellomodelloading class I can display the .obj file but not move it with my mouse to for example see the back of my 3D model  :? 

thanks in advance

hmm ok, you have to start() StandardGame, before you can create your Gamestate.

Well, you probably forgot to post the error you say you had. The code seems fine, but I have not tried it… There is an example about loading jme models in ModelLoader too, so you can check if there are significant differences between that and your way of doing it.

mhh i don't see where you attach the loaded model to the scenegraph.



You need to create a GameState and attach the node returned from loadModel() to its rootNode.



Its best to check out the different Tests which use StandardGame in the jmetest package.

tryed to add a gamestate to my program but now I get a null pointer exception  :smiley:



this is my main class :

package be.khleuven.dhondtjim;


import com.jme.app.*;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;
import com.jme.util.*;
import com.jmex.game.*;
import com.jmex.game.state.*;
import com.jmex.editors.swing.settings.*;
import com.jmex.physics.*;
import com.jmex.physics.util.states.*;
import com.jmex.physics.impl.ode.OdePhysicsSpace;

import java.util.concurrent.*;
public class StartRaceGame extends Node {
   
   StandardGame game;
   static GameState gamest;
      
      
   

   public StartRaceGame() {
      game = new StandardGame("VGO racing");
      
      
      game.getSettings().setStencilBits(8);
      try {
         GameSettingsPanel.prompt(game.getSettings());
      } catch (Exception e) {
         System.exit(-1);
      }
      game.start();
   }
   
   public static void laadGameState()
   {
      gamest=new GameState();
      GameStateManager.getInstance().attachChild(gamest);
      gamest.setActive(true);
   }
   public static void main(String[] args) {
      laadGameState();
      
   }

}



this is my Gamestate class:

package be.khleuven.dhondtjim;



import java.util.HashMap;
import java.io.*;
import java.nio.FloatBuffer;

import jmetest.renderer.TestEnvMap;


import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.input.ChaseCamera;
import com.jme.input.InputHandler;
import com.jme.input.*;
import com.jme.input.action.*;
import com.jme.input.thirdperson.ThirdPersonMouseLook;
import com.jme.light.DirectionalLight;
import com.jme.math.Plane;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.renderer.pass.RenderPass;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Quad;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.FogState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jmex.effects.water.WaterRenderPass;
import com.jmex.game.state.*;
import com.jmex.physics.*;
import com.jmex.physics.impl.ode.OdePhysicsSpace;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.*;
import com.jmex.physics.util.states.*;
import com.jme.bounding.*;
import com.jme.scene.*;
import com.jme.util.TextureManager;
import com.jme.math.*;
import com.jmex.physics.contact.*;
import org.odejava.*;

public class GameState extends DebugGameState {

   
private Car car;
private ChaseCamera chaser;
   
   
   
   public GameState() {
      super(true);
      
         createCar();
   }
   
   private void initGame() {
      createCar();
      // TODO Auto-generated method stub
      
   }

   public void update(float f) {
      super.update(f);
      

   }
   

   
   public void createCar() {
      
      car = new Car();
      car.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      car.setLocalTranslation(0,8,0);
      this.getRootNode().attachChild(car);
   }
   

   
   
   
   
}



and this is my car class:

package be.khleuven.dhondtjim;



import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.Joint;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.PhysicsUpdateCallback;
import com.jmex.physics.RotationalJointAxis;
import com.jmex.physics.TranslationalJointAxis;
import com.jmex.physics.contact.ContactCallback;
import com.jmex.physics.contact.ContactHandlingDetails;
import com.jmex.physics.contact.MutableContactInfo;
import com.jmex.physics.contact.PendingContact;
import com.jmex.physics.material.Material;
import com.jmex.audio.*;
import java.io.*;
import java.net.*;

public class Car extends Node {
   
   
   PhysicsSpace ps;
   
   public DynamicPhysicsNode carmodel;
   
   
   
   int state;
   

   public Car()
   {
      this.ps = ps;
      this.loadCarModel();
   }
      
   
   private void loadCarModel() {
      carmodel = ps.createDynamicNode();
      Node chassisModel = Util.loadModel("SpeedyCar.jme");
      chassisModel.setLocalScale(1);
      carmodel.attachChild(chassisModel);
      carmodel.updateRenderState();
      carmodel.setMaterial(Material.IRON);
      
      this.attachChild(carmodel);

      
   }
   
   
   private void coast(float f) {

   }

   public void setLocalTranslation(Vector3f v) {
      this.carmodel.getLocalTranslation().set(v);
   }
}



don't know what I'm doing wrong this is the error :

9-mei-2008 10:49:32 com.jme.scene.Node <init>
INFO: Node created.
9-mei-2008 10:49:32 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Exception in thread "main" java.lang.NullPointerException
at com.jmex.game.state.BasicGameState.<init>(BasicGameState.java:59)
at com.jmex.game.state.TextGameState.<init>(TextGameState.java:57)
at com.jmex.game.state.StatisticsGameState.<init>(StatisticsGameState.java:44)
at com.jmex.game.state.DebugGameState.<init>(DebugGameState.java:79)
at be.khleuven.dhondtjim.GameState.<init>(GameState.java:58)
at be.khleuven.dhondtjim.StartRaceGame.laadGameState(StartRaceGame.java:41)
at be.khleuven.dhondtjim.StartRaceGame.main(StartRaceGame.java:46)

You need to instantiate StandardGame before creating any Gamestates.

Try something like this:


public class StartRaceGame extends Node {
   
   StandardGame game;
   static GameState gamest;
   
   public static void laadGameState()
   {
      game = new StandardGame("VGO racing");
      game.getSettings().setStencilBits(8);
      try {
         GameSettingsPanel.prompt(game.getSettings());
      } catch (Exception e) {
         System.exit(-1);
      }

      gamest=new GameState();
      GameStateManager.getInstance().attachChild(gamest);
      gamest.setActive(true);

      game.start();
   }

   public static void main(String[] args) {
      laadGameState();
   }

}

Well try-ed it and still get the same errors, I think something is wrong in my gamestate class, it keeps pointing out to the constructor of that class that something is wrong  :?

started my gamestate like you proposed and now I get the option menu of Jmonkey and it loads a black screen and then I get this errors:



11-mei-2008 16:51:10 com.jme.input.joystick.DummyJoystickInput <init>

INFO: Joystick support is disabled

11-mei-2008 16:51:10 com.jme.system.lwjgl.LWJGLDisplaySystem <init>

INFO: LWJGL Display System created.

11-mei-2008 16:51:11 com.jme.renderer.lwjgl.LWJGLRenderer <init>

INFO: LWJGLRenderer created. W:  640H: 480

11-mei-2008 16:51:11 com.jme.renderer.AbstractCamera <init>

INFO: Camera created.

11-mei-2008 16:51:11 com.jmex.audio.openal.OpenALSystem setupSourcePool

INFO: max source channels: 64

11-mei-2008 16:51:11 com.jmex.game.state.GameStateManager create

INFO: Created GameStateManager

11-mei-2008 16:51:11 com.jme.util.lwjgl.LWJGLTimer <init>

INFO: Timer resolution: 1000 ticks per second

11-mei-2008 16:51:11 com.jme.scene.Node <init>

INFO: Node created.

11-mei-2008 16:51:11 com.jme.scene.Node <init>

INFO: Node created.

11-mei-2008 16:51:11 com.jme.scene.Node attachChild

INFO: Child (Text) attached to this node (TextNode)

11-mei-2008 16:51:11 com.jme.scene.Node <init>

INFO: Node created.

11-mei-2008 16:51:11 com.jme.scene.Node <init>

INFO: Node created.

Exception in thread "main" java.lang.NullPointerException

at be.khleuven.dhondtjim.Car.loadCarModel(Car.java:44)

at be.khleuven.dhondtjim.Car.<init>(Car.java:39)

at be.khleuven.dhondtjim.GameState.createCar(GameState.java:75)

at be.khleuven.dhondtjim.GameState.initGame(GameState.java:62)

at be.khleuven.dhondtjim.GameState.<init>(GameState.java:57)

at be.khleuven.dhondtjim.StartRaceGame.laadGameState(StartRaceGame.java:37)

at be.khleuven.dhondtjim.StartRaceGame.main(StartRaceGame.java:45)

this are the changes I made in my main class where I load everything


package be.khleuven.dhondtjim;


import com.jme.app.*;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;
import com.jme.util.*;
import com.jmex.game.*;
import com.jmex.game.state.*;
import com.jmex.editors.swing.settings.*;
import com.jmex.physics.*;
import com.jmex.physics.util.states.*;
import com.jmex.physics.impl.ode.OdePhysicsSpace;

import java.util.concurrent.*;
public class StartRaceGame extends Node {
   
   private static StandardGame game;
   private static GameState gamest;
      
      
   

   public static void laadGameState() {
      game = new StandardGame("VGO racing");
      
      
      game.getSettings().setStencilBits(8);
      try {
         GameSettingsPanel.prompt(game.getSettings());
      } catch (Exception e) {
         System.exit(-1);
      }
      //this is changed
                game.start();
      gamest=new GameState();
      GameStateManager.getInstance().attachChild(gamest);
      gamest.setActive(true);
      
   }
   

   public static void main(String[] args) {
      laadGameState();
      
   }

}

the basic setting looks good now i think,

just check where your accessing a null reference, the debugger is your best friend :slight_smile:



For example the PhysicsSpace in your Car Class is not initialized.

You should use PhysicsGameState instead of DebugGameState as a base for that.


Core-Dump said:

the basic setting looks good now i think,
just check where your accessing a null reference, the debugger is your best friend :)

For example the PhysicsSpace in your Car Class is not initialized.
You should use PhysicsGameState instead of DebugGameState as a base for that.



well I try'd debugging but we never learned that in school so I'm trying to figure out what it all means and stuff, I can't see something wrong (when I click on my variabels I see they all got an Id but thats it I'm using eclipse btw  :P, I can't see whats there value  :?), but what you said like the PhysicsSpace not being intialized is correct. but I don't know how to use the implement the PhysicsGameState like you suggested. I'm very new to JME and don't know how to use all the classes, I look up some things in the API's or by looking at the code from other people but still I dont get it how to solve my errors and to display my first 3D model on the screen.

sorry for being a noob lolz :D