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-01-09 21:46:45 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-01-09 21:46:45 +0300
commitb410a70fa9ba09bf9c1091d87f38f0ed8dae4895 (patch)
tree1d29e31952f861dbf02f8433f6e6861f5607f587 /io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
parent52111c31d7d0d39893b11a5242cbfe2bfbda0d12 (diff)
glTF export: enhancement & fixes:
* implement KHR_materials_unlit export * Fix primitive restart values * Fix jpg uri/mime type * Fix bug when image has no color channels * Check animation has actions * Ignore meshes without primitives * Fix materials when not selected in export settings * Improve error message for invalid animation target type * Animation with errors are ignored, but export continues * Export of BaseColorFactor
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_image.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
index a694cac3..6b969668 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import re
import bpy
import typing
@@ -30,13 +31,17 @@ def gather_image(
export_settings):
if not __filter_image(blender_shader_sockets_or_texture_slots, export_settings):
return None
+
+ uri = __gather_uri(blender_shader_sockets_or_texture_slots, export_settings)
+ mime_type = __gather_mime_type(uri.filepath if uri is not None else "")
+
image = gltf2_io.Image(
buffer_view=__gather_buffer_view(blender_shader_sockets_or_texture_slots, export_settings),
extensions=__gather_extensions(blender_shader_sockets_or_texture_slots, export_settings),
extras=__gather_extras(blender_shader_sockets_or_texture_slots, export_settings),
- mime_type=__gather_mime_type(blender_shader_sockets_or_texture_slots, export_settings),
+ mime_type=mime_type,
name=__gather_name(blender_shader_sockets_or_texture_slots, export_settings),
- uri=__gather_uri(blender_shader_sockets_or_texture_slots, export_settings)
+ uri=uri
)
return image
@@ -51,7 +56,7 @@ def __gather_buffer_view(sockets_or_slots, export_settings):
if export_settings[gltf2_blender_export_keys.FORMAT] != 'GLTF_SEPARATE':
image = __get_image_data(sockets_or_slots, export_settings)
return gltf2_io_binary_data.BinaryData(
- data=image.to_image_data(__gather_mime_type(sockets_or_slots, export_settings)))
+ data=image.to_image_data(__gather_mime_type()))
return None
@@ -63,9 +68,13 @@ def __gather_extras(sockets_or_slots, export_settings):
return None
-def __gather_mime_type(sockets_or_slots, export_settings):
- return 'image/png'
- # return 'image/jpeg'
+def __gather_mime_type(filepath=""):
+ extension_types = {'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg'}
+ default_extension = extension_types['.png']
+
+ matches = re.findall(r'\.\w+$', filepath)
+ extension = matches[0] if len(matches) > 0 else default_extension
+ return extension_types[extension] if extension.lower() in extension_types.keys() else default_extension
def __gather_name(sockets_or_slots, export_settings):
@@ -98,6 +107,8 @@ def __get_image_data(sockets_or_slots, export_settings):
# in a helper class. During generation of the glTF in the exporter these will then be combined to actual binary
# ressources.
def split_pixels_by_channels(image: bpy.types.Image, export_settings) -> typing.List[typing.List[float]]:
+ assert image.channels > 0, "Image '{}' has no color channels and cannot be exported.".format(image.name)
+
channelcache = export_settings['gltf_channelcache']
if image.name in channelcache:
return channelcache[image.name]