diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2018-12-11 23:51:40 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2018-12-11 23:51:40 +0300 |
commit | 5aa12449c934b4ae2d429586be118bc79a17752a (patch) | |
tree | d5df27b57de29d3ccf524d2526fa0eb26e1b81c9 /io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py | |
parent | ed2c64455a78bcc43a0fefbb6cd3a3e0220c5168 (diff) |
glTF Exporter: optimizations & fixes
* image optimizations
* options refactoring
* Fix T59047
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py')
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py b/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py index b1408b62..6561567e 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py @@ -20,6 +20,9 @@ from io_scene_gltf2.io.exp import gltf2_io_binary_data from io_scene_gltf2.io.exp import gltf2_io_image_data from io_scene_gltf2.io.exp import gltf2_io_buffer +import bpy +import os +from shutil import copyfile class GlTF2Exporter: """ @@ -141,9 +144,18 @@ class GlTF2Exporter: :return: """ for image in self.__images: - uri = output_path + image.name + ".png" - with open(uri, 'wb') as f: - f.write(image.to_png_data()) + dst_path = output_path + image.name + ".png" + + src_path = bpy.path.abspath(image.filepath) + if os.path.isfile(src_path): + # Source file exists. + if os.path.abspath(dst_path) != os.path.abspath(src_path): + # Only copy, if source and destination are not the same. + copyfile(src_path, dst_path) + else: + # Source file does not exist e.g. it is packed or has been generated. + with open(dst_path, 'wb') as f: + f.write(image.to_png_data()) def add_scene(self, scene: gltf2_io.Scene, active: bool = True): """ |