SDK
- add FBX support via blender to SDK importer/converter git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@11037 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
03892ed642
commit
10f675b23b
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.gde.blender.filetypes;
|
package com.jme3.gde.blender.filetypes;
|
||||||
|
|
||||||
import com.jme3.gde.core.assets.SpatialAssetDataObject;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.openide.awt.ActionID;
|
import org.openide.awt.ActionID;
|
||||||
import org.openide.awt.ActionReference;
|
import org.openide.awt.ActionReference;
|
||||||
@ -21,13 +20,13 @@ import org.openide.util.NbBundle.Messages;
|
|||||||
})
|
})
|
||||||
@MIMEResolver.ExtensionRegistration(
|
@MIMEResolver.ExtensionRegistration(
|
||||||
displayName = "#LBL_Blender3ds_LOADER",
|
displayName = "#LBL_Blender3ds_LOADER",
|
||||||
mimeType = "application/x-3ds",
|
mimeType = "application/x-3ds",
|
||||||
extension = {"3ds", "3DS"})
|
extension = {"3ds", "3DS"})
|
||||||
@DataObject.Registration(
|
@DataObject.Registration(
|
||||||
mimeType = "application/x-3ds",
|
mimeType = "application/x-3ds",
|
||||||
iconBase = "com/jme3/gde/blender/blender.png",
|
iconBase = "com/jme3/gde/blender/blender.png",
|
||||||
displayName = "#LBL_Blender3ds_LOADER",
|
displayName = "#LBL_Blender3ds_LOADER",
|
||||||
position = 300)
|
position = 300)
|
||||||
@ActionReferences({
|
@ActionReferences({
|
||||||
@ActionReference(
|
@ActionReference(
|
||||||
path = "Loaders/application/x-3ds/Actions",
|
path = "Loaders/application/x-3ds/Actions",
|
||||||
|
@ -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;
|
||||||
|
// }
|
||||||
|
}
|
@ -30,6 +30,7 @@ public class Scripts {
|
|||||||
}
|
}
|
||||||
checkScript(folder, "import_3ds.py");
|
checkScript(folder, "import_3ds.py");
|
||||||
checkScript(folder, "import_dae.py");
|
checkScript(folder, "import_dae.py");
|
||||||
|
checkScript(folder, "import_fbx.py");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkScript(FileObject folder, String name) {
|
private static void checkScript(FileObject folder, String name) {
|
||||||
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user