Blender model export

Hi, I'm trying to export this model (http://stblender.iindigo3d.com/models/federationdefiant.zip) from this page: http://stblender.iindigo3d.com/meshes_startrek.html



And I'm using the jmeXMLExport.py for Blender (at http://wwwhomes.uni-bielefeld.de/krabien/jmestuff/jmeXMLExport.py).



But I cannot export that model, I get an error in Blender:


starting export to jME XML file format...


Traceback (most recent call last):
  File "<string>", line 1156, in main
  File "<string>", line 710, in writeObject
  File "<string>", line 767, in writeMesh
  File "<string>", line 229, in __init__
AttributeError: 'NoneType' object has no attribute 'getAmb'



I'm using Blender 2.43.

Thanks! :slight_smile: Great help.



Now I have:

  • Succesfully exported the model from blender into a jme xml
  • And also converted the xml to jme binary
  • Unpacked all the texture images of the blender model



    So, now I have a jme model and all the texture, so I try to load the model into jME, but I get this error:


java.lang.NullPointerException
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)
   at com.jme.scene.batch.TriangleBatch.draw(Unknown Source)
   at com.jme.renderer.RenderQueue.renderOpaqueBucket(Unknown Source)
   at com.jme.renderer.RenderQueue.renderBuckets(Unknown Source)
   at com.jme.renderer.Renderer.renderQueue(Unknown Source)
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(Unknown Source)
   at com.jme.app.BaseGame.start(Unknown Source)
   at invaders3d.Invaders3D.main(Invaders3D.java:56)
13.3.2007 13:05:34 com.jme.app.BaseGame start
INFO: Application ending.



Before I get this exception I see many warning (one for each texture being loaded), and each of those warning sounds like this:

WARNING: Attempted to apply texture with size that is not power of 2: 543 x 943
13.3.2007 13:05:33 com.jme.scene.state.lwjgl.LWJGLTextureState load
WARNING: Rescaling image to 512 x 1024 !!!




I do have everything packed into one zip file if you want to try this yourself ( I would appreciate it! :) )
http://www.private.is/arni/models/federationdefiant.zip
- All textures included
- Original blender file included
- jME xml file included
- jME binary file included

(ps. The textures need to be in the working directory of the java program.)

I tried loading that model into blender and it seems to be messed up, I couldnt edit it at all.

The model looks just fine in Blender. I can export to XML, but not with material. And I want the material to export as well (the textures I guess are included there).

oops,  :// my bad, I guess the model does load ok. I have no idea how to export the images Ive never seen it done from a model.

I just grabbed the jmetest, jmetest.renderer.loader.TestBinaryXML and modified the paths to point at your model and textures.

Tested again from work with what I put in CVS last night and it works ok.  I placed the inner federationdefiant folder from your zip in the root of my jme project and changed the test like so:


### Eclipse Workspace Patch 1.0
#P jme
Index: src/jmetest/renderer/loader/TestBinaryXML.java
===================================================================
RCS file: /cvs/jme/src/jmetest/renderer/loader/TestBinaryXML.java,v
retrieving revision 1.9
diff -u -r1.9 TestBinaryXML.java
--- src/jmetest/renderer/loader/TestBinaryXML.java   5 Feb 2007 17:10:20 -0000   1.9
+++ src/jmetest/renderer/loader/TestBinaryXML.java   14 Mar 2007 15:31:10 -0000
@@ -34,6 +34,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.URL;
@@ -73,9 +75,9 @@
 
         // Send XML file to jME binary
         XMLtoBinary c1=new XMLtoBinary();
-        URL xmldoc=TestBinaryXML.class.getClassLoader().getResource("jmetest/data/XML documents/newSampleScene.xml");
+        File f=new File("federationdefiant/federationdefiant.xml");
         ByteArrayOutputStream BO1=new ByteArrayOutputStream();
-        c1.sendXMLtoBinary(xmldoc.openStream(),BO1);
+        c1.sendXMLtoBinary(new FileInputStream(f),BO1);
 
         // Send jME binary to XML
         BinaryToXML btx=new BinaryToXML();
@@ -83,7 +85,7 @@
 
         // Send jME binary to a jME Scene Graph
         JmeBinaryReader jbr=new JmeBinaryReader();
-        jbr.setProperty("texclasspath","jmetest/data/images/");
+        jbr.setProperty("texdirfile","federationdefiant/");
         Node fileScene=jbr.loadBinaryFormat(new ByteArrayInputStream(BO1.toByteArray()));
 
         // Send a jME SceneGraph to jME Binary



Here's a screenshot:

http://www.renanse.com/jme/jmebin_shot.jpg

Ok, thanks. I'll try it when I get home. Model looks nicer, but I'm wondering what those two half-cylinders are that go straight through the ship.



I'll let you know :slight_smile: thanks alot for your help, really really appreciate it.

No prob!

Quick fix: in Blender, in the shading buttons (F5), select "World buttons", and create a new world - it is needed for color calculations.



(Technical detail: Since the blender default scene comes with a pre-installed world, and nobody I ever heard of removed it because it's needed for rendering anyway, i didn't care to test for one being there - I might change that in a future version, but not now.)



Note that the exporter won't unpack the packed textures for you, to do that, open an "UV/Image editor" window in blender, and select "Image->Unpack Image" for every single Image in the blend file - they will be saved to disk that way, and can then be loaded by the jME model loader.

nice one hevee  8) I didnt see the Image->unpack image option, but it also works if you click the package icon next to the image name in Image tab.

The warnings are there to inform you that the images have to be rescaled to be used as textures, since they are not x by y sized, with x and y both being powers of 2 (like 256, 512, 1024…). Most video cards do not like that. In my experience, this is not a problem with jME and "better" graphics cards, but older, or "non-gaming" cards like most onboard laptop graphics chips, seem to have trouble with that even though something (jME? lwjgl?) seems to try re-scaling them. I used to have this error on a test machine with an older intel onboard graphics chip, and it was fixed by using power of two image dimensions.

All that being said, I'm sorry I can't test your model and textures right now, I simply don't have the time :frowning: Maybe auto-texture-scaling has long been fixed to work with older video cards, and I just don't know it - so, by any means, if somebody else has something to say on this issue, follow their advice :slight_smile:

It seems that jME does (or so I asssume from the warning messages) rescale the textures, so I don't think it should be a problem.



I'll try rescaling them by hand and use them.





edit: ok, I rescaled the textures down to n^2 size… but I still get above nullpointerexception.

The NPE is probably a case of a default TriMesh batch being drawn.  If you create a new TriMesh, it initializes its batch list with a single new TriangleBatch with a null indexBuffer.  Typically you would setup this buffer, or replace the default batch, etc.



Looks like the old JMEBinaryReader simply adds batches it reads to the Trimeshes it creates, leaving that default buffer in place.  I'm adding a quick fix in CVS, but I'm not in a great position to test at this time so I am doing it blindly.  Please help me test this.

Update: I've finished checking this in.  Let me know how things go.

renanse said:

Update: I've finished checking this in.  Let me know how things go.


Now I get:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
   at java.util.ArrayList.RangeCheck(Unknown Source)
   at java.util.ArrayList.get(Unknown Source)
   at com.jme.scene.TriMesh.getBatch(TriMesh.java:464)
   at com.jme.scene.TriMesh.getBatch(TriMesh.java:1)
   at com.jmex.model.XMLparser.JmeBinaryReader.readBegining(JmeBinaryReader.java:269)
   at com.jmex.model.XMLparser.JmeBinaryReader.loadBinaryFormat(JmeBinaryReader.java:162)
   at com.jmex.model.XMLparser.JmeBinaryReader.loadBinaryFormat(JmeBinaryReader.java:191)
   at invaders3d.Invaders3D.buildPlayer(Invaders3D.java:160)
   at invaders3d.Invaders3D.initGame(Invaders3D.java:134)
   at com.jme.app.BaseGame.start(BaseGame.java:56)
   at invaders3d.Invaders3D.main(Invaders3D.java:63)



Even on a .jme mesh that loaded previously (the one included in the zip file).

edit: My loading code:

        Node model = null;
       
       
        try {
            URL ship = Invaders3D.class.getClassLoader().getResource("defiant.jme");
            JmeBinaryReader jbr = new JmeBinaryReader();
            jbr.setProperty("bound", "box");
            model = jbr.loadBinaryFormat(ship.openStream());
            model.setLocalScale(.25f);
        } catch (IOException e) {
            e.printStackTrace();
        }

Tried this code also:


       try {
         model = (Node) BinaryImporter.getInstance().load( new File("res/models/defiant.jme") );
      } catch (Exception e) {
         e.printStackTrace();
      }



got:

java.io.IOException: Not in GZIP format
   at java.util.zip.GZIPInputStream.readHeader(Unknown Source)
   at java.util.zip.GZIPInputStream.<init>(Unknown Source)
   at java.util.zip.GZIPInputStream.<init>(Unknown Source)
   at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:87)
   at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:179)
   at com.jme.util.export.binary.BinaryImporter.load(BinaryImporter.java:174)
   at invaders3d.Invaders3D.buildPlayer(Invaders3D.java:169)
   at invaders3d.Invaders3D.initGame(Invaders3D.java:134)
   at com.jme.app.BaseGame.start(BaseGame.java:56)
   at invaders3d.Invaders3D.main(Invaders3D.java:63)



:/

Ok, first off, sorry the "fix" was not correct.  I should have waited to get in front of a machine I could test your model with.  I have done that now and tracked down the issue.  The .xml version of your model now loads fine. (EDIT: this is in CVS.)



Second, the old XML and XML->Binary code is deprecated and not compatible with the new binary format.  Hopefully once we have an XML importer/exporter for the new system, someone will port the blender exporter.

What code are you using to load the xml file? I've tried many instances of model loading code but still no luck :confused:



I have the newest from the cvs head.