Example #1
0
def createMirrorCnxTemplate(model, in_controlers=None):

    cnx_prop = model.Properties(MIRROR_PROP_NAME)
    if not cnx_prop:
        cnx_prop = model.AddProperty("gear_Mirror", False, MIRROR_PROP_NAME)
        cnx_grid = cnx_prop.Parameters("CnxGridHidden").Value
        connections = par.getDictFromGridData(cnx_grid)

    if in_controlers is not None:

        controlers = XSIFactory.CreateObject("XSI.Collection")
        controlers.AddItems(in_controlers)

        cnx_grid.BeginEdit()

        pbar = uit.progressBar(controlers.Count, 1, "Creating Mirror Template",
                               "", False)

        # Adding selected controlers to Connection map
        for ctl in controlers:
            pbar.StatusText = ctl.Name
            connections = addMirroringRule(ctl, cnx_grid, connections)
            pbar.Increment()

        pbar.Visible = False

        par.setDataGridFromDict(cnx_grid, connections)
        cnx_prop.Parameters("Count").Value = len(connections)

        cnx_grid.EndEdit()

    return cnx_grid
Example #2
0
def createMirrorCnxTemplate(model, in_controlers=None):

    cnx_prop = model.Properties(MIRROR_PROP_NAME)
    if not cnx_prop:
        cnx_prop = model.AddProperty("gear_Mirror", False, MIRROR_PROP_NAME)
        cnx_grid = cnx_prop.Parameters("CnxGridHidden").Value
        connections = par.getDictFromGridData(cnx_grid)

    if in_controlers is not None:
        
        controlers = XSIFactory.CreateObject("XSI.Collection")
        controlers.AddItems(in_controlers)

        cnx_grid.BeginEdit()

        pbar = uit.progressBar(controlers.Count, 1, "Creating Mirror Template", "", False)

        # Adding selected controlers to Connection map
        for ctl in controlers:
            pbar.StatusText = ctl.Name
            connections = addMirroringRule(ctl, cnx_grid, connections)
            pbar.Increment()

        pbar.Visible = False

        par.setDataGridFromDict(cnx_grid, connections)
        cnx_prop.Parameters("Count").Value = len(connections)

        cnx_grid.EndEdit()

    return cnx_grid
Example #3
0
def pruneWeights(envelope_op,
                 points=None,
                 threshold=.1,
                 remove=False,
                 showPBar=False):

    # Get weights array
    mesh = envelope_op.Parent3DObject
    point_count = mesh.ActivePrimitive.Geometry.Points.Count
    weights_tuple = envelope_op.Weights.Array
    weights = [
        weights_tuple[j][i] for i in range(len(weights_tuple[0]))
        for j in range(len(weights_tuple))
    ]

    deformer_count = envelope_op.Deformers.Count
    used_deformers = XSIFactory.CreateObject("XSI.Collection")
    used_deformers.Unique = True

    if points is None:
        points = range(point_count)

    if showPBar:
        pbar = uit.progressBar(
            len(points), 1,
            str(len(points)) + " points to prune on : " + mesh.Name, "0",
            False)

    # Prune Weights
    pointsToNormalize = []
    for point_index in points:

        if showPBar:
            pbar.StatusText = point_index

        for deformer_index, deformer in enumerate(envelope_op.Deformers):

            if weights[point_index * deformer_count +
                       deformer_index] <= threshold:
                weights[point_index * deformer_count + deformer_index] = 0
                if not point_index in pointsToNormalize:
                    pointsToNormalize.append(point_index)
            else:
                used_deformers.Add(deformer)

        if showPBar:
            pbar.Increment()

    if showPBar:
        pbar.Visible = False

    # Normalize points
    envelope_op.Weights.Array = weights
    normalizeWeights(envelope_op, pointsToNormalize)
    freezeEnvelope(envelope_op)

    # Rebuilt Envelope ------------------------------------------------
    # If True, we rebuilt the envelope a first time without the unused deformers
    if remove:

        gear.log("There is " +
                 str(envelope_op.Deformers.Count - used_deformers.Count) +
                 " deformers that will be removed")

        path = XSIUtils.ResolvePath("Temp")
        preset_name = mesh.Name + "_Weights"

        env_prop = envelope_op.PortAt(4, 0, 0).Target2
        xsi.SavePreset(env_prop, preset_name, path, None, 1, None, None)
        xsi.RemoveFlexEnv(mesh)

        envelope_op = mesh.ApplyEnvelope(used_deformers)
        env_prop = envelope_op.PortAt(4, 0, 0).Target2

        xsi.LoadPreset(path + "/" + preset_name, env_prop)

    # Rebuilt the envelope to get the correct colors and normalisation warning
    envelope_op = rebuiltEnvelope(envelope_op)

    return envelope_op
Example #4
0
def pruneWeights(envelope_op, points=None, threshold=.1, remove=False, showPBar=False):

    # Get weights array
    mesh = envelope_op.Parent3DObject
    point_count = mesh.ActivePrimitive.Geometry.Points.Count
    weights_tuple = envelope_op.Weights.Array
    weights = [weights_tuple[j][i] for i in range(len(weights_tuple[0])) for j in range(len(weights_tuple))]

    deformer_count = envelope_op.Deformers.Count
    used_deformers = XSIFactory.CreateObject("XSI.Collection")
    used_deformers.Unique = True

    if points is None:
        points = range(point_count)

    if showPBar:
        pbar = uit.progressBar(len(points), 1, str(len(points)) + " points to prune on : "+mesh.Name, "0", False)

    # Prune Weights
    pointsToNormalize = []
    for point_index in points:

        if showPBar:
            pbar.StatusText = point_index

        for deformer_index, deformer in enumerate(envelope_op.Deformers):

            if weights[point_index*deformer_count + deformer_index] <= threshold:
                weights[point_index*deformer_count + deformer_index] = 0
                if not point_index in pointsToNormalize:
                    pointsToNormalize.append(point_index)
            else:
                used_deformers.Add(deformer)

        if showPBar:
            pbar.Increment()

    if showPBar:
        pbar.Visible = False

    # Normalize points
    envelope_op.Weights.Array = weights
    normalizeWeights(envelope_op, pointsToNormalize)
    freezeEnvelope(envelope_op)

    # Rebuilt Envelope ------------------------------------------------
    # If True, we rebuilt the envelope a first time without the unused deformers
    if remove:

        gear.log("There is "+str(envelope_op.Deformers.Count - used_deformers.Count) + " deformers that will be removed")

        path = XSIUtils.ResolvePath("Temp")
        preset_name = mesh.Name +"_Weights"

        env_prop = envelope_op.PortAt(4, 0, 0).Target2
        xsi.SavePreset(env_prop, preset_name, path, None, 1, None, None)
        xsi.RemoveFlexEnv(mesh)

        envelope_op = mesh.ApplyEnvelope(used_deformers)
        env_prop = envelope_op.PortAt(4, 0, 0).Target2

        xsi.LoadPreset(path +"/"+ preset_name, env_prop)

    # Rebuilt the envelope to get the correct colors and normalisation warning
    envelope_op = rebuiltEnvelope(envelope_op)

    return envelope_op