[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1457] trunk/py/scripts/addons/ io_scene_fbx: revert part of r1424, included a patch on FBX export by accident.
Campbell Barton
ideasman42 at gmail.com
Thu Jan 20 22:45:56 CET 2011
Revision: 1457
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1457
Author: campbellbarton
Date: 2011-01-20 21:45:55 +0000 (Thu, 20 Jan 2011)
Log Message:
-----------
revert part of r1424, included a patch on FBX export by accident.
Revision Links:
--------------
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1424
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_fbx/__init__.py
trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
Modified: trunk/py/scripts/addons/io_scene_fbx/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/__init__.py 2011-01-20 14:07:19 UTC (rev 1456)
+++ trunk/py/scripts/addons/io_scene_fbx/__init__.py 2011-01-20 21:45:55 UTC (rev 1457)
@@ -18,6 +18,18 @@
# <pep8 compliant>
+bl_info = {
+ "name": "Autodesk FBX format",
+ "author": "Campbell Barton",
+ "location": "File > Import-Export",
+ "description": "Import-Export FBX meshes, UV's, vertex colors, materials, textures, cameras and lamps",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+ "Scripts/Import-Export/Autodesk_FBX",
+ "tracker_url": "",
+ "support": 'OFFICIAL',
+ "category": "Import-Export"}
+
# To support reload properly, try to access a package var, if it's there, reload everything
if "bpy" in locals():
import imp
Modified: trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/export_fbx.py 2011-01-20 14:07:19 UTC (rev 1456)
+++ trunk/py/scripts/addons/io_scene_fbx/export_fbx.py 2011-01-20 21:45:55 UTC (rev 1457)
@@ -20,9 +20,6 @@
# Script copyright (C) Campbell Barton
-# Modified by Steven Batchelor on 01/16/2011 to include these features:
-# 1. Bone and object rotation constraints.
-
"""
This script is an exporter to the FBX file format.
@@ -31,16 +28,17 @@
import os
import time
-import math # math.pi
-import shutil # for file copying
+import math # math.pi
+import shutil # for file copying
import bpy
from mathutils import Vector, Euler, Matrix
+
# XXX not used anymore, images are copied one at a time
def copy_images(dest_dir, textures):
import shutil
-
+
if not dest_dir.endswith(os.sep):
dest_dir += os.sep
@@ -54,16 +52,17 @@
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 already there
+ if not Blender.sys.exists(dest_image_path): # Image isnt already there
print("\tCopying %r > %r" % (image_path, dest_image_path))
try:
shutil.copy(image_path, dest_image_path)
- copyCount+=1
+ copyCount += 1
except:
print("\t\tWarning, file failed to copy, skipping.")
print('\tCopied %d images' % copyCount)
+
# I guess FBX uses degrees instead of radians (Arystan).
# Call this function just before writing to FBX.
# 180 / math.pi == 57.295779513
@@ -84,30 +83,31 @@
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'
+ 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
+ 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
+ name = data.name if data else None
orig_name = name
if other:
@@ -122,26 +122,41 @@
#except: pass
if not name:
- name = 'unnamed' # blank string, ASKING FOR TROUBLE!
+ name = 'unnamed' # blank string, ASKING FOR TROUBLE!
else:
- 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
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 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
@@ -163,8 +178,9 @@
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
# duplicated in OBJ exporter
def getVertsFromGroup(me, group_index):
@@ -177,6 +193,7 @@
return ret
+
# ob must be OB_MESH
def BPyMesh_meshWeight2List(ob, me):
''' Takes a mesh and return its group names and a list of lists, one list per vertex.
@@ -185,14 +202,14 @@
'''
# Clear the vert group.
- groupNames= [g.name for g in ob.vertex_groups]
- len_groupNames= len(groupNames)
+ groupNames = [g.name for g in ob.vertex_groups]
+ len_groupNames = len(groupNames)
if not len_groupNames:
# no verts? return a vert aligned empty list
return [[] for i in range(len(me.vertices))], []
else:
- vWeightList= [[0.0]*len_groupNames for i in range(len(me.vertices))]
+ vWeightList = [[0.0] * len_groupNames for i in range(len(me.vertices))]
for i, v in enumerate(me.vertices):
for g in v.groups:
@@ -200,24 +217,24 @@
return groupNames, vWeightList
+
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(me)
except:
- return [],[]
+ return [], []
if not groupNames:
- return [],[]
+ return [], []
for i, vWeights in enumerate(vWeightList):
tot = 0.0
for w in vWeights:
- tot+=w
+ tot += w
if tot:
for j, w in enumerate(vWeights):
- vWeights[j] = w/tot
+ vWeights[j] = w / tot
return groupNames, vWeightList
@@ -229,33 +246,34 @@
'''
+
# This func can be called with just the filepath
def save(operator, context, filepath="",
- GLOBAL_MATRIX = None,
- EXP_OBS_SELECTED = True,
- EXP_MESH = True,
- EXP_MESH_APPLY_MOD = True,
- EXP_ARMATURE = True,
- EXP_LAMP = True,
- EXP_CAMERA = True,
- EXP_EMPTY = True,
- EXP_IMAGE_COPY = False,
- ANIM_ENABLE = True,
- ANIM_OPTIMIZE = True,
- ANIM_OPTIMIZE_PRECISSION = 6,
- ANIM_ACTION_ALL = False,
- BATCH_ENABLE = False,
- BATCH_GROUP = True,
- BATCH_FILE_PREFIX = '',
- BATCH_OWN_DIR = False
+ GLOBAL_MATRIX=None,
+ EXP_OBS_SELECTED=True,
+ EXP_MESH=True,
+ EXP_MESH_APPLY_MOD=True,
+ EXP_ARMATURE=True,
+ EXP_LAMP=True,
+ EXP_CAMERA=True,
+ EXP_EMPTY=True,
+ EXP_IMAGE_COPY=False,
+ ANIM_ENABLE=True,
+ ANIM_OPTIMIZE=True,
+ ANIM_OPTIMIZE_PRECISSION=6,
+ ANIM_ACTION_ALL=False,
+ BATCH_ENABLE=False,
+ BATCH_GROUP=True,
+ BATCH_FILE_PREFIX='',
+ BATCH_OWN_DIR=False
):
- #XXX, missing arg
+ #XXX, missing arg
batch_objects = None
# testing
- mtx_x90 = Matrix.Rotation( math.pi/2.0, 3, 'X') # used
- mtx4_z90 = Matrix.Rotation( math.pi/2.0, 4, 'Z')
+ mtx_x90 = Matrix.Rotation(math.pi / 2.0, 3, 'X') # used
+ mtx4_z90 = Matrix.Rotation(math.pi / 2.0, 4, 'Z')
if GLOBAL_MATRIX is None:
GLOBAL_MATRIX = Matrix()
@@ -269,21 +287,18 @@
# get the path component of filepath
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)
# while fbxpath and fbxpath[-1] not in ('/', '\\'):
# fbxpath = fbxpath[:-1]
if not fbxpath:
-# if not filepath:
# XXX
print('Error%t|Directory does not exist!')
# Draw.PupMenu('Error%t|Directory does not exist!')
return
tmp_exists = bpy.utils.exists(fbxpath)
-# tmp_exists = Blender.sys.exists(fbxpath)
if tmp_exists != 2:
# XXX
@@ -295,7 +310,6 @@
fbxpath += os.sep
del tmp_exists
-
if BATCH_GROUP:
data_seq = bpy.data.groups
else:
@@ -303,13 +317,11 @@
# 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
+ 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 + bpy.path.clean_name(data.name)
-
if BATCH_OWN_DIR:
new_fbxpath = fbxpath + newname + os.sep
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list