Skip to content

Commit

Permalink
- Fixed: With Unit Scale not at 0.01 NLA animation will not export
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier150 committed Jun 19, 2021
1 parent fd00d41 commit 7a358c6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
5 changes: 3 additions & 2 deletions blender-for-unrealengine/bfu_export_single_fbx_nla_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def ExportSingleFbxNLAAnim(

animation_data = AnimationManagment()
animation_data.SaveAnimationData(obj)
animation_data.SetAnimationData(active)
animation_data.SetAnimationData(active, True)

if active.ExportAsProxy:
ApplyProxyData(active)
Expand All @@ -112,7 +112,8 @@ def ExportSingleFbxNLAAnim(
savedUnitLength = bpy.context.scene.unit_settings.scale_length
bpy.context.scene.unit_settings.scale_length *= 1/rrf
oldScale = active.scale.z
ApplySkeletalExportScale(active, rrf)

ApplySkeletalExportScale(active, rrf, animation_data)
RescaleAllActionCurve(rrf*oldScale)
for selected in bpy.context.selected_objects:
if selected.type == "MESH":
Expand Down
54 changes: 49 additions & 5 deletions blender-for-unrealengine/bfu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,16 @@ def SaveAnimationData(self, obj):
self.action_extrapolation = obj.animation_data.action_extrapolation
self.action_blend_type = obj.animation_data.action_blend_type
self.action_influence = obj.animation_data.action_influence
self.nla_tracks_ref = obj.animation_data.nla_tracks
self.use_animation_data = True
else:
self.use_animation_data = False

def ClearAnimationData(self, obj):
obj.animation_data_clear()

def SetAnimationData(self, obj):
def SetAnimationData(self, obj, copy_nla=False):
print(obj.name)
if self.use_animation_data:
obj.animation_data_create()

Expand All @@ -256,6 +258,44 @@ def SetAnimationData(self, obj):
obj.animation_data.action_blend_type = self.action_blend_type
obj.animation_data.action_influence = self.action_influence

if copy_nla:
#Clear nla_tracks
nla_tracks_len = len(obj.animation_data.nla_tracks)
for x in range(nla_tracks_len):
obj.animation_data.nla_tracks.remove(obj.animation_data.nla_tracks[0])

#Add Current nla_tracks
for nla_track in self.nla_tracks_ref:
new_nla_track = obj.animation_data.nla_tracks.new()
#new_nla_track.active = nla_track.active
new_nla_track.is_solo = nla_track.is_solo
new_nla_track.lock = nla_track.lock
new_nla_track.mute = nla_track.mute
new_nla_track.name = nla_track.name
new_nla_track.select = nla_track.select
for strip in nla_track.strips:
new_strip = new_nla_track.strips.new(strip.name, strip.frame_start, strip.action)
#new_strip.action = strip.action
new_strip.action_frame_end = strip.action_frame_end
new_strip.action_frame_start = strip.action_frame_start
#new_strip.active = strip.active
new_strip.blend_in = strip.blend_in
new_strip.blend_out = strip.blend_out
new_strip.blend_type = strip.blend_type
new_strip.extrapolation = strip.extrapolation
#new_strip.fcurves = strip.fcurves #TO DO
new_strip.frame_end = strip.frame_end
#new_strip.frame_start = strip.frame_start
new_strip.influence = strip.influence
#new_strip.modifiers = strip.modifiers #TO DO
new_strip.mute = strip.mute
#new_strip.name = strip.name
new_strip.repeat = strip.repeat
new_strip.scale = strip.scale
new_strip.select = strip.select
new_strip.strip_time = strip.strip_time
#new_strip.strips = strip.strips #TO DO


def SafeModeSet(target_mode='OBJECT', obj=None):
if bpy.ops.object.mode_set.poll():
Expand Down Expand Up @@ -943,12 +983,16 @@ def ApplyExportTransform(obj):
obj.scale = saveScale


def ApplySkeletalExportScale(armature, rescale):
def ApplySkeletalExportScale(armature, rescale, target_animation_data = None):

# This function will rescale the armature and applys the new scale

animation_data = AnimationManagment()
animation_data.SaveAnimationData(armature)
animation_data.ClearAnimationData(armature)
if target_animation_data is None:
animation_data = AnimationManagment()
animation_data.SaveAnimationData(armature)
animation_data.ClearAnimationData(armature)
else:
animation_data = target_animation_data

armature.scale = armature.scale*rescale

Expand Down

0 comments on commit 7a358c6

Please sign in to comment.