Blender jme exporter in the making

Just to let you know:

I did a little bit of work on the object animation feature today. Objects (resp. Spatials) are animated using the same keyframes text as morph target animation, which in my opinion allows for greater flexibility, because the artist won’t have to care about which ways of animating objects in blender will produce what kind of movement in jme (blender’s IPOs, for example, are a feature no game engine I know of has an equivalent for).

Unfortunately, this will delay Object hierarchy exporting, because I haven’t yet found an appealing way to spare the parent’s transformation from what gets applied to the child Spatial. One solution I am thinking of is to

  1. get the world space transform for my Object

    and
  2. walk up the hierarchy tree, inverse applying all parent’s transformations along the way…

    Can anybody tell me if I am roughly on the right way, or if there might be a simpler solution to this?



    Oh, btw, the early, but functional version of the object animation export feature (along with some minor bugfixes) is, as usual, in the file http://wwwhomes.uni-bielefeld.de/krabien/jmestuff/jmeXMLExport.py.

    Note that I haven’t updated the demo scene this time.

I wish I could help. I don’t really know blender’s format too well. If you want to move a child and parent seperatly, maybe they should be siblings instead of children?

Thanks, Cep, for offering your help once again. The point of my planned hierarchy exporter is to maintain the object hierarchy assigned in blender. Let me clarify: I get the Object’s (Blender’s equivalent to jME’s Spatial) world transform from blender, which has all parent’s transforms already applied. Now, if I would just parent the resulting jME Node to it’s old parent’s again, their transforms would be applied once more. Which I don’t want. Right now, a simpler approach than the one stated above comes to my mind, however: I just have to inverse apply the direct parent’s world transform, instead of walking up the entire hierarchy. I’ll try that, first.

BTW, Cep, have you looked at the threads

http://www.jmonkeyengine.com/jmeforum/viewtopic.php?p=11960#11960 and http://www.jmonkeyengine.com/jmeforum/viewtopic.php?p=11869#11869?

I really would appreciate your comments there. Thank you.

So lets say you have two nodes A and B with world transform matrix AWorld and BWorld. A is suppose to be the parent of B. What you really want is the local transforms for A and B, called Alocal and Blocal.



AWorld = ALocal * Identity = ALocal (beacuse A is the parent)

BWorld = ALocal * BLocal

BWorld = AWorld * BLocal

[InverseOfAWorld]*BWorld = [InverseOfAWorld]AWorldBLocal

[InverseOfAWorld]*BWorld = Identity * BLocal

[InverseOfAWorld]*BWorld = BLocal



Now the only problem is to calculate [InverseOfAWorld]. If you set the matrix up as a 4x4 translation/rotation/scale matrix, you could calculate that with some matrix math. I haven’t looked, but I bet there’s tons of formulas for matrix inversions on google.



PS: I responded to those threads.

I was trying to use this but it doesn’t seem to be working for me, when I choose JME exporter from the scripts list it returns instantly, no errors or any kind of indication of anything happening, I couldn’t find any files either. I don’t know python and I’m not that familiar with blender but shouldn’t something visible have occured (looking at the py file it looks like maybe a file dialog should come up or something). If this is normal, where did the files go?

OK, I figured it out… my window with the script buttons in it wasn’t big enough so I didn’t see the buttons… man the blender interface is weird (I really hate the lack of windows style dialogs too).

Hi there, I’m quite new to JME so, please, be patient



I have exported a cube from blender to make the xml file. Into my code I have put this:



XMLDecoder d = new XMLDecoder(
                          new BufferedInputStream(
                              new FileInputStream("scene.xml")));
        Object result = d.readObject();
        d.close();                   
   rootNode = (Node)result;


but when I run it I got a huge output of errors loading the data...

where is the trick?

can you please post the stack trace. If its either a URL malformed exception, or a Nullpointer refering to your FileInputStream, then it can’t find the file…



DP

The file is found…


12-mag-2005 18.36.29 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
java.lang.Exception: Unrecognized opening tag: scene
Continuing ...
java.lang.Exception: Unrecognized opening tag: node name="rootNode"
Continuing ...
java.lang.Exception: Unrecognized opening tag: node name="Cube" translation="13
0052986 -12.3543243 14.1778336" rotation="0.5 0.5 0.5 0.5" scale="4.0 4.0 4.0"
Continuing ...
java.lang.Exception: Unrecognized opening tag: mesh name="Cube.nocull"
Continuing ...
java.lang.Exception: Unrecognized opening tag: vertex data="1.0 0.9999999 -1.0
0.9999996 1.0000004 -1.0000001 -1.0 1.0 0.9999999 1.0000005 0.9999995 1.0 -1.00
0004 -0.9999996 1.0 -1.0000001 -0.9999999 -1.0 0.9999993 -1.0000006 1.0000001 1
0 -1.0 -0.9999999 "
Continuing ...
java.lang.Exception: Unrecognized closing tag: vertex
Continuing ...
java.lang.Exception: Unrecognized opening tag: normal data="0.5773492 0.5773492
-0.5773492 -0.5773492 0.5773492 -0.5773492 -0.5773492 0.5773492 0.5773492 0.577
492 0.5773492 0.5773492 -0.5773492 -0.5773492 0.5773492 -0.5773492 -0.5773492 -
.5773492 0.5773492 -0.5773492 0.5773492 0.5773492 -0.5773492 -0.5773492 "
Continuing ...
java.lang.Exception: Unrecognized closing tag: normal
Continuing ...
java.lang.Exception: Unrecognized opening tag: index data="0 1 2 2 3 0 4 2 1 1
 4 6 4 5 5 7 6 7 0 3 3 6 7 2 4 6 6 3 2 1 0 7 7 5 1"
Continuing ...
java.lang.Exception: Unrecognized closing tag: index
Continuing ...
java.lang.Exception: Unrecognized opening tag: materialstate diffuse="1.0 1.0 1
0 1.0" ambient="0.0 0.0 0.0 1.0" emissive="0.0 0.0 0.0 1.0" specular="0.25 0.25
0.25 1.0" shiny="12.5244618" alpha="1.0"
Continuing ...
java.lang.Exception: Unrecognized closing tag: materialstate
Continuing ...
java.lang.Exception: Unrecognized opening tag: texturestate
Continuing ...
java.lang.Exception: Unrecognized opening tag: texture file="e:netBeans4jmeSt
ffsrcmediacube.jpg" texnum="0" wrap="4"
Continuing ...
java.lang.Exception: Unrecognized closing tag: texture
Continuing ...
java.lang.Exception: Unrecognized closing tag: texturestate
Continuing ...
java.lang.Exception: Unrecognized closing tag: mesh
Continuing ...
java.lang.Exception: Unrecognized closing tag: node
Continuing ...
java.lang.Exception: Unrecognized closing tag: node
Continuing ...
java.lang.Exception: Unrecognized closing tag: scene
Continuing ...
java.util.NoSuchElementException
12-mag-2005 18.36.31 com.jme.app.SimpleGame cleanup
INFO: Cleaning up resources.
12-mag-2005 18.36.31 com.jme.app.BaseGame start
INFO: Application ending.

[darko]#>

err… I saw that there is a chapter about model loading in Starter.pdf. I think I’ve found the “solution”: I need to export from xml to .jme and follow what the example code does…

uff… it doesn’t work… :frowning:



could someone gently show those 4 lines of code to load a .jme file?

are you converting your xml file to jme binary?

Yep, I’ve tried both with .xml and .jme but my knowledge about IO in Java is quite bad and I don’t understand how to open the .jme



I imagine the algo, in pseudo-code should be something like:



JmeBinaryReader jbr= new JmeBinaryReader();



Node ciccio=jbr.loadBinaryFormat( pointer to .jme file );



but I don’t knoe how to point to the .jme file… I’m confused about InputStream, FileInputStream, BufferedInputStream and all of the other 1000 classes to read a file :?

help… :’(



my source now:



public class Rttd extends SimpleGame {
    public static void main(String[] args) {
        Rttd app = new Rttd();
   app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }
 
    protected void simpleInitGame() {
   Node model = null;
        JmeBinaryReader jbr = new JmeBinaryReader();
        try  {   
              URL modelURL= Rttd.class.getClassLoader().getResource("c:\rttd\cube.jme");                     
            model = jbr.loadBinaryFormat(modelURL.openStream());
            jbr.setProperty("bound", "box");
        } catch(Exception e) {
            System.out.println("Model could not be loaded:" +   
               e.getMessage());
        }
        rootNode.attachChild(model);
   }
}



it compares a black window without the usual information about FPS, number of vertex, ecc...

and this output into the shell:


[darko]#>java -cp c:lwjgljme.jar;c:lwjgllwjgl.jar;. -Djava.library.path=c:l
wjgl Rttd
13-mag-2005 10.53.35 com.jme.app.BaseGame start
INFO: Application started.
13-mag-2005 10.53.35 com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
13-mag-2005 10.53.35 com.jme.system.PropertiesIO load
INFO: Read properties
13-mag-2005 10.54.01 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
13-mag-2005 10.54.02 com.jme.system.PropertiesIO save
INFO: Saved properties
13-mag-2005 10.54.02 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
13-mag-2005 10.54.07 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  640H: 480
13-mag-2005 10.54.07 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
13-mag-2005 10.54.12 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 3579545 ticks per second
13-mag-2005 10.54.13 com.jme.scene.Node <init>
INFO: Node created.
13-mag-2005 10.54.42 com.jme.scene.Node <init>
INFO: Node created.
13-mag-2005 10.54.42 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
Model could not be loaded:null

[darko]#>

You have to first convert the .xml file to the .jme format before you load it into the scene.



XMLtoBinary myConverter = new XMLtoBinary();

URL myDocument = YourClass.class.getClassLoader().getResource("your file");

ByteArrayOutputStream myBAOS = new ByteArrayOutputStream();

myConverter.sendXMLtoBinary(myDocument.openStream(), myBAOS);

JmeBinaryReader myJBR = new JmeBinaryReader();

yourNode=myJBR.loadBinaryFormat(new ByteArrayInputStream(myBAOS.toByteArray()));



Not sure whether this works, my environment is messed up at the moment, and i'm not an expert.

thanks for the tip, but it really doesn’t want to work. I’ve tried both with:



URL myDocument = Rttd.class.getClassLoader().getResource("c:\rttd\cube.xml");


and:


URL myDocument = Rttd.class.getClassLoader().getResource("c:\rttd\cube.jme");



(Naturally those file are, respectivelly, in xml and jme format.

But the output is always the same:


....
13-mag-2005 11.53.54 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
Model could not be loaded:null
13-mag-2005 11.53.56 com.jme.app.SimpleGame cleanup
INFO: Cleaning up resources.
13-mag-2005 11.53.56 com.jme.app.BaseGame start
INFO: Application ending.

[darko]#>

Put the .xml file in your workspace and then use the relative path.



I don’t know the exact URL Syntax for absolute paths at the moment.





Instead of

URL myDocument = YourClass.class.getClassLoader().getResource("your file");
[/code

type

[code]
URL myDocument = new URL("file:/C:/rttd/cube.xml")
[/code][code]

URL myDocument = YourClass.class.getClassLoader().getResource("your file");

[/code



type



[code]

URL myDocument = new URL("file:/C:/rttd/cube.xml")

[/code]

i’m going to give up… no, it doesn’t work, again.



The message is always:


INFO: Node created.
Model could not be loaded:3772338
13-mag-2005 15.10.20 com.jme.app.SimpleGame cleanup
INFO: Cleaning up resources.
13-mag-2005 15.10.20 com.jme.app.BaseGame start
INFO: Application ending.



Then I've tried to export a simple cube in obj format. This time it works, but it doesn't load the material and the cube from the JME window is terrifying.. it seems like some faces are missing, even if I've put all normals out. may the exporter of blender 2.26 don't work very well?

uff... I don't know where blink my head... :'(

Ehi men… I got it !!!















I’ve exported in obj format and yessss… now it works. guess what was the matter?? As usually I never set the Mir color (never needed to change it from 0xFFFFFF). I’ve noticed that importing the Maggie model of the example loading class… uff… well… I’m happy now



I would make a sticky thread for this… to avoid others this pain.

That error looks like that node’s child doesn’t have any controllers.