forked from bartvdbraak/blender
script now passes pep8 checking tool.
This commit is contained in:
parent
d9c24f7e7c
commit
7bc46973d2
@ -34,6 +34,7 @@ import shutil # for file copying
|
|||||||
import bpy
|
import bpy
|
||||||
from mathutils import Vector, Euler, Matrix
|
from mathutils import Vector, Euler, Matrix
|
||||||
|
|
||||||
|
|
||||||
# XXX not used anymore, images are copied one at a time
|
# XXX not used anymore, images are copied one at a time
|
||||||
def copy_images(dest_dir, textures):
|
def copy_images(dest_dir, textures):
|
||||||
import shutil
|
import shutil
|
||||||
@ -61,6 +62,7 @@ def copy_images(dest_dir, textures):
|
|||||||
|
|
||||||
print('\tCopied %d images' % copyCount)
|
print('\tCopied %d images' % copyCount)
|
||||||
|
|
||||||
|
|
||||||
# I guess FBX uses degrees instead of radians (Arystan).
|
# I guess FBX uses degrees instead of radians (Arystan).
|
||||||
# Call this function just before writing to FBX.
|
# Call this function just before writing to FBX.
|
||||||
# 180 / math.pi == 57.295779513
|
# 180 / math.pi == 57.295779513
|
||||||
@ -81,15 +83,17 @@ sane_name_mapping_group = {}
|
|||||||
sane_name_mapping_ob['Scene'] = 'Scene_'
|
sane_name_mapping_ob['Scene'] = 'Scene_'
|
||||||
sane_name_mapping_ob['blend_root'] = 'blend_root_'
|
sane_name_mapping_ob['blend_root'] = 'blend_root_'
|
||||||
|
|
||||||
|
|
||||||
def increment_string(t):
|
def increment_string(t):
|
||||||
name = t
|
name = t
|
||||||
num = ''
|
num = ''
|
||||||
while name and name[-1].isdigit():
|
while name and name[-1].isdigit():
|
||||||
num = name[-1] + num
|
num = name[-1] + num
|
||||||
name = name[:-1]
|
name = name[:-1]
|
||||||
if num: return '%s%d' % (name, int(num)+1)
|
if num:
|
||||||
else: return name + '_0'
|
return '%s%d' % (name, int(num) + 1)
|
||||||
|
else:
|
||||||
|
return name + '_0'
|
||||||
|
|
||||||
|
|
||||||
# todo - Disallow the name 'Scene' and 'blend_root' - it will bugger things up.
|
# todo - Disallow the name 'Scene' and 'blend_root' - it will bugger things up.
|
||||||
@ -103,8 +107,7 @@ def sane_name(data, dct):
|
|||||||
other = None
|
other = None
|
||||||
use_other = False
|
use_other = False
|
||||||
|
|
||||||
if data: name = data.name
|
name = data.name if data else None
|
||||||
else: name = None
|
|
||||||
orig_name = name
|
orig_name = name
|
||||||
|
|
||||||
if other:
|
if other:
|
||||||
@ -124,7 +127,8 @@ def sane_name(data, dct):
|
|||||||
|
|
||||||
name = bpy.path.clean_name(name) # use our own
|
name = bpy.path.clean_name(name) # use our own
|
||||||
|
|
||||||
while name in iter(dct.values()): name = increment_string(name)
|
while name in iter(dct.values()):
|
||||||
|
name = increment_string(name)
|
||||||
|
|
||||||
if use_other: # even if other is None - orig_name_other will be a string or None
|
if use_other: # even if other is None - orig_name_other will be a string or None
|
||||||
dct[orig_name, orig_name_other] = name
|
dct[orig_name, orig_name_other] = name
|
||||||
@ -133,11 +137,25 @@ def sane_name(data, dct):
|
|||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def sane_obname(data): return sane_name(data, sane_name_mapping_ob)
|
|
||||||
def sane_matname(data): return sane_name(data, sane_name_mapping_mat)
|
def sane_obname(data):
|
||||||
def sane_texname(data): return sane_name(data, sane_name_mapping_tex)
|
return sane_name(data, sane_name_mapping_ob)
|
||||||
def sane_takename(data): return sane_name(data, sane_name_mapping_take)
|
|
||||||
def sane_groupname(data): return sane_name(data, sane_name_mapping_group)
|
|
||||||
|
def sane_matname(data):
|
||||||
|
return sane_name(data, sane_name_mapping_mat)
|
||||||
|
|
||||||
|
|
||||||
|
def sane_texname(data):
|
||||||
|
return sane_name(data, sane_name_mapping_tex)
|
||||||
|
|
||||||
|
|
||||||
|
def sane_takename(data):
|
||||||
|
return sane_name(data, sane_name_mapping_take)
|
||||||
|
|
||||||
|
|
||||||
|
def sane_groupname(data):
|
||||||
|
return sane_name(data, sane_name_mapping_group)
|
||||||
|
|
||||||
# def derived_paths(fname_orig, basepath, FORCE_CWD=False):
|
# def derived_paths(fname_orig, basepath, FORCE_CWD=False):
|
||||||
# '''
|
# '''
|
||||||
@ -162,6 +180,7 @@ def sane_groupname(data): return sane_name(data, sane_name_mapping_group)
|
|||||||
def mat4x4str(mat):
|
def mat4x4str(mat):
|
||||||
return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([f for v in mat for f in v])
|
return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([f for v in mat for f in v])
|
||||||
|
|
||||||
|
|
||||||
# XXX not used
|
# XXX not used
|
||||||
# duplicated in OBJ exporter
|
# duplicated in OBJ exporter
|
||||||
def getVertsFromGroup(me, group_index):
|
def getVertsFromGroup(me, group_index):
|
||||||
@ -174,6 +193,7 @@ def getVertsFromGroup(me, group_index):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
# ob must be OB_MESH
|
# ob must be OB_MESH
|
||||||
def BPyMesh_meshWeight2List(ob, me):
|
def BPyMesh_meshWeight2List(ob, me):
|
||||||
''' Takes a mesh and return its group names and a list of lists, one list per vertex.
|
''' Takes a mesh and return its group names and a list of lists, one list per vertex.
|
||||||
@ -197,10 +217,10 @@ def BPyMesh_meshWeight2List(ob, me):
|
|||||||
|
|
||||||
return groupNames, vWeightList
|
return groupNames, vWeightList
|
||||||
|
|
||||||
|
|
||||||
def meshNormalizedWeights(ob, me):
|
def meshNormalizedWeights(ob, me):
|
||||||
try: # account for old bad BPyMesh
|
try: # account for old bad BPyMesh
|
||||||
groupNames, vWeightList = BPyMesh_meshWeight2List(ob, me)
|
groupNames, vWeightList = BPyMesh_meshWeight2List(ob, me)
|
||||||
# groupNames, vWeightList = BPyMesh.meshWeight2List(me)
|
|
||||||
except:
|
except:
|
||||||
return [], []
|
return [], []
|
||||||
|
|
||||||
@ -226,6 +246,7 @@ header_comment = \
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
# This func can be called with just the filepath
|
# This func can be called with just the filepath
|
||||||
def save(operator, context, filepath="",
|
def save(operator, context, filepath="",
|
||||||
GLOBAL_MATRIX=None,
|
GLOBAL_MATRIX=None,
|
||||||
@ -266,21 +287,18 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
# get the path component of filepath
|
# get the path component of filepath
|
||||||
tmp_exists = bpy.utils.exists(fbxpath)
|
tmp_exists = bpy.utils.exists(fbxpath)
|
||||||
# tmp_exists = Blender.sys.exists(fbxpath)
|
|
||||||
|
|
||||||
if tmp_exists != 2: # a file, we want a path
|
if tmp_exists != 2: # a file, we want a path
|
||||||
fbxpath = os.path.dirname(fbxpath)
|
fbxpath = os.path.dirname(fbxpath)
|
||||||
# while fbxpath and fbxpath[-1] not in ('/', '\\'):
|
# while fbxpath and fbxpath[-1] not in ('/', '\\'):
|
||||||
# fbxpath = fbxpath[:-1]
|
# fbxpath = fbxpath[:-1]
|
||||||
if not fbxpath:
|
if not fbxpath:
|
||||||
# if not filepath:
|
|
||||||
# XXX
|
# XXX
|
||||||
print('Error%t|Directory does not exist!')
|
print('Error%t|Directory does not exist!')
|
||||||
# Draw.PupMenu('Error%t|Directory does not exist!')
|
# Draw.PupMenu('Error%t|Directory does not exist!')
|
||||||
return
|
return
|
||||||
|
|
||||||
tmp_exists = bpy.utils.exists(fbxpath)
|
tmp_exists = bpy.utils.exists(fbxpath)
|
||||||
# tmp_exists = Blender.sys.exists(fbxpath)
|
|
||||||
|
|
||||||
if tmp_exists != 2:
|
if tmp_exists != 2:
|
||||||
# XXX
|
# XXX
|
||||||
@ -292,7 +310,6 @@ def save(operator, context, filepath="",
|
|||||||
fbxpath += os.sep
|
fbxpath += os.sep
|
||||||
del tmp_exists
|
del tmp_exists
|
||||||
|
|
||||||
|
|
||||||
if BATCH_GROUP:
|
if BATCH_GROUP:
|
||||||
data_seq = bpy.data.groups
|
data_seq = bpy.data.groups
|
||||||
else:
|
else:
|
||||||
@ -300,13 +317,11 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
# call this function within a loop with BATCH_ENABLE == False
|
# call this function within a loop with BATCH_ENABLE == False
|
||||||
orig_sce = context.scene
|
orig_sce = context.scene
|
||||||
# orig_sce = bpy.data.scenes.active
|
|
||||||
|
|
||||||
new_fbxpath = fbxpath # own dir option modifies, we need to keep an original
|
new_fbxpath = fbxpath # own dir option modifies, we need to keep an original
|
||||||
for data in data_seq: # scene or group
|
for data in data_seq: # scene or group
|
||||||
newname = BATCH_FILE_PREFIX + bpy.path.clean_name(data.name)
|
newname = BATCH_FILE_PREFIX + bpy.path.clean_name(data.name)
|
||||||
|
|
||||||
|
|
||||||
if BATCH_OWN_DIR:
|
if BATCH_OWN_DIR:
|
||||||
new_fbxpath = fbxpath + newname + os.sep
|
new_fbxpath = fbxpath + newname + os.sep
|
||||||
# path may already exist
|
# path may already exist
|
||||||
@ -316,7 +331,6 @@ def save(operator, context, filepath="",
|
|||||||
# if Blender.sys.exists(new_fbxpath) == 0:
|
# if Blender.sys.exists(new_fbxpath) == 0:
|
||||||
os.mkdir(new_fbxpath)
|
os.mkdir(new_fbxpath)
|
||||||
|
|
||||||
|
|
||||||
filepath = new_fbxpath + newname + '.fbx'
|
filepath = new_fbxpath + newname + '.fbx'
|
||||||
|
|
||||||
print('\nBatch exporting %s as...\n\t%r' % (data, filepath))
|
print('\nBatch exporting %s as...\n\t%r' % (data, filepath))
|
||||||
@ -335,11 +349,8 @@ def save(operator, context, filepath="",
|
|||||||
# TODO - BUMMER! Armatures not in the group wont animate the mesh
|
# TODO - BUMMER! Armatures not in the group wont animate the mesh
|
||||||
|
|
||||||
else: # scene
|
else: # scene
|
||||||
|
|
||||||
|
|
||||||
data_seq.active = data
|
data_seq.active = data
|
||||||
|
|
||||||
|
|
||||||
# Call self with modified args
|
# Call self with modified args
|
||||||
# Dont pass batch options since we already usedt them
|
# Dont pass batch options since we already usedt them
|
||||||
write(filepath, data.objects,
|
write(filepath, data.objects,
|
||||||
@ -408,7 +419,6 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
# not public
|
# not public
|
||||||
pose = fbxArm.blenObject.pose
|
pose = fbxArm.blenObject.pose
|
||||||
# pose = fbxArm.blenObject.getPose()
|
|
||||||
self.__pose_bone = pose.bones[self.blenName]
|
self.__pose_bone = pose.bones[self.blenName]
|
||||||
|
|
||||||
# store a list if matricies here, (poseMatrix, head, tail)
|
# store a list if matricies here, (poseMatrix, head, tail)
|
||||||
@ -434,7 +444,6 @@ def save(operator, context, filepath="",
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
self.__anim_poselist[f] = self.__pose_bone.matrix.copy()
|
self.__anim_poselist[f] = self.__pose_bone.matrix.copy()
|
||||||
# self.__anim_poselist[f] = self.__pose_bone.poseMatrix.copy()
|
|
||||||
|
|
||||||
# get pose from frame.
|
# get pose from frame.
|
||||||
def getPoseMatrix(self, f): # ----------------------------------------------
|
def getPoseMatrix(self, f): # ----------------------------------------------
|
||||||
@ -466,7 +475,6 @@ def save(operator, context, filepath="",
|
|||||||
def flushAnimData(self):
|
def flushAnimData(self):
|
||||||
self.__anim_poselist.clear()
|
self.__anim_poselist.clear()
|
||||||
|
|
||||||
|
|
||||||
class my_object_generic(object):
|
class my_object_generic(object):
|
||||||
__slots__ = ("fbxName",
|
__slots__ = ("fbxName",
|
||||||
"blenObject",
|
"blenObject",
|
||||||
@ -492,9 +500,11 @@ def save(operator, context, filepath="",
|
|||||||
self.blenObject = ob
|
self.blenObject = ob
|
||||||
self.fbxGroupNames = []
|
self.fbxGroupNames = []
|
||||||
self.fbxParent = None # set later on IF the parent is in the selection.
|
self.fbxParent = None # set later on IF the parent is in the selection.
|
||||||
if matrixWorld: self.matrixWorld = GLOBAL_MATRIX * matrixWorld
|
if matrixWorld:
|
||||||
else: self.matrixWorld = GLOBAL_MATRIX * ob.matrix_world
|
self.matrixWorld = GLOBAL_MATRIX * matrixWorld
|
||||||
# else: self.matrixWorld = ob.matrixWorld * GLOBAL_MATRIX
|
else:
|
||||||
|
self.matrixWorld = GLOBAL_MATRIX * ob.matrix_world
|
||||||
|
|
||||||
self.__anim_poselist = {} # we should only access this
|
self.__anim_poselist = {} # we should only access this
|
||||||
|
|
||||||
def parRelMatrix(self):
|
def parRelMatrix(self):
|
||||||
@ -535,10 +545,6 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print('\nFBX export starting... %r' % filepath)
|
print('\nFBX export starting... %r' % filepath)
|
||||||
start_time = time.clock()
|
start_time = time.clock()
|
||||||
try:
|
try:
|
||||||
@ -549,7 +555,6 @@ def save(operator, context, filepath="",
|
|||||||
scene = context.scene
|
scene = context.scene
|
||||||
world = scene.world
|
world = scene.world
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------- Write the header first
|
# ---------------------------- Write the header first
|
||||||
file.write(header_comment)
|
file.write(header_comment)
|
||||||
if time:
|
if time:
|
||||||
@ -580,7 +585,6 @@ def save(operator, context, filepath="",
|
|||||||
file.write('\nCreationTime: "%.4i-%.2i-%.2i %.2i:%.2i:%.2i:000"' % curtime)
|
file.write('\nCreationTime: "%.4i-%.2i-%.2i %.2i:%.2i:%.2i:000"' % curtime)
|
||||||
file.write('\nCreator: "Blender version %s"' % bpy.app.version_string)
|
file.write('\nCreator: "Blender version %s"' % bpy.app.version_string)
|
||||||
|
|
||||||
|
|
||||||
pose_items = [] # list of (fbxName, matrix) to write pose data for, easier to collect allong the way
|
pose_items = [] # list of (fbxName, matrix) to write pose data for, easier to collect allong the way
|
||||||
|
|
||||||
# --------------- funcs for exporting
|
# --------------- funcs for exporting
|
||||||
@ -612,7 +616,8 @@ def save(operator, context, filepath="",
|
|||||||
else:
|
else:
|
||||||
# This is bad because we need the parent relative matrix from the fbx parent (if we have one), dont use anymore
|
# This is bad because we need the parent relative matrix from the fbx parent (if we have one), dont use anymore
|
||||||
#if ob and not matrix: matrix = ob.matrix_world * GLOBAL_MATRIX
|
#if ob and not matrix: matrix = ob.matrix_world * GLOBAL_MATRIX
|
||||||
if ob and not matrix: raise Exception("error: this should never happen!")
|
if ob and not matrix:
|
||||||
|
raise Exception("error: this should never happen!")
|
||||||
|
|
||||||
matrix_rot = matrix
|
matrix_rot = matrix
|
||||||
#if matrix:
|
#if matrix:
|
||||||
@ -627,7 +632,7 @@ def save(operator, context, filepath="",
|
|||||||
matrix_rot = matrix_rot * mtx_x90
|
matrix_rot = matrix_rot * mtx_x90
|
||||||
elif ob and ob.type == 'CAMERA':
|
elif ob and ob.type == 'CAMERA':
|
||||||
y = Vector((0.0, 1.0, 0.0)) * matrix_rot
|
y = Vector((0.0, 1.0, 0.0)) * matrix_rot
|
||||||
matrix_rot = Matrix.Rotation(math.pi/2, 3, y) * matrix_rot
|
matrix_rot = Matrix.Rotation(math.pi / 2.0, 3, y) * matrix_rot
|
||||||
# else do nothing.
|
# else do nothing.
|
||||||
|
|
||||||
loc = tuple(loc)
|
loc = tuple(loc)
|
||||||
@ -635,9 +640,9 @@ def save(operator, context, filepath="",
|
|||||||
scale = tuple(scale)
|
scale = tuple(scale)
|
||||||
else:
|
else:
|
||||||
if not loc:
|
if not loc:
|
||||||
loc = 0,0,0
|
loc = 0.0, 0.0, 0.0
|
||||||
scale = 1,1,1
|
scale = 1.0, 1.0, 1.0
|
||||||
rot = 0,0,0
|
rot = 0.0, 0.0, 0.0
|
||||||
|
|
||||||
return loc, rot, scale, matrix, matrix_rot
|
return loc, rot, scale, matrix, matrix_rot
|
||||||
|
|
||||||
@ -746,7 +751,6 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
return loc, rot, scale, matrix, matrix_rot
|
return loc, rot, scale, matrix, matrix_rot
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------- Armatures
|
# -------------------------------------------- Armatures
|
||||||
#def write_bone(bone, name, matrix_mod):
|
#def write_bone(bone, name, matrix_mod):
|
||||||
def write_bone(my_bone):
|
def write_bone(my_bone):
|
||||||
@ -757,7 +761,6 @@ def save(operator, context, filepath="",
|
|||||||
poseMatrix = write_object_props(my_bone.blenBone)[3] # dont apply bone matricies anymore
|
poseMatrix = write_object_props(my_bone.blenBone)[3] # dont apply bone matricies anymore
|
||||||
pose_items.append((my_bone.fbxName, poseMatrix))
|
pose_items.append((my_bone.fbxName, poseMatrix))
|
||||||
|
|
||||||
|
|
||||||
# file.write('\n\t\t\tProperty: "Size", "double", "",%.6f' % ((my_bone.blenData.head['ARMATURESPACE'] - my_bone.blenData.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length)
|
# file.write('\n\t\t\tProperty: "Size", "double", "",%.6f' % ((my_bone.blenData.head['ARMATURESPACE'] - my_bone.blenData.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length)
|
||||||
file.write('\n\t\t\tProperty: "Size", "double", "",1')
|
file.write('\n\t\t\tProperty: "Size", "double", "",1')
|
||||||
|
|
||||||
@ -1035,7 +1038,8 @@ def save(operator, context, filepath="",
|
|||||||
light_type_items = {'POINT': 0, 'SUN': 1, 'SPOT': 2, 'HEMI': 3, 'AREA': 4}
|
light_type_items = {'POINT': 0, 'SUN': 1, 'SPOT': 2, 'HEMI': 3, 'AREA': 4}
|
||||||
light_type = light_type_items[light.type]
|
light_type = light_type_items[light.type]
|
||||||
|
|
||||||
if light_type > 2: light_type = 1 # hemi and area lights become directional
|
if light_type > 2:
|
||||||
|
light_type = 1 # hemi and area lights become directional
|
||||||
|
|
||||||
# mode = light.mode
|
# mode = light.mode
|
||||||
if light.shadow_method == 'RAY_SHADOW' or light.shadow_method == 'BUFFER_SHADOW':
|
if light.shadow_method == 'RAY_SHADOW' or light.shadow_method == 'BUFFER_SHADOW':
|
||||||
@ -1059,13 +1063,13 @@ def save(operator, context, filepath="",
|
|||||||
file.write('\n\t\t\tProperty: "DrawFrontFacingVolumetricLight", "bool", "",0')
|
file.write('\n\t\t\tProperty: "DrawFrontFacingVolumetricLight", "bool", "",0')
|
||||||
file.write('\n\t\t\tProperty: "GoboProperty", "object", ""')
|
file.write('\n\t\t\tProperty: "GoboProperty", "object", ""')
|
||||||
file.write('\n\t\t\tProperty: "Color", "Color", "A+",1,1,1')
|
file.write('\n\t\t\tProperty: "Color", "Color", "A+",1,1,1')
|
||||||
file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy*100, 200))) # clamp below 200
|
file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy * 100.0, 200.0))) # clamp below 200
|
||||||
if light.type == 'SPOT':
|
if light.type == 'SPOT':
|
||||||
file.write('\n\t\t\tProperty: "Cone angle", "Cone angle", "A+",%.2f' % math.degrees(light.spot_size))
|
file.write('\n\t\t\tProperty: "Cone angle", "Cone angle", "A+",%.2f' % math.degrees(light.spot_size))
|
||||||
file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50')
|
file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50')
|
||||||
file.write('\n\t\t\tProperty: "Color", "Color", "A",%.2f,%.2f,%.2f' % tuple(light.color))
|
file.write('\n\t\t\tProperty: "Color", "Color", "A",%.2f,%.2f,%.2f' % tuple(light.color))
|
||||||
|
|
||||||
file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy*100, 200))) # clamp below 200
|
file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy * 100.0, 200.0))) # clamp below 200
|
||||||
|
|
||||||
file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50')
|
file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50')
|
||||||
file.write('\n\t\t\tProperty: "LightType", "enum", "",%i' % light_type)
|
file.write('\n\t\t\tProperty: "LightType", "enum", "",%i' % light_type)
|
||||||
@ -1096,7 +1100,8 @@ def save(operator, context, filepath="",
|
|||||||
# matrixOnly is not used at the moment
|
# matrixOnly is not used at the moment
|
||||||
def write_null(my_null=None, fbxName=None, matrixOnly=None):
|
def write_null(my_null=None, fbxName=None, matrixOnly=None):
|
||||||
# ob can be null
|
# ob can be null
|
||||||
if not fbxName: fbxName = my_null.fbxName
|
if not fbxName:
|
||||||
|
fbxName = my_null.fbxName
|
||||||
|
|
||||||
file.write('\n\tModel: "Model::%s", "Null" {' % fbxName)
|
file.write('\n\tModel: "Model::%s", "Null" {' % fbxName)
|
||||||
file.write('\n\t\tVersion: 232')
|
file.write('\n\t\tVersion: 232')
|
||||||
@ -1106,8 +1111,10 @@ def save(operator, context, filepath="",
|
|||||||
poseMatrix = write_object_props(None, None, matrixOnly)[3]
|
poseMatrix = write_object_props(None, None, matrixOnly)[3]
|
||||||
|
|
||||||
else: # all other Null's
|
else: # all other Null's
|
||||||
if my_null: poseMatrix = write_object_props(my_null.blenObject, None, my_null.parRelMatrix())[3]
|
if my_null:
|
||||||
else: poseMatrix = write_object_props()[3]
|
poseMatrix = write_object_props(my_null.blenObject, None, my_null.parRelMatrix())[3]
|
||||||
|
else:
|
||||||
|
poseMatrix = write_object_props()[3]
|
||||||
|
|
||||||
pose_items.append((fbxName, poseMatrix))
|
pose_items.append((fbxName, poseMatrix))
|
||||||
|
|
||||||
@ -1121,9 +1128,10 @@ def save(operator, context, filepath="",
|
|||||||
}''')
|
}''')
|
||||||
|
|
||||||
# Material Settings
|
# Material Settings
|
||||||
if world: world_amb = tuple(world.ambient_color)
|
if world:
|
||||||
# if world: world_amb = world.getAmb()
|
world_amb = world.ambient_color[:]
|
||||||
else: world_amb = (0,0,0) # Default value
|
else:
|
||||||
|
world_amb = 0.0, 0.0, 0.0 # default value
|
||||||
|
|
||||||
def write_material(matname, mat):
|
def write_material(matname, mat):
|
||||||
file.write('\n\tMaterial: "Material::%s", "" {' % matname)
|
file.write('\n\tMaterial: "Material::%s", "" {' % matname)
|
||||||
@ -1137,7 +1145,7 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
mat_dif = mat.diffuse_intensity
|
mat_dif = mat.diffuse_intensity
|
||||||
mat_amb = mat.ambient
|
mat_amb = mat.ambient
|
||||||
mat_hard = (float(mat.specular_hardness)-1)/5.10
|
mat_hard = (float(mat.specular_hardness) - 1.0) / 5.10
|
||||||
mat_spec = mat.specular_intensity / 2.0
|
mat_spec = mat.specular_intensity / 2.0
|
||||||
mat_alpha = mat.alpha
|
mat_alpha = mat.alpha
|
||||||
mat_emit = mat.emit
|
mat_emit = mat.emit
|
||||||
@ -1234,7 +1242,6 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
file.write('\n\t\t\tProperty: "Path", "charptr", "", "%s"' % fname_strip)
|
file.write('\n\t\t\tProperty: "Path", "charptr", "", "%s"' % fname_strip)
|
||||||
|
|
||||||
|
|
||||||
file.write('''
|
file.write('''
|
||||||
Property: "StartFrame", "int", "",0
|
Property: "StartFrame", "int", "",0
|
||||||
Property: "StopFrame", "int", "",0
|
Property: "StopFrame", "int", "",0
|
||||||
@ -1248,11 +1255,11 @@ def save(operator, context, filepath="",
|
|||||||
UseMipMap: 0''')
|
UseMipMap: 0''')
|
||||||
|
|
||||||
file.write('\n\t\tFilename: "%s"' % fname_strip)
|
file.write('\n\t\tFilename: "%s"' % fname_strip)
|
||||||
if fname_strip: fname_strip = '/' + fname_strip
|
if fname_strip:
|
||||||
|
fname_strip = '/' + fname_strip
|
||||||
file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # make relative
|
file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # make relative
|
||||||
file.write('\n\t}')
|
file.write('\n\t}')
|
||||||
|
|
||||||
|
|
||||||
def write_texture(texname, tex, num):
|
def write_texture(texname, tex, num):
|
||||||
# if tex is None then this is a dummy tex
|
# if tex is None then this is a dummy tex
|
||||||
file.write('\n\tTexture: "Texture::%s", "TextureVideoClip" {' % texname)
|
file.write('\n\tTexture: "Texture::%s", "TextureVideoClip" {' % texname)
|
||||||
@ -1268,7 +1275,6 @@ def save(operator, context, filepath="",
|
|||||||
Property: "Scaling", "Vector", "A+",1,1,1''')
|
Property: "Scaling", "Vector", "A+",1,1,1''')
|
||||||
file.write('\n\t\t\tProperty: "Texture alpha", "Number", "A+",%i' % num)
|
file.write('\n\t\t\tProperty: "Texture alpha", "Number", "A+",%i' % num)
|
||||||
|
|
||||||
|
|
||||||
# WrapModeU/V 0==rep, 1==clamp, TODO add support
|
# WrapModeU/V 0==rep, 1==clamp, TODO add support
|
||||||
file.write('''
|
file.write('''
|
||||||
Property: "TextureTypeUse", "enum", "",0
|
Property: "TextureTypeUse", "enum", "",0
|
||||||
@ -1430,7 +1436,6 @@ def save(operator, context, filepath="",
|
|||||||
file.write('\n\t\tShading: Y')
|
file.write('\n\t\tShading: Y')
|
||||||
file.write('\n\t\tCulling: "CullingOff"')
|
file.write('\n\t\tCulling: "CullingOff"')
|
||||||
|
|
||||||
|
|
||||||
# Write the Real Mesh data here
|
# Write the Real Mesh data here
|
||||||
file.write('\n\t\tVertices: ')
|
file.write('\n\t\tVertices: ')
|
||||||
i = -1
|
i = -1
|
||||||
@ -1484,7 +1489,6 @@ def save(operator, context, filepath="",
|
|||||||
file.write(',%i,%i' % ed_val)
|
file.write(',%i,%i' % ed_val)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
file.write('\n\t\tEdges: ')
|
file.write('\n\t\tEdges: ')
|
||||||
i = -1
|
i = -1
|
||||||
for ed in me_edges:
|
for ed in me_edges:
|
||||||
@ -1511,10 +1515,12 @@ def save(operator, context, filepath="",
|
|||||||
i = -1
|
i = -1
|
||||||
for v in me_vertices:
|
for v in me_vertices:
|
||||||
if i == -1:
|
if i == -1:
|
||||||
file.write('%.15f,%.15f,%.15f' % v.normal[:]); i=0
|
file.write('%.15f,%.15f,%.15f' % v.normal[:])
|
||||||
|
i = 0
|
||||||
else:
|
else:
|
||||||
if i == 2:
|
if i == 2:
|
||||||
file.write('\n '); i=0
|
file.write('\n\t\t\t ')
|
||||||
|
i = 0
|
||||||
file.write(',%.15f,%.15f,%.15f' % v.normal[:])
|
file.write(',%.15f,%.15f,%.15f' % v.normal[:])
|
||||||
i += 1
|
i += 1
|
||||||
file.write('\n\t\t}')
|
file.write('\n\t\t}')
|
||||||
@ -1531,10 +1537,12 @@ def save(operator, context, filepath="",
|
|||||||
i = -1
|
i = -1
|
||||||
for f in me_faces:
|
for f in me_faces:
|
||||||
if i == -1:
|
if i == -1:
|
||||||
file.write('%i' % f.use_smooth); i=0
|
file.write('%i' % f.use_smooth)
|
||||||
|
i = 0
|
||||||
else:
|
else:
|
||||||
if i == 54:
|
if i == 54:
|
||||||
file.write('\n '); i=0
|
file.write('\n\t\t\t ')
|
||||||
|
i = 0
|
||||||
file.write(',%i' % f.use_smooth)
|
file.write(',%i' % f.use_smooth)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@ -1552,16 +1560,17 @@ def save(operator, context, filepath="",
|
|||||||
i = -1
|
i = -1
|
||||||
for ed in me_edges:
|
for ed in me_edges:
|
||||||
if i == -1:
|
if i == -1:
|
||||||
file.write('%i' % (ed.use_edge_sharp)); i=0
|
file.write('%i' % (ed.use_edge_sharp))
|
||||||
|
i = 0
|
||||||
else:
|
else:
|
||||||
if i == 54:
|
if i == 54:
|
||||||
file.write('\n '); i=0
|
file.write('\n\t\t\t ')
|
||||||
|
i = 0
|
||||||
file.write(',%i' % (ed.use_edge_sharp))
|
file.write(',%i' % (ed.use_edge_sharp))
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
file.write('\n\t\t}')
|
file.write('\n\t\t}')
|
||||||
|
|
||||||
|
|
||||||
# Write VertexColor Layers
|
# Write VertexColor Layers
|
||||||
# note, no programs seem to use this info :/
|
# note, no programs seem to use this info :/
|
||||||
collayers = []
|
collayers = []
|
||||||
@ -1613,8 +1622,6 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
file.write('\n\t\t}')
|
file.write('\n\t\t}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Write UV and texture layers.
|
# Write UV and texture layers.
|
||||||
uvlayers = []
|
uvlayers = []
|
||||||
if do_uvs:
|
if do_uvs:
|
||||||
@ -1715,9 +1722,7 @@ def save(operator, context, filepath="",
|
|||||||
TextureId: ''')
|
TextureId: ''')
|
||||||
file.write('\n\t\t}')
|
file.write('\n\t\t}')
|
||||||
|
|
||||||
|
|
||||||
# Done with UV/textures.
|
# Done with UV/textures.
|
||||||
|
|
||||||
if do_materials:
|
if do_materials:
|
||||||
file.write('\n\t\tLayerElementMaterial: 0 {')
|
file.write('\n\t\tLayerElementMaterial: 0 {')
|
||||||
file.write('\n\t\t\tVersion: 101')
|
file.write('\n\t\t\tVersion: 101')
|
||||||
@ -1752,11 +1757,15 @@ def save(operator, context, filepath="",
|
|||||||
i = -1
|
i = -1
|
||||||
for f, uf in zip(me_faces, uv_faces):
|
for f, uf in zip(me_faces, uv_faces):
|
||||||
# for f in me_faces:
|
# for f in me_faces:
|
||||||
try: mat = mats[f.material_index]
|
try:
|
||||||
except:mat = None
|
mat = mats[f.material_index]
|
||||||
|
except:
|
||||||
|
mat = None
|
||||||
|
|
||||||
if do_uvs: tex = uf.image # WARNING - MULTI UV LAYER IMAGES NOT SUPPORTED :/
|
if do_uvs:
|
||||||
else: tex = None
|
tex = uf.image # WARNING - MULTI UV LAYER IMAGES NOT SUPPORTED :/
|
||||||
|
else:
|
||||||
|
tex = None
|
||||||
|
|
||||||
if i == -1:
|
if i == -1:
|
||||||
i = 0
|
i = 0
|
||||||
@ -1808,7 +1817,6 @@ def save(operator, context, filepath="",
|
|||||||
TypedIndex: 0
|
TypedIndex: 0
|
||||||
}''')
|
}''')
|
||||||
|
|
||||||
|
|
||||||
file.write('\n\t\t}')
|
file.write('\n\t\t}')
|
||||||
|
|
||||||
if len(uvlayers) > 1:
|
if len(uvlayers) > 1:
|
||||||
@ -1838,7 +1846,8 @@ def save(operator, context, filepath="",
|
|||||||
if len(collayers) > 1:
|
if len(collayers) > 1:
|
||||||
# Take into account any UV layers
|
# Take into account any UV layers
|
||||||
layer_offset = 0
|
layer_offset = 0
|
||||||
if uvlayers: layer_offset = len(uvlayers)-1
|
if uvlayers:
|
||||||
|
layer_offset = len(uvlayers) - 1
|
||||||
|
|
||||||
for i in range(layer_offset, len(collayers) + layer_offset):
|
for i in range(layer_offset, len(collayers) + layer_offset):
|
||||||
file.write('\n\t\tLayer: %i {' % i)
|
file.write('\n\t\tLayer: %i {' % i)
|
||||||
@ -1866,7 +1875,6 @@ def save(operator, context, filepath="",
|
|||||||
MultiLayer: 0
|
MultiLayer: 0
|
||||||
}''')
|
}''')
|
||||||
|
|
||||||
|
|
||||||
# add meshes here to clear because they are not used anywhere.
|
# add meshes here to clear because they are not used anywhere.
|
||||||
meshes_to_clear = []
|
meshes_to_clear = []
|
||||||
|
|
||||||
@ -1890,8 +1898,10 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
# if EXP_OBS_SELECTED is false, use sceens objects
|
# if EXP_OBS_SELECTED is false, use sceens objects
|
||||||
if not batch_objects:
|
if not batch_objects:
|
||||||
if EXP_OBS_SELECTED: tmp_objects = context.selected_objects
|
if EXP_OBS_SELECTED:
|
||||||
else: tmp_objects = scene.objects
|
tmp_objects = context.selected_objects
|
||||||
|
else:
|
||||||
|
tmp_objects = scene.objects
|
||||||
else:
|
else:
|
||||||
tmp_objects = batch_objects
|
tmp_objects = batch_objects
|
||||||
|
|
||||||
@ -1912,7 +1922,6 @@ def save(operator, context, filepath="",
|
|||||||
# This causes the makeDisplayList command to effect the mesh
|
# This causes the makeDisplayList command to effect the mesh
|
||||||
scene.frame_set(scene.frame_current)
|
scene.frame_set(scene.frame_current)
|
||||||
|
|
||||||
|
|
||||||
for ob_base in tmp_objects:
|
for ob_base in tmp_objects:
|
||||||
|
|
||||||
# ignore dupli children
|
# ignore dupli children
|
||||||
@ -1936,7 +1945,8 @@ def save(operator, context, filepath="",
|
|||||||
elif tmp_ob_type == 'ARMATURE':
|
elif tmp_ob_type == 'ARMATURE':
|
||||||
if EXP_ARMATURE:
|
if EXP_ARMATURE:
|
||||||
# TODO - armatures dont work in dupligroups!
|
# TODO - armatures dont work in dupligroups!
|
||||||
if ob not in ob_arms: ob_arms.append(ob)
|
if ob not in ob_arms:
|
||||||
|
ob_arms.append(ob)
|
||||||
# ob_arms.append(ob) # replace later. was "ob_arms.append(sane_obname(ob), ob)"
|
# ob_arms.append(ob) # replace later. was "ob_arms.append(sane_obname(ob), ob)"
|
||||||
elif tmp_ob_type == 'EMPTY':
|
elif tmp_ob_type == 'EMPTY':
|
||||||
if EXP_EMPTY:
|
if EXP_EMPTY:
|
||||||
@ -1944,10 +1954,11 @@ def save(operator, context, filepath="",
|
|||||||
elif EXP_MESH:
|
elif EXP_MESH:
|
||||||
origData = True
|
origData = True
|
||||||
if tmp_ob_type != 'MESH':
|
if tmp_ob_type != 'MESH':
|
||||||
# me = bpy.data.meshes.new()
|
try:
|
||||||
try: me = ob.create_mesh(scene, True, 'PREVIEW')
|
me = ob.create_mesh(scene, True, 'PREVIEW')
|
||||||
# try: me.getFromObject(ob)
|
except:
|
||||||
except: me = None
|
me = None
|
||||||
|
|
||||||
if me:
|
if me:
|
||||||
meshes_to_clear.append(me)
|
meshes_to_clear.append(me)
|
||||||
mats = me.materials
|
mats = me.materials
|
||||||
@ -1955,9 +1966,7 @@ def save(operator, context, filepath="",
|
|||||||
else:
|
else:
|
||||||
# Mesh Type!
|
# Mesh Type!
|
||||||
if EXP_MESH_APPLY_MOD:
|
if EXP_MESH_APPLY_MOD:
|
||||||
# me = bpy.data.meshes.new()
|
|
||||||
me = ob.create_mesh(scene, True, 'PREVIEW')
|
me = ob.create_mesh(scene, True, 'PREVIEW')
|
||||||
# me.getFromObject(ob)
|
|
||||||
|
|
||||||
# print ob, me, me.getVertGroupNames()
|
# print ob, me, me.getVertGroupNames()
|
||||||
meshes_to_clear.append(me)
|
meshes_to_clear.append(me)
|
||||||
@ -1965,7 +1974,6 @@ def save(operator, context, filepath="",
|
|||||||
mats = me.materials
|
mats = me.materials
|
||||||
else:
|
else:
|
||||||
me = ob.data
|
me = ob.data
|
||||||
# me = ob.getData(mesh=1)
|
|
||||||
mats = me.materials
|
mats = me.materials
|
||||||
|
|
||||||
# # Support object colors
|
# # Support object colors
|
||||||
@ -1978,7 +1986,6 @@ def save(operator, context, filepath="",
|
|||||||
# del tmp_ob_mats
|
# del tmp_ob_mats
|
||||||
# del tmp_colbits
|
# del tmp_colbits
|
||||||
|
|
||||||
|
|
||||||
if me:
|
if me:
|
||||||
# # This WILL modify meshes in blender if EXP_MESH_APPLY_MOD is disabled.
|
# # This WILL modify meshes in blender if EXP_MESH_APPLY_MOD is disabled.
|
||||||
# # so strictly this is bad. but only in rare cases would it have negative results
|
# # so strictly this is bad. but only in rare cases would it have negative results
|
||||||
@ -1994,8 +2001,10 @@ def save(operator, context, filepath="",
|
|||||||
tex = uf.image
|
tex = uf.image
|
||||||
textures[tex] = texture_mapping_local[tex] = None
|
textures[tex] = texture_mapping_local[tex] = None
|
||||||
|
|
||||||
try: mat = mats[f.material_index]
|
try:
|
||||||
except: mat = None
|
mat = mats[f.material_index]
|
||||||
|
except:
|
||||||
|
mat = None
|
||||||
|
|
||||||
materials[mat, tex] = material_mapping_local[mat, tex] = None # should use sets, wait for blender 2.5
|
materials[mat, tex] = material_mapping_local[mat, tex] = None # should use sets, wait for blender 2.5
|
||||||
|
|
||||||
@ -2016,7 +2025,6 @@ def save(operator, context, filepath="",
|
|||||||
armob = ob.parent
|
armob = ob.parent
|
||||||
blenParentBoneName = ob.parent_bone
|
blenParentBoneName = ob.parent_bone
|
||||||
|
|
||||||
|
|
||||||
if armob and armob not in ob_arms:
|
if armob and armob not in ob_arms:
|
||||||
ob_arms.append(armob)
|
ob_arms.append(armob)
|
||||||
|
|
||||||
@ -2044,8 +2052,8 @@ def save(operator, context, filepath="",
|
|||||||
ob_meshes.append(my_mesh)
|
ob_meshes.append(my_mesh)
|
||||||
|
|
||||||
# not forgetting to free dupli_list
|
# not forgetting to free dupli_list
|
||||||
if ob_base.dupli_list: ob_base.free_dupli_list()
|
if ob_base.dupli_list:
|
||||||
|
ob_base.free_dupli_list()
|
||||||
|
|
||||||
if EXP_ARMATURE:
|
if EXP_ARMATURE:
|
||||||
# now we have the meshes, restore the rest arm position
|
# now we have the meshes, restore the rest arm position
|
||||||
@ -2102,7 +2110,6 @@ def save(operator, context, filepath="",
|
|||||||
if my_bone.blenBone.use_deform:
|
if my_bone.blenBone.use_deform:
|
||||||
my_bone.blenMeshes[my_mesh.fbxName] = me
|
my_bone.blenMeshes[my_mesh.fbxName] = me
|
||||||
|
|
||||||
|
|
||||||
# parent bone: replace bone names with our class instances
|
# parent bone: replace bone names with our class instances
|
||||||
# my_mesh.fbxBoneParent is None or a blender bone name initialy, replacing if the names match.
|
# my_mesh.fbxBoneParent is None or a blender bone name initialy, replacing if the names match.
|
||||||
if my_mesh.fbxBoneParent == my_bone.blenName:
|
if my_mesh.fbxBoneParent == my_bone.blenName:
|
||||||
@ -2125,10 +2132,9 @@ def save(operator, context, filepath="",
|
|||||||
|
|
||||||
del my_bone_blenParent
|
del my_bone_blenParent
|
||||||
|
|
||||||
|
|
||||||
# Build blenObject -> fbxObject mapping
|
# Build blenObject -> fbxObject mapping
|
||||||
# this is needed for groups as well as fbxParenting
|
# this is needed for groups as well as fbxParenting
|
||||||
for ob in bpy.data.objects: ob.tag = False
|
bpy.data.objects.tag(False)
|
||||||
|
|
||||||
# using a list of object names for tagging (Arystan)
|
# using a list of object names for tagging (Arystan)
|
||||||
|
|
||||||
@ -2158,11 +2164,9 @@ def save(operator, context, filepath="",
|
|||||||
if parent and parent.tag: # does it exist and is it in the mapping
|
if parent and parent.tag: # does it exist and is it in the mapping
|
||||||
my_ob.fbxParent = tmp_obmapping[parent]
|
my_ob.fbxParent = tmp_obmapping[parent]
|
||||||
|
|
||||||
|
|
||||||
del tmp_obmapping
|
del tmp_obmapping
|
||||||
# Finished finding groups we use
|
# Finished finding groups we use
|
||||||
|
|
||||||
|
|
||||||
materials = [(sane_matname(mat_tex_pair), mat_tex_pair) for mat_tex_pair in materials.keys()]
|
materials = [(sane_matname(mat_tex_pair), mat_tex_pair) for mat_tex_pair in materials.keys()]
|
||||||
textures = [(sane_texname(tex), tex) for tex in textures.keys() if tex]
|
textures = [(sane_texname(tex), tex) for tex in textures.keys() if tex]
|
||||||
materials.sort() # sort by name
|
materials.sort() # sort by name
|
||||||
@ -2338,7 +2342,6 @@ Objects: {''')
|
|||||||
NbPoseNodes: ''')
|
NbPoseNodes: ''')
|
||||||
file.write(str(len(pose_items)))
|
file.write(str(len(pose_items)))
|
||||||
|
|
||||||
|
|
||||||
for fbxName, matrix in pose_items:
|
for fbxName, matrix in pose_items:
|
||||||
file.write('\n\t\tPoseNode: {')
|
file.write('\n\t\tPoseNode: {')
|
||||||
file.write('\n\t\t\tNode: "Model::%s"' % fbxName)
|
file.write('\n\t\t\tNode: "Model::%s"' % fbxName)
|
||||||
@ -2347,7 +2350,6 @@ Objects: {''')
|
|||||||
|
|
||||||
file.write('\n\t}')
|
file.write('\n\t}')
|
||||||
|
|
||||||
|
|
||||||
# Finish Writing Objects
|
# Finish Writing Objects
|
||||||
# Write global settings
|
# Write global settings
|
||||||
file.write('''
|
file.write('''
|
||||||
@ -2451,7 +2453,6 @@ Connections: {''')
|
|||||||
# for instance, defining the material->mesh connection
|
# for instance, defining the material->mesh connection
|
||||||
# before the mesh->blend_root crashes cinema4d
|
# before the mesh->blend_root crashes cinema4d
|
||||||
|
|
||||||
|
|
||||||
# write the fake root node
|
# write the fake root node
|
||||||
file.write('\n\tConnect: "OO", "Model::blend_root", "Model::Scene"')
|
file.write('\n\tConnect: "OO", "Model::blend_root", "Model::Scene"')
|
||||||
|
|
||||||
@ -2466,11 +2467,8 @@ Connections: {''')
|
|||||||
for my_mesh in ob_meshes:
|
for my_mesh in ob_meshes:
|
||||||
# Connect all materials to all objects, not good form but ok for now.
|
# Connect all materials to all objects, not good form but ok for now.
|
||||||
for mat, tex in my_mesh.blenMaterials:
|
for mat, tex in my_mesh.blenMaterials:
|
||||||
if mat: mat_name = mat.name
|
mat_name = mat.name if mat else None
|
||||||
else: mat_name = None
|
tex_name = tex.name if tex else None
|
||||||
|
|
||||||
if tex: tex_name = tex.name
|
|
||||||
else: tex_name = None
|
|
||||||
|
|
||||||
file.write('\n\tConnect: "OO", "Material::%s", "Model::%s"' % (sane_name_mapping_mat[mat_name, tex_name], my_mesh.fbxName))
|
file.write('\n\tConnect: "OO", "Material::%s", "Model::%s"' % (sane_name_mapping_mat[mat_name, tex_name], my_mesh.fbxName))
|
||||||
|
|
||||||
@ -2500,7 +2498,6 @@ Connections: {''')
|
|||||||
for fbxMeshObName in my_bone.blenMeshes: # .keys()
|
for fbxMeshObName in my_bone.blenMeshes: # .keys()
|
||||||
file.write('\n\tConnect: "OO", "Model::%s", "SubDeformer::Cluster %s %s"' % (my_bone.fbxName, fbxMeshObName, my_bone.fbxName))
|
file.write('\n\tConnect: "OO", "Model::%s", "SubDeformer::Cluster %s %s"' % (my_bone.fbxName, fbxMeshObName, my_bone.fbxName))
|
||||||
|
|
||||||
|
|
||||||
#for bonename, bone, obname, me, armob in ob_bones:
|
#for bonename, bone, obname, me, armob in ob_bones:
|
||||||
for my_bone in ob_bones:
|
for my_bone in ob_bones:
|
||||||
# Always parent to armature now
|
# Always parent to armature now
|
||||||
@ -2522,7 +2519,6 @@ Connections: {''')
|
|||||||
|
|
||||||
file.write('\n}')
|
file.write('\n}')
|
||||||
|
|
||||||
|
|
||||||
# Needed for scene footer as well as animation
|
# Needed for scene footer as well as animation
|
||||||
render = scene.render
|
render = scene.render
|
||||||
|
|
||||||
@ -2535,7 +2531,8 @@ Connections: {''')
|
|||||||
fps = float(render.fps)
|
fps = float(render.fps)
|
||||||
start = scene.frame_start
|
start = scene.frame_start
|
||||||
end = scene.frame_end
|
end = scene.frame_end
|
||||||
if end < start: start, end = end, st
|
if end < start:
|
||||||
|
start, end = end, st
|
||||||
|
|
||||||
# comment the following line, otherwise we dont get the pose
|
# comment the following line, otherwise we dont get the pose
|
||||||
# if start==end: ANIM_ENABLE = False
|
# if start==end: ANIM_ENABLE = False
|
||||||
@ -2562,7 +2559,6 @@ Connections: {''')
|
|||||||
# bpy.data.actions.tag = False
|
# bpy.data.actions.tag = False
|
||||||
tmp_actions = bpy.data.actions[:]
|
tmp_actions = bpy.data.actions[:]
|
||||||
|
|
||||||
|
|
||||||
# find which actions are compatible with the armatures
|
# find which actions are compatible with the armatures
|
||||||
# blenActions is not yet initialized so do it now.
|
# blenActions is not yet initialized so do it now.
|
||||||
tmp_act_count = 0
|
tmp_act_count = 0
|
||||||
@ -2650,7 +2646,6 @@ Takes: {''')
|
|||||||
;Models animation
|
;Models animation
|
||||||
;----------------------------------------------------''')
|
;----------------------------------------------------''')
|
||||||
|
|
||||||
|
|
||||||
# set pose data for all bones
|
# set pose data for all bones
|
||||||
# do this here incase the action changes
|
# do this here incase the action changes
|
||||||
'''
|
'''
|
||||||
@ -2671,7 +2666,6 @@ Takes: {''')
|
|||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
#for bonename, bone, obname, me, armob in ob_bones:
|
#for bonename, bone, obname, me, armob in ob_bones:
|
||||||
for ob_generic in (ob_bones, ob_meshes, ob_null, ob_cameras, ob_lights, ob_arms):
|
for ob_generic in (ob_bones, ob_meshes, ob_null, ob_cameras, ob_lights, ob_arms):
|
||||||
|
|
||||||
@ -2692,8 +2686,10 @@ Takes: {''')
|
|||||||
# ----------------
|
# ----------------
|
||||||
for TX_LAYER, TX_CHAN in enumerate('TRS'): # transform, rotate, scale
|
for TX_LAYER, TX_CHAN in enumerate('TRS'): # transform, rotate, scale
|
||||||
|
|
||||||
if TX_CHAN=='T': context_bone_anim_vecs = [mtx[0].translation_part() for mtx in context_bone_anim_mats]
|
if TX_CHAN == 'T':
|
||||||
elif TX_CHAN=='S': context_bone_anim_vecs = [mtx[0].scale_part() for mtx in context_bone_anim_mats]
|
context_bone_anim_vecs = [mtx[0].translation_part() for mtx in context_bone_anim_mats]
|
||||||
|
elif TX_CHAN == 'S':
|
||||||
|
context_bone_anim_vecs = [mtx[0].scale_part() for mtx in context_bone_anim_mats]
|
||||||
elif TX_CHAN == 'R':
|
elif TX_CHAN == 'R':
|
||||||
# Was....
|
# Was....
|
||||||
# elif TX_CHAN=='R': context_bone_anim_vecs = [mtx[1].to_euler() for mtx in context_bone_anim_mats]
|
# elif TX_CHAN=='R': context_bone_anim_vecs = [mtx[1].to_euler() for mtx in context_bone_anim_mats]
|
||||||
@ -2702,8 +2698,10 @@ Takes: {''')
|
|||||||
context_bone_anim_vecs = []
|
context_bone_anim_vecs = []
|
||||||
prev_eul = None
|
prev_eul = None
|
||||||
for mtx in context_bone_anim_mats:
|
for mtx in context_bone_anim_mats:
|
||||||
if prev_eul: prev_eul = mtx[1].to_euler('XYZ', prev_eul)
|
if prev_eul:
|
||||||
else: prev_eul = mtx[1].to_euler()
|
prev_eul = mtx[1].to_euler('XYZ', prev_eul)
|
||||||
|
else:
|
||||||
|
prev_eul = mtx[1].to_euler()
|
||||||
context_bone_anim_vecs.append(tuple_rad_to_deg(prev_eul))
|
context_bone_anim_vecs.append(tuple_rad_to_deg(prev_eul))
|
||||||
|
|
||||||
file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation
|
file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation
|
||||||
@ -2779,9 +2777,12 @@ Takes: {''')
|
|||||||
# frame is already one less then blenders frame
|
# frame is already one less then blenders frame
|
||||||
file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(frame), val))
|
file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(frame), val))
|
||||||
|
|
||||||
if i==0: file.write('\n\t\t\t\t\t\tColor: 1,0,0')
|
if i == 0:
|
||||||
elif i==1: file.write('\n\t\t\t\t\t\tColor: 0,1,0')
|
file.write('\n\t\t\t\t\t\tColor: 1,0,0')
|
||||||
elif i==2: file.write('\n\t\t\t\t\t\tColor: 0,0,1')
|
elif i == 1:
|
||||||
|
file.write('\n\t\t\t\t\t\tColor: 0,1,0')
|
||||||
|
elif i == 2:
|
||||||
|
file.write('\n\t\t\t\t\t\tColor: 0,0,1')
|
||||||
|
|
||||||
file.write('\n\t\t\t\t\t}')
|
file.write('\n\t\t\t\t\t}')
|
||||||
file.write('\n\t\t\t\t\tLayerType: %i' % (TX_LAYER + 1))
|
file.write('\n\t\t\t\t\tLayerType: %i' % (TX_LAYER + 1))
|
||||||
@ -2814,11 +2815,9 @@ Takes: {''')
|
|||||||
file.write('\n\tCurrent: ""')
|
file.write('\n\tCurrent: ""')
|
||||||
file.write('\n}')
|
file.write('\n}')
|
||||||
|
|
||||||
|
|
||||||
# write meshes animation
|
# write meshes animation
|
||||||
#for obname, ob, mtx, me, mats, arm, armname in ob_meshes:
|
#for obname, ob, mtx, me, mats, arm, armname in ob_meshes:
|
||||||
|
|
||||||
|
|
||||||
# Clear mesh data Only when writing with modifiers applied
|
# Clear mesh data Only when writing with modifiers applied
|
||||||
for me in meshes_to_clear:
|
for me in meshes_to_clear:
|
||||||
bpy.data.meshes.remove(me)
|
bpy.data.meshes.remove(me)
|
||||||
@ -2881,12 +2880,10 @@ Takes: {''')
|
|||||||
ob_meshes[:] = []
|
ob_meshes[:] = []
|
||||||
ob_null[:] = []
|
ob_null[:] = []
|
||||||
|
|
||||||
|
|
||||||
# copy images if enabled
|
# copy images if enabled
|
||||||
# if EXP_IMAGE_COPY:
|
# if EXP_IMAGE_COPY:
|
||||||
# # copy_images( basepath, [ tex[1] for tex in textures if tex[1] != None ])
|
# # copy_images( basepath, [ tex[1] for tex in textures if tex[1] != None ])
|
||||||
# bpy.util.copy_images( [ tex[1] for tex in textures if tex[1] != None ], basepath)
|
# bpy.util.copy_images( [ tex[1] for tex in textures if tex[1] != None ], basepath)
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
print('export finished in %.4f sec.' % (time.clock() - start_time))
|
print('export finished in %.4f sec.' % (time.clock() - start_time))
|
||||||
|
Loading…
Reference in New Issue
Block a user