- add FBX support via blender to SDK importer/converter git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@11037 75d07b2b-3a1a-0410-a2c5-0572b91ccdcaexperimental
parent
03892ed642
commit
10f675b23b
@ -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;
|
||||
// }
|
||||
} |
@ -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…
Reference in new issue