Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2019-12-29 15:05:31 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-12-29 15:05:31 +0300
commit60a11a0fc4426f01e87be0e019c5d909889e511e (patch)
treec0d957f5697574ceaac5a5698159b47fa9f7efd8 /io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py
parenta659ebbd5dbbc7bf7c3737275213a69b82968207 (diff)
glTF exporter: add option to export textures into a folder
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py34
1 files changed, 25 insertions, 9 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 fe50b407..2c44a018 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re
+import os
+import urllib.parse
from typing import List
from ... import get_version_string
@@ -20,6 +22,7 @@ from io_scene_gltf2.io.com import gltf2_io_extensions
from io_scene_gltf2.io.exp import gltf2_io_binary_data
from io_scene_gltf2.io.exp import gltf2_io_buffer
from io_scene_gltf2.io.exp import gltf2_io_image_data
+from io_scene_gltf2.blender.exp import gltf2_blender_export_keys
class GlTF2Exporter:
@@ -29,9 +32,11 @@ class GlTF2Exporter:
Any child properties are replaced with references where necessary
"""
- def __init__(self, copyright=None):
+ def __init__(self, export_settings):
+ self.export_settings = export_settings
self.__finalized = False
+ copyright = export_settings[gltf2_blender_export_keys.COPYRIGHT] or None
asset = gltf2_io.Asset(
copyright=copyright,
extensions=None,
@@ -143,14 +148,15 @@ class GlTF2Exporter:
self.__gltf.extensions_required.append('KHR_draco_mesh_compression')
self.__gltf.extensions_used.append('KHR_draco_mesh_compression')
- def finalize_images(self, output_path):
+ def finalize_images(self):
"""
Write all images.
-
- Due to a current limitation the output_path must be the same as that of the glTF file
- :param output_path:
- :return:
"""
+ output_path = self.export_settings[gltf2_blender_export_keys.TEXTURE_DIRECTORY]
+
+ if self.__images:
+ os.makedirs(output_path, exist_ok=True)
+
for name, image in self.__images.items():
dst_path = output_path + "/" + name + image.file_extension
with open(dst_path, 'wb') as f:
@@ -222,12 +228,17 @@ class GlTF2Exporter:
name += "-" + str(count)
count += 1
- # TODO: we need to know the image url at this point already --> maybe add all options to the constructor of the
- # exporter
# TODO: allow embedding of images (base64)
self.__images[name] = image
- return name + image.file_extension
+
+ texture_dir = self.export_settings[gltf2_blender_export_keys.TEXTURE_DIRECTORY]
+ abs_path = os.path.join(texture_dir, name + image.file_extension)
+ rel_path = os.path.relpath(
+ abs_path,
+ start=self.export_settings[gltf2_blender_export_keys.FILE_DIRECTORY],
+ )
+ return _path_to_uri(rel_path)
@classmethod
def __get_key_path(cls, d: dict, keypath: List[str], default):
@@ -313,3 +324,8 @@ class GlTF2Exporter:
# do nothing for any type that does not match a glTF schema (primitives)
return node
+def _path_to_uri(path):
+ path = os.path.normpath(path)
+ path = path.replace(os.sep, '/')
+ return urllib.parse.quote(path)
+