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:
authorPeter Kim <pk15950@gmail.com>2021-08-26 13:22:25 +0300
committerPeter Kim <pk15950@gmail.com>2021-08-26 13:22:25 +0300
commit850d2a45cee6ddbc2ef088de2e0cf0fa77b86bc4 (patch)
tree37ed2dbd029ede22a92e07c8bb1d8eb85a11b60a
parent918c4d365b1c26707f3ed6b3e429c4ee9263b06b (diff)
parentb701b514de3671376de790358b2562214b964895 (diff)
Merge branch 'master' into xr-controller-support
-rwxr-xr-xio_scene_gltf2/__init__.py10
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather.py4
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py47
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py17
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py19
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py6
-rw-r--r--io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py6
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py6
-rw-r--r--node_wrangler.py10
-rw-r--r--space_view3d_copy_attributes.py6
10 files changed, 101 insertions, 30 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index ccb4517d..08f5cbd1 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, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
- "version": (1, 7, 17),
+ "version": (1, 7, 23),
'blender': (2, 91, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
@@ -122,12 +122,12 @@ class ExportGLTF2_Base:
items=(('GLB', 'glTF Binary (.glb)',
'Exports a single file, with all data packed in binary form. '
'Most efficient and portable, but more difficult to edit later'),
- ('GLTF_EMBEDDED', 'glTF Embedded (.gltf)',
- 'Exports a single file, with all data packed in JSON. '
- 'Less efficient than binary, but easier to edit later'),
('GLTF_SEPARATE', 'glTF Separate (.gltf + .bin + textures)',
'Exports multiple files, with separate JSON, binary and texture data. '
- 'Easiest to edit later')),
+ 'Easiest to edit later'),
+ ('GLTF_EMBEDDED', 'glTF Embedded (.gltf)',
+ 'Exports a single file, with all data packed in JSON. '
+ 'Less efficient than binary, but easier to edit later')),
description=(
'Output format and embedding options. Binary is most efficient, '
'but JSON (embedded or separate) may be easier to edit later'
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
index 6f46918a..6f68c19e 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
@@ -116,6 +116,10 @@ def __gather_animations(blender_scene, export_settings):
to_delete_idx.append(anim_idx)
+ # Merging extensions
+ # Provide a hook to handle extension merging since there is no way to know author intent
+ export_user_extensions('merge_animation_extensions_hook', export_settings, animations[anim_idx], animations[base_animation_idx])
+
# Merging extras
# Warning, some values can be overwritten if present in multiple merged animations
if animations[anim_idx].extras is not None:
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
index 114ff901..3046a1ce 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
@@ -69,6 +69,11 @@ def gather_animation_channels(blender_action: bpy.types.Action,
bones_to_be_animated, _, _ = gltf2_blender_gather_skins.get_bone_tree(None, blender_object)
bones_to_be_animated = [blender_object.pose.bones[b.name] for b in bones_to_be_animated]
+ list_of_animated_bone_channels = []
+ for channel_group in __get_channel_groups(blender_action, blender_object, export_settings):
+ channel_group_sorted = __get_channel_group_sorted(channel_group, blender_object)
+ list_of_animated_bone_channels.extend([(gltf2_blender_get.get_object_from_datapath(blender_object, get_target_object_path(i.data_path)).name, get_target_property_name(i.data_path)) for i in channel_group])
+
for bone in bones_to_be_animated:
for p in ["location", "rotation_quaternion", "scale"]:
channel = __gather_animation_channel(
@@ -80,8 +85,10 @@ def gather_animation_channels(blender_action: bpy.types.Action,
bake_range_start,
bake_range_end,
blender_action.name,
- None)
- channels.append(channel)
+ None,
+ (bone.name, p) in list_of_animated_bone_channels)
+ if channel is not None:
+ channels.append(channel)
# Retrieve animation on armature object itself, if any
@@ -91,7 +98,7 @@ def gather_animation_channels(blender_action: bpy.types.Action,
if len(channel_group) == 0:
# Only errors on channels, ignoring
continue
- channel = __gather_animation_channel(channel_group, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name, None)
+ channel = __gather_animation_channel(channel_group, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name, None, False)
if channel is not None:
channels.append(channel)
@@ -109,8 +116,10 @@ def gather_animation_channels(blender_action: bpy.types.Action,
bake_range_start,
bake_range_end,
blender_action.name,
- obj)
- channels.append(channel)
+ obj,
+ False)
+ if channel is not None:
+ channels.append(channel)
else:
for channel_group in __get_channel_groups(blender_action, blender_object, export_settings):
@@ -118,7 +127,17 @@ def gather_animation_channels(blender_action: bpy.types.Action,
if len(channel_group_sorted) == 0:
# Only errors on channels, ignoring
continue
- channel = __gather_animation_channel(channel_group_sorted, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name, None)
+ channel = __gather_animation_channel(
+ channel_group_sorted,
+ blender_object,
+ export_settings,
+ None,
+ None,
+ bake_range_start,
+ bake_range_end,
+ blender_action.name,
+ None,
+ False)
if channel is not None:
channels.append(channel)
@@ -189,17 +208,25 @@ def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve],
bake_range_start,
bake_range_end,
action_name: str,
- driver_obj
+ driver_obj,
+ node_channel_is_animated: bool
) -> typing.Union[gltf2_io.AnimationChannel, None]:
if not __filter_animation_channel(channels, blender_object, export_settings):
return None
__target= __gather_target(channels, blender_object, export_settings, bake_bone, bake_channel, driver_obj)
if __target.path is not None:
+ sampler = __gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name, driver_obj, node_channel_is_animated)
+
+ if sampler is None:
+ # After check, no need to animate this node for this channel
+ return None
+
+
animation_channel = gltf2_io.AnimationChannel(
extensions=__gather_extensions(channels, blender_object, export_settings, bake_bone),
extras=__gather_extras(channels, blender_object, export_settings, bake_bone),
- sampler=__gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name, driver_obj),
+ sampler=sampler,
target=__target
)
@@ -249,7 +276,8 @@ def __gather_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_range_start,
bake_range_end,
action_name,
- driver_obj
+ driver_obj,
+ node_channel_is_animated: bool
) -> gltf2_io.AnimationSampler:
return gltf2_blender_gather_animation_samplers.gather_animation_sampler(
channels,
@@ -260,6 +288,7 @@ def __gather_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name,
driver_obj,
+ node_channel_is_animated,
export_settings
)
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
index 3bf5b97c..932ea25e 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
@@ -22,6 +22,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_get
from io_scene_gltf2.blender.exp.gltf2_blender_gather_drivers import get_sk_drivers, get_sk_driver_values
from . import gltf2_blender_export_keys
from io_scene_gltf2.io.com import gltf2_io_debug
+import numpy as np
class Keyframe:
@@ -193,6 +194,7 @@ def gather_keyframes(blender_object_if_armature: typing.Optional[bpy.types.Objec
bake_range_end,
action_name: str,
driver_obj,
+ node_channel_is_animated: bool,
export_settings
) -> typing.List[Keyframe]:
"""Convert the blender action groups' fcurves to keyframes for use in glTF."""
@@ -309,6 +311,21 @@ def gather_keyframes(blender_object_if_armature: typing.Optional[bpy.types.Objec
keyframes.append(key)
+ # For armature only
+ # Check if all values are the same
+ # In that case, if there is no real keyframe on this channel for this given bone,
+ # We can ignore this keyframes
+ # if there are some fcurve, we can keep only 2 keyframes, first and last
+ if blender_object_if_armature is not None:
+ std = np.ptp(np.ptp([[k.value[i] for i in range(len(keyframes[0].value))] for k in keyframes], axis=0))
+
+ if node_channel_is_animated is True: # fcurve on this bone for this property
+ # Keep animation, but keep only 2 keyframes if data are not changing
+ return [keyframes[0], keyframes[-1]] if std < 0.0001 and len(keyframes) >= 2 else keyframes
+ else: # bone is not animated (no fcurve)
+ # Not keeping if not changing property
+ return None if std < 0.0001 else keyframes
+
return keyframes
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 d555bcb9..d3b9e022 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
@@ -39,6 +39,7 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name: str,
driver_obj,
+ node_channel_is_animated: bool,
export_settings
) -> gltf2_io.AnimationSampler:
@@ -61,11 +62,17 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
else:
matrix_parent_inverse = mathutils.Matrix.Identity(4).freeze()
+ input = __gather_input(channels, blender_object_if_armature, non_keyed_values,
+ bake_bone, bake_channel, bake_range_start, bake_range_end, action_name, driver_obj, node_channel_is_animated, export_settings)
+
+ if input is None:
+ # After check, no need to animate this node for this channel
+ return None
+
sampler = gltf2_io.AnimationSampler(
extensions=__gather_extensions(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel),
extras=__gather_extras(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel),
- input=__gather_input(channels, blender_object_if_armature, non_keyed_values,
- bake_bone, bake_channel, bake_range_start, bake_range_end, action_name, driver_obj, export_settings),
+ input=input,
interpolation=__gather_interpolation(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel),
output=__gather_output(channels,
matrix_parent_inverse,
@@ -77,6 +84,7 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name,
driver_obj,
+ node_channel_is_animated,
export_settings)
)
@@ -229,6 +237,7 @@ def __gather_input(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name,
driver_obj,
+ node_channel_is_animated: bool,
export_settings
) -> gltf2_io.Accessor:
"""Gather the key time codes."""
@@ -241,7 +250,11 @@ def __gather_input(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name,
driver_obj,
+ node_channel_is_animated,
export_settings)
+ if keyframes is None:
+ # After check, no need to animation this node
+ return None
times = [k.seconds for k in keyframes]
return gltf2_blender_gather_accessors.gather_accessor(
@@ -306,6 +319,7 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name,
driver_obj,
+ node_channel_is_animated: bool,
export_settings
) -> gltf2_io.Accessor:
"""Gather the data of the keyframes."""
@@ -318,6 +332,7 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
bake_range_end,
action_name,
driver_obj,
+ node_channel_is_animated,
export_settings)
if bake_bone is not None:
target_datapath = "pose.bones['" + bake_bone + "']." + bake_channel
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
index 06e6860c..819c8085 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
@@ -121,12 +121,12 @@ def __gather_animation(blender_action: bpy.types.Action,
print_console("WARNING", "Animation '{}' could not be exported. Cause: {}".format(name, error))
return None
- # To allow reuse of samplers in one animation,
- __link_samplers(animation, export_settings)
-
if not animation.channels:
return None
+ # To allow reuse of samplers in one animation,
+ __link_samplers(animation, export_settings)
+
export_user_extensions('gather_animation_hook', export_settings, animation, blender_action, blender_object)
return animation
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py
index 4dcad66f..561f246c 100644
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py
@@ -56,6 +56,9 @@ def get_sk_drivers(blender_armature):
sk_name = child.data.shape_keys.path_resolve(get_target_object_path(sk_c.data_path)).name
except:
continue
+ # Do not take into account this driver if corresponding SK is disabled
+ if child.data.shape_keys.key_blocks[sk_name].mute is True:
+ continue
idx = shapekeys_idx[sk_name]
idx_channel_mapping.append((shapekeys_idx[sk_name], sk_c))
existing_idx = dict(idx_channel_mapping)
@@ -65,7 +68,8 @@ def get_sk_drivers(blender_armature):
else:
all_sorted_channels.append(existing_idx[i])
- drivers.append((child, tuple(all_sorted_channels)))
+ if len(all_sorted_channels) > 0:
+ drivers.append((child, tuple(all_sorted_channels)))
return tuple(drivers)
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 7b58c0f9..a2fc57be 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
@@ -140,6 +140,12 @@ def __filter_node(blender_object, blender_scene, export_settings):
if not found:
return False
+ if blender_object.type == 'LIGHT':
+ return export_settings[gltf2_blender_export_keys.LIGHTS]
+
+ if blender_object.type == 'CAMERA':
+ return export_settings[gltf2_blender_export_keys.CAMERAS]
+
return True
diff --git a/node_wrangler.py b/node_wrangler.py
index 09d9b06f..4b77d109 100644
--- a/node_wrangler.py
+++ b/node_wrangler.py
@@ -3176,7 +3176,7 @@ class NWAddPrincipledSetup(Operator, NWBase, ImportHelper):
relative_path: BoolProperty(
name='Relative Path',
- description='Select the file relative to the blend file',
+ description='Set the file path relative to the blend file, when possible',
default=True
)
@@ -3276,10 +3276,10 @@ class NWAddPrincipledSetup(Operator, NWBase, ImportHelper):
import_path = self.directory
if self.relative_path:
if bpy.data.filepath:
- import_path = bpy.path.relpath(self.directory)
- else:
- self.report({'WARNING'}, 'Relative paths cannot be used with unsaved scenes!')
- print('Relative paths cannot be used with unsaved scenes!')
+ try:
+ import_path = bpy.path.relpath(self.directory)
+ except ValueError:
+ pass
# Add found images
print('\nMatched Textures:')
diff --git a/space_view3d_copy_attributes.py b/space_view3d_copy_attributes.py
index 2d1fff59..29da77ab 100644
--- a/space_view3d_copy_attributes.py
+++ b/space_view3d_copy_attributes.py
@@ -575,11 +575,7 @@ class CopySelectedObjectConstraints(Operator):
for obj in selected:
for index, flag in enumerate(self.selection):
if flag:
- old_constraint = active.constraints[index]
- new_constraint = obj.constraints.new(
- active.constraints[index].type
- )
- generic_copy(old_constraint, new_constraint)
+ obj.constraints.copy(active.constraints[index])
return{'FINISHED'}