Layers¶
Examples¶
Basic usage: initialize layers on given skin cluster, add, list and delete layers.
from ngSkinTools2.api import init_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)[source]¶
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
- Return type
- class ngSkinTools2.api.Layers(target)[source]¶
Layers manages skinning layers on provided target (skinCluster or a mesh)
- property prune_weights_filter_threshold¶
- property influence_limit_per_vertex¶
- add(name, force_empty=False, parent=None)[source]¶
creates new layer with given name and returns its ID; when force_empty flag is set to true, layer weights will not be populated from skin cluster.
- current_layer()[source]¶
get current layer that was previously marked as current with
Layer.set_current()
.Warning
Scheduled for removal. API calls should specify target layer explicitly
- property mesh¶
- property data_node¶
- property config¶
Layer¶
- class ngSkinTools2.api.Layer(mesh, id, state=None)[source]¶
- 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
- property locked_influences¶
list of locked influence indexes
- Type
list[int]
- effects: LayerEffects¶
configure effects for this layer
- property paint_targets¶
list of paint targets to be set as current for this layer
- Type
list[str or int]
- 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
- set_current()[source]¶
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)[source]¶
Modify weights in the layer.
- Parameters
influence (int/str) – either index of an influence, or named paint target (one of
NamedPaintTarget
values)weights_list (list[int]) – weights for each vertex (must match number of vertices in skin cluster)
undo_enabled (bool) – set to False if you don’t need undo, for slight performance boost
- class ngSkinTools2.api.LayerEffects(layer, state=None)[source]¶
- configure_mirror(everything=None, mirror_mask=None, mirror_weights=None, mirror_dq=None, mirror_direction=None)[source]¶
Enable/disable components for mirror effect:
>>> layer.effects.configure_mirror(mirror_mask=True) >>> layer.effects.configure_mirror(mirror_dq=False) >>> # equivalent of setting all flags to False >>> layer.effects.configure_mirror(everything=False)
Mirroring direction must be set explicitly.
>>> from ngSkinTools2.api import MirrorOptions >>> layer.effects.configure_mirror(mirror_mask=True,mirror_direction=MirrorOptions.directionPositiveToNegative)
- Parameters
mirror_mask (bool) – should mask be mirrored with this effect?
mirror_weights (bool) – should influence weights be mirrored with this effect?
mirror_dq (bool) – should dq weights be mirrored with this effect?
mirror_direction (int) – mirroring direction. Use MirrorOptions.directionPositiveToNegative, MirrorOptions.directionNegativeToPositive or MirrorOptions.directionFlip