Jump to content
  • Advertisement
Sign in to follow this  
StephenMiddleton

3ds max skin problem

This topic is 2635 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, not sure if this is the right section for this topic, but here goes:

I'm trying to write a script to transfer a skinned mesh from one CAT skeleton to an identical standard bone skeleton in 3ds Max. Everything is working fine for most meshes, however, I have one that is causing a problem:

After removing all of the CAT bones from the modifier, then adding the standard bones to it, everything is fine. Then, after reapplying the original weights, the mesh pops off with translation to the right of the skeleton. The weights are fine, but it's like the bind happened with the mesh in the wrong spot. When I disable the modifier, the mesh pops back to it's original position.

I'm new to Max, and this doesn't make a lot of sense to me. I've tried recreating a new skin modifier, and that works, but I have some other problems with the skinops interface doing it that way (skinops.getnumbervertices seems to return 0 always).

Anyone have any ideas?

Here's the code:



fn transferSkinToNewSkeleton skinnedObj: targetSuffix: =
(
if ((isKindOf skinnedObj Node) and
(classof targetSuffix == string) and
(hasSkinModifier skinnedObj == true)) then
(
prepareMaxForSkinOps skinnedObj
local s = skinnedObj.skin
local skinWeights = #(#())
local numBones = skinOps.getNumberBones s
local numVerts = skinOps.getNumberVertices s

-- build an indexed list of all bones currently in skin
-- include the skin weights for vertices in the same order
for vertID = 1 to numVerts do
(
local vertWeighting = #()
local numWeights = skinOps.getVertexWeightCount s vertID
--print ("vertex: " + (vertID as string) + ", numWeights: " + (numWeights as string))
for weightID = 1 to numWeights do
(
vertWeighting[weightID] = smVertexWeight()

local boneID = skinOps.getVertexWeightBoneID s vertID weightID
local boneName = skinOps.getBoneName s boneID 0
vertWeighting[weightID].boneNode = getNodeByName boneName
vertWeighting[weightID].weight = skinOps.getVertexWeight s vertID weightID
--print ("weight #" + (weightID as string) + ", bone: " + vertWeighting[weightID].boneNode.name + ", weight: " + (vertWeighting[weightID].weight as string))
)

skinWeights[vertID] = vertWeighting
)

-- get list of all bones
-- (NOTE: this should eventually be using something more sophisticated than searching by name)
local boneList = for boneID = 1 to numBones collect skinOps.getBoneName s boneID 0

-- remove the bones
print "removing all bones..."
for boneID = 1 to numBones do skinOps.removeBone s 1

-- I added this section to try to rebuild the skin modifier -- has problems because (skinOps.getNumberVertices s) returns 0, and we get an error when trying to reassign weights
maxOps.collapseNode skinnedObj true
addModifier skinnedObj (Skin())
s = skinnedObj.skin
prepareMaxForSkinOps skinnedObj

-- readd new bones
for boneID = 1 to boneList.count do
(
local targetBoneName = (boneList[boneID] + targetSuffix)
print ("adding bone: " + targetBoneName + " (boneID=" + (boneID as string) + ")")
local boneNode = getNodeByName targetBoneName -- hopefully we can find a corresponding bone!
skinOps.addBone s boneNode 1
)

-- s.weightAllVertices = true

print ("numVerts = " + ((skinOps.getNumberVertices s) as string))

-- rebuild skin modifier with new bones
for vertID = 1 to numVerts do
(
local numWeights = skinWeights[vertID].count
for weightID = 1 to numWeights do
(
local boneID = findItem boneList skinWeights[vertID][weightID].boneNode.name
skinOps.setVertexWeights s vertID boneID skinWeights[vertID][weightID].weight
)
)
)
)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!