[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21414] branches/soc-2009-kazanbas: - slowly starting FBX exporter conversion

Arystanbek Dyussenov arystan.d at gmail.com
Tue Jul 7 21:13:05 CEST 2009


Revision: 21414
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21414
Author:   kazanbas
Date:     2009-07-07 21:13:05 +0200 (Tue, 07 Jul 2009)

Log Message:
-----------
- slowly starting FBX exporter conversion
- added Bone.matrix and Bone.armature_matrix

Modified Paths:
--------------
    branches/soc-2009-kazanbas/release/io/export_obj.py
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_armature.c

Added Paths:
-----------
    branches/soc-2009-kazanbas/release/io/export_fbx.py
    branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_pose_api.c

Copied: branches/soc-2009-kazanbas/release/io/export_fbx.py (from rev 21285, branches/soc-2009-kazanbas/release/scripts/export_fbx.py)
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_fbx.py	                        (rev 0)
+++ branches/soc-2009-kazanbas/release/io/export_fbx.py	2009-07-07 19:13:05 UTC (rev 21414)
@@ -0,0 +1,3112 @@
+#!BPY
+"""
+Name: 'Autodesk FBX (.fbx)...'
+Blender: 249
+Group: 'Export'
+Tooltip: 'Selection to an ASCII Autodesk FBX '
+"""
+__author__ = "Campbell Barton"
+__url__ = ['www.blender.org', 'blenderartists.org']
+__version__ = "1.2"
+
+__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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+# --------------------------------------------------------------------------
+
+import os
+
+try:
+	import time
+	# import os # only needed for batch export, nbot used yet
+except:
+	time = None # use this to check if they have python modules installed
+
+# for python 2.3 support
+try:
+	set()
+except:
+	try:
+		from sets import Set as set
+	except:
+		set = None # so it complains you dont have a !
+
+# # os is only needed for batch 'own dir' option
+# try:
+# 	import os
+# except:
+# 	os = None
+
+import Blender
+import bpy
+from Blender.Mathutils import Matrix, Vector, RotationMatrix
+
+import BPyObject
+import BPyMesh
+import BPySys
+import BPyMessages
+
+## This was used to make V, but faster not to do all that
+##valid = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_,.()[]{}'
+##v = range(255)
+##for c in valid: v.remove(ord(c))
+v = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,42,43,47,58,59,60,61,62,63,64,92,94,96,124,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254]
+invalid = ''.join([chr(i) for i in v])
+def cleanName(name):
+	for ch in invalid:	name = name.replace(ch, '_')
+	return name
+del v, i
+
+
+def copy_file(source, dest):
+	file = open(source, 'rb')
+	data = file.read()
+	file.close()
+	
+	file = open(dest, 'wb')
+	file.write(data)
+	file.close()
+
+
+def copy_images(dest_dir, textures):
+	if not dest_dir.endswith(os.sep):
+		dest_dir += os.sep
+	
+	image_paths = set()
+	for tex in textures:
+		image_paths.add(Blender.sys.expandpath(tex.filename))
+	
+	# Now copy images
+	copyCount = 0
+	for image_path in image_paths:
+		if Blender.sys.exists(image_path):
+			# Make a name for the target path.
+			dest_image_path = dest_dir + image_path.split('\\')[-1].split('/')[-1]
+			if not Blender.sys.exists(dest_image_path): # Image isnt alredy there
+				print '\tCopying "%s" > "%s"' % (image_path, dest_image_path)
+				try:
+					copy_file(image_path, dest_image_path)
+					copyCount+=1
+				except:
+					print '\t\tWarning, file failed to copy, skipping.'
+	
+	print '\tCopied %d images' % copyCount
+
+mtx4_identity = Matrix()
+
+# testing
+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
+
+def strip_path(p):
+	return p.split('\\')[-1].split('/')[-1]
+
+# Used to add the scene name into the filename without using odd chars	
+sane_name_mapping_ob = {}
+sane_name_mapping_mat = {}
+sane_name_mapping_tex = {}
+sane_name_mapping_take = {}
+sane_name_mapping_group = {}
+
+# Make sure reserved names are not used
+sane_name_mapping_ob['Scene'] = 'Scene_'
+sane_name_mapping_ob['blend_root'] = 'blend_root_'
+
+def increment_string(t):
+	name = t
+	num = ''
+	while name and name[-1].isdigit():
+		num = name[-1] + num
+		name = name[:-1]
+	if num:	return '%s%d' % (name, int(num)+1)	
+	else:	return name + '_0'
+
+
+
+# todo - Disallow the name 'Scene' and 'blend_root' - it will bugger things up.
+def sane_name(data, dct):
+	#if not data: return None
+	
+	if type(data)==tuple: # materials are paired up with images
+		data, other = data
+		use_other = True
+	else:
+		other = None
+		use_other = False
+	
+	if data:	name = data.name
+	else:		name = None
+	orig_name = name
+	
+	if other:
+		orig_name_other = other.name
+		name = '%s #%s' % (name, orig_name_other)
+	else:
+		orig_name_other = None
+	
+	# dont cache, only ever call once for each data type now,
+	# so as to avoid namespace collision between types - like with objects <-> bones
+	#try:		return dct[name]
+	#except:		pass
+	
+	if not name:
+		name = 'unnamed' # blank string, ASKING FOR TROUBLE!
+	else:
+		#name = BPySys.cleanName(name)
+		name = cleanName(name) # use our own
+	
+	while name in dct.itervalues():	name = increment_string(name)
+	
+	if use_other: # even if other is None - orig_name_other will be a string or None
+		dct[orig_name, orig_name_other] = name
+	else:
+		dct[orig_name] = 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_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):
+	'''
+	fname_orig - blender path, can be relative
+	basepath - fname_rel will be relative to this
+	FORCE_CWD - dont use the basepath, just add a ./ to the filename.
+		use when we know the file will be in the basepath.
+	'''
+	fname = Blender.sys.expandpath(fname_orig)
+	fname_strip = strip_path(fname)
+	if FORCE_CWD:	fname_rel = '.' + os.sep + fname_strip
+	else:				fname_rel = Blender.sys.relpath(fname, basepath)
+	if fname_rel.startswith('//'): fname_rel = '.' + os.sep + fname_rel[2:]
+	return fname, fname_strip, fname_rel
+
+
+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 ])
+
+def meshNormalizedWeights(me):
+	try: # account for old bad BPyMesh
+		groupNames, vWeightList = BPyMesh.meshWeight2List(me)
+	except:
+		return [],[]
+	
+	if not groupNames:
+		return [],[]
+	
+	for i, vWeights in enumerate(vWeightList):
+		tot = 0.0
+		for w in vWeights:
+			tot+=w
+		
+		if tot:
+			for j, w in enumerate(vWeights):
+				vWeights[j] = w/tot
+	
+	return groupNames, vWeightList
+
+header_comment = \
+'''; FBX 6.1.0 project file
+; Created by Blender FBX Exporter
+; for support mail: ideasman42 at gmail.com
+; ----------------------------------------------------
+
+'''
+
+# This func can be called with just the filename
+def write(filename, batch_objects = None, \
+		context = None,
+		EXP_OBS_SELECTED =			True,
+		EXP_MESH =					True,
+		EXP_MESH_APPLY_MOD =		True,
+		EXP_MESH_HQ_NORMALS =		False,
+		EXP_ARMATURE =				True,
+		EXP_LAMP =					True,
+		EXP_CAMERA =				True,
+		EXP_EMPTY =					True,
+		EXP_IMAGE_COPY =			False,
+		GLOBAL_MATRIX =				Matrix(),
+		ANIM_ENABLE =				True,
+		ANIM_OPTIMIZE =				True,
+		ANIM_OPTIMIZE_PRECISSION =	6,
+		ANIM_ACTION_ALL =			False,
+		BATCH_ENABLE =				False,
+		BATCH_GROUP =				True,
+		BATCH_SCENE =				False,
+		BATCH_FILE_PREFIX =			'',
+		BATCH_OWN_DIR =				False
+	):
+	
+	# ----------------- Batch support!
+	if BATCH_ENABLE:
+		if os == None:	BATCH_OWN_DIR = False
+		
+		fbxpath = filename
+		
+		# get the path component of filename
+		tmp_exists = bpy.sys.exists(fbxpath)
+# 		tmp_exists = Blender.sys.exists(fbxpath)
+		
+		if tmp_exists != 2: # a file, we want a path
+			while fbxpath and fbxpath[-1] not in ('/', '\\'):
+				fbxpath = fbxpath[:-1]
+			if not filename:
+				# XXX
+				print('Error%t|Directory does not exist!')
+# 				Draw.PupMenu('Error%t|Directory does not exist!')
+				return
+
+			tmp_exists = bpy.sys.exists(fbxpath)
+# 			tmp_exists = Blender.sys.exists(fbxpath)
+		
+		if tmp_exists != 2:
+			# XXX
+			print('Error%t|Directory does not exist!')
+# 			Draw.PupMenu('Error%t|Directory does not exist!')
+			return
+		
+		if not fbxpath.endswith(os.sep):
+			fbxpath += os.sep
+		del tmp_exists
+		
+		
+		if BATCH_GROUP:
+			data_seq = bpy.data.groups
+		else:
+			data_seq = bpy.data.scenes
+		
+		# call this function within a loop with BATCH_ENABLE == False
+		orig_sce = context.scene
+# 		orig_sce = bpy.data.scenes.active
+		
+		
+		new_fbxpath = fbxpath # own dir option modifies, we need to keep an original
+		for data in data_seq: # scene or group
+			newname = BATCH_FILE_PREFIX + cleanName(data.name)
+# 			newname = BATCH_FILE_PREFIX + BPySys.cleanName(data.name)
+			
+			
+			if BATCH_OWN_DIR:
+				new_fbxpath = fbxpath + newname + os.sep
+				# path may alredy exist

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list