[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11971] trunk/blender/release/scripts/ export_fbx.py: fbx update from stable (parent/ child hierarchy isnt flattened anymore)
Campbell Barton
cbarton at metavr.com
Sat Sep 8 10:49:56 CEST 2007
Revision: 11971
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11971
Author: campbellbarton
Date: 2007-09-08 10:49:56 +0200 (Sat, 08 Sep 2007)
Log Message:
-----------
fbx update from stable (parent/child hierarchy isnt flattened anymore)
Modified Paths:
--------------
trunk/blender/release/scripts/export_fbx.py
Modified: trunk/blender/release/scripts/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/export_fbx.py 2007-09-08 08:48:13 UTC (rev 11970)
+++ trunk/blender/release/scripts/export_fbx.py 2007-09-08 08:49:56 UTC (rev 11971)
@@ -12,11 +12,7 @@
__bpydoc__ = """\
This script is an exporter to the FBX file format.
-Usage:
-
-Select the objects you wish to export and run this script from "File->Export" menu.
-All objects that can be represented as a mesh (mesh, curve, metaball, surface, text3d)
-will be exported as mesh data.
+http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx
"""
# --------------------------------------------------------------------------
# FBX Export v0.1 by Campbell Barton (AKA Ideasman)
@@ -120,33 +116,21 @@
mtx4_identity = Matrix()
-mtx_z90 = RotationMatrix(90, 3, 'z')
-mtx_x90 = RotationMatrix(90, 3, 'x')
-
# testing
-mtx_x90 = RotationMatrix( 90, 3, 'x')
-mtx_x90n = RotationMatrix(-90, 3, 'x')
-mtx_y90 = RotationMatrix( 90, 3, 'y')
-mtx_y90n = RotationMatrix(-90, 3, 'y')
-mtx_z90 = RotationMatrix( 90, 3, 'z')
-mtx_z90n = RotationMatrix(-90, 3, 'z')
+mtx_x90 = RotationMatrix( 90, 3, 'x') # used
+#mtx_x90n = RotationMatrix(-90, 3, 'x')
+#mtx_y90 = RotationMatrix( 90, 3, 'y')
+#mtx_y90n = RotationMatrix(-90, 3, 'y')
+#mtx_z90 = RotationMatrix( 90, 3, 'z')
+#mtx_z90n = RotationMatrix(-90, 3, 'z')
+#mtx4_x90 = RotationMatrix( 90, 4, 'x')
+mtx4_x90n = RotationMatrix(-90, 4, 'x') # used
+#mtx4_y90 = RotationMatrix( 90, 4, 'y')
+mtx4_y90n = RotationMatrix(-90, 4, 'y') # used
+mtx4_z90 = RotationMatrix( 90, 4, 'z') # used
+mtx4_z90n = RotationMatrix(-90, 4, 'z') # used
-mtx4_x90 = RotationMatrix( 90, 4, 'x')
-mtx4_x90n = RotationMatrix(-90, 4, 'x')
-mtx4_y90 = RotationMatrix( 90, 4, 'y')
-mtx4_y90n = RotationMatrix(-90, 4, 'y')
-mtx4_z90 = RotationMatrix( 90, 4, 'z')
-mtx4_z90n = RotationMatrix(-90, 4, 'z')
-
-XVEC = Vector(1, 0, 0)
-XVECN = Vector(-1, 0, 0)
-YVEC = Vector(0, 1, 0)
-YVECN = Vector(0, -1, 0)
-ZVEC = Vector(0, 0, 1)
-ZVECN = Vector(0, 0, -1)
-
-
def strip_path(p):
return p.split('\\')[-1].split('/')[-1]
@@ -256,10 +240,7 @@
BATCH_FILE_PREFIX = '',
BATCH_OWN_DIR = False
):
-
-
-
# ----------------- Batch support!
if BATCH_ENABLE:
if os == None: BATCH_OWN_DIR = False
@@ -267,7 +248,6 @@
fbxpath = filename
# get the path component of filename
-
tmp_exists = Blender.sys.exists(fbxpath)
if tmp_exists != 2: # a file, we want a path
@@ -436,16 +416,19 @@
'''
# end
- def getAnimMatrix(self, frame):
- arm_mat = self.fbxArm.matrixWorld
+ def getAnimParRelMatrix(self, frame):
+ #arm_mat = self.fbxArm.matrixWorld
+ #arm_mat = self.fbxArm.parRelMatrix()
if not self.parent:
- return mtx4_z90 * (self.getPoseMatrix(frame) * arm_mat)
+ #return mtx4_z90 * (self.getPoseMatrix(frame) * arm_mat) # dont apply arm matrix anymore
+ return mtx4_z90 * self.getPoseMatrix(frame)
else:
- return (mtx4_z90 * ((self.getPoseMatrix(frame) * arm_mat))) * (mtx4_z90 * (self.parent.getPoseMatrix(frame) * arm_mat)).invert()
+ #return (mtx4_z90 * ((self.getPoseMatrix(frame) * arm_mat))) * (mtx4_z90 * (self.parent.getPoseMatrix(frame) * arm_mat)).invert()
+ return (mtx4_z90 * (self.getPoseMatrix(frame))) * (mtx4_z90 * self.parent.getPoseMatrix(frame)).invert()
# we need thes because cameras and lights modified rotations
- def getAnimMatrixRot(self, frame):
- return self.getAnimMatrix(frame)
+ def getAnimParRelMatrixRot(self, frame):
+ return self.getAnimParRelMatrix(frame)
def flushAnimData(self):
self.__anim_poselist.clear()
@@ -457,19 +440,33 @@
self.fbxName = sane_obname(ob)
self.blenObject = ob
self.fbxGroupNames = []
+ self.fbxParent = None # set later on IF the parent is in the selection.
if matrixWorld: self.matrixWorld = matrixWorld * GLOBAL_MATRIX
else: self.matrixWorld = ob.matrixWorld * GLOBAL_MATRIX
- self.__anim_poselist = {}
+ self.__anim_poselist = {} # we should only access this
+ def parRelMatrix(self):
+ if self.fbxParent:
+ return self.matrixWorld * self.fbxParent.matrixWorld.copy().invert()
+ else:
+ return self.matrixWorld
+
def setPoseFrame(self, f):
self.__anim_poselist[f] = self.blenObject.matrixWorld.copy()
- def getAnimMatrix(self, frame):
- return self.__anim_poselist[frame] * GLOBAL_MATRIX
+ def getAnimParRelMatrix(self, frame):
+ if self.fbxParent:
+ #return (self.__anim_poselist[frame] * self.fbxParent.__anim_poselist[frame].copy().invert() ) * GLOBAL_MATRIX
+ return (self.__anim_poselist[frame] * GLOBAL_MATRIX) * (self.fbxParent.__anim_poselist[frame] * GLOBAL_MATRIX).invert()
+ else:
+ return self.__anim_poselist[frame] * GLOBAL_MATRIX
- def getAnimMatrixRot(self, frame):
+ def getAnimParRelMatrixRot(self, frame):
type = self.blenObject.type
- matrix_rot = (self.__anim_poselist[frame] * GLOBAL_MATRIX).rotationPart()
+ if self.fbxParent:
+ matrix_rot = (((self.__anim_poselist[frame] * GLOBAL_MATRIX) * (self.fbxParent.__anim_poselist[frame] * GLOBAL_MATRIX).invert())).rotationPart()
+ else:
+ matrix_rot = (self.__anim_poselist[frame] * GLOBAL_MATRIX).rotationPart()
# Lamps need to be rotated
if type =='Lamp':
@@ -488,7 +485,11 @@
print '\nFBX export starting...', filename
start_time = Blender.sys.time()
- file = open(filename, 'w')
+ try:
+ file = open(filename, 'w')
+ except:
+ return False
+
sce = bpy.data.scenes.active
world = sce.world
@@ -533,11 +534,13 @@
if isinstance(ob, Blender.Types.BoneType):
# we know we have a matrix
- matrix = mtx4_z90 * (ob.matrix['ARMATURESPACE'] * matrix_mod)
+ # matrix = mtx4_z90 * (ob.matrix['ARMATURESPACE'] * matrix_mod)
+ matrix = mtx4_z90 * ob.matrix['ARMATURESPACE'] # dont apply armature matrix anymore
parent = ob.parent
if parent:
- par_matrix = mtx4_z90 * (parent.matrix['ARMATURESPACE'] * matrix_mod)
+ #par_matrix = mtx4_z90 * (parent.matrix['ARMATURESPACE'] * matrix_mod)
+ par_matrix = mtx4_z90 * parent.matrix['ARMATURESPACE'] # dont apply armature matrix anymore
matrix = matrix * par_matrix.copy().invert()
matrix_rot = matrix.rotationPart()
@@ -547,7 +550,10 @@
rot = tuple(matrix_rot.toEuler())
else:
- if ob and not matrix: matrix = ob.matrixWorld * GLOBAL_MATRIX
+ # 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.matrixWorld * GLOBAL_MATRIX
+ if ob and not matrix: raise "error: this should never happen!"
+
matrix_rot = matrix
#if matrix:
# matrix = matrix_scale * matrix
@@ -686,18 +692,19 @@
file.write('\n\tModel: "Model::%s", "Limb" {' % my_bone.fbxName)
file.write('\n\t\tVersion: 232')
- poseMatrix = write_object_props(my_bone.blenBone, None, None, my_bone.fbxArm.matrixWorld)[3]
+ #poseMatrix = write_object_props(my_bone.blenBone, None, None, my_bone.fbxArm.parRelMatrix())[3]
+ poseMatrix = write_object_props(my_bone.blenBone)[3] # dont apply bone matricies anymore
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.matrixWorld).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')
- #((my_bone.blenData.head['ARMATURESPACE'] * my_bone.fbxArm.matrixWorld) - (my_bone.blenData.tail['ARMATURESPACE'] * my_bone.fbxArm.matrixWorld)).length)
+ #((my_bone.blenData.head['ARMATURESPACE'] * my_bone.fbxArm.matrixWorld) - (my_bone.blenData.tail['ARMATURESPACE'] * my_bone.fbxArm.parRelMatrix())).length)
"""
file.write('\n\t\t\tProperty: "LimbLength", "double", "",%.6f' %\
- ((my_bone.blenBone.head['ARMATURESPACE'] - my_bone.blenBone.tail['ARMATURESPACE']) * my_bone.fbxArm.matrixWorld).length)
+ ((my_bone.blenBone.head['ARMATURESPACE'] - my_bone.blenBone.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length)
"""
file.write('\n\t\t\tProperty: "LimbLength", "double", "",%.6f' %\
@@ -849,7 +856,7 @@
file.write('\n\tModel: "Model::%s", "Camera" {' % my_cam.fbxName )
file.write('\n\t\tVersion: 232')
- loc, rot, scale, matrix, matrix_rot = write_object_props(my_cam.blenObject)
+ loc, rot, scale, matrix, matrix_rot = write_object_props(my_cam.blenObject, None, my_cam.parRelMatrix())
file.write('\n\t\t\tProperty: "Roll", "Roll", "A+",0')
file.write('\n\t\t\tProperty: "FieldOfView", "FieldOfView", "A+",%.6f' % data.angle)
@@ -954,7 +961,7 @@
file.write('\n\tModel: "Model::%s", "Light" {' % my_light.fbxName)
file.write('\n\t\tVersion: 232')
- write_object_props(my_light.blenObject)
+ write_object_props(my_light.blenObject, None, my_light.parRelMatrix())
# Why are these values here twice?????? - oh well, follow the holy sdk's output
@@ -977,6 +984,8 @@
else:
do_light = 1
+ scale = abs(GLOBAL_MATRIX.scalePart()[0]) # scale is always uniform in this case
+
file.write('\n\t\t\tProperty: "LightType", "enum", "",%i' % light_type)
file.write('\n\t\t\tProperty: "CastLightOnObject", "bool", "",1')
file.write('\n\t\t\tProperty: "DrawVolumetricLight", "bool", "",1')
@@ -985,11 +994,11 @@
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: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy*100, 200))) # clamp below 200
- file.write('\n\t\t\tProperty: "Cone angle", "Cone angle", "A+",%.2f' % light.spotSize)
+ file.write('\n\t\t\tProperty: "Cone angle", "Cone angle", "A+",%.2f' % light.spotSize * scale)
file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50')
file.write('\n\t\t\tProperty: "Color", "Color", "A",%.2f,%.2f,%.2f' % tuple(light.col))
file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy*100, 200))) # clamp below 200
- file.write('\n\t\t\tProperty: "Cone angle", "Cone angle", "A+",%.2f' % light.spotSize)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list