Total n00b app#3 - Milkshape loader

Hi,



I’m currently trying to load a MilkShape model/figure into my scene just to view. I don’t have any animations in it as I will want to add a controller camera to follow it like with the Quake 3 loader/TrackingController in jme 0.1.



At the moment I have nothing appearing, but it does compile, could someone tell me what I’m missing please.



I did remember to open the model I got in MilkShape as ms3d & then save it as ASCII.



Model ninja = null;

//add in Milkshape model
      ninja = new MilkshapeASCIIModel("Milkshape Model", "ninja/ninja.txt");
      ninja.load("ninja/ninja.txt", "ninja/");
      ninja.setLocalTranslation(new Vector3f(105, tb.getHeight(105, 105) + 5, 105));
      rootNode.attachChild(ninja);



I'm probably doing something stupid but i can't see what.

Do you see the model if you don’t translate it? I.e. just load the model, not worrying about terrain yet.

your loading the model twice by doing:



ninja = new MilkshapeASCIIModel("Milkshape Model", "ninja/ninja.txt");
ninja.load("ninja/ninja.txt", "ninja/");



Also, its better to do this:


ninja = new MilkshapeASCIIModel("MilkShape Model");
ninja.load(TheBestEverGame.class.getClassLoader().getResource("com/data/ninja/ninja.txt");



TheBestEverGame is the class in which your loading from.

Also, try lowering the localScale:


ninja.setLocalScale(0.1f);


That helped me out quite a few times :)

Check with the camera settings, because sometimes the z variable in the localTranslation isn't actually the depth. It might be the left, so your model could be way off to the right/top, or even , behind the camera.

See if any of those help

I notice you attach the model to the root node, but when you call updateGeometricState, it’s on the sceneNode, so it never gets called on the model… Maybe if you changed that second to last call to:



rootNode.updateGeometricState(0.0f, true);



That might help?

I managed to load it up in a blank scene - its very faint & rather small - so something to figure out I think.



I really need to find a good camera tutorial so I can figure out what I’m doing.

I’ve managed to view my model where I placed it (without using TerrainBlock.getHeight(x,z)), but it appears only when I attach it to the terrainNode & then it is textured & seemingly rendered as the terrain is. When I move a small distance from the model it moves out of view.



I’ve tried attaching it to the root or sceneNodes & nothing appears.



I done the following at the end of my InitGame() method:


      //add in Milkshape model
      ninja = new MilkshapeASCIIModel("Milkshape Model", "ninja/ninja.txt");
      ninja.load(TestApp10.class.getClassLoader().getResource("ninja/ninja.txt"));
      ninja.getAnimationController().setSpeed(10.0f);
      ninja.getAnimationController().setRepeatType(Controller.RT_CYCLE);
      ( (DeformationJointController) ninja.getAnimationController()).
         setUpdateModelBounds(true);
      ninja.setLocalScale(118.0f);
      //ninja.setLocalTranslation(new Vector3f(205, tb.getHeight(205, 0) + 105, 0));
      ninja.setLocalTranslation(new Vector3f(205, 200, 205));
      //terrainNode.attachChild(ninja);
      sceneNode.attachChild(ninja);

      //manage scenegraph nodes
      sceneNode.attachChild(terrainNode);

      rootNode.attachChild(sceneNode);
      sceneNode.updateGeometricState(0.0f, true);
      rootNode.updateRenderState();

my website has a tutorial on how to properly setup the camera. If you wanna check it out:



http://www.volatile7.tk



It is dated by about 3 weeks or so. All I can think of that will be changed is from SimpleGame to BaseGame. :slight_smile:

Thanks I’ll have a look :slight_smile:



Has anyone else got the milkshape loader working with terrain? If so I’d be really interested to know how you added your model onto the terrain.



Thanks.

"DarkProphet" wrote:
my website has a tutorial on how to properly setup the camera.

I read the tutorial to see if I could learn something.

The only thing I learned is that a pyramid has 6 sides, and not the 4 that I'd always been taught. :)

At first, I was going to suggest you call it a "trapazoidagon" (for lack of a better guess), but I finally figured out that it's just some form of hexahedron, which is probably a better term.

-Mike

DarkProphet is perfectly correct in calling it a pyramid. The pyramid is formed from the eye point to the far plane. The near plane simply truncates the pyramid for viewing, but it is a pyramid non-the-less. I believe the correct OpenGL term is a truncated pyramid.

Yes, as I fell asleep last night, I did indeed realize this. The point of the pyramid is your eye.



I also realized that a pyramid can have 4, 5, 6, or any number greater than 3 sides.



mouth.open(); foot.insert();



None-the-less, the frustrum itself is a hexagon :slight_smile: [or truncated-four-sided pyramid]



-Mike

phewf, had me worried there for a sec. I thought that m knowledge of furstrums, although very limited, might go down the drain!

Does every MilkShape model you load have to have a texture?



I’m having problems loading a model without any.



But could it be that I need certain default elements in my model? The model I’m loading consists of a sphere and a box to look like a tree, but do I need anything else?

Hmmm, people were complaining about not being able to load models without textures before, but I have implemented all their suggested fixes. What problems do you have exactly? Are you getting any exceptions?

My code:



      //add in Milkshape tree - cuases errors - asked why on forum

      tree = new MilkshapeASCIIModel("Tree", "tree/tree.txt");
      tree.load(TestApp17.class.getClassLoader().getResource("tree/tree.txt"));
      tree.setLocalScale(2.0f);
      tree.setLocalTranslation(new Vector3f(430, tb.getHeight(430, 230), 230));
      sceneNode.attachChild(tree);




My errors:


INFO: Child (blade) attached to this node (Milkshape Model)
06-May-2004 16:38:23 com.jme.scene.Node attachChild
INFO: Child (Milkshape Model) attached to this node (3D Scene Node)
06-May-2004 16:38:23 com.jme.scene.Node
INFO: Node created.
06-May-2004 16:38:23 com.jme.scene.Node attachChild
INFO: Child (Box01) attached to this node (Tree)
06-May-2004 16:38:23 com.jme.scene.Node attachChild
INFO: Child (Sphere05) attached to this node (Tree)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at java.lang.String.substring(Unknown Source)
at com.jme.util.TextureManager.loadTexture(Unknown Source)
at com.jme.util.TextureManager.loadTexture(Unknown Source)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.loadTexture(Unknown S
ource)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.parseMaterials(Unknow
n Source)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.load(Unknown Source)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.load(Unknown Source)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.(Unknown Source
)
at TestApp17.initGame(TestApp17.java:283)
at com.jme.app.BaseGame.start(Unknown Source)
at TestApp17.main(TestApp17.java:61)
com.jme.system.JmeException: Error loading Milkshape ASCII file:tree/tree.txt
at com.jme.scene.model.msascii.MilkshapeASCIIModel.load(Unknown Source)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.load(Unknown Source)
at com.jme.scene.model.msascii.MilkshapeASCIIModel.(Unknown Source
)
at TestApp17.initGame(TestApp17.java:283)
at com.jme.app.BaseGame.start(Unknown Source)
at TestApp17.main(TestApp17.java:61)
06-May-2004 16:38:23 com.jme.app.BaseGame start
INFO: Application ending.



As I said it is only a green sphere attched to a brown box to look like acrude sort of tree.

Thanks.

are you running off of source? If so, make sure that



com.jme.scene.model.msascii.MilkshapeASCIIModel has:



private TextureState loadTexture(String file) {

if(file == null || file.trim().length() == 0) {

return null;

}



if so, add a statement to printout what the String file is.

I’m actually using the website jar as I’ve been having problems connecting to CVS.



I suppose the website jar is different?

Can you send me your Milkshape model so I can test with it? I’ll get it working then send you a rebuilt jar or something.

Ok doing it now.



Peter