[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1828] trunk/py/scripts/addons: common option to export paths for FBX and OBJ
Campbell Barton
ideasman42 at gmail.com
Thu Apr 14 10:49:26 CEST 2011
Revision: 1828
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1828
Author: campbellbarton
Date: 2011-04-14 08:49:26 +0000 (Thu, 14 Apr 2011)
Log Message:
-----------
common option to export paths for FBX and OBJ
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_3ds/export_3ds.py
trunk/py/scripts/addons/io_scene_fbx/__init__.py
trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
trunk/py/scripts/addons/io_scene_obj/__init__.py
trunk/py/scripts/addons/io_scene_obj/export_obj.py
Modified: trunk/py/scripts/addons/io_scene_3ds/export_3ds.py
===================================================================
--- trunk/py/scripts/addons/io_scene_3ds/export_3ds.py 2011-04-14 04:27:42 UTC (rev 1827)
+++ trunk/py/scripts/addons/io_scene_3ds/export_3ds.py 2011-04-14 08:49:26 UTC (rev 1828)
@@ -893,6 +893,7 @@
import bpy
import time
+ import io_utils
from io_utils import create_derived_objects, free_derived_objects
'''Save the Blender scene to a 3ds file.'''
@@ -901,8 +902,6 @@
time1 = time.clock()
# Blender.Window.WaitCursor(1)
- sce = context.scene
-
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
@@ -921,15 +920,11 @@
kfdata = make_kfdata()
'''
- # Get all the supported objects selected in this scene:
- # ob_sel= list(sce.objects.context)
- # mesh_objects = [ (ob, me) for ob in ob_sel for me in (BPyMesh.getMeshFromObject(ob, None, True, False, sce),) if me ]
- # empty_objects = [ ob for ob in ob_sel if ob.type == 'Empty' ]
-
# Make a list of all materials used in the selected meshes (use a dictionary,
# each material is added once):
materialDict = {}
mesh_objects = []
+
scene = context.scene
if use_selection:
Modified: trunk/py/scripts/addons/io_scene_fbx/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/__init__.py 2011-04-14 04:27:42 UTC (rev 1827)
+++ trunk/py/scripts/addons/io_scene_fbx/__init__.py 2011-04-14 08:49:26 UTC (rev 1828)
@@ -41,6 +41,7 @@
import bpy
from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
+import io_utils
from io_utils import ExportHelper
@@ -69,7 +70,6 @@
EXP_MESH = BoolProperty(name="Meshes", description="Export mesh objects", default=True)
EXP_MESH_APPLY_MOD = BoolProperty(name="Modifiers", description="Apply modifiers to mesh objects", default=True)
# EXP_MESH_HQ_NORMALS = BoolProperty(name="HQ Normals", description="Generate high quality normals", default=True)
- EXP_IMAGE_COPY = BoolProperty(name="Copy Image Files", description="Copy image files to the destination path", default=False)
# armature animation
ANIM_ENABLE = BoolProperty(name="Enable Animation", description="Export keyframe animation", default=True)
ANIM_OPTIMIZE = BoolProperty(name="Optimize Keyframes", description="Remove double keyframes", default=True)
@@ -87,6 +87,8 @@
BATCH_OWN_DIR = BoolProperty(name="Own Dir", description="Create a dir for each exported file", default=True)
use_metadata = BoolProperty(name="Use Metadata", default=True, options={'HIDDEN'})
+ path_mode = io_utils.path_reference_mode
+
@property
def check_extension(self):
return self.batch_mode == 'OFF'
Modified: trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/export_fbx.py 2011-04-14 04:27:42 UTC (rev 1827)
+++ trunk/py/scripts/addons/io_scene_fbx/export_fbx.py 2011-04-14 08:49:26 UTC (rev 1828)
@@ -35,34 +35,6 @@
from mathutils import Vector, 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
-
- image_paths = set()
- for tex in textures:
- image_paths.add(bpy.path.abspath(tex.filepath))
-
- # 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 already there
- print("\tCopying %r > %r" % (image_path, dest_image_path))
- try:
- shutil.copy(image_path, dest_image_path)
- 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
@@ -157,26 +129,7 @@
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 filepath.
-# use when we know the file will be in the basepath.
-# '''
-# fname = bpy.path.abspath(fname_orig)
-# # fname = Blender.sys.expandpath(fname_orig)
-# fname_strip = os.path.basename(fname)
-# # fname_strip = strip_path(fname)
-# if FORCE_CWD:
-# fname_rel = '.' + os.sep + fname_strip
-# else:
-# fname_rel = bpy.path.relpath(fname, basepath)
-# # 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])
@@ -257,28 +210,29 @@
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,
use_metadata=True,
+ path_mode='AUTO',
):
- # testing
- mtx_x90 = Matrix.Rotation(math.pi / 2.0, 3, 'X') # used
+ import io_utils
+
+ mtx_x90 = Matrix.Rotation(math.pi / 2.0, 3, 'X')
mtx4_z90 = Matrix.Rotation(math.pi / 2.0, 4, 'Z')
if GLOBAL_MATRIX is None:
GLOBAL_MATRIX = Matrix()
- # end batch support
-
# Use this for working out paths relative to the export location
- basepath = os.path.dirname(filepath) or '.'
- basepath += os.sep
-# basepath = Blender.sys.dirname(filepath)
+ base_src = os.path.dirname(bpy.data.filepath)
+ base_dst = os.path.dirname(filepath)
+ # collect images to copy
+ copy_set = set()
+
# ----------------------------------------------
# storage classes
class my_bone_class(object):
@@ -1139,22 +1093,6 @@
file.write('\n\t\t}')
file.write('\n\t}')
- def copy_image(image):
- fn = bpy.path.abspath(image.filepath)
- fn_strip = os.path.basename(fn)
-
- if EXP_IMAGE_COPY:
- rel = fn_strip
- fn_abs_dest = os.path.join(basepath, fn_strip)
- if not os.path.exists(fn_abs_dest):
- shutil.copy(fn, fn_abs_dest)
- elif bpy.path.is_subdir(fn, basepath):
- rel = os.path.relpath(fn, basepath)
- else:
- rel = fn
-
- return (rel, fn_strip)
-
# tex is an Image (Arystan)
def write_video(texname, tex):
# Same as texture really!
@@ -1168,10 +1106,10 @@
Property: "Width", "int", "",0
Property: "Height", "int", "",0''')
if tex:
- fname_rel, fname_strip = copy_image(tex)
-# fname, fname_strip, fname_rel = derived_paths(tex.filepath, basepath, EXP_IMAGE_COPY)
+ fname_rel = io_utils.path_reference(tex.filepath, base_src, base_dst, path_mode, "", copy_set)
+ fname_strip = os.path.basename(fname_rel)
else:
- fname = fname_strip = fname_rel = ''
+ fname_strip = fname_rel = ""
file.write('\n\t\t\tProperty: "Path", "charptr", "", "%s"' % fname_strip)
@@ -1188,8 +1126,6 @@
UseMipMap: 0''')
file.write('\n\t\tFilename: "%s"' % fname_strip)
- if fname_strip:
- fname_strip = '/' + fname_strip
file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # make relative
file.write('\n\t}')
@@ -1229,10 +1165,10 @@
file.write('\n\t\tMedia: "Video::%s"' % texname)
if tex:
- fname_rel, fname_strip = copy_image(tex)
-# fname, fname_strip, fname_rel = derived_paths(tex.filepath, basepath, EXP_IMAGE_COPY)
+ fname_rel = io_utils.path_reference(tex.filepath, base_src, base_dst, path_mode, "", copy_set)
+ fname_strip = os.path.basename(fname_rel)
else:
- fname = fname_strip = fname_rel = ''
+ fname_strip = fname_rel = ""
file.write('\n\t\tFileName: "%s"' % fname_strip)
file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # need some make relative command
@@ -2810,12 +2746,11 @@
ob_meshes[:] = []
ob_null[:] = []
- # copy images if enabled
-# if EXP_IMAGE_COPY:
-# # 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)
file.close()
+ # copy all collected files.
+ io_utils.path_reference_copy(copy_set)
+
print('export finished in %.4f sec.' % (time.clock() - start_time))
return {'FINISHED'}
Modified: trunk/py/scripts/addons/io_scene_obj/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/__init__.py 2011-04-14 04:27:42 UTC (rev 1827)
+++ trunk/py/scripts/addons/io_scene_obj/__init__.py 2011-04-14 08:49:26 UTC (rev 1828)
@@ -43,6 +43,7 @@
import bpy
from bpy.props import BoolProperty, FloatProperty, StringProperty
+import io_utils
from io_utils import ExportHelper, ImportHelper
@@ -102,7 +103,7 @@
use_hq_normals = BoolProperty(name="High Quality Normals", description="", default=True)
use_uvs = BoolProperty(name="UVs", description="", default=True)
use_materials = BoolProperty(name="Materials", description="", default=True)
- copy_images = BoolProperty(name="Copy Images", description="", default=False)
+ # copy_images = BoolProperty(name="Copy Images", description="", default=False)
use_triangles = BoolProperty(name="Triangulate", description="", default=False)
use_vertex_groups = BoolProperty(name="Polygroups", description="", default=False)
use_nurbs = BoolProperty(name="Nurbs", description="", default=False)
@@ -113,6 +114,8 @@
group_by_material = BoolProperty(name="Material Groups", description="", default=False)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list