Skip to content

Commit 86f2e6f

Browse files
committed
print a warning if visibility channel is available in animation import on 4.4.3
1 parent d783ba8 commit 86f2e6f

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

io_mesh_w3d/common/utils/animation_import.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,52 +56,54 @@ def set_rotation(bone, frame, value):
5656
bone.keyframe_insert(data_path='rotation_quaternion', frame=frame)
5757

5858

59-
def set_visibility(bone, frame, value):
59+
def set_visibility(context, bone, frame, value):
6060
if isinstance(bone, bpy.types.Bone):
6161
if bpy.app.version != (4, 4, 3): #TODO fix 4.4.3
6262
bone.visibility = value
6363
bone.keyframe_insert(data_path='visibility', frame=frame, options=creation_options)
64+
else:
65+
context.warning(f'bone visibility channels are currently not supported for blender 4.4.3!')
6466
else:
6567
bone.hide_viewport = bool(value)
6668
bone.keyframe_insert(data_path='hide_viewport', frame=frame, options=creation_options)
6769

6870

69-
def set_keyframe(bone, channel, frame, value):
71+
def set_keyframe(context, bone, channel, frame, value):
7072
if is_visibility(channel):
71-
set_visibility(bone, frame, value)
73+
set_visibility(context, bone, frame, value)
7274
elif is_translation(channel):
7375
set_translation(bone, channel.type, frame, value)
7476
else:
7577
set_rotation(bone, frame, value)
7678

7779

78-
def apply_timecoded(bone, channel):
80+
def apply_timecoded(context, bone, channel):
7981
for key in channel.time_codes:
80-
set_keyframe(bone, channel, key.time_code, key.value)
82+
set_keyframe(context, bone, channel, key.time_code, key.value)
8183

8284

83-
def apply_motion_channel_time_coded(bone, channel):
85+
def apply_motion_channel_time_coded(context, bone, channel):
8486
for datum in channel.data:
85-
set_keyframe(bone, channel, datum.time_code, datum.value)
87+
set_keyframe(context, bone, channel, datum.time_code, datum.value)
8688

8789

88-
def apply_motion_channel_adaptive_delta(bone, channel):
90+
def apply_motion_channel_adaptive_delta(context, bone, channel):
8991
data = decode(channel.type, channel.vector_len, channel.num_time_codes, channel.data.scale, channel.data.data)
9092
for i in range(channel.num_time_codes):
91-
set_keyframe(bone, channel, i, data[i])
93+
set_keyframe(context, bone, channel, i, data[i])
9294

9395

94-
def apply_adaptive_delta(bone, channel):
96+
def apply_adaptive_delta(context, bone, channel):
9597
data = decode(channel.type, channel.vector_len, channel.num_time_codes, channel.scale, channel.data)
9698
for i in range(channel.num_time_codes):
97-
set_keyframe(bone, channel, i, data[i])
99+
set_keyframe(context, bone, channel, i, data[i])
98100

99101

100-
def apply_uncompressed(bone, channel):
102+
def apply_uncompressed(context, bone, channel):
101103
for index in range(channel.last_frame - channel.first_frame + 1):
102104
data = channel.data[index]
103105
frame = index + channel.first_frame
104-
set_keyframe(bone, channel, frame, data)
106+
set_keyframe(context, bone, channel, frame, data)
105107

106108

107109
def process_channels(context, hierarchy, channels, rig, apply_func):
@@ -110,7 +112,7 @@ def process_channels(context, hierarchy, channels, rig, apply_func):
110112
if obj is None:
111113
continue
112114

113-
apply_func(obj, channel)
115+
apply_func(context, obj, channel)
114116

115117

116118
def process_motion_channels(context, hierarchy, channels, rig):
@@ -120,9 +122,9 @@ def process_motion_channels(context, hierarchy, channels, rig):
120122
continue
121123

122124
if channel.delta_type == 0:
123-
apply_motion_channel_time_coded(obj, channel)
125+
apply_motion_channel_time_coded(context, obj, channel)
124126
else:
125-
apply_motion_channel_adaptive_delta(obj, channel)
127+
apply_motion_channel_adaptive_delta(context, obj, channel)
126128

127129

128130
def create_animation(context, rig, animation, hierarchy):

tests/common/cases/structs/test_animation.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# <pep8 compliant>
22
# Written by Stephan Vedder and Michael Schnabel
33

4-
import io
4+
import io, bpy
55
from tests.common.helpers.animation import *
66
from tests.utils import TestCase
77
from unittest.mock import patch, call
@@ -12,8 +12,12 @@ def test_write_read(self):
1212
expected = get_animation()
1313

1414
self.assertEqual(52, expected.header.size())
15-
self.assertEqual(683, expected.size(False))
16-
self.assertEqual(691, expected.size())
15+
if bpy.app.version == (4, 4, 3):
16+
self.assertEqual(645, expected.size(False))
17+
self.assertEqual(653, expected.size())
18+
else:
19+
self.assertEqual(683, expected.size(False))
20+
self.assertEqual(691, expected.size())
1721

1822
self.write_read_test(expected, W3D_CHUNK_ANIMATION, Animation.read, compare_animations, self, True)
1923

0 commit comments

Comments
 (0)