Import, export and transfer


Export weigths to file:

    import os
    from ngSkinTools2 import api as ngst_api

    output_file_name = os.path.join(target_dir, 'export_sample_mesh.json')
    ngst_api.export_json("sample_mesh", file=output_file_name)

Import weights from file:

    # prerequisites: mesh with skinCluster attached, "sampleMesh" in our case

    config = InfluenceMappingConfig()
    config.use_distance_matching = True
    config.use_name_matching = False
    ngst_api.import_json("sampleMesh", file=output_file_name, influences_mapping_config=config)

Transfer with default settings: vertices mapped with closestPoint rule, and influences with default settings for mesh-to-mesh transfer (using InfluenceMappingConfig.transfer_defaults()).

    from ngSkinTools2 import api as ngst_api

    # prerequisites: we have two meshes with skinCluster attached ready
    source = "sample_source_mesh"
    destination = "sample_destination_mesh"

    # normally we would assume that source mesh already has skin layers created,
    # but for example's sake, just create some layers on the fly
    source_layers = ngst_api.init_layers(source)
    l1 = source_layers.add("layer1")
    l1.set_weights(0, [1.0] * 4)
    l1.set_weights(1, [.2, .2, .8, .8])
    l2 = source_layers.add("layer_two")
    l2.set_weights(1, [1, 1, 0, 0])
    l3 = source_layers.add("layer3", parent=l1)
    l4 = source_layers.add("layer4", parent=l1)

    # there is no need to init layers on destination,
    # but if destination had layers already, then  transferred layers
    # would be created on top of old ones

    # so this line is all you need, if you have source mesh ready with skinning layers,
    # and destination mesh with skinCluster attached.
    ngst_api.transfer_layers(source, destination)

To customize transfer options for vertex and influences mapping:

    infl_config = ngst_api.InfluenceMappingConfig.transfer_defaults()
    infl_config.use_label_matching = False
    infl_config.use_distance_matching = True
    infl_config.use_name_matching = False

    ngst_api.transfer_layers("sample_source_mesh", "sample_destination_mesh",

API reference

ngSkinTools2.api.export_json(target, file)

Save skinning layers to file in json format, to be later used in import_json

  • target (str) – source mesh or skin cluster node name

  • file (str) – file path to save json to

ngSkinTools2.api.import_json(target, file, vertex_transfer_mode='closestPoint', influences_mapping_config=<ngSkinTools2.api.influenceMapping.InfluenceMappingConfig object>)

Transfer layers from file into provided target mesh. Existing layers, if any, will be preserved

  • target (str) – destination mesh or skin cluster node name

  • file (str) – file path to load json from

  • influences_mapping_config (InfluenceMappingConfig) –

class ngSkinTools2.api.InfluenceMappingConfig

This class represents a configuration for how influences are matched for weights mirroring or transfering between meshes.

globs = [('L_*', 'R_*'), ('l_*', 'r_*'), ('lf_*', 'rt_*'), ('*_lf', '*_rt')]

For mirrored influences matching, this specifies the globs that will be used for name substitution

use_name_matching = True

should matching by name be used?

use_label_matching = True

should matching by label be used?

use_distance_matching = True

should matching by influence X,Y,Z coordinates be used?

distance_threshold = 0.001

When matching by distance, if distance between two positions is greater than this threshold, that pair of influences is not considered as potential match.

property mirror_axis

Mirror axis (0 - X, 1 - Y, 2 - Z)

When mirror axis is not None, matching is done in “mirror” mode:

  • left/right side .globs are used;

  • matching by position uses mirrorAxis to invert positions first;



classmethod transfer_defaults()

Builds a mapping configuration that is suitable as default for transferring between meshes (or importing)


default transfer configuration

Return type


class ngSkinTools2.api.InfluenceMapping
static asIntIntMapping(mapping)
class ngSkinTools2.api.VertexTransferMode
closestPoint = 'closestPoint'

When vertices from two surface are matched, each destination mesh vertex finds a closest point on source mesh, and weights are calculated based on the triangle weights of that closest point.

uvSpace = 'uvSpace'

Similar to closestPoint strategy, but matching is done in UV space instead of XYZ space.

vertexId = 'vertexId'

Vertices are matched by ID. Not usable for mirroring; this is used for transfer/import cases where meshes are known to be identical