Weight tools

Examples

Set Weights

This API is what “Set Weights” tab uses: instead of painting various tools via brush (replace, smooth, etc), you can apply the tool to the whole mesh selection.

from maya import cmds

from ngSkinTools2.api import (
    Layers,
    NamedPaintTarget,
    PaintModeSettings,
    flood_weights,
)

# we need a layer reference for this, so we'll take first layer from our sample mesh
layers = Layers(sample_mesh)
layer = layers.list()[0]

# build settings for the flood
settings = PaintModeSettings()
settings.mode = PaintMode.replace
settings.intensity = 0.3

# make vertex selection to apply the change to the subset of your mesh
cmds.select(sample_mesh + ".vtx[0:3]")
flood_weights(target=layer, influence=1, settings=settings)
flood_weights(target=layer, influence=NamedPaintTarget.MASK, settings=settings)

# smoothing does not require current influence
settings.mode = PaintMode.smooth
settings.intensity = 0.01
settings.iterations = 30
flood_weights(target=layer, settings=settings)

# ...but we can smooth only selected influences as well
flood_weights(target=layer, influences=[1, 2], settings=settings)

API reference

ngSkinTools2.api.flood_weights(target, influence=None, influences=None, settings=None)[source]

Apply paint tool in the layer with the given settings.

Parameters
  • target – layer or mesh to set the weights in.

  • influence – target influence: either an int for the logical index of the influence, or one of NamedPaintTarget constants. Can be skipped if tool mode is Smooth or Sharpen.

  • influences – if specified, overrides “influence” and allows passing multiple influences instead. Only supported by flood and sharpen at the moment.

class ngSkinTools2.api.PaintModeSettings[source]

Brush/Flood settings

mode = 1

Tool mode. One of the PaintMode values.

intensity = 1.0

tool intensity;

iterations = 1

iterations; repeats the same smooth operation given number of times - using this parameter instead of calling flood_weights multiple times.

brush_shape = 0
brush_radius = 10
mirror = False

is automatic mirroring on or off

distribute_to_other_influences = False
influences_limit = 0

influences limit per vertex to ensure while smoothing

brush_projection_mode = 0

brush projection mode, one of BrushProjectionMode values.

sample_joint_on_stroke_start = False
tablet_mode = 0
use_volume_neighbours = False
limit_to_component_selection = False
fixed_influences_per_vertex = False

only applicable for smooth mode; when set to True, smoothing will not add additional influences to a vertex.

apply_primary_brush()[source]
apply_alternative_brush()[source]
apply_inverted_brush()[source]
from_dict(values: dict) ngSkinTools2.api.paint.PaintModeSettings[source]
to_dict() dict[source]
class ngSkinTools2.api.PaintMode[source]

Constants for paint mode

replace = 1
add = 2
scale = 3
smooth = 4
sharpen = 5
classmethod all()[source]
ngSkinTools2.api.assign_from_closest_joint(target: str, layer: Layer, influences: List[int] = None) None[source]

For each selected vertex, picks a nearest joint and assigns 1.0 weight to that joint.

Operates on the currently active component selection, or whole mesh, depending on selection.

Parameters
  • target (str) – skinned mesh or skin cluster node name;

  • layer (Layer) – int or Layer object to apply weights to;

  • influences (List[int]) – selects only from provided subset of skinCluster influences.

ngSkinTools2.api.unify_weights(target, layer, overall_effect, single_cluster_mode)[source]

For all selected vertices, calculates average weights and assigns that value to each vertice. The effect is that all vertices end up having same weights.

Operates on the currently active component selection, or whole mesh, depending on selection.

Parameters
  • target (str) – skinned mesh or skin cluster node name;

  • layer (Layer) – int or Layer object to apply weights to;

  • overall_effect (float) – value between 0.0 and 1.0, intensity of the operation. When applying newly calculated weights to the skin cluster, the formula is weights = lerp(originalWeights, newWeights, overallEffect).

  • single_cluster_mode (bool) – if true, all weights will receive the same average. If false, each connected mesh shell will be computed independently.