# -*- coding: utf-8 -*- """ :author: Jeremy Ernst :description: This module contains the class for a pose object, which has methods for gathering data for creating a pose, loading a pose, saving a pose, etc. """ import artv2.tools.system.logger.output_logger as logger import artv2.utilities.general_utilities as utils import artv2.utilities.rigging_utilities as rig_utils # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # class Pose(object): """ Creates a pose object, which can gather data for creating a pose, load a pose, or save a pose. The constructor is passed a list of controls for which to either gather data for or load data onto. """ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def __init__(self, controls): self.logger = logger.OutputLogger(self.__class__.__name__) self.controls = utils.convert_to_pynodes(controls) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def create_pose(self, name): """ Gathers the data from this object's controls and returns that data in a dictionary. example usage: .. code-block:: python # create a pose instance with some joints as the "controls" import artv2.components.base_components.pose as pose cmds.select("root", hi=True) poseInst = pose.Pose(cmds.ls(sl=True)) # with our pose instance, create a pose named "test". data = poseInst.create_pose("test") :param name: Name for the created pose. :return: Dictionary of pose data. """ self.logger.info("{0}.create_pose: Saving pose with name: {1}".format(self.__class__.__name__, name)) pose_data = {"name": name} attrs = ["translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ", "scaleX", "scaleY", "scaleZ"] for control in self.controls: attr_data = {} for attribute in attrs: if control.attr(attribute).isKeyable(): attr_data[attribute] = control.attr(attribute).get() attr_data["worldMatrix"] = control.worldMatrix.get().__melobject__() pose_data[control.nodeName(stripNamespace=True)] = attr_data return pose_data # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def load_pose(self, pose_data): """ Loads the given pose data on this object's controls. example usage: .. code-block:: python # create a pose instance with some joints as the "controls" import artv2.components.base_components.pose as pose cmds.select("root", hi=True) poseInst = pose.Pose(cmds.ls(sl=True)) # with our pose instance, load the data from a created pose from earlier. poseInst.load_pose(data) :param pose_data: pose data dictionary to load onto controls. """ self.logger.info("{0}.load_pose: Loading pose".format(self.__class__.__name__)) for control in self.controls: name = control.name(stripNamespace=True) if name in pose_data: data = pose_data.get(name) for attribute in data: if control.attr(attribute).isKeyable(): if rig_utils.attr_is_settable(control.attr(attribute)): value = data.get(attribute) control.attr(attribute).set(value)