Explorar el Código

the export script now copies textures to output folder with same name as project file

Jhonny Göransson hace 14 años
padre
commit
986625ae52

+ 14 - 2
utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -27,6 +27,7 @@ TODO
 import bpy
 import bpy
 import mathutils
 import mathutils
 
 
+import shutil
 import os
 import os
 import os.path
 import os.path
 import math
 import math
@@ -1190,6 +1191,14 @@ def generate_textures_scene(data):
 
 
     # TODO: extract just textures actually used by some objects in the scene
     # TODO: extract just textures actually used by some objects in the scene
 
 
+    rel_dest_dir = (os.path.basename(fpath).split(".")[0] + "\\").replace("\\","\\\\")
+    abs_dest_dir = fpath.split(".")[0] + "\\"
+
+    try:
+        os.makedirs(abs_dest_dir)
+    except OSError:
+        pass
+
     for texture in bpy.data.textures:
     for texture in bpy.data.textures:
 
 
         if texture.type == 'IMAGE' and texture.image:
         if texture.type == 'IMAGE' and texture.image:
@@ -1199,6 +1208,8 @@ def generate_textures_scene(data):
             texture_id = img.name
             texture_id = img.name
             texture_file = extract_texture_filename(img)
             texture_file = extract_texture_filename(img)
             
             
+            shutil.copy(img.filepath,abs_dest_dir + texture_file)
+
             extras = ""
             extras = ""
             if texture.repeat_x != 1 or texture.repeat_y != 1:
             if texture.repeat_x != 1 or texture.repeat_y != 1:
                 extras = ',\n        "repeat": [%f, %f]' % (texture.repeat_x, texture.repeat_y)
                 extras = ',\n        "repeat": [%f, %f]' % (texture.repeat_x, texture.repeat_y)
@@ -1208,7 +1219,7 @@ def generate_textures_scene(data):
 
 
             texture_string = TEMPLATE_TEXTURE % {
             texture_string = TEMPLATE_TEXTURE % {
             "texture_id"   : generate_string(texture_id),
             "texture_id"   : generate_string(texture_id),
-            "texture_file" : generate_string(texture_file),
+            "texture_file" : generate_string(rel_dest_dir + texture_file),
             "extras"       : extras
             "extras"       : extras
             }
             }
             chunks.append(texture_string)
             chunks.append(texture_string)
@@ -1540,6 +1551,8 @@ def generate_ascii_scene(data):
     return text
     return text
 
 
 def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds,option_url_base_type):
 def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds,option_url_base_type):
+    global fpath
+    fpath = filepath
 
 
     source_file = os.path.basename(bpy.data.filepath)
     source_file = os.path.basename(bpy.data.filepath)
 
 
@@ -1672,5 +1685,4 @@ def save(operator, context, filepath = "",
                     option_scale,
                     option_scale,
                     True)
                     True)
 
 
-
     return {'FINISHED'}
     return {'FINISHED'}