Browse Source

Port matrix44 controller generation to new fcurve merging method

pull/40/head
Adam Johnson 9 years ago
parent
commit
e8c71eb121
  1. 79
      korman/exporter/animation.py
  2. 7
      korman/exporter/material.py

79
korman/exporter/animation.py

@ -227,37 +227,28 @@ class AnimationConverter:
return True return True
return False return False
def make_matrix44_controller(self, pos_fcurves, scale_fcurves, default_pos, default_scale): def make_matrix44_controller(self, fcurves, pos_path, scale_path, pos_default, scale_default):
pos_keyframes, pos_bez = self._process_keyframes(pos_fcurves) def convert_matrix_keyframe(**kwargs):
scale_keyframes, scale_bez = self._process_keyframes(scale_fcurves) pos = kwargs.get(pos_path)
if not pos_keyframes and not scale_keyframes: scale = kwargs.get(scale_path)
matrix = hsMatrix44()
# Note: scale and pos are dicts, so we can't unpack
matrix.setTranslate(hsVector3(pos[0], pos[1], pos[2]))
matrix.setScale(hsVector3(scale[0], scale[1], scale[2]))
return matrix
fcurves = [i for i in fcurves if i.data_path == pos_path or i.data_path == scale_path]
if not fcurves:
return None return None
# Matrix keyframes cannot do bezier schtuff default_values = { pos_path: pos_default, scale_path: scale_default }
if pos_bez or scale_bez: keyframes = self._process_fcurves(fcurves, convert_matrix_keyframe, default_values)
self._exporter().report.warn("Matrix44 controllers cannot use bezier keyframes--forcing linear", indent=3) if not keyframes:
return None
# Let's pair up the pos and scale schtuff based on frame numbers. I realize that we're creating
# a lot of temporary objects, but until I see profiling results that this is terrible, I prefer
# to have code that makes sense.
keyframes = []
for pos, scale in itertools.zip_longest(pos_keyframes, scale_keyframes, fillvalue=None):
if pos is None:
keyframes.append((None, scale))
elif scale is None:
keyframes.append((pos, scale))
elif pos.frame_num == scale.frame_num:
keyframes.append((pos, scale))
elif pos.frame_num < scale.frame_num:
keyframes.append((pos, None))
keyframes.append((None, scale))
elif pos.frame_num > scale.frame_num:
keyframes.append((None, scale))
keyframes.append((pos, None))
# Now we make the controller # Now we make the controller
ctrl = self._make_matrix44_controller(pos_fcurves, scale_fcurves, keyframes, default_pos, default_scale) return self._make_matrix44_controller(keyframes)
return ctrl
def make_pos_controller(self, fcurves, default_xform, convert=None): def make_pos_controller(self, fcurves, default_xform, convert=None):
pos_curves = [i for i in fcurves if i.data_path == "location" and i.keyframe_points] pos_curves = [i for i in fcurves if i.data_path == "location" and i.keyframe_points]
@ -303,41 +294,17 @@ class AnimationConverter:
ctrl = self._make_scalar_leaf_controller(keyframes, bezier) ctrl = self._make_scalar_leaf_controller(keyframes, bezier)
return ctrl return ctrl
def _make_matrix44_controller(self, pos_fcurves, scale_fcurves, keyframes, default_pos, default_scale): def _make_matrix44_controller(self, keyframes):
ctrl = plLeafController() ctrl = plLeafController()
keyframe_type = hsKeyFrame.kMatrix44KeyFrame keyframe_type = hsKeyFrame.kMatrix44KeyFrame
exported_frames = [] exported_frames = []
pcurves = { i.array_index: i for i in pos_fcurves }
scurves = { i.array_index: i for i in scale_fcurves }
def eval_fcurve(fcurves, keyframe, i, default_xform): for keyframe in keyframes:
try:
return fcurves[i].evaluate(keyframe.frame_num_blender)
except KeyError:
return default_xform[i]
for pos_key, scale_key in keyframes:
valid_key = pos_key if pos_key is not None else scale_key
exported = hsMatrix44Key() exported = hsMatrix44Key()
exported.frame = valid_key.frame_num exported.frame = keyframe.frame_num
exported.frameTime = valid_key.frame_time exported.frameTime = keyframe.frame_time
exported.type = keyframe_type exported.type = keyframe_type
exported.value = keyframe.value
if pos_key is not None:
pos_value = [pos_key.values[i] if i in pos_key.values else eval_fcurve(pcurves, pos_key, i, default_pos) for i in range(3)]
else:
pos_value = [eval_fcurve(pcurves, valid_key, i, default_pos) for i in range(3)]
if scale_key is not None:
scale_value = [scale_key.values[i] if i in scale_key.values else eval_fcurve(scurves, scale_key, i, default_scale) for i in range(3)]
else:
scale_value = [eval_fcurve(scurves, valid_key, i, default_scale) for i in range(3)]
pos_value = hsVector3(*pos_value)
scale_value = hsVector3(*scale_value)
value = hsMatrix44()
value.setTranslate(pos_value)
value.setScale(scale_value)
exported.value = value
exported_frames.append(exported) exported_frames.append(exported)
ctrl.keys = (exported_frames, keyframe_type) ctrl.keys = (exported_frames, keyframe_type)
return ctrl return ctrl

7
korman/exporter/material.py

@ -295,11 +295,12 @@ class MaterialConverter:
return None return None
def _export_layer_transform_animation(self, tex_slot, base_layer, fcurves): def _export_layer_transform_animation(self, tex_slot, base_layer, fcurves):
pos_fcurves = [i for i in fcurves if i.data_path.find("offset") != -1] path = tex_slot.path_from_id()
scale_fcurves = [i for i in fcurves if i.data_path.find("scale") != -1] pos_path = "{}.offset".format(path)
scale_path = "{}.scale".format(path)
# Plasma uses the controller to generate a matrix44... so we have to produce a leaf controller # Plasma uses the controller to generate a matrix44... so we have to produce a leaf controller
ctrl = self._exporter().animation.make_matrix44_controller(pos_fcurves, scale_fcurves, tex_slot.offset, tex_slot.scale) ctrl = self._exporter().animation.make_matrix44_controller(fcurves, pos_path, scale_path, tex_slot.offset, tex_slot.scale)
return ctrl return ctrl
def _export_texture_type_environment_map(self, bo, layer, slot): def _export_texture_type_environment_map(self, bo, layer, slot):

Loading…
Cancel
Save