[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4355] trunk/py/scripts/addons/ io_mesh_vrml2: add path-mode property to be able to copy the exported image .
Campbell Barton
ideasman42 at gmail.com
Mon Mar 11 14:47:10 CET 2013
Revision: 4355
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4355
Author: campbellbarton
Date: 2013-03-11 13:47:10 +0000 (Mon, 11 Mar 2013)
Log Message:
-----------
add path-mode property to be able to copy the exported image.
Modified Paths:
--------------
trunk/py/scripts/addons/io_mesh_vrml2/__init__.py
trunk/py/scripts/addons/io_mesh_vrml2/export_vrml2.py
Modified: trunk/py/scripts/addons/io_mesh_vrml2/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_vrml2/__init__.py 2013-03-11 13:20:27 UTC (rev 4354)
+++ trunk/py/scripts/addons/io_mesh_vrml2/__init__.py 2013-03-11 13:47:10 UTC (rev 4355)
@@ -40,7 +40,7 @@
import os
import bpy
from bpy.props import CollectionProperty, StringProperty, BoolProperty, EnumProperty
-from bpy_extras.io_utils import ExportHelper
+from bpy_extras.io_utils import ExportHelper, path_reference_mode
class ExportVRML(bpy.types.Operator, ExportHelper):
"""Export a single object as a VRML2, """ \
@@ -71,8 +71,11 @@
use_uv = BoolProperty(
name="Texture/UVs",
description="Export the active texture and UV coords",
- default=True)
+ default=True,
+ )
+ path_mode = path_reference_mode
+
@classmethod
def poll(cls, context):
obj = context.active_object
@@ -96,6 +99,9 @@
row = layout.row()
row.active = self.use_color
row.prop(self, "color_type")
+ row = layout.row()
+ row.prop(self, "path_mode")
+
def menu_func_export(self, context):
Modified: trunk/py/scripts/addons/io_mesh_vrml2/export_vrml2.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_vrml2/export_vrml2.py 2013-03-11 13:20:27 UTC (rev 4354)
+++ trunk/py/scripts/addons/io_mesh_vrml2/export_vrml2.py 2013-03-11 13:47:10 UTC (rev 4355)
@@ -19,19 +19,35 @@
# <pep8-80 compliant>
import bpy
+import bpy_extras
import bmesh
import os
def save_bmesh(fw, bm,
use_color, color_type, material_colors,
- use_uv, uv_image):
- fw('#VRML V2.0 utf8\n')
- fw('#modeled using blender3d http://blender.org\n')
+ use_uv, uv_image,
+ path_mode, copy_set):
+
+ base_src = os.path.dirname(bpy.data.filepath)
+ base_dst = os.path.dirname(fw.__self__.name)
+
fw('Shape {\n')
fw('\tappearance Appearance {\n')
if use_uv:
fw('\t\ttexture ImageTexture {\n')
- fw('\t\t\turl "%s"\n' % os.path.basename(uv_image.filepath))
+ filepath = uv_image.filepath
+ filepath_full = bpy.path.abspath(filepath, library=uv_image.library)
+ filepath_ref = bpy_extras.io_utils.path_reference(filepath_full, base_src, base_dst, path_mode, "textures", copy_set, uv_image.library)
+ filepath_base = os.path.basename(filepath_full)
+
+ images = [
+ filepath_ref,
+ filepath_base,
+ filepath_full,
+ ]
+ fw('\t\t\turl [ %s ]\n' % " ".join(['"%s"' % f for f in images]) )
+ del images
+ del filepath_ref, filepath_base, filepath_full, filepath
fw('\t\t}\n') # end 'ImageTexture'
else:
fw('\t\tmaterial Material {\n')
@@ -152,7 +168,8 @@
def save_object(fw, scene, obj,
use_mesh_modifiers,
use_color, color_type,
- use_uv):
+ use_uv,
+ path_mode, copy_set):
assert(obj.type == 'MESH')
@@ -204,23 +221,13 @@
if uv_image is None:
use_uv = False
- material_colors = []
save_bmesh(fw, bm,
use_color, color_type, material_colors,
- use_uv, uv_image)
+ use_uv, uv_image,
+ path_mode, copy_set)
bm.free()
-def save_object_fp(filepath, scene, obj,
- use_mesh_modifiers,
- use_color, color_type,
- use_uv):
- file = open(filepath, 'w', encoding='utf-8')
- save_object(file.write, scene, obj,
- use_mesh_modifiers,
- use_color, color_type,
- use_uv)
- file.close()
def save(operator,
context,
@@ -228,11 +235,26 @@
use_mesh_modifiers=True,
use_color=True,
color_type='MATERIAL',
- use_uv=True):
+ use_uv=True,
+ path_mode='AUTO'):
- save_object_fp(filepath, context.scene, context.object,
- use_mesh_modifiers,
- use_color, color_type,
- use_uv)
+ # store files to copy
+ copy_set = set()
+ file = open(filepath, 'w', encoding='utf-8')
+ fw = file.write
+ fw('#VRML V2.0 utf8\n')
+ fw('#modeled using blender3d http://blender.org\n')
+
+ save_object(fw, context.scene, context.object,
+ use_mesh_modifiers,
+ use_color, color_type,
+ use_uv,
+ path_mode, copy_set)
+
+ file.close()
+
+ # copy all collected files.
+ bpy_extras.io_utils.path_reference_copy(copy_set)
+
return {'FINISHED'}
More information about the Bf-extensions-cvs
mailing list