def update_keyframes(self): with self.output: fp = lambda x: "%f,%f,%f" % x fq = lambda x: "%f,%f,%f,%f" % x options = [(self.format_keyframe(t, p, q), i) for i, (t, p, q) in enumerate( zip(self.times, self.positions, self.quaternions))] self.select_keyframes.options = options self.position_track = pythreejs.VectorKeyframeTrack( name='.position', times=self.times, values=self.positions, interpolation=self.select_interpolation.value) self.rotation_track = pythreejs.QuaternionKeyframeTrack( name='.quaternion', times=self.times, values=self.quaternions, interpolation=self.select_interpolation.value) if len(self.positions): self.camera_clip = pythreejs.AnimationClip( tracks=[self.position_track, self.rotation_track]) self.mixer = pythreejs.AnimationMixer(self.camera) self.camera_action = pythreejs.AnimationAction( self.mixer, self.camera_clip, self.camera) self.camera_action_box.children = [self.camera_action] else: self.camera_action_box.children = []
def create_group_action(self, objs, transformations, times): # TODO: how to start multiple animations at once if len(transformations) != len(times): raise ValueError("Pass equal amount of transformations and times") x, y, z, w = objs[0].quaternion Tinit = Rotation.from_quaternion([w, x, y, z]) * Translation( objs[0].position) positions = [] quaternions = [] for M in transformations: Sc, Sh, R, T, P = (M * Tinit).decomposed() positions.append(list(T.translation)) quaternions.append(R.quaternion.xyzw) position_track = p3js.VectorKeyframeTrack(name='.position', times=times, values=list( flatten(positions))) rotation_track = p3js.QuaternionKeyframeTrack( name='.quaternion', times=times, values=list(flatten(quaternions))) animation_group = p3js.AnimationObjectGroup() animation_group.exec_three_obj_method('add', objs[0]) # this is not working obj_clip = p3js.AnimationClip(tracks=[position_track, rotation_track]) mixer = p3js.AnimationMixer(animation_group) obj_action = p3js.AnimationAction(mixer, obj_clip, animation_group) return obj_action
def create_action(self, obj, transformations, times): if len(transformations) != len(times): raise ValueError("Pass equal amount of transformations and times") x, y, z, w = obj.quaternion Tinit = Rotation.from_quaternion([w, x, y, z]) * Translation(obj.position) positions = [] quaternions = [] for M in transformations: Sc, Sh, R, T, P = (M * Tinit).decompose() positions.append(list(T.translation)) quaternions.append(R.quaternion.xyzw) position_track = p3js.VectorKeyframeTrack(name='.position', times=times, values=list(flatten(positions))) rotation_track = p3js.QuaternionKeyframeTrack(name='.quaternion', times=times, values=list(flatten(quaternions))) obj_clip = p3js.AnimationClip(tracks=[position_track, rotation_track]) obj_action = p3js.AnimationAction(p3js.AnimationMixer(obj), obj_clip, obj) return obj_action