Layers

Examples

Basic usage: initialize layers on given skin cluster, add, list and delete layers.

    from ngSkinTools2.api import init_layers, Layers

    layers = init_layers("skinCluster1")
    # alternatively, if layers are already enabled on this mesh,
    # layers = Layers("skinCluster1")

    layer_base = layers.add("base weights")
    layer_one = layers.add("one")
    layer_two = layers.add("two", parent=layer_one)

    # layer_one instance was created before we added layer_two,
    # so we need to reload it with latest data to see recent updates
    assert layer_one.children == []
    layer_one.reload()
    assert layer_one.children == [layer_two]

    assert layer_one.parent is None
    assert layer_two.parent.name == "one"
    all_layers = layers.list()
    assert all_layers[0].name == "base weights"
    assert all_layers[1].name == "one"
    assert all_layers[2].name == "two"

    layers.delete(layer_two)

Sample manipulation of layer attributes

    # basic properties - just treat like fields
    layer_one.enabled = False
    layer_one.enabled = True
    layer_one.name = "arms"
    layer_one.opacity = 0.8

    # enable mirror effect on everything: mask, dq, influence weights
    layer_one.effects.configure_mirror(everything=True)

    # enable mirror effect on just influence weights
    layer_one.effects.configure_mirror(mirror_weights=True)

Manipulation of weight buffers. Refer to influences by their logical index (connection index in dependency graph).

    from ngSkinTools2.api import NamedPaintTarget

    # mask is by default empty
    assert layer_one.get_weights(NamedPaintTarget.MASK) == []
    # when setting weights, list length must match number of vertices in skinCluster
    layer_one.set_weights(NamedPaintTarget.MASK, [0.9, 0, 1, 1])
    layer_one.set_weights(0, [1, 1, 1, 1])
    # settings weights to influence #1 will override weights on influence #0
    layer_one.set_weights(1, [0, 0, 1, 1])
    assert layer_one.get_weights(0) == [1, 1, 0, 0]

API reference

Layers

ngSkinTools2.api.init_layers(target)

Attach ngSkinTools data node to given target. Does nothing if layers are already attached.

Parameters

target (str) – skin cluster or mesh node to attach layers to

Returns

Layers instance to further query/modify layers data.

Return type

Layers

class ngSkinTools2.api.Layers(target)

Layers manages skinning layers on provided target (skinCluster or a mesh)

param target

name of skin cluster node or skinned mesh.

property prune_weights_filter_threshold
property influence_limit_per_vertex
add(name, forceEmpty=False, parent=None)

creates new layer with given name and returns it’s ID; when forceEmpty flag is set to true, layer weights will not be populated from skin cluster.

delete(layer)
list()

returns all layers as Layer objects.

list_influences()
current_layer()

get current layer that was previously marked as current with Layer.set_current().

Warning

Scheduled for removal. API calls should specify target layer explicitly

set_influences_mirror_mapping(influencesMapping)
is_enabled()

returns true if skinning layers are enabled for the given mesh :return:

property data_node

Layer

class ngSkinTools2.api.Layer(mesh, id, state=None)
property name

Layer name

Type

str

property enabled

is layer enabled or disabled

Type

bool

property opacity

value between 1.0 and 0

Type

float

property paint_target

currently active paint target for this layer (either an influence or one of named targets)

Type

str or int

property index

layer index in parent’s child list; set to reorder

Type

int

classmethod load(mesh, layerId)
reload()

Refresh layer data from plugin.

property parent

layer parent, or None, if layer is at root level.

Type

Layer

property num_children

a bit more lightweight method to count number of child layers than len(children()), as it does not prefetch children data.

Type

int

property children

lazily load children if needed, and return as Layer objects

Type

list[Layer]

set_current()

Set as “default” layer for other operations.

Warning

Scheduled for removal. API calls should specify target layer explicitly

set_weights(influence, weights_list, undo_enabled=True)

Modify weights in the layer.

influence

either index of an influence, or named paint target

weights_list

weights for each vertex (must match number of vertices in skin cluster)

undo_enabled

set to False if you don’t need undo, for slight performance boost

get_weights(influence)

get influence (or named paint target) weights for all vertices

get_used_influences()
Return type

list[int]