Import/export API consists of:
- Data objects:
Influence; data objects are intermediate objects between exporters, importers and actual skin layer data in layers node;
- Importers are used to load LayerData object from external format, e.g. XML or JSON
- Similarly, exporters serialize LayerData objects into external formats.
For example, to import layers from XML into mesh you’d have to do the following:
from ngSkinTools.importExport import XmlImporter # create layers from importer = XmlImporter() # read file contents here using one of your prefered methods xml = loadFileData('path/to/my.xml') # load layer data data = importer.process(xml) # set that into given mesh data.saveTo('skinnedMesh')
To export, the process is reversed - we load data from skinned mesh (which should have skin layers initialized for it) and save it to file:
from ngSkinTools.importExport import LayerData,XmlExporter data = LayerData() data.loadFrom('skinnedMesh') exporter = XmlExporter() xml = exporter.process(data) saveXmlToFile(xml,'path/to/my.xml')
Note that neither importers nor exporters work with files directly - instead, they use/produce content as strings.
Having this modular approach instead allows for more usage paths other than “import from file” and “export to file”. Not only it allows plugging in new importers/exporters; instead loading data from external source, it can be created on the fly; loaded layer data can be manipulated and saved back to mesh; it’s even possible to convert from one format to another!
To create layer data object, do one of the following:
import with an Importer:
data = JsonImporter().process(jsonString)
load from a skinned mesh:
data = LayerData() data.loadFrom('rig|mesh|bodyMesh')
construct from scratch:
data = LayerData() layer = Layer() # set layer properties influence = Influence() # set influence properties layer.addInfluence(influence) data.addLayer(layer)
LayerData is an ordinary python object, containing a list of layers, which in turn
contains a list of influences. For properties of each object, see below documentation.
For more usage reference, look into implementations of XML/JSON importers/exporters.
Intermediate data object between ngSkinTools core and importers/exporters, representing all layers info in one skin cluster.
a list of
InfluenceInfoobjects. Provides information about influences that were found on exported skin data, and used for influence matching when importing.
register new layer into this data object
Parameters: layer (Layer) – layer object to add.
addMirrorInfluenceAssociationOverride(sourceInfluence, destinationInfluence=None, selfReference=False, bidirectional=True)¶
Adds mirror influence association override, similar to UI of “Add influences association”. Self reference creates a source<->source association, bidirectional means that destination->source link is added as well
a convenience method to retrieve a list of names of all influences used in this layer data object
loads data from actual skin cluster and prepares it for exporting. supply skin cluster or skinned mesh as an argument
saves data to actual skin cluster
Represents single layer; can contain any amount of influences.
layer name. Default value: None; set/use as any python string.
layer opacity. Defaults to 0.0. Set to float value between 0.0 and 1.0
layer on/off flag. Default value is False. Set to True or False.
layer mask: list of floats. Set to None for uninitialized mask, or to float list, containing as many values as there are vertices in a target mesh.
dual quaternion blend weights. None if not defined for this layer, or float list, one value per vertex in the target mesh.
index of parent layer (in the context of this model’s layer list)
Single influence in a layer
vertex weights for this influence. Set to float list, containing as many values as there are vertices in a target mesh.
Full path of the influence in the scene. Required value when importing data back into skin cluster, as influences are associated by name in current implementation.
Logical index for this influence in a skin cluster. Not required for import and only provided in export as a reference.