[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15378] branches/soc-2008-djd/release/ scripts: Done with fbx, ply, xfig, md2
Dhanannjay Deo
dhandeo at gmail.com
Sat Jun 28 21:25:08 CEST 2008
Revision: 15378
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15378
Author: djd
Date: 2008-06-28 21:24:17 +0200 (Sat, 28 Jun 2008)
Log Message:
-----------
Done with fbx, ply, xfig, md2
Fixed indentation in some files
Modified Paths:
--------------
branches/soc-2008-djd/release/scripts/export_fbx.py
branches/soc-2008-djd/release/scripts/im_ex_test_suite.py
branches/soc-2008-djd/release/scripts/md2_export.py
branches/soc-2008-djd/release/scripts/ply_export.py
branches/soc-2008-djd/release/scripts/xfig_export.py
Modified: branches/soc-2008-djd/release/scripts/export_fbx.py
===================================================================
--- branches/soc-2008-djd/release/scripts/export_fbx.py 2008-06-28 14:19:25 UTC (rev 15377)
+++ branches/soc-2008-djd/release/scripts/export_fbx.py 2008-06-28 19:24:17 UTC (rev 15378)
@@ -37,25 +37,25 @@
# --------------------------------------------------------------------------
try:
- import time
- # import os # only needed for batch export, nbot used yet
+ 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
+ time = None # use this to check if they have python modules installed
# for python 2.3 support
try:
- set()
+ set()
except:
- try:
- from sets import Set as set
- except:
- set = None # so it complains you dont have a !
+ 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
+ import os
except:
- os = None
+ os = None
import Blender
import bpy
@@ -75,44 +75,44 @@
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
+ 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()
+ 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(Blender.sys.sep):
- dest_dir += Blender.sys.sep
-
- image_paths = set()
- for img in textures:
- image_paths.add(Blender.sys.expandpath(img.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
+ if not dest_dir.endswith(Blender.sys.sep):
+ dest_dir += Blender.sys.sep
+
+ image_paths = set()
+ for img in textures:
+ image_paths.add(Blender.sys.expandpath(img.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()
@@ -132,7 +132,7 @@
mtx4_z90n = RotationMatrix(-90, 4, 'z') # used
def strip_path(p):
- return p.split('\\')[-1].split('/')[-1]
+ return p.split('\\')[-1].split('/')[-1]
# Used to add the scene name into the filename without using odd chars
sane_name_mapping_ob = {}
@@ -146,37 +146,37 @@
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'
+ 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
- name = data.name
-
- # 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
-
- orig_name = name
- 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)
-
- dct[orig_name] = name
- return name
+ #if not data: return None
+ name = data.name
+
+ # 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
+
+ orig_name = name
+ 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)
+
+ 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)
@@ -188,27 +188,27 @@
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 ])
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
+ 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
@@ -220,2449 +220,2450 @@
# This func can be called with just the filename
def write(filename, batch_objects = 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 = 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:
- Draw.PupMenu('Error%t|Directory does not exist!')
- return
-
- tmp_exists = Blender.sys.exists(fbxpath)
-
- if tmp_exists != 2:
- Draw.PupMenu('Error%t|Directory does not exist!')
- return
-
- if not fbxpath.endswith(Blender.sys.sep):
- fbxpath += Blender.sys.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 = 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 + BPySys.cleanName(data.name)
-
-
- if BATCH_OWN_DIR:
- new_fbxpath = fbxpath + newname + Blender.sys.sep
- # path may alredy exist
- # TODO - might exist but be a file. unlikely but should probably account for it.
-
- if Blender.sys.exists(new_fbxpath) == 0:
- os.mkdir(new_fbxpath)
-
-
- filename = new_fbxpath + newname + '.fbx'
-
- print '\nBatch exporting %s as...\n\t"%s"' % (data, filename)
-
- if BATCH_GROUP: #group
- # group, so objects update properly, add a dummy scene.
- sce = bpy.data.scenes.new()
- sce.Layers = (1<<20) -1
- bpy.data.scenes.active = sce
- for ob_base in data.objects:
- sce.objects.link(ob_base)
-
- sce.update(1)
-
- # TODO - BUMMER! Armatures not in the group wont animate the mesh
-
- else:# scene
-
-
- data_seq.active = data
-
-
- # Call self with modified args
- # Dont pass batch options since we alredy usedt them
- write(filename, data.objects,
- False,
- EXP_MESH,
- EXP_MESH_APPLY_MOD,
- EXP_MESH_HQ_NORMALS,
- EXP_ARMATURE,
- EXP_LAMP,
- EXP_CAMERA,
- EXP_EMPTY,
- EXP_IMAGE_COPY,
- GLOBAL_MATRIX,
- ANIM_ENABLE,
- ANIM_OPTIMIZE,
- ANIM_OPTIMIZE_PRECISSION,
- ANIM_ACTION_ALL
- )
-
- if BATCH_GROUP:
- # remove temp group scene
- bpy.data.scenes.unlink(sce)
-
- bpy.data.scenes.active = orig_sce
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list