cleanup duplicate GPL haeders, blender made 2.4x __bpydoc__ into __doc__, removed version info, (thats what svn logs are for).
also moved create_derived_objects & free_derived_objects into io_utils, used by x3d and 3ds.
This commit is contained in:
@@ -18,36 +18,13 @@
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__ = "Campbell Barton"
|
||||
__url__ = ['www.blender.org', 'blenderartists.org']
|
||||
__version__ = "1.2"
|
||||
# Script copyright (C) Campbell Barton
|
||||
|
||||
__bpydoc__ = """\
|
||||
"""
|
||||
This script is an exporter to the FBX file format.
|
||||
|
||||
http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx
|
||||
"""
|
||||
# --------------------------------------------------------------------------
|
||||
# FBX Export v0.1 by Campbell Barton (AKA Ideasman)
|
||||
# --------------------------------------------------------------------------
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
import time
|
||||
@@ -3026,300 +3003,8 @@ Takes: {''')
|
||||
# bpy.util.copy_images( [ tex[1] for tex in textures if tex[1] != None ], basepath)
|
||||
|
||||
print('export finished in %.4f sec.' % (time.clock() - start_time))
|
||||
# print 'export finished in %.4f sec.' % (Blender.sys.time() - start_time)
|
||||
return True
|
||||
|
||||
|
||||
# --------------------------------------------
|
||||
# UI Function - not a part of the exporter.
|
||||
# this is to separate the user interface from the rest of the exporter.
|
||||
# from Blender import Draw, Window
|
||||
EVENT_NONE = 0
|
||||
EVENT_EXIT = 1
|
||||
EVENT_REDRAW = 2
|
||||
EVENT_FILESEL = 3
|
||||
|
||||
GLOBALS = {}
|
||||
|
||||
# export opts
|
||||
|
||||
def do_redraw(e,v): GLOBALS['EVENT'] = e
|
||||
|
||||
# toggle between these 2, only allow one on at once
|
||||
def do_obs_sel(e,v):
|
||||
GLOBALS['EVENT'] = e
|
||||
GLOBALS['EXP_OBS_SCENE'].val = 0
|
||||
GLOBALS['EXP_OBS_SELECTED'].val = 1
|
||||
|
||||
def do_obs_sce(e,v):
|
||||
GLOBALS['EVENT'] = e
|
||||
GLOBALS['EXP_OBS_SCENE'].val = 1
|
||||
GLOBALS['EXP_OBS_SELECTED'].val = 0
|
||||
|
||||
def do_batch_type_grp(e,v):
|
||||
GLOBALS['EVENT'] = e
|
||||
GLOBALS['BATCH_GROUP'].val = 1
|
||||
GLOBALS['BATCH_SCENE'].val = 0
|
||||
|
||||
def do_batch_type_sce(e,v):
|
||||
GLOBALS['EVENT'] = e
|
||||
GLOBALS['BATCH_GROUP'].val = 0
|
||||
GLOBALS['BATCH_SCENE'].val = 1
|
||||
|
||||
def do_anim_act_all(e,v):
|
||||
GLOBALS['EVENT'] = e
|
||||
GLOBALS['ANIM_ACTION_ALL'][0].val = 1
|
||||
GLOBALS['ANIM_ACTION_ALL'][1].val = 0
|
||||
|
||||
def do_anim_act_cur(e,v):
|
||||
if GLOBALS['BATCH_ENABLE'].val and GLOBALS['BATCH_GROUP'].val:
|
||||
Draw.PupMenu('Warning%t|Cant use this with batch export group option')
|
||||
else:
|
||||
GLOBALS['EVENT'] = e
|
||||
GLOBALS['ANIM_ACTION_ALL'][0].val = 0
|
||||
GLOBALS['ANIM_ACTION_ALL'][1].val = 1
|
||||
|
||||
def fbx_ui_exit(e,v):
|
||||
GLOBALS['EVENT'] = e
|
||||
|
||||
def do_help(e,v):
|
||||
url = 'http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx'
|
||||
print('Trying to open web browser with documentation at this address...')
|
||||
print('\t' + url)
|
||||
|
||||
try:
|
||||
import webbrowser
|
||||
webbrowser.open(url)
|
||||
except:
|
||||
Blender.Draw.PupMenu("Error%t|Opening a webbrowser requires a full python installation")
|
||||
print('...could not open a browser window.')
|
||||
|
||||
|
||||
|
||||
# run when export is pressed
|
||||
#def fbx_ui_write(e,v):
|
||||
def fbx_ui_write(filename, context):
|
||||
|
||||
# Dont allow overwriting files when saving normally
|
||||
if not GLOBALS['BATCH_ENABLE'].val:
|
||||
if not BPyMessages.Warning_SaveOver(filename):
|
||||
return
|
||||
|
||||
GLOBALS['EVENT'] = EVENT_EXIT
|
||||
|
||||
# Keep the order the same as above for simplicity
|
||||
# the [] is a dummy arg used for objects
|
||||
|
||||
Blender.Window.WaitCursor(1)
|
||||
|
||||
# Make the matrix
|
||||
GLOBAL_MATRIX = mtx4_identity
|
||||
GLOBAL_MATRIX[0][0] = GLOBAL_MATRIX[1][1] = GLOBAL_MATRIX[2][2] = GLOBALS['_SCALE'].val
|
||||
if GLOBALS['_XROT90'].val: GLOBAL_MATRIX = mtx4_x90n * GLOBAL_MATRIX
|
||||
if GLOBALS['_YROT90'].val: GLOBAL_MATRIX = mtx4_y90n * GLOBAL_MATRIX
|
||||
if GLOBALS['_ZROT90'].val: GLOBAL_MATRIX = mtx4_z90n * GLOBAL_MATRIX
|
||||
|
||||
ret = write(\
|
||||
filename, None,\
|
||||
context,
|
||||
GLOBALS['EXP_OBS_SELECTED'].val,\
|
||||
GLOBALS['EXP_MESH'].val,\
|
||||
GLOBALS['EXP_MESH_APPLY_MOD'].val,\
|
||||
GLOBALS['EXP_MESH_HQ_NORMALS'].val,\
|
||||
GLOBALS['EXP_ARMATURE'].val,\
|
||||
GLOBALS['EXP_LAMP'].val,\
|
||||
GLOBALS['EXP_CAMERA'].val,\
|
||||
GLOBALS['EXP_EMPTY'].val,\
|
||||
GLOBALS['EXP_IMAGE_COPY'].val,\
|
||||
GLOBAL_MATRIX,\
|
||||
GLOBALS['ANIM_ENABLE'].val,\
|
||||
GLOBALS['ANIM_OPTIMIZE'].val,\
|
||||
GLOBALS['ANIM_OPTIMIZE_PRECISSION'].val,\
|
||||
GLOBALS['ANIM_ACTION_ALL'][0].val,\
|
||||
GLOBALS['BATCH_ENABLE'].val,\
|
||||
GLOBALS['BATCH_GROUP'].val,\
|
||||
GLOBALS['BATCH_SCENE'].val,\
|
||||
GLOBALS['BATCH_FILE_PREFIX'].val,\
|
||||
GLOBALS['BATCH_OWN_DIR'].val,\
|
||||
)
|
||||
|
||||
Blender.Window.WaitCursor(0)
|
||||
GLOBALS.clear()
|
||||
|
||||
if ret == False:
|
||||
Draw.PupMenu('Error%t|Path cannot be written to!')
|
||||
|
||||
|
||||
def fbx_ui():
|
||||
# Only to center the UI
|
||||
x,y = GLOBALS['MOUSE']
|
||||
x-=180; y-=0 # offset... just to get it centered
|
||||
|
||||
Draw.Label('Export Objects...', x+20,y+165, 200, 20)
|
||||
|
||||
if not GLOBALS['BATCH_ENABLE'].val:
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['EXP_OBS_SELECTED'] = Draw.Toggle('Selected Objects', EVENT_REDRAW, x+20, y+145, 160, 20, GLOBALS['EXP_OBS_SELECTED'].val, 'Export selected objects on visible layers', do_obs_sel)
|
||||
GLOBALS['EXP_OBS_SCENE'] = Draw.Toggle('Scene Objects', EVENT_REDRAW, x+180, y+145, 160, 20, GLOBALS['EXP_OBS_SCENE'].val, 'Export all objects in this scene', do_obs_sce)
|
||||
Draw.EndAlign()
|
||||
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['_SCALE'] = Draw.Number('Scale:', EVENT_NONE, x+20, y+120, 140, 20, GLOBALS['_SCALE'].val, 0.01, 1000.0, 'Scale all data, (Note! some imports dont support scaled armatures)')
|
||||
GLOBALS['_XROT90'] = Draw.Toggle('Rot X90', EVENT_NONE, x+160, y+120, 60, 20, GLOBALS['_XROT90'].val, 'Rotate all objects 90 degrees about the X axis')
|
||||
GLOBALS['_YROT90'] = Draw.Toggle('Rot Y90', EVENT_NONE, x+220, y+120, 60, 20, GLOBALS['_YROT90'].val, 'Rotate all objects 90 degrees about the Y axis')
|
||||
GLOBALS['_ZROT90'] = Draw.Toggle('Rot Z90', EVENT_NONE, x+280, y+120, 60, 20, GLOBALS['_ZROT90'].val, 'Rotate all objects 90 degrees about the Z axis')
|
||||
Draw.EndAlign()
|
||||
|
||||
y -= 35
|
||||
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['EXP_EMPTY'] = Draw.Toggle('Empty', EVENT_NONE, x+20, y+120, 60, 20, GLOBALS['EXP_EMPTY'].val, 'Export empty objects')
|
||||
GLOBALS['EXP_CAMERA'] = Draw.Toggle('Camera', EVENT_NONE, x+80, y+120, 60, 20, GLOBALS['EXP_CAMERA'].val, 'Export camera objects')
|
||||
GLOBALS['EXP_LAMP'] = Draw.Toggle('Lamp', EVENT_NONE, x+140, y+120, 60, 20, GLOBALS['EXP_LAMP'].val, 'Export lamp objects')
|
||||
GLOBALS['EXP_ARMATURE'] = Draw.Toggle('Armature', EVENT_NONE, x+200, y+120, 60, 20, GLOBALS['EXP_ARMATURE'].val, 'Export armature objects')
|
||||
GLOBALS['EXP_MESH'] = Draw.Toggle('Mesh', EVENT_REDRAW, x+260, y+120, 80, 20, GLOBALS['EXP_MESH'].val, 'Export mesh objects', do_redraw) #, do_axis_z)
|
||||
Draw.EndAlign()
|
||||
|
||||
if GLOBALS['EXP_MESH'].val:
|
||||
# below mesh but
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['EXP_MESH_APPLY_MOD'] = Draw.Toggle('Modifiers', EVENT_NONE, x+260, y+100, 80, 20, GLOBALS['EXP_MESH_APPLY_MOD'].val, 'Apply modifiers to mesh objects') #, do_axis_z)
|
||||
GLOBALS['EXP_MESH_HQ_NORMALS'] = Draw.Toggle('HQ Normals', EVENT_NONE, x+260, y+80, 80, 20, GLOBALS['EXP_MESH_HQ_NORMALS'].val, 'Generate high quality normals') #, do_axis_z)
|
||||
Draw.EndAlign()
|
||||
|
||||
GLOBALS['EXP_IMAGE_COPY'] = Draw.Toggle('Copy Image Files', EVENT_NONE, x+20, y+80, 160, 20, GLOBALS['EXP_IMAGE_COPY'].val, 'Copy image files to the destination path') #, do_axis_z)
|
||||
|
||||
|
||||
Draw.Label('Export Armature Animation...', x+20,y+45, 300, 20)
|
||||
|
||||
GLOBALS['ANIM_ENABLE'] = Draw.Toggle('Enable Animation', EVENT_REDRAW, x+20, y+25, 160, 20, GLOBALS['ANIM_ENABLE'].val, 'Export keyframe animation', do_redraw)
|
||||
if GLOBALS['ANIM_ENABLE'].val:
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['ANIM_OPTIMIZE'] = Draw.Toggle('Optimize Keyframes', EVENT_REDRAW, x+20, y+0, 160, 20, GLOBALS['ANIM_OPTIMIZE'].val, 'Remove double keyframes', do_redraw)
|
||||
if GLOBALS['ANIM_OPTIMIZE'].val:
|
||||
GLOBALS['ANIM_OPTIMIZE_PRECISSION'] = Draw.Number('Precission: ', EVENT_NONE, x+180, y+0, 160, 20, GLOBALS['ANIM_OPTIMIZE_PRECISSION'].val, 1, 16, 'Tolerence for comparing double keyframes (higher for greater accuracy)')
|
||||
Draw.EndAlign()
|
||||
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['ANIM_ACTION_ALL'][1] = Draw.Toggle('Current Action', EVENT_REDRAW, x+20, y-25, 160, 20, GLOBALS['ANIM_ACTION_ALL'][1].val, 'Use actions currently applied to the armatures (use scene start/end frame)', do_anim_act_cur)
|
||||
GLOBALS['ANIM_ACTION_ALL'][0] = Draw.Toggle('All Actions', EVENT_REDRAW, x+180,y-25, 160, 20, GLOBALS['ANIM_ACTION_ALL'][0].val, 'Use all actions for armatures', do_anim_act_all)
|
||||
Draw.EndAlign()
|
||||
|
||||
|
||||
Draw.Label('Export Batch...', x+20,y-60, 300, 20)
|
||||
GLOBALS['BATCH_ENABLE'] = Draw.Toggle('Enable Batch', EVENT_REDRAW, x+20, y-80, 160, 20, GLOBALS['BATCH_ENABLE'].val, 'Automate exporting multiple scenes or groups to files', do_redraw)
|
||||
|
||||
if GLOBALS['BATCH_ENABLE'].val:
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['BATCH_GROUP'] = Draw.Toggle('Group > File', EVENT_REDRAW, x+20, y-105, 160, 20, GLOBALS['BATCH_GROUP'].val, 'Export each group as an FBX file', do_batch_type_grp)
|
||||
GLOBALS['BATCH_SCENE'] = Draw.Toggle('Scene > File', EVENT_REDRAW, x+180, y-105, 160, 20, GLOBALS['BATCH_SCENE'].val, 'Export each scene as an FBX file', do_batch_type_sce)
|
||||
|
||||
# Own dir requires OS module
|
||||
if os:
|
||||
GLOBALS['BATCH_OWN_DIR'] = Draw.Toggle('Own Dir', EVENT_NONE, x+20, y-125, 80, 20, GLOBALS['BATCH_OWN_DIR'].val, 'Create a dir for each exported file')
|
||||
GLOBALS['BATCH_FILE_PREFIX'] = Draw.String('Prefix: ', EVENT_NONE, x+100, y-125, 240, 20, GLOBALS['BATCH_FILE_PREFIX'].val, 64, 'Prefix each file with this name ')
|
||||
else:
|
||||
GLOBALS['BATCH_FILE_PREFIX'] = Draw.String('Prefix: ', EVENT_NONE, x+20, y-125, 320, 20, GLOBALS['BATCH_FILE_PREFIX'].val, 64, 'Prefix each file with this name ')
|
||||
|
||||
|
||||
Draw.EndAlign()
|
||||
|
||||
#y+=80
|
||||
|
||||
'''
|
||||
Draw.BeginAlign()
|
||||
GLOBALS['FILENAME'] = Draw.String('path: ', EVENT_NONE, x+20, y-170, 300, 20, GLOBALS['FILENAME'].val, 64, 'Prefix each file with this name ')
|
||||
Draw.PushButton('..', EVENT_FILESEL, x+320, y-170, 20, 20, 'Select the path', do_redraw)
|
||||
'''
|
||||
# Until batch is added
|
||||
#
|
||||
|
||||
|
||||
#Draw.BeginAlign()
|
||||
Draw.PushButton('Online Help', EVENT_REDRAW, x+20, y-160, 100, 20, 'Open online help in a browser window', do_help)
|
||||
Draw.PushButton('Cancel', EVENT_EXIT, x+130, y-160, 100, 20, 'Exit the exporter', fbx_ui_exit)
|
||||
Draw.PushButton('Export', EVENT_FILESEL, x+240, y-160, 100, 20, 'Export the fbx file', do_redraw)
|
||||
|
||||
#Draw.PushButton('Export', EVENT_EXIT, x+180, y-160, 160, 20, 'Export the fbx file', fbx_ui_write)
|
||||
#Draw.EndAlign()
|
||||
|
||||
# exit when mouse out of the view?
|
||||
# GLOBALS['EVENT'] = EVENT_EXIT
|
||||
|
||||
#def write_ui(filename):
|
||||
def write_ui():
|
||||
|
||||
# globals
|
||||
GLOBALS['EVENT'] = EVENT_REDRAW
|
||||
#GLOBALS['MOUSE'] = Window.GetMouseCoords()
|
||||
GLOBALS['MOUSE'] = [i/2 for i in Window.GetScreenSize()]
|
||||
GLOBALS['FILENAME'] = ''
|
||||
'''
|
||||
# IF called from the fileselector
|
||||
if filename == None:
|
||||
GLOBALS['FILENAME'] = filename # Draw.Create(Blender.sys.makename(ext='.fbx'))
|
||||
else:
|
||||
GLOBALS['FILENAME'].val = filename
|
||||
'''
|
||||
GLOBALS['EXP_OBS_SELECTED'] = Draw.Create(1) # dont need 2 variables but just do this for clarity
|
||||
GLOBALS['EXP_OBS_SCENE'] = Draw.Create(0)
|
||||
|
||||
GLOBALS['EXP_MESH'] = Draw.Create(1)
|
||||
GLOBALS['EXP_MESH_APPLY_MOD'] = Draw.Create(1)
|
||||
GLOBALS['EXP_MESH_HQ_NORMALS'] = Draw.Create(0)
|
||||
GLOBALS['EXP_ARMATURE'] = Draw.Create(1)
|
||||
GLOBALS['EXP_LAMP'] = Draw.Create(1)
|
||||
GLOBALS['EXP_CAMERA'] = Draw.Create(1)
|
||||
GLOBALS['EXP_EMPTY'] = Draw.Create(1)
|
||||
GLOBALS['EXP_IMAGE_COPY'] = Draw.Create(0)
|
||||
# animation opts
|
||||
GLOBALS['ANIM_ENABLE'] = Draw.Create(1)
|
||||
GLOBALS['ANIM_OPTIMIZE'] = Draw.Create(1)
|
||||
GLOBALS['ANIM_OPTIMIZE_PRECISSION'] = Draw.Create(4) # decimal places
|
||||
GLOBALS['ANIM_ACTION_ALL'] = [Draw.Create(0), Draw.Create(1)] # not just the current action
|
||||
|
||||
# batch export options
|
||||
GLOBALS['BATCH_ENABLE'] = Draw.Create(0)
|
||||
GLOBALS['BATCH_GROUP'] = Draw.Create(1) # cant have both of these enabled at once.
|
||||
GLOBALS['BATCH_SCENE'] = Draw.Create(0) # see above
|
||||
GLOBALS['BATCH_FILE_PREFIX'] = Draw.Create(Blender.sys.makename(ext='_').split('\\')[-1].split('/')[-1])
|
||||
GLOBALS['BATCH_OWN_DIR'] = Draw.Create(0)
|
||||
# done setting globals
|
||||
|
||||
# Used by the user interface
|
||||
GLOBALS['_SCALE'] = Draw.Create(1.0)
|
||||
GLOBALS['_XROT90'] = Draw.Create(True)
|
||||
GLOBALS['_YROT90'] = Draw.Create(False)
|
||||
GLOBALS['_ZROT90'] = Draw.Create(False)
|
||||
|
||||
# best not do move the cursor
|
||||
# Window.SetMouseCoords(*[i/2 for i in Window.GetScreenSize()])
|
||||
|
||||
# hack so the toggle buttons redraw. this is not nice at all
|
||||
while GLOBALS['EVENT'] != EVENT_EXIT:
|
||||
|
||||
if GLOBALS['BATCH_ENABLE'].val and GLOBALS['BATCH_GROUP'].val and GLOBALS['ANIM_ACTION_ALL'][1].val:
|
||||
#Draw.PupMenu("Warning%t|Cant batch export groups with 'Current Action' ")
|
||||
GLOBALS['ANIM_ACTION_ALL'][0].val = 1
|
||||
GLOBALS['ANIM_ACTION_ALL'][1].val = 0
|
||||
|
||||
if GLOBALS['EVENT'] == EVENT_FILESEL:
|
||||
if GLOBALS['BATCH_ENABLE'].val:
|
||||
txt = 'Batch FBX Dir'
|
||||
name = Blender.sys.expandpath('//')
|
||||
else:
|
||||
txt = 'Export FBX'
|
||||
name = Blender.sys.makename(ext='.fbx')
|
||||
|
||||
Blender.Window.FileSelector(fbx_ui_write, txt, name)
|
||||
#fbx_ui_write('/test.fbx')
|
||||
break
|
||||
|
||||
Draw.UIBlock(fbx_ui, 0)
|
||||
|
||||
|
||||
# GLOBALS.clear()
|
||||
|
||||
from bpy.props import *
|
||||
from io_utils import ExportHelper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user