[Bf-extensions-cvs] [b93459de] master: glTF exporter: fix various animation & texture export
Julien Duroure
noreply at git.blender.org
Mon May 13 23:42:44 CEST 2019
Commit: b93459de4bf85b51826cca1c79a2602804e796c4
Author: Julien Duroure
Date: Mon May 13 23:42:16 2019 +0200
Branches: master
https://developer.blender.org/rBAb93459de4bf85b51826cca1c79a2602804e796c4
glTF exporter: fix various animation & texture export
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/blender/exp/gltf2_blender_extract.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_texture.py
M io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index a8673634..35d80a91 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
- "version": (0, 9, 6),
+ "version": (0, 9, 7),
'blender': (2, 80, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
index 6bdbcdad..1597621b 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
@@ -105,9 +105,6 @@ def convert_swizzle_scale(scale, export_settings):
def decompose_transition(matrix, export_settings):
translation, rotation, scale = matrix.decompose()
- # Put w at the end.
- rotation = Quaternion((rotation[1], rotation[2], rotation[3], rotation[0]))
-
return translation, rotation, scale
def extract_primitive_floor(a, indices, use_tangents):
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
index dc3b6d30..ea5f9641 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
@@ -116,8 +116,6 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
target_datapath = channels[0].data_path
- transform = mathutils.Matrix.Identity(4)
-
is_yup = export_settings[gltf2_blender_export_keys.YUP]
# bone animations need to be handled differently as they are in a different coordinate system
@@ -141,6 +139,10 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
bone.parent.bone.matrix_local.inverted(), bone.bone.matrix_local)
transform = correction_matrix_local
+ else:
+ transform = mathutils.Matrix.Identity(4)
+ else:
+ transform = parent_inverse
values = []
for keyframe in keyframes:
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
index a34048a0..c4040c4c 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py
@@ -14,6 +14,7 @@
from . import gltf2_blender_export_keys
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
+from io_scene_gltf2.blender.exp import gltf2_blender_generate_extras
from io_scene_gltf2.io.com import gltf2_io
import bpy
@@ -44,6 +45,8 @@ def __gather_extensions(blender_camera, export_settings):
def __gather_extras(blender_camera, export_settings):
+ if export_settings['gltf_extras']:
+ return gltf2_blender_generate_extras.generate_extras(blender_camera)
return None
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 8550610f..818a6fa1 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py
@@ -36,21 +36,37 @@ def gather_image(
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)
- buffer_view = __gather_buffer_view(blender_shader_sockets_or_texture_slots, export_settings)
- if not (uri is not None or buffer_view is not None):
+ image_data = __get_image_data(blender_shader_sockets_or_texture_slots, export_settings)
+ if image_data is None:
# The blender image has no data
return None
- image = gltf2_io.Image(
+ mime_type = __gather_mime_type(blender_shader_sockets_or_texture_slots, export_settings)
+ name = __gather_name(blender_shader_sockets_or_texture_slots, export_settings)
+
+ uri = __gather_uri(image_data, mime_type, name, export_settings)
+ buffer_view = __gather_buffer_view(image_data, mime_type, name, export_settings)
+
+ return __make_image(
+ buffer_view,
+ __gather_extensions(blender_shader_sockets_or_texture_slots, export_settings),
+ __gather_extras(blender_shader_sockets_or_texture_slots, export_settings),
+ mime_type,
+ name,
+ uri,
+ export_settings
+ )
+
+ at cached
+def __make_image(buffer_view, extensions, extras, mime_type, name, uri, export_settings):
+ return gltf2_io.Image(
buffer_view=buffer_view,
- 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),
- name=__gather_name(blender_shader_sockets_or_texture_slots, export_settings),
+ extensions=extensions,
+ extras=extras,
+ mime_type=mime_type,
+ name=name,
uri=uri
)
- return image
def __filter_image(sockets_or_slots, export_settings):
@@ -59,13 +75,10 @@ def __filter_image(sockets_or_slots, export_settings):
return True
-def __gather_buffer_view(sockets_or_slots, export_settings):
+ at cached
+def __gather_buffer_view(image_data, mime_type, name, export_settings):
if export_settings[gltf2_blender_export_keys.FORMAT] != 'GLTF_SEPARATE':
- image = __get_image_data(sockets_or_slots, export_settings)
- if image is None:
- return None
- return gltf2_io_binary_data.BinaryData(
- data=image.encode(__gather_mime_type(sockets_or_slots, export_settings)))
+ return gltf2_io_binary_data.BinaryData(data=image_data.encode(mime_type))
return None
@@ -100,14 +113,14 @@ def __gather_name(sockets_or_slots, export_settings):
return image_name
-def __gather_uri(sockets_or_slots, export_settings):
+ at cached
+def __gather_uri(image_data, mime_type, name, export_settings):
if export_settings[gltf2_blender_export_keys.FORMAT] == 'GLTF_SEPARATE':
# as usual we just store the data in place instead of already resolving the references
- mime_type = __gather_mime_type(sockets_or_slots, export_settings)
return gltf2_io_image_data.ImageData(
- data=__get_image_data(sockets_or_slots, export_settings).encode(mime_type=mime_type),
+ data=image_data.encode(mime_type=mime_type),
mime_type=mime_type,
- name=__gather_name(sockets_or_slots, export_settings)
+ name=name
)
return None
@@ -122,9 +135,9 @@ def __is_slot(sockets_or_slots):
def __get_image_data(sockets_or_slots, export_settings) -> gltf2_blender_image.ExportImage:
- # For shared ressources, such as images, we just store the portion of data that is needed in the glTF property
+ # For shared resources, such as images, we just store the portion of data that is needed in the glTF property
# in a helper class. During generation of the glTF in the exporter these will then be combined to actual binary
- # ressources.
+ # resources.
def split_pixels_by_channels(image: bpy.types.Image, export_settings) -> typing.Optional[typing.List[typing.List[float]]]:
channelcache = export_settings['gltf_channelcache']
if image.name in channelcache:
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
index 410c12d3..57889970 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
@@ -52,8 +52,8 @@ def gather_joint(blender_bone, export_settings):
translation, rotation, scale = (None, None, None)
if trans[0] != 0.0 or trans[1] != 0.0 or trans[2] != 0.0:
translation = [trans[0], trans[1], trans[2]]
- if rot[0] != 0.0 or rot[1] != 0.0 or rot[2] != 0.0 or rot[3] != 1.0:
- rotation = [rot[0], rot[1], rot[2], rot[3]]
+ if rot[0] != 1.0 or rot[1] != 0.0 or rot[2] != 0.0 or rot[3] != 0.0:
+ rotation = [rot[1], rot[2], rot[3], rot[0]]
if sca[0] != 1.0 or sca[1] != 1.0 or sca[2] != 1.0:
scale = [sca[0], sca[1], sca[2]]
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
index 1671d6de..7dfed738 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
@@ -258,19 +258,23 @@ def __gather_name(blender_object, export_settings):
def __gather_trans_rot_scale(blender_object, export_settings):
- trans = gltf2_blender_extract.convert_swizzle_location(blender_object.location, export_settings)
+ if blender_object.matrix_parent_inverse == Matrix.Identity(4):
+ trans = blender_object.location
- if blender_object.rotation_mode in ['QUATERNION', 'AXIS_ANGLE']:
- rotation = blender_object.rotation_quaternion
- else:
- rotation = blender_object.rotation_euler.to_quaternion()
-
- rotation = gltf2_blender_extract.convert_swizzle_rotation(rotation, export_settings)
+ if blender_object.rotation_mode in ['QUATERNION', 'AXIS_ANGLE']:
+ rot = blender_object.rotation_quaternion
+ else:
+ rot = blender_object.rotation_euler.to_quaternion()
- # Put w at the end.
- rot = Quaternion((rotation[1], rotation[2], rotation[3], rotation[0]))
+ sca = blender_object.scale
+ else:
+ # matrix_local = matrix_parent_inverse*location*rotation*scale
+ # Decomposing matrix_local gives less accuracy, but is needed if matrix_parent_inverse is not the identity.
+ trans, rot, sca = gltf2_blender_extract.decompose_transition(blender_object.matrix_local, export_settings)
- sca = gltf2_blender_extract.convert_swizzle_scale(blender_object.scale, export_settings)
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list