Exemple #1
0
def rebuiltEnvelope(envelope_op):

    geo = envelope_op.Parent3DObject
    deformers = envelope_op.Deformers

    weights = envelope_op.Weights.Array
    xsi.RemoveFlexEnv(geo)
    envelope_op = geo.ApplyEnvelope(deformers)
    envelope_op.Weights.Array = weights

    return envelope_op
Exemple #2
0
def removeEnvDeformer(envelope_op, obj):

    mesh = envelope_op.Parent3DObject
    points = mesh.ActivePrimitive.Geometry.Points
    point_count = points.Count
    deformers = envelope_op.Deformers
    deformer_count = deformers.Count
    index = 0
    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))
    ]
    new_deformers = XSIFactory.CreateObject("XSI.Collection")

    # Process
    for deformer_index, deformer in enumerate(deformers):
        if obj.FullName == deformer.FullName:
            index = deformer_index
        else:
            new_deformers.add(deformer)

    newWeight = []
    for point_index in range(point_count):
        newWeight.extend(
            weights[point_index * deformer_count:point_index * deformer_count +
                    index])
        newWeight.extend(
            weights[point_index * deformer_count + index +
                    1:point_index * deformer_count + deformer_count])

    # Delete the old Envelope and add the new one with the new Deformers
    xsi.RemoveFlexEnv(mesh)
    envelope_op = mesh.ApplyEnvelope(new_deformers)
    envelope_op.Weights.Array = newWeight

    return envelope_op
Exemple #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