@@ -122,24 +122,34 @@ def split_hips(self, animation, bone='Hips'):
122122 new_anim .NumFrames = animation .NumFrames
123123 new_anim .SequenceLength = animation .SequenceLength
124124
125+ # first step is generatin the 'root' track
126+ # we need to do it before anything else, as the 'root' track must be the 0 one
125127 for index , name in enumerate (animation .AnimationTrackNames ):
126- data = animation .get_raw_animation_track (index )
127128 if name == bone :
129+ data = animation .get_raw_animation_track (index )
128130 # extract root motion
129- root_motion = [position - data .pos_keys [0 ] for position in data .pos_keys ]
130-
131- # remove root motion from original track
132- data .pos_keys = [data .pos_keys [0 ]]
133- new_anim .add_new_raw_track (name , data )
131+ root_motion = [(position - data .pos_keys [0 ]) for position in data .pos_keys ]
134132
135133 # create a new track (the root motion one)
136134 root_data = FRawAnimSequenceTrack ()
137135 root_data .pos_keys = root_motion
138136 # ensure empty rotations !
139137 root_data .rot_keys = [FQuat ()]
140138
141- # add the track
139+ # add the track
142140 new_anim .add_new_raw_track ('root' , root_data )
141+ break
142+ else :
143+ raise DialogException ('Unable to find bone {0}' .format (bone ))
144+
145+ # now append the original tracks, but removes the position keys
146+ # from the original root bone
147+ for index , name in enumerate (animation .AnimationTrackNames ):
148+ data = animation .get_raw_animation_track (index )
149+ if name == bone :
150+ # remove root motion from original track
151+ data .pos_keys = [data .pos_keys [0 ]]
152+ new_anim .add_new_raw_track (name , data )
143153 else :
144154 new_anim .add_new_raw_track (name , data )
145155
0 commit comments