@classmethod
    def normalize_sss_weights(cls):
        """normalizes the sss weights so their total weight is 1.0

        if a aiStandard is assigned to the selected object it searches for an
        aiSkin in the emission channel.

        the script considers 0.7 as the highest diffuse value for aiStandard
        """
        # get the shader of the selected object
        assigned_shader = pm.ls(
            pm.ls(sl=1)[0].getShape().outputs(type='shadingEngine')[0].inputs(),
            mat=1
        )[0]

        if assigned_shader.type() == 'aiStandard':
            sss_shader = assigned_shader.attr('emissionColor').inputs()[0]
            diffuse_weight = assigned_shader.attr('Kd').get()
        else:
            sss_shader = assigned_shader
            diffuse_weight = 0

        def get_attr_or_texture(attr):
            if attr.inputs():
                # we probably have a texture assigned
                # so use its multiply attribute
                texture = attr.inputs()[0]
                attr = texture.attr('multiply')
                if isinstance(texture, pm.nt.AiImage):
                    attr = texture.attr('multiply')
                elif isinstance(texture, pm.nt.File):
                    attr = texture.attr('colorGain')
            return attr

        shallow_attr = get_attr_or_texture(
            sss_shader.attr('shallowScatterWeight')
        )
        mid_attr = get_attr_or_texture(sss_shader.attr('midScatterWeight'))
        deep_attr = get_attr_or_texture(sss_shader.attr('deepScatterWeight'))

        shallow_weight = shallow_attr.get()
        if isinstance(shallow_weight, tuple):
            shallow_weight = (
                shallow_weight[0] + shallow_weight[1] + shallow_weight[2]
            ) / 3.0

        mid_weight = mid_attr.get()
        if isinstance(mid_weight, tuple):
            mid_weight = (
                mid_weight[0] + mid_weight[1] + mid_weight[2]
            ) / 3.0

        deep_weight = deep_attr.get()
        if isinstance(deep_weight, tuple):
            deep_weight = (
                deep_weight[0] + deep_weight[1] + deep_weight[2]
            ) / 3.0

        total_sss_weight = shallow_weight + mid_weight + deep_weight

        mult = (1 - diffuse_weight / 0.7) / total_sss_weight
        try:
            shallow_attr.set(shallow_weight * mult)
        except RuntimeError:
            w = shallow_weight * mult
            shallow_attr.set(w, w, w)

        try:
            mid_attr.set(mid_weight * mult)
        except RuntimeError:
            w = mid_weight * mult
            mid_attr.set(w, w, w)

        try:
            deep_attr.set(deep_weight * mult)
        except __HOLE__:
            w = deep_weight * mult
            deep_attr.set(w, w, w)
dataset/ETHPy150Open eoyilmaz/anima/anima/env/mayaEnv/toolbox.py/Render.normalize_sss_weights