diff --git a/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/Blender3dsDataObject.java b/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/Blender3dsDataObject.java index e6e623b98..8623d7ee0 100644 --- a/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/Blender3dsDataObject.java +++ b/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/Blender3dsDataObject.java @@ -4,7 +4,6 @@ */ package com.jme3.gde.blender.filetypes; -import com.jme3.gde.core.assets.SpatialAssetDataObject; import java.io.IOException; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; @@ -20,65 +19,65 @@ import org.openide.util.NbBundle.Messages; "LBL_Blender3ds_LOADER=3DS Files (via Blender)" }) @MIMEResolver.ExtensionRegistration( - displayName = "#LBL_Blender3ds_LOADER", -mimeType = "application/x-3ds", -extension = {"3ds", "3DS"}) + displayName = "#LBL_Blender3ds_LOADER", + mimeType = "application/x-3ds", + extension = {"3ds", "3DS"}) @DataObject.Registration( - mimeType = "application/x-3ds", -iconBase = "com/jme3/gde/blender/blender.png", -displayName = "#LBL_Blender3ds_LOADER", -position = 300) + mimeType = "application/x-3ds", + iconBase = "com/jme3/gde/blender/blender.png", + displayName = "#LBL_Blender3ds_LOADER", + position = 300) @ActionReferences({ @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "System", id = "org.openide.actions.OpenAction"), - position = 100, - separatorAfter = 200), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.OpenAction"), + position = 100, + separatorAfter = 200), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "Edit", id = "org.openide.actions.CutAction"), - position = 300), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.CutAction"), + position = 300), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"), - position = 400, - separatorAfter = 500), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"), + position = 400, + separatorAfter = 500), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"), - position = 600), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"), + position = 600), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "System", id = "org.openide.actions.RenameAction"), - position = 700, - separatorAfter = 800), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.RenameAction"), + position = 700, + separatorAfter = 800), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"), - position = 900, - separatorAfter = 1000), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"), + position = 900, + separatorAfter = 1000), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"), - position = 1100, - separatorAfter = 1200), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"), + position = 1100, + separatorAfter = 1200), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "System", id = "org.openide.actions.ToolsAction"), - position = 1300), + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.ToolsAction"), + position = 1300), @ActionReference( - path = "Loaders/application/x-3ds/Actions", - id = - @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"), - position = 1400) + path = "Loaders/application/x-3ds/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"), + position = 1400) }) public class Blender3dsDataObject extends AbstractBlenderImportDataObject { diff --git a/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/BlenderFbxDataObject.java b/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/BlenderFbxDataObject.java new file mode 100644 index 000000000..31d29ea22 --- /dev/null +++ b/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/BlenderFbxDataObject.java @@ -0,0 +1,93 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.blender.filetypes; + +import java.io.IOException; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.MIMEResolver; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectExistsException; +import org.openide.loaders.MultiFileLoader; +import org.openide.util.NbBundle.Messages; + +@Messages({ + "LBL_BlenderFbx_LOADER=Files of BlenderFbx" +}) +@MIMEResolver.ExtensionRegistration( + displayName = "#LBL_BlenderFbx_LOADER", + mimeType = "application/fbx", + extension = {"fbx"}) +@DataObject.Registration( + mimeType = "application/fbx", + iconBase = "com/jme3/gde/blender/blender.png", + displayName = "#LBL_BlenderFbx_LOADER", + position = 300) +@ActionReferences({ + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.OpenAction"), + position = 100, + separatorAfter = 200), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.CutAction"), + position = 300), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"), + position = 400, + separatorAfter = 500), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"), + position = 600), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.RenameAction"), + position = 700, + separatorAfter = 800), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"), + position = 900, + separatorAfter = 1000), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"), + position = 1100, + separatorAfter = 1200), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.ToolsAction"), + position = 1300), + @ActionReference( + path = "Loaders/application/fbx/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"), + position = 1400) +}) +public class BlenderFbxDataObject extends AbstractBlenderImportDataObject { + + public BlenderFbxDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { + super(pf, loader); + SUFFIX = "3ds"; +// registerEditor("application/fbx", false); + } +// @Override +// protected int associateLookup() { +// return 1; +// } +} diff --git a/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/Scripts.java b/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/Scripts.java index 116d424b5..3bd7e356f 100644 --- a/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/Scripts.java +++ b/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/Scripts.java @@ -30,6 +30,7 @@ public class Scripts { } checkScript(folder, "import_3ds.py"); checkScript(folder, "import_dae.py"); + checkScript(folder, "import_fbx.py"); } private static void checkScript(FileObject folder, String name) { diff --git a/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/import_fbx.py b/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/import_fbx.py new file mode 100644 index 000000000..296932d5f --- /dev/null +++ b/sdk/jme3-blender/src/com/jme3/gde/blender/scripts/import_fbx.py @@ -0,0 +1,83 @@ +# 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.3ds" \ +# --o="/tmp/hello.blend" \ +# +# See blender --help for details. + +import bpy + +# Imports a file using importer +def import_file(file_path): + # Import the model + bpy.ops.import_scene.fbx(filepath = file_path) + +# Clear existing objects. +def clear_scene(): + scene = bpy.context.scene + scene.camera = None + for obj in scene.objects: + scene.objects.unlink(obj) + +# Save current scene as .blend file +def save_file(save_path): + # Check if output file exists already + try: + f = open(save_path, 'w') + f.close() + ok = True + except: + print("Cannot save to path %r" % save_path) + + import traceback + traceback.print_exc() + + # Save .blend file + if ok: + bpy.ops.wm.save_as_mainfile(filepath=save_path) + +def main(): + import sys # to get command line args + import 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 arguments + argv = sys.argv + + if "--" not in argv: + argv = [] # as if no args are passed + else: + argv = argv[argv.index("--") + 1:] # get all args after "--" + + # When --help or no args are given, print this help + usage_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 args + + if not argv: + parser.print_help() + return + + # Run the conversion + clear_scene() + import_file(args.file_path) + save_file(args.save_path) + + print("batch job finished, exiting") + + +if __name__ == "__main__": + main()