ngskintool commands that can be used in pymel?

345 views
Skip to first unread message

Esther Zuidgeest

unread,
Oct 13, 2015, 8:03:42 AM10/13/15
to ngSkinTools user list
Hey Viktoras!
I was wondering if it is possible to drive ngskin tools through pymel commands?
If that were possible i could write scripts that for example import a json file onto a mesh automatically.

viktoras

unread,
Oct 13, 2015, 9:11:35 AM10/13/15
to ngski...@googlegroups.com
hi,

Well in python I have some wrappers ngSkinTools.importExport module, so it's a bit on the higher level than just pymel commands. However, with all the import changes I forgot to update API documentation for this.

For a simple transfer when a retargeting is not required (same influences as on export, same vertices as on export), this should be enough:

Example export:

   layerData = LayerData()
    layerData.loadFrom('skinnedMesh')
    exporter = JsonExporter()
    jsonContents = exporter.process(layerData)
    # string "jsonContents" can now be saved to an external file
   

Example import:

.. code-block:: python

    # assume that jsonContents is already loaded from file
    importer = JsonImporter()
    layerData = importer.process(jsonContents)
    layerData.saveTo('skinnedMesh')


--
You received this message because you are subscribed to the Google Groups "ngSkinTools user list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngskintools...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

viktoras

unread,
Oct 13, 2015, 9:31:55 AM10/13/15
to ngski...@googlegroups.com
Sorry, letter got send in the middle of the writing.

Continuing, if you want to import by mapping weights on updated mesh, influence names, etc, then there's a bit more work to be done. It's a bit a rather clunky code, I should rethink it somehow:

from ngSkinTools.influenceMapping import InfluenceMapping
from ngSkinTools.mllInterface import MllInterface
from ngSkinTools.importExport import JsonImporter

# your target mesh here
destinationMesh = "pPlane1"

# parse json and save to in-memory layer manager
layerData = JsonImporter().process("{your json document contents here}")
layerData.saveTo(MllInterface.TARGET_REFERENCE_MESH)

# build influence matching engine.
inflMapping = InfluenceMapping()
inflMapping.nameMatchRule.setPrefixes("L_", "R_")
inflMapping.nameMatchRule.ignoreNamespaces = True
inflMapping.distanceMatchRule.mirrorAxis = 0
inflMapping.distanceMatchRule.maxThreshold = 0.1
inflmapping.sourceInfluences = layerData.influences
inflmapping.destinationInfluences = MllInterface(mesh=destinationMesh).listInfluenceInfo()
# calculate source-destination influence map
inflmapping.calculate()

# transfer weights on to your target mesh with all the remapping happening
MllInterface(mesh=MllInterface.TARGET_REFERENCE_MESH).transferWeights(destinationMesh,influencesMapping=inflmapping.mapping,vertexTransferMode="closestPoint")

Esther Zuidgeest

unread,
Oct 13, 2015, 11:35:31 AM10/13/15
to ngSkinTools user list
Unfortunately im not very proficient with maya api, but the information might still be usefull to someone.

viktoras

unread,
Oct 14, 2015, 1:47:43 AM10/14/15
to ngSkinTools user list

hm.. I was pretty sure you wanted to write a python script to transfer weights automatically?:)

In that case, what would work for you instead? Something like this?

import_json_with_default_settings("weights file.json", "|my_rig|my_mesh")



On Tue, 13 Oct 2015 18:35 Esther Zuidgeest <estherz...@gmail.com> wrote:
Unfortunately im not very proficient with maya api, but the information might still be usefull to someone.

--
Reply all
Reply to author
Forward
Message has been deleted
0 new messages