Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XSI-to-Maya cometSaveWeights export (snippet)
"""
Alan Fregtman's SaveCometWeights for XSI -- http://darkvertex.com/
(snippet edition -- v1.1)
** USAGE:
1. Select one or more enveloped meshes and run this from the script editor.
2. You will have the weights saved as "WEIGHTS__objectname.txt" in Comet's SaveWeights format
under the active XSI project directory.
3. In Maya, use Michael Comet's SaveWeights tool (melscript) to import the weights file.
** NOTES:
You can find Comet's script in this zip of his tools:
http://www.comet-cartoons.com/MELfiles/cometScripts.zip
but if you use Maya 2011, you'll need this specific version of Comet's SaveWeights script:
http://s3.darkvertex.com/hlinked/4forums/cometSaveWeights_Maya2011.zip
** CometSaveWeights FORMAT spec:
The file looks like this:
[WEIGHTS]
[COMPONENT]
objName.vtx[vertexID]
worldPosX worldPosY worldPosZ
localPosX localPosY localPosZ
[END-WEIGHTS]
[JOINTS]
jointName1
jointName2
jointName3
...
[END-JOINTS]
// Comments look like this.
"""
from time import clock
from win32com.client import constants as c
xsi = Application
lm = xsi.LogMessage
start_time = clock()
for obj in list(xsi.Selection):
lm( obj.FullName )
env = obj.Envelopes(0)
deformer = env.Deformers
weights = env.GetWeights2()
points = obj.ActivePrimitive.Geometry.Points
oTrans = obj.Kinematics.Local.Transform
filepath = XSIUtils.BuildPath(xsi.ActiveProject2.Path, "WEIGHTS__%s.txt" % obj.Name)
cometFile = open(filepath, 'w+')
cometFile.write("// [WEIGHTS]\n")
oPBar = XSIUIToolkit.ProgressBar
oPBar.Maximum = points.Count
oPBar.Step = 1
oPBar.CancelEnabled = True
oPBar.Caption = "SAVING ENVELOPE/SKIN WEIGHTS:"
oPBar.Visible = True
more = ""
for i in xrange(0, points.Count):
oPBar.StatusText = "Vertex #%s" % i
if oPBar.CancelPressed:
break
more += "[COMPONENT]\n%s.vtx[%s]\n" % (obj.Name, i)
oLocalPos = points(i).Position
more += "%s %s %s\n" % (oLocalPos.X, oLocalPos.Y, oLocalPos.Z)
oGlobalPos = XSIMath.MapObjectPositionToWorldSpace(oTrans, oLocalPos)
more += "%s %s %s\n" % (oGlobalPos.X, oGlobalPos.Y, oGlobalPos.Z)
for d in xrange(0, deformer.Count):
# In XSI weights are 0 to 100, but in Maya, weights go from 0 to 1, so...
mayaWeight = ( float(weights(i)[d]) / 100 )
if mayaWeight > 0.0:
more += "%s %s " % (deformer(d).Name, mayaWeight)
more += "\n"
cometFile.write(more)
more = ""
oPBar.Increment()
oPBar.Visible = False
cometFile.write( "[END-WEIGHTS]\n[JOINTS]\n%s\n[END-JOINTS]\n\n" % "\n".join([item.Name for item in deformer]) )
timeTaken = clock() - start_time
comment = "Exported %s points in %s seconds. (Speed: ~%s points/sec)" % (points.Count, round(timeTaken, 3), round((float(points.Count) / timeTaken), 3))
lm(comment)
cometFile.write("// "+comment+"\n")
cometFile.close() # Done! :D
# Look out on http://darkvertex.com/ for the pretty plugin edition someday, maybe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.