Untitled

 avatar
unknown
plain_text
a year ago
3.9 kB
16
Indexable
"""
Default build file copied for all new assets
"""
# python modules
import os
import json

# maya modules
import maya.cmds as mc

# iRig modules
from rig_factory.build.base_objects import RigBuild, GuideBuild

# show modules
from dja_scripts import dja_build
reload(dja_build)


class AssetRigBuilder(dja_build.AssetRigBuilder):

    def before_create_container(self):
        """ This will happen at the very BEGINNING of the build """
        super(AssetRigBuilder, self).before_create_container()

    def after_create_deformation_rig(self):
        """ This function runs before deformers are imported """
        super(AssetRigBuilder, self).after_create_deformation_rig()

    def after_finish_create(self):
        """ This function runs after deformers are imported """
        super(AssetRigBuilder, self).after_finish_create()
        locator_attr_transfer()
        mc.setAttr("Settings_Ctrl.usePosedCurve", 1)
        connect_handle_to_curves()
        display_objs = ['Volume_Animated_BifrostGraph', 'Bubbles_Animated_BifrostGraph']
        for obj in display_objs:
            mc.connectAttr('Settings_Ctrl.geometryDisplay', '{}.overrideDisplayType'.format(obj))

        # Adding command to fix value of attr from Asset.
        particle_speed_attr()

    def before_finalize(self):
        """ This function runs at publish time """
        super(AssetRigBuilder, self).before_finalize()

    def after_finalize(self):
        """ This function runs at publish time """
        super(AssetRigBuilder, self).after_finalize()


class AssetGuideBuilder(dja_build.AssetGuideBuilder):

    def before_create_container(self):
        """
        This will happen at the very BEGINNING of the build
        """
        super(AssetGuideBuilder, self).before_create_container()

    def before_create_parts(self):
        """
        This function runs after parts are created
        """
        super(AssetGuideBuilder, self).before_create_parts()


def locator_attr_transfer():
    main_loc_name = 'Bifrost_Controls_Loc'

    new_attr_list = [u'radius', u'numberOfBubbles', u'bubbleScaleMin', u'bubbleScaleMax',
                     u'particleDistanceFromPathMax',
                     u'particleSpeed', u'particleSpeedRandom', u'noiseStrength', u'noiseScale', u'noiseSpeed', 
                     u'endsBuffer', u'endsBufferRandom', 'usePosedCurve', 'displayAnimatedBubbles']

    default_list = []
    type_list = []

    for attr in new_attr_list:
        default_list += mc.attributeQuery(attr, n=main_loc_name, ld=True)
        type_list.append(mc.attributeQuery(attr, n=main_loc_name, at=True))

    for i, attr in enumerate(new_attr_list):
        mc.addAttr('Settings_Ctrl', longName=attr, attributeType=type_list[i],
                    defaultValue=default_list[i], k=1)

    # connect settings ctrl attr to loc attr

    for attr in new_attr_list:
        mc.connectAttr('Settings_Ctrl.' + attr, main_loc_name + '.' + attr, f=1)

    # mc.connectAttr('Settings_Ctrl.useSplitter', 'C_ParticleHandle_Main_Ctrl.visibility')


def connect_handle_to_curves():
    ctrl_and_curves = {
        'C_PathStraight_Main_Ctrl': 'PathStraight_Deform_Crv',
        'C_Path_Main_Ctrl': 'Path_Deform_Crv'
    }
    for ctrl, crv in ctrl_and_curves.items():
        zro_grp = ctrl.replace('Ctrl', 'Zro')
        motion_path = mc.pathAnimation(zro_grp, crv, name='{}_motionPath'.format(zro_grp), fractionMode=True,
                                       follow=True
                                       )
        mc.addAttr(ctrl, ln='Slide', at='double', dv=0, min=0, max=1, k=True)
        mc.connectAttr('{}.Slide'.format(ctrl), '{}.uValue'.format(motion_path), f=True)


def particle_speed_attr():

    mc.setAttr('Settings_Ctrl.particleSpeed', 3200)
Editor is loading...
Leave a Comment