This sample is a part of the CharacterMarkerSetFromActor.py script. The full script is located in
def GetOrCreateSkeletonNode(pIndex,pPrefix,pCreateIfNotExisting=True):
if IsValidSkeletonNodeId(pIndex) == False:
return None
lName = GetFBSkeletonNodeIdName(pIndex,pPrefix)
lSkeletonNode = FBFindObjectByFullName('Model::'+lName)
if lSkeletonNode == None and pCreateIfNotExisting:
if FBSkeletonNodeId.values[pIndex] != FBSkeletonNodeId.kFBSkeletonReferenceIndex:
lSkeletonNode = FBModelSkeleton(lName)
else:
lSkeletonNode = FBModelNull(lName)
lSkeletonNode.Show = True
return lSkeletonNode
def CreateSkeletonForActor(pActor,pPrefix):
lState = pActor.GetCurrentSkeletonState(True)
lGX = FBMatrix()
for enum in FBSkeletonNodeId.values:
if IsValidSkeletonNodeId(enum):
lState.GetNodeMatrix(FBSkeletonNodeId.values[enum],lGX)
lSkeletonNode = GetOrCreateSkeletonNode(enum,pPrefix)
lParentId = GetFBSkeletonNodeIdParentId(enum)
lParentSkeletonNode = GetOrCreateSkeletonNode(lParentId,pPrefix)
lSkeletonNode.SetMatrix(lGX)
if lParentSkeletonNode != None:
lSkeletonNode.Parent = lParentSkeletonNode
def MapSkeletonBone(pCharacter, pIndex, pPrefix):
lModel = GetOrCreateSkeletonNode(pIndex,pPrefix)
if lModel != None and pCharacter != None:
lMappingPropName = lSkeletonNodeCharacterizationMapping[FBSkeletonNodeId.values[pIndex]]
lMappingProp = pCharacter.PropertyList.Find(lMappingPropName,False)
if lMappingProp != None:
lMappingProp.ConnectSrc(lModel)
else:
print 'Could not characterize: ' + lModel.Name + '; MappingName: ' + lMappingPropName
def CharacterizeActorSkeleton(pPrefix):
lCharacter = FBCharacter(pPrefix+'Character')
for enum in FBSkeletonNodeId.values:
if IsValidSkeletonNodeId(enum):
MapSkeletonBone(lCharacter, enum, pPrefix)
lCharacter.SetCharacterizeOn(True)
FBSystem().Scene.Evaluate()
return lCharacter
def ConvertActorToCharacter(pActor, pPrefix):
# create the skeleton from the actor
CreateSkeletonForActor(pActor,pPrefix)
# Set up characterization and lock the character
lChar = CharacterizeActorSkeleton(pPrefix)