예제 #1
0
def set_animdata(item, anim_data, start_frame=None):
    """
    Sets animation on component's animation node

    :param item: item to get data from
    :type item: pyfbsdk component

    :param anim_data: dict of data
    :type anim_data: dict

    :param frame_offset: frame offset value
    :type frame_offset: int
    """
    # make sure anim data contains translation and rotation entries
    if not anim_data.get("Translation", None):
        raise RuntimeError("No translation in animation data!")

    if not anim_data.get("Rotation", None):
        raise RuntimeError("No rotation in animation data!")

    # get frame offset
    frame_offset = 0
    anim_start_frame = get_startframe(anim_data)
    if start_frame is not None and anim_start_frame is not None:
        frame_offset = start_frame - anim_start_frame

    # set translation static
    item.Translation = pyfbsdk.FBVector3d(
        [value[0].get("value", 0.0) for value in anim_data["Translation"]])

    for i, value in enumerate(anim_data["Translation"]):
        if not value[0].get("static", False):
            item.Translation.SetAnimated(True)
            trans_anim_node = item.Translation.GetAnimationNode()
            set_curve_data(
                trans_anim_node.Nodes[i].FCurve,
                value,
                frame_offset)

    # set rotation
    item.Rotation = pyfbsdk.FBVector3d(
        [value[0].get("value", 0.0) for value in anim_data["Rotation"]])

    for i, value in enumerate(anim_data["Rotation"]):
        if not value[0].get("static", False):
            item.Rotation.SetAnimated(True)
            rots_anim_node = item.Rotation.GetAnimationNode()
            set_curve_data(
                rots_anim_node.Nodes[i].FCurve,
                value,
                frame_offset)

    LOG.info("Animation set on {0}".format(item.LongName))
    def create_null_object(self):
        """
		Creates a null object to accept the constraint of the system.
		
		*Arguments:*
			* ``None``
		
		*Keyword Arguments:*
			* ``None``
		
		*Returns:*
			* ``None`` 
		
		*Author:*
			* Jon Logsdon, [email protected], 5/22/2014 1:48:10 PM
		"""

        global constrain_null, child_obj, parent_obj
        constrain_null = pyfbsdk.FBModelNull("OnePointConst_UserNode")
        selected = vmobu.core.get_selection_order()
        for i in range(len(selected)):
            if i == 0:
                child_obj = selected[i]
            if i == 1:
                parent_obj = selected[i]

        constrain_null_vector = pyfbsdk.FBVector3d()
        constrain_null.GetVector(
            constrain_null_vector,
            pyfbsdk.FBModelTransformationType.kModelTranslation)
        constrain_null.GetVector(
            constrain_null_vector,
            pyfbsdk.FBModelTransformationType.kModelRotation)

        pyfbsdk.FBSystem().Scene.Evaluate()

        constrain_null.SetVector(
            pyfbsdk.FBVector3d(self.pos_null_vector),
            pyfbsdk.FBModelTransformationType.kModelTranslation)
        constrain_null.SetVector(
            pyfbsdk.FBVector3d(self.pos_null_vector),
            pyfbsdk.FBModelTransformationType.kModelRotation)

        for comp in pyfbsdk.FBSystem().Scene.Components:
            comp.Selected = False
예제 #3
0
def get_scale(node, world_space=False):
    """
    Returns node scale vector
    :param node: FBModel
    :param world_space: bool, Whether to return the vector in world or local space.
    :return: FBVector3d or None
    """

    node = node_utils.get_model_node_by_name(node)
    if not node:
        return None

    vector = pyfbsdk.FBVector3d()
    node.GetVector(vector, MATRIX_TYPE_DICT['Scaling', world_space])

    return vector
예제 #4
0
 def add_geometry(self, vertices, indices, name):
     mesh = native.FBMesh(name)
     mesh.GeometryBegin()
     for v in vertices:
         mesh.VertexAdd(v[0], v[1], v[2])
     for f in zip(*[iter(indices)] * 3):
         mesh.PolygonBegin()
         for i in f:
             mesh.PolygonVertexAdd(i)
         mesh.PolygonEnd()
     mesh.ComputeVertexNormals(True)
     mesh.GeometryEnd()
     model = native.FBModelCube(name)
     model.Geometry = mesh
     v = native.FBVector3d(5, 5, 5)
     model.Scaling = v
     model.Show = True
     return model
def run():
    One_Point_Constraint().create_null_object()

    null_vector = pyfbsdk.FBVector3d()
    constrain_null.GetVector(
        null_vector, pyfbsdk.FBModelTransformationType.kModelTranslation)
    constrain_null.GetVector(null_vector,
                             pyfbsdk.FBModelTransformationType.kModelRotation)

    child_obj.Parent = constrain_null

    selected = vmobu.core.get_selection_order()
    constraint_pc = pyfbsdk.FBConstraintManager().TypeCreateConstraint(3)
    constraint_pc.Name = "OnePointConst"

    constraint_pc.ReferenceAdd(1, parent_obj)
    constraint_pc.ReferenceAdd(0, constrain_null)

    constraint_pc.Snap()
 def __init__(self):
     self.aux_vector = pyfbsdk.FBVector3d()
     self.pos_null_vector = pyfbsdk.FBVector3d()