Mll Interface¶
-
class
ngSkinTools.mllInterface.
MllInterface
(mesh=None)[source]¶ A wrapper object to call functionality from ngSkinLayer command. Most operations operate on current selection, or on target mesh that was set in advance. All edit operations are undoable.
Example usage:
from ngSkinTools.mllInterface import MllInterface mll = MllInterface() mll.setCurrentMesh('myMesh') mll.initLayers() id = mll.createLayer('initial weights') mll.setInfluenceWeights(id,0,[0.0,0.0,1.0,1.0]) ...
-
setCurrentMesh
(mesh)[source]¶ Set mesh we’ll be working on with in this wrapper. Use None to operate on current selection instead.
Parameters: mesh (str) – mesh node name/path
-
getLayersAvailable
()[source]¶ returns true if layer data is available for target mesh
Return type: bool
-
getCurrentLayer
()[source]¶ get layer that is marked as selected on MLL side; current layer is used for many things, for example, as a paint target.
Return type: int
-
getTargetInfo
()[source]¶ Returns a tuple with mesh and skin cluster node names where skinLayer data is (or can be) attached.
If current mesh (or selection) is not suitable for attaching layers, returns None
Return type: (str,str)
-
getVertCount
()[source]¶ For initialized layer info, returns number of vertices layer manager sees in the mesh. This might be different to actual vertex count in the mesh, if mesh has post-skin cluster mesh modifiers (as vertex merge or smooth)
Return type: int
-
getLayerName
(layerId)[source]¶ get layer name by ID
Parameters: layerId (int) – layer ID Return type: str
-
setLayerOpacity
(layerId, opacity)[source]¶ Set opacity for given layer. Use values between
0.0
and1.0
-
listLayers
()[source]¶ returns iterator to layer list; each element is a tuple:
(layer ID, layer name)
-
listLayerInfluences
(layerId=None, activeInfluences=True)[source]¶ returns iterator to layer influences. each element is a tuple
(influence name,influence logical index)
-
getLayerMask
(layerId)[source]¶ returns layer mask weights as float list. if mask is not initialized, returns empty list
-
setLayerMask
(layerId, weights)[source]¶ Set mask for given layer. Supply float list for weights, e.g.
[0.0,1.0,0.6]
. Supply empty list to set mask into uninitialized state.
-
getDualQuaternionWeights
(layerId)[source]¶ returns layer DQ weights as float list. if DQ weights are not painted for this layer, returns empty list
-
setDualQuaternionWeights
(layerId, weights)[source]¶ Set dual-quaternion weights for given layer. Supply float list for weights, e.g.
[0.0,1.0,0.6]
. Supply empty list to set into uninitialized state.
-
getInfluenceWeights
(layerId, influence)[source]¶ returns influence weights as float list. :param influence: either a logical influence index or named influences “mask”, “dq”
-
setInfluenceWeights
(layerId, influence, weights, undoEnabled=True)[source]¶ Set weights for given influence in a layer. Provide weights as float list; vertex count should match result of
getVertCount()
If weight values are higher than 1.0, they will be capped at 1.0.
-
snapshotLayerWeights
(layerId)[source]¶ remembers current weights and restores them after undo; redo restores weights that were there before first undo
-
setLayerWeightsBufferSize
(layerId, numInfluences)[source]¶ sets layer weights buffer size no less than X influences
-
createLayer
(name, forceEmpty=False)[source]¶ 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.
Returns: layer ID Return type: int
-
setCurrentLayer
(layerId)[source]¶ Set current layer :param int layerId: layerId earlier obtained via createLayer; can be None, will equate to having to current layer
-
setCurrentPaintTarget
(paintTarget)[source]¶ universal way to set current paint target.
Parameters: paintTarget – influence index or named paint target: mask
,dq
;
-
getCurrentPaintTarget
()[source]¶ if there is a named target selected, returns “mask” or “dq”; if no target is selected, returns
None
; otherwise returns influence index
-
getMirrorAxis
()[source]¶ Get axis that is used in the mirror operation. Can be one of: ‘x’, ‘y’, ‘z’, or ‘undefined’
-
mirrorLayerWeights
(layerId, mirrorWidth=0.0, mirrorLayerWeights=True, mirrorLayerMask=True, mirrorDualQuaternion=True, mirrorDirection=1)[source]¶ Mirror weights in a layer.
Parameters: - layerId (int) – id of a target layer
- mirrorWidth (float) – width of a seam axis
- mirrorLayerMask (bool) – should mask be mirrored?
- mirrorLayerWeights (bool) – should weights be mirrored?
- mirrorDualQuaternion (bool) – should dual quaternion blend weights be mirrored?
- mirrorDirection (int) – direction to mirror; use MirrorDirection constants for reference.
-
configureInfluencesMirrorMapping
(influencesMapping)[source]¶ Parameters: influencesMapping (dict) – a “source->destination”
-
configureVertexMirrorMapping
(mirrorAxis, vertexTransferMode)[source]¶ Parameters: - mirrorAxis – ‘X’, ‘Y’ or ‘Z’
- vertexTransferMode – ‘uvSpace’, ‘closestPoint’
-
beginDataUpdate
()[source]¶ starts batch data update mode, putting layer data into suspended state - certain internal updates are switched off, making multiple layer data changes like setLayerWeights or setLayerOpacity run faster; updates will take place when endDataUpdate is called.
begin..endDataUpdate() pairs can be stacked (e.g. methods inside begin..end can call begin..end themselves) - updates will resume only when most outer pair finishes executing.
-
batchUpdateContext
()[source]¶ a helper method to use in a “with” statement, e.g.:
with mll.batchUpdateContext(): mll.setLayerWeights(...) mll.setLayerOpacity(...)
this is the same as:
mll.beginDataUpdate() try: mll.setLayerWeights(...) mll.setLayerOpacity(...) finally: mll.endDataUpdate()
-
setWeightsReferenceMesh
(vertices, triangles)[source]¶ create an in-memory reference mesh with layer manager initialized; this mesh and layer info can be accessed later by setting target mesh to MllInterface.TARGET_REFERENCE_MESH.
Parameters: - vertices (list) – a float array, listing x y z for first vertex, then second, etc;
- triangles (list) – an int array, listing vertex IDs for first triangle, then second, etc.
-
getReferenceMeshVerts
()[source]¶ Returns: a list of floats, where each three values is a vertex XYZ for reference mesh vertices
-
getReferenceMeshTriangles
()[source]¶ Returns: a list of integers, where each three values describe mesh vert IDs that make up a triangle in the reference mesh
-
getInfluenceLimitPerVertex
()[source]¶ Returns: current value of “influence limit per vertex” setting for this mesh. 0
is returned when there’s no limit.
-
setInfluenceLimitPerVertex
(limit=None)[source]¶ Set max number of influences permitted for this mesh/skin cluster. This limit will be applied as a post-processing filter, before writting data to skin cluster.
See ngSkinTools user manual for more info on this mechanic.
Parameters: limit (int) – max number of influences allowed; provide 0
orNone
to remove the limit.
-
listInfluenceIndexes
()[source]¶ Returns: list of logical indexes for all influences in this skin cluster
-
listInfluencePaths
()[source]¶ Returns: list of influence names for all influences in this skin cluster
-
listInfluencePivots
()[source]¶ Returns coordinates for influence pivots for all influences in this skin cluster;
Returns: a list where each element is 3-float tuple, e.g. `[(1.0,2.0,3.0),(0,0,0),...]`
-
listInfluenceInfo
()[source]¶ Returns a list of influences in this skin cluster, where each influence is represented as
importExport.InfluenceInfo
.Return type: List[ngSkinTools.importExport.InfluenceInfo]
-
transferWeights
(targetMesh, influencesMapping, vertexTransferMode=None)[source]¶ Transfer weights from self.mesh onto the targetMesh. Layers are always appended to the list of existing layers; if you wish to replace old layers, delete them after the transfer (doing so before might deform the mesh and mess up vertex transfer associations).
Parameters: - targetMesh (str) – a mesh to perform transfer to
- influencesMapping (dict) – a dictionary of [source influence logical ID]->destination influence logical ID
- vertexTransferMode (str) – “closestPoint”,”uvSpace” or “vertexId”
-
layerMergeDown
(layerId)[source]¶ Merges given layer the layer below it.
Parameters: layerId (int) – layer to be merged
-
pruneWeights
(layerId=None, threshold=0.01)[source]¶ Remove weights in influence weights lower than provided threshold; upscale remaining weights, preserving transparency of the layer.
Parameters: - layerId (int) – layer to be processed; if not provided, will use currently active layer
- threshold (float) – weights below this value will be set to 0
-