Sunday 27 May 2012

Blend2Java - Exporting 3D Objects from Blender for Java

Aim

The aim of this tutorial is to allow a complete beginner, who has absolutely no previous knowledge of Blend2Java, Python, or Blender scripting, to export a 3D object that they have created in Blender, into a form that can be later used by Java3D and my other tutorials.



Step 1 - Get Blend2Java

Go here and download it. It's free, just like all things that I cover in my tutorials.





Once you have downloaded it. Open the Zip file.





You should get the following screen.





Extract the files to the desktop





Once you've extracted the files and opened the folder you should see the following:







Step 2 - Editing the export.py script for use in blender.

Open the export.py file in notepad and you should see the following:





Insert the following code into the top of the file and then save it.

#!BPY
"""
Name: 'Blend2Java'
Blender: 248
Group: 'Export'
"""

Note that the 248 stands for version 2.48, change this number for your blender version. (It says when you start blender up)







Step 3 - Using the export.py script to export your 3D object.

Now we need to load the export.py script into blender. Open up blender.





press shift+f11 to open the scripting window, as shown below.





Open the python script by clicking the button shown below:





You should then get the following menu.





Select your exporg.py file that you edited earlier and saved. Then open it.







Run the python script



You should get the following menu asking you for the output directory and the start export button.





Enter the directory you wish the files to be exported to. I put it as C:/test as shown. Then press the stat export button.





Your files wil now be in the folder you specified, as shown. This file can be used by Java3D later.



Well done your finished!





  • Note: If you have any problems please comment about the issues and I will try to solve them in a troubleshooting section of this post. Please do not comment about any spelling/grammar mistakes. Thank you.

9 comments:

  1. I'm following this " tutorial" to export a Blender object , but when I run the script export.py file, an error is thrown in import gzip command. Could you let me know which procedures to perform such a script would run altogether?
    Sorry, my English is basic.

    Thank you for attention

    ReplyDelete
  2. I had this problem as well. You need to put parentheses around all of the text following each of the print statements.

    ReplyDelete
  3. I am getting the error "No module named Blender" at the import Blender statement.

    ReplyDelete
  4. When I run this it says Gzip Module not supported. How doth I fix this?

    ReplyDelete
  5. i had an error at 'import Blender' saying module Blender not found
    i fixed it by replacing Blender with bpy, but now I have an error at 'from bpy import NMesh' saying cannot import NMesh

    ReplyDelete
  6. becouse of different java versions Bro , in example they use an old version of Vlender

    ReplyDelete
  7. blender2java uses python2 but the new versions of blender uses python3.7 so... yes

    ReplyDelete
  8. if you use older versions it ll work

    ReplyDelete