January 30, 2013 at 03:16 #202668+10
What shall I say.. Its in svn now
With blender bundled and some python script magic I was able to teach the SDK to use blender as an importer, so now the Model Import Tool and the right-click “Convert to j3o” option also work for 3DS and Collada DAE files This also means you can now batch-convert multiple 3ds or dae files by copying them to the assets folder and selecting multiple files (@jagwire)
For those who are interested in how it works and how it can be extended, have a look at the commit. Blender is called with the –background and –python-script command line options to convert the files, the scripts are in the commit as well. The model is first imported in blender and then saved as a blend file, finally imported via @Kaelthas great importer. All this happens in the background without blender even popping up. The python script does not much more than call the importer command and then save the file.
I actually found a template in blender (blender text editor) showing basically everything I needed to know, might also be interesting for people who want to do other blender-related tools like a model “game-readiness-checker”, the things described on our blender wiki page as automated processes in the SDK and stuff like that ;)
Using this we can support all kinds of files basically, we do have to add support for each format separately but its very easy to do so from now on if theres a blender importer :D Note that still doesn’t get rid of the issue of “not game-ready model” ;)
– The model import tool might fail when textures are not referenced externally by blender (and thus not reported or recognized by the importer), the model will show successfully in the preview but not successfully be converted to j3o in the project. Copy the model and textures to the assets folder to avoid this issue and convert the model. Most probably the model will not successfully display the textures anyway (they are not in slots that jme supports, still they keep the model from loading when they are not there in blender).
NormenJanuary 30, 2013 at 04:41 #202672+1
This.January 30, 2013 at 06:24 #202677+1
this is huge Normen.January 30, 2013 at 07:35 #202686+1
Awesome :)! Good job as usualJanuary 30, 2013 at 07:53 #202687
Super Puper!January 30, 2013 at 08:49 #202695+1
Great !January 30, 2013 at 13:47 #202735+1
This is great stuff! Well played.February 1, 2013 at 04:52 #203036+3
2792pKeymasterFebruary 1, 2013 at 08:12 #203053
@normen , don’t you think to add LWO support? Lightwave users will be happy.
But you will need to switch the addon on. It’s off by default.
In python to switch the addon on you will need to do this:
You will need to do this every time when blender runs.February 1, 2013 at 12:32 #203075
When blender is downloaded from the web and put in the installer, I can’t go to that menu in between.. I guess somebody has to prepare presets and blender configuration hints so we know how to manipulate the settings files etc ;)February 1, 2013 at 13:24 #203079
When blender is downloaded from the web and put in the installer, I can’t go to that menu in between.. I guess somebody has to prepare presets and blender configuration hints so we know how to manipulate the settings files etc ;)
You can enable the script in your python:
Voila, and you can run the lwo importer as obj importer…February 1, 2013 at 14:57 #203088
Btw, I see other interesting importers there like MakeHuman etc.. I guess some of these need some post-processing but some would definitely be interesting for jME. We can extend the BlendKey to have extended options for scripts as well btwFebruary 1, 2013 at 15:03 #203090
Ok, I talkedt to Normen and he said that JME already has LWo importer. But anyway i did the LWO importer through the blender.
If you want to use it somewhen you are welcome.
Java12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485# This script invokes blender to import and save external model formats as# .blend files to be processed further.## Example usage for this importer:# blender –background –factory-startup –python $HOME/import_3ds.py — \# –i=”/tmp/hello.lwo” \# –o=”/tmp/hello.blend” \## See blender –help for details.import bpy# Imports a file using importerdef import_file(file_path):# Enable LightWave addonbpy.ops.wm.addon_enable(module=”io_import_scene_lwo”)# Import the modelbpy.ops.import_scene.lwo(filepath = file_path)# Clear existing objects.def clear_scene():scene = bpy.context.scenescene.camera = Nonefor obj in scene.objects:scene.objects.unlink(obj)# Save current scene as .blend filedef save_file(save_path):# Check if output file exists alreadytry:f = open(save_path, ‘w’)f.close()ok = Trueexcept:print(“Cannot save to path %r” % save_path)import tracebacktraceback.print_exc()# Save .blend fileif ok:bpy.ops.wm.save_as_mainfile(filepath=save_path)def main():import sys # to get command line argsimport argparse # to parse options for us and print a nice help message# get the args passed to blender after “–“, all of which are ignored by# blender so scripts may receive their own argumentsargv = sys.argvif “–” not in argv:argv =  # as if no args are passedelse:argv = argv[argv.index(“–“) + 1:] # get all args after “–”# When –help or no args are given, print this helpusage_text = \“Run blender in background mode with this script:”” blender –background –factory-startup –python ” + __file__ + ” — [options]”parser = argparse.ArgumentParser(description=usage_text)# Possible types are: string, int, long, choice, float and complex.parser.add_argument(“-i”, “–input”, dest=”file_path”, metavar=’FILE’,help=”Import the specified file”)parser.add_argument(“-o”, “–output”, dest=”save_path”, metavar=’FILE’,help=”Save the generated file to the specified path”)args = parser.parse_args(argv) # In this example we wont use the argsif not argv:parser.print_help()return# Run the conversionclear_scene()import_file(args.file_path)save_file(args.save_path)print(“batch job finished, exiting”)if __name__ == “__main__”:main()
You must be logged in to reply to this topic.