SDK:
- make blender import scripts more generic and easy to extend git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10246 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
cf66bd4d45
commit
834049e69a
@ -1,30 +1,30 @@
|
|||||||
# This script is an example of how you can run blender from the command line
|
# This script invokes blender to import and save external model formats as
|
||||||
# (in background mode with no interface) to automate tasks, in this example it
|
# .blend files to be processed further.
|
||||||
# creates a text object, camera and light, then renders and/or saves it.
|
|
||||||
# This example also shows how you can parse command line options to scripts.
|
|
||||||
#
|
#
|
||||||
# Example usage for this test.
|
# Example usage for this importer:
|
||||||
# blender --background --factory-startup --python $HOME/background_job.py -- \
|
# blender --background --factory-startup --python $HOME/import_3ds.py -- \
|
||||||
# --text="Hello World" \
|
# --i="/tmp/hello.3ds" \
|
||||||
# --render="/tmp/hello" \
|
# --o="/tmp/hello.blend" \
|
||||||
# --save="/tmp/hello.blend"
|
|
||||||
#
|
|
||||||
# Notice:
|
|
||||||
# '--factory-startup' is used to avoid the user default settings from
|
|
||||||
# interfearing with automated scene generation.
|
|
||||||
#
|
|
||||||
# '--' causes blender to ignore all following arguments so python can use them.
|
|
||||||
#
|
#
|
||||||
# See blender --help for details.
|
# See blender --help for details.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
|
# Imports a file using importer
|
||||||
def convert_file(file_path, save_path):
|
def import_file(file_path):
|
||||||
|
# Import the model
|
||||||
bpy.ops.import_scene.autodesk_3ds(filepath = file_path)
|
bpy.ops.import_scene.autodesk_3ds(filepath = file_path)
|
||||||
|
|
||||||
|
# Clear existing objects.
|
||||||
|
def clear_scene():
|
||||||
scene = bpy.context.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:
|
try:
|
||||||
f = open(save_path, 'w')
|
f = open(save_path, 'w')
|
||||||
f.close()
|
f.close()
|
||||||
@ -35,6 +35,7 @@ def convert_file(file_path, save_path):
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
# Save .blend file
|
||||||
if ok:
|
if ok:
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=save_path)
|
bpy.ops.wm.save_as_mainfile(filepath=save_path)
|
||||||
|
|
||||||
@ -70,14 +71,10 @@ def main():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Clear existing objects.
|
|
||||||
scene = bpy.context.scene
|
|
||||||
scene.camera = None
|
|
||||||
for obj in scene.objects:
|
|
||||||
scene.objects.unlink(obj)
|
|
||||||
|
|
||||||
# Run the conversion
|
# Run the conversion
|
||||||
convert_file(args.file_path, args.save_path)
|
clear_scene()
|
||||||
|
import_file(args.file_path)
|
||||||
|
save_file(args.save_path)
|
||||||
|
|
||||||
print("batch job finished, exiting")
|
print("batch job finished, exiting")
|
||||||
|
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
# This script is an example of how you can run blender from the command line
|
# This script invokes blender to import and save external model formats as
|
||||||
# (in background mode with no interface) to automate tasks, in this example it
|
# .blend files to be processed further.
|
||||||
# creates a text object, camera and light, then renders and/or saves it.
|
|
||||||
# This example also shows how you can parse command line options to scripts.
|
|
||||||
#
|
#
|
||||||
# Example usage for this test.
|
# Example usage for this importer:
|
||||||
# blender --background --factory-startup --python $HOME/background_job.py -- \
|
# blender --background --factory-startup --python $HOME/import_3ds.py -- \
|
||||||
# --text="Hello World" \
|
# --i="/tmp/hello.3ds" \
|
||||||
# --render="/tmp/hello" \
|
# --o="/tmp/hello.blend" \
|
||||||
# --save="/tmp/hello.blend"
|
|
||||||
#
|
|
||||||
# Notice:
|
|
||||||
# '--factory-startup' is used to avoid the user default settings from
|
|
||||||
# interfearing with automated scene generation.
|
|
||||||
#
|
|
||||||
# '--' causes blender to ignore all following arguments so python can use them.
|
|
||||||
#
|
#
|
||||||
# See blender --help for details.
|
# See blender --help for details.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
|
# Imports a file using importer
|
||||||
def convert_file(file_path, save_path):
|
def import_file(file_path):
|
||||||
|
# Import the model
|
||||||
bpy.ops.wm.collada_import(filepath = file_path)
|
bpy.ops.wm.collada_import(filepath = file_path)
|
||||||
|
|
||||||
|
# Clear existing objects.
|
||||||
|
def clear_scene():
|
||||||
scene = bpy.context.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:
|
try:
|
||||||
f = open(save_path, 'w')
|
f = open(save_path, 'w')
|
||||||
f.close()
|
f.close()
|
||||||
@ -35,6 +35,7 @@ def convert_file(file_path, save_path):
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
# Save .blend file
|
||||||
if ok:
|
if ok:
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=save_path)
|
bpy.ops.wm.save_as_mainfile(filepath=save_path)
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ def main():
|
|||||||
# When --help or no args are given, print this help
|
# When --help or no args are given, print this help
|
||||||
usage_text = \
|
usage_text = \
|
||||||
"Run blender in background mode with this script:"
|
"Run blender in background mode with this script:"
|
||||||
" blender --background --python " + __file__ + " -- [options]"
|
" blender --background --factory-startup --python " + __file__ + " -- [options]"
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description=usage_text)
|
parser = argparse.ArgumentParser(description=usage_text)
|
||||||
|
|
||||||
@ -70,14 +71,10 @@ def main():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Clear existing objects.
|
|
||||||
scene = bpy.context.scene
|
|
||||||
scene.camera = None
|
|
||||||
for obj in scene.objects:
|
|
||||||
scene.objects.unlink(obj)
|
|
||||||
|
|
||||||
# Run the conversion
|
# Run the conversion
|
||||||
convert_file(args.file_path, args.save_path)
|
clear_scene()
|
||||||
|
import_file(args.file_path)
|
||||||
|
save_file(args.save_path)
|
||||||
|
|
||||||
print("batch job finished, exiting")
|
print("batch job finished, exiting")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user