Samples/Character/CharacterMarkerSet.py

Samples/Character/CharacterMarkerSet.py
1 # Copyright 2012 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Shows how to create Character Marker Set and setup markers
8 #
9 # Topic: FBCharacter
10 #
11 from pyfbsdk import *
12 import random
13 
14 def CreateAndSetupMarkerSet(pCharacter):
15  # Create marker set
16  pCharacter.CreateCharacterMarkerSet(True)
17 
18  # Get newly created marker set
19  lMarkerSet = pCharacter.PropertyList.Find("MarkerSet")[0]
20 
21  # Get property list for hips markers
22  lHipMarkers = lMarkerSet.PropertyList.Find("Hips.Markers")
23 
24  # Create markers - just to be able to show how to assign them to joint
25  lJointModel = pCharacter.GetModel(FBBodyNodeId.kFBHipsNodeId)
26  lMarkerModel_T = FBVector3d()
27 
28  if lJointModel:
29  for i in range(4):
30  lJointModel.GetVector(lMarkerModel_T, FBModelTransformationType.kModelTranslation, True)
31  lMarkerModel_T[0] = lMarkerModel_T[0]+random.randint(-30, 30)
32  lMarkerModel_T[2] = lMarkerModel_T[2]+random.randint(-30, 30)
33  lMarker = FBModelNull("Marker")
34  lMarker.SetVector(lMarkerModel_T, FBModelTransformationType.kModelTranslation, True)
35  lMarker.Show = True
36 
37  if lMarker:
38  lHipMarkers.ConnectSrc(lMarker)
39 
40  lNewGoalModel = pCharacter.GetGoalModel(FBBodyNodeId.kFBHipsNodeId)
41 
42  if lNewGoalModel:
43  lVec = FBVector3d()
44  lVec2 = FBVector3d()
45 
46  # check snap position
47  lNewGoalModel.GetVector(lVec, FBModelTransformationType.kModelTranslation, True)
48  lJointModel.GetVector(lVec2, FBModelTransformationType.kModelTranslation, True)
49 
50  print lVec, lVec2
51 
52  # check snap rotation
53  lNewGoalModel.GetVector(lVec, FBModelTransformationType.kModelRotation, True)
54  lJointModel.GetVector(lVec2, FBModelTransformationType.kModelRotation, True)
55 
56  print lVec, lVec2
57 
58  # Unassign the last added marker.
59  if lMarker:
60  lHipMarkers.DisconnectSrc( lMarker )
61 
62 
63 lCharacter = FBApplication().CurrentCharacter
64 if lCharacter:
65  CreateAndSetupMarkerSet(lCharacter)