Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.52 KB | None | 0 0
  1. from fbx import *
  2. #from samples.ImportScene.DisplayCommon import *
  3. def DisplayString(pHeader, pValue="" , pSuffix=""):
  4. lString = pHeader
  5. lString += str(pValue)
  6. lString += pSuffix
  7. print(lString)
  8.  
  9. def DisplayBool(pHeader, pValue, pSuffix=""):
  10. lString = pHeader
  11. if pValue:
  12. lString += "true"
  13. else:
  14. lString += "false"
  15. lString += pSuffix
  16. print(lString)
  17.  
  18. def DisplayInt(pHeader, pValue, pSuffix=""):
  19. lString = pHeader
  20. lString += str(pValue)
  21. lString += pSuffix
  22. print(lString)
  23.  
  24. def DisplayDouble(pHeader, pValue, pSuffix=""):
  25. DebugLog("%s%f%s" % (pHeader, pValue, pSuffix))
  26.  
  27. def Display2DVector(pHeader, pValue, pSuffix=""):
  28. DebugLog("%s%f, %f%s" % (pHeader, pValue[0], pValue[1], pSuffix))
  29.  
  30. def Display3DVector(pHeader, pValue, pSuffix=""):
  31. DebugLog("%s%f, %f, %f%s" % (pHeader, pValue[0], pValue[1], pValue[2], pSuffix))
  32.  
  33. def Display4DVector(pHeader, pValue, pSuffix=""):
  34. DebugLog("%s%f, %f, %f, %f%s" % (pHeader, pValue[0], pValue[1], pValue[2], pValue[3], pSuffix))
  35.  
  36. def DisplayColor(pHeader, pValue, pSuffix=""):
  37. DebugLog("%s%f (red), %f (green), %f (blue)%s" % (pHeader, pValue.mRed, pValue.mGreen, pValue.mBlue, pSuffix))
  38.  
  39.  
  40. #from fbx import *
  41.  
  42. #FBX_FILE_PATH_AND_NAME_AND_EXT="D:/work/FBXSDK/fbxsdk00100/Solder_Model_FBX_ASCII_2016_2017_settings_.fbx"
  43. FBX_FILE_PATH_AND_NAME_AND_EXT="D:/work/FBXSDK/for_yamakawa/SoldierProject/scenes/FBX/Solder_Model_ASCII_2016_2017_motion00200.fbx"
  44. print(u"00100. fbx_manager=========================================================== ")
  45. """
  46. fbx_manager = FbxManager.Create()
  47. print(u"00200. fbx_scene")
  48.  
  49. fbx_scene = FbxScene.Create(fbx_manager, "MyScene")
  50.  
  51. print(u"00300. fbx_importer")
  52. fbx_importer = FbxImporter.Create(fbx_manager, "")
  53. fbx_importer.Initialize(FBX_FILE_PATH_AND_NAME_AND_EXT)
  54.  
  55. fbx_importer.Destroy()
  56. print(u"end00200. fbx_scene")
  57. fbx_scene.Destroy()
  58. print(u"end 00100. fbx_manager")
  59. fbx_manager.Destroy()
  60.  
  61. """
  62.  
  63.  
  64.  
  65. # -*- coding: utf-8 -*-
  66. from maya import cmds
  67. import maya as maya
  68. import pymel.core as pm
  69. #import Debug
  70. #Debug=Debug.Debug
  71. Yen="\\"
  72. #Dir_AppDataLocal="\AppData\Local\Temp\Adobe\After Effects"
  73. #FullPass_AppDataLocal ="C:\Users"+Yen+UserNameStr+Dir_AppDataLocal+Yen+fileNameStr
  74. FileName="DustDataTextFile.txt"
  75. FullPass_DustDataTextFile_TXT= "D:\work\FBXSDK\DLLinPy\FBXSDK201701py"+Yen+"fbxproj\ImportScene"+Yen+FileName
  76. print("FullPass_DustDataTextFile_TXT="+FullPass_DustDataTextFile_TXT)
  77. def DebugLog(strData):
  78. mystr=strData
  79. print(mystr)
  80. if mystr=="":
  81. print("DebugLog (mystr ) is empty....................")
  82. else:
  83. fileReWrite(FullPass_DustDataTextFile_TXT,mystr)
  84. #fileWrite(FullPass_DustDataTextFile_TXT,mystr)
  85. #fileWrite("C:\Users\akiyaman\AppData\Roaming\Adobe\Common","ABC")
  86. #----------------ファイルを作る------------------
  87. def fileWrite(fullPass,DataStr):
  88. print("fileWrite fullPass= "+fullPass)
  89. print("fileWrite DataStr= "+DataStr)
  90. f = open(fullPass, 'w') # 書き込みモードで開く
  91. #str = "This Data is Temp Please Delete" # 書き込む文字列
  92. #f = open('text.txt', 'w') # 書き込みモードで開く
  93. #f.write(str) # 引数の文字列をファイルに書き込む
  94. f.write(DataStr) # 引数の文字列をファイルに書き込む
  95. f.close() # ファイルを閉じる
  96.  
  97. def fileReWrite(fullPass,DataStr):
  98. print("fileWrite fullPass= "+fullPass)
  99. print("fileWrite DataStr= "+DataStr)
  100. f = open(fullPass, 'a') # 追記書き込みモードで開く
  101. #str = "This Data is Temp Please Delete" # 書き込む文字列
  102. #f = open('text.txt', 'w') # 書き込みモードで開く
  103. #f.write(str) # 引数の文字列をファイルに書き込む
  104. f.write(DataStr) # 引数の文字列をファイルに書き込む
  105. f.close() # ファイルを閉じる
  106.  
  107. def fileWriteTemp(fullPass):
  108. fileWrite(fullPass,"DustDataTextFile")
  109.  
  110.  
  111. #===================class Node=========================
  112. class Node() :
  113. def __init__(self, name, parent) :
  114. self.name = name
  115. self.parent = parent
  116. self.children = None
  117. self.type = None
  118. def addChild(self, child) :
  119. if not self.children : self.children = list()
  120. self.children.append(child)
  121.  
  122. def getTypeName(fbxNode) :
  123. nodeAttr = fbxNode.GetNodeAttribute()
  124. e = nodeAttr.GetAttributeType()
  125. sType = "Unknown"
  126. if FbxNodeAttribute.eNull == e : sType = "Null"
  127. elif FbxNodeAttribute.eMarker == e : sType = "Marker"
  128. elif FbxNodeAttribute.eSkeleton == e : sType = "Skeleton"
  129. elif FbxNodeAttribute.eMesh == e : sType = "Mesh"
  130. elif FbxNodeAttribute.eNurbs == e : sType = "Nurbs"
  131. elif FbxNodeAttribute.ePatch == e : sType = "Patch"
  132. elif FbxNodeAttribute.eCamera == e : sType = "Camera"
  133. elif FbxNodeAttribute.eLight == e : sType = "Light"
  134. return sType
  135.  
  136. def getHierarchy(fbxNode, node) :
  137. num = fbxNode.GetChildCount()
  138. DebugLog("getHierarchy(fbxNode= "+str(fbxNode)+", node.name= "+str(node.name)+")")
  139. if 0 == num : return
  140. for i in range(num) :
  141. fbxChild = fbxNode.GetChild(i)
  142. nodeChild = Node(fbxChild.GetName(), node)
  143. nodeChild.type = getTypeName(fbxChild)
  144. node.addChild(nodeChild)
  145. getHierarchy(fbxChild, nodeChild)
  146.  
  147. def printHierarchy(node, padding) :
  148. print padding + node.name
  149. if not node.children : return
  150. for child in node.children : printHierarchy(child, padding+" ")
  151.  
  152. def addTreeItem(item, node) :
  153. if not node.children : return
  154. for child in node.children :
  155. i = QTreeWidgetItem()
  156. i.setText(0, "%s (%s)"%(child.name, child.type))
  157. item.addChild(i)
  158. addTreeItem(i, child)
  159. #===================class Node=========================
  160. #===================GetMesh =========================
  161. def GetMesh(node):
  162. mesh=node.GetMesh();
  163. DebugLog("mesh== "+str(mesh))
  164. if mesh ==None:
  165. DebugLog("mesh==None")
  166.  
  167.  
  168. #===================GetMesh =========================
  169. #===================GetKeyCurve=========================
  170. def GetKeyCurve(fbxImporter,pScene):
  171. print ("===========GetKeyCurve(pScene= "+str(fbxImporter)+" pScene="+str(pScene)+" )===========")
  172. print ("GetKeyCurve(pScene= "+str(fbxImporter)+" pScene="+str(pScene)+" )")
  173. #==SDKの1シーンであるFbxScene sceneをルートとして次のようにします:
  174. #==① アニメーションスタック数取得
  175. #int nbAnimStacks = pScene->GetSrcObjectCount<FbxAnimStack>()
  176.  
  177. print ("----GetKeyCurve( fbxImporter.GetAnimStackCount()= "+str(fbxImporter.GetAnimStackCount())+" -------------------")
  178. intAnimStacks=0
  179. intAnimStacks=fbxImporter.GetAnimStackCount()
  180. print ("----GetKeyCurve------ intAnimStacks= "+str(intAnimStacks)+" -------------------")
  181. print ("----GetKeyCurve( fbxImporter.GetActiveAnimStackName()= "+str(fbxImporter.GetActiveAnimStackName())+" -------------------")
  182. #int intAnimStacks = fbxImporter.GetAnimStackCount()
  183. #print ("nbAnimStacks= "+str(nbAnimStacks))
  184. #==② アニメーションスタック取得
  185. #for ( int i = 0; i < nbAnimStacks; i++ )
  186. #FbxAnimStack* lAnimStack = pScene->GetSrcObject<FbxAnimStack>(i);
  187. TakeInfoList= [0 for i in range(1)]
  188. del TakeInfoList[0]
  189. for i in range(0, intAnimStacks):
  190. DebugLog("for i="+str(i))
  191. pTakeInfo=fbxImporter.GetTakeInfo(i);
  192. DebugLog("for pTakeInfo="+str(pTakeInfo))
  193. pTakeName = pTakeInfo.mName;
  194. DebugLog("for pTakeName="+str(pTakeName))
  195. mImportName = pTakeInfo.mImportName;
  196. DebugLog("for mImportName="+str(mImportName))
  197.  
  198. #fbxAnimStack = fbxImporter.GetAnimStackCount(i)
  199. #DebugLog("for fbxAnimStack="+str(fbxAnimStack));
  200. TakeInfoList.append(pTakeInfo);
  201.  
  202. TakeInfoListLen=len(TakeInfoList)
  203. i=0
  204. DebugLog("TakeInfoListLen= "+str(TakeInfoListLen))
  205. for i in range(0, TakeInfoListLen):
  206. strTakeInfoList_i_mName = TakeInfoList[i].mName
  207. print("strTakeInfoList_i_mName= "+strTakeInfoList_i_mName);
  208. str_A="strTakeInfoList_i_mName="+strTakeInfoList_i_mName
  209. #DebugLog(str_A)
  210. TakeInfo=TakeInfoList[i]
  211. print ("===========GetAnimationLayer ===========")
  212.  
  213. #==③ アニメーションレイヤー数を取得
  214. #int nbAnimLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
  215. DebugLog("TakeInfo="+str(TakeInfo))
  216. DebugLog("TakeInfo.mName="+str(TakeInfo.mName))
  217. DebugLog("TakeInfo.mCurrentLayer="+str(TakeInfo.mCurrentLayer))
  218. if(TakeInfo.mCurrentLayer==-1):
  219. DebugLog("TakeInfo.mLayerInfoList= AnimLayer is None is This FBX is None Animation File !!!!!!!")
  220. else:
  221. DebugLog("TakeInfo.mLayerInfoList="+str(TakeInfo.mLayerInfoList))
  222.  
  223. #DebugLog("lAnimStack="+str(lAnimStack.))
  224. #AnimLayers=
  225. DisplayAnimation(pScene)
  226. """
  227. #==④ アニメーションレイヤーを取得
  228. for ( int i = 0; i < nbAnimLayers; i++ )
  229.   FbxAnimLayer* pAnimLayer = pAnimStack->GetMember<FbxAnimLayer>(l);
  230.  
  231. #==⑤ ノードが持っているアニメーションカーブをアニメーションレイヤーから取得
  232. FbxAnimCurve* pAnimCurve = pNode->LclTranslation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);
  233.  
  234. ⑥ カーブ内のキータイムを取得
  235. int nbKeyCount = pAnimCurve->KeyGetCount();
  236. for ( int i = 0; i < nbAnimLayers; i++ )
  237. FbxTime keyTime = pAnimCurve->KeyGetTime( nbKeyCount )
  238. """
  239.  
  240. #===========================引用 D:\work\FBXSDK\FBX\FBX Python SDK\2016.1.1\samples\ImportScene\DisplayAnimation.py
  241.  
  242.  
  243. from fbx import FbxAnimStack
  244.  
  245. #from fbx import FbxAnimLayer
  246. #from fbx import FbxProperty
  247. #from fbx import FbxNodeAttribute
  248.  
  249. def DisplayAnimation(pScene):
  250. DebugLog("=============================DisplayAnimation.py===DisplayAnimation(pScene = "+ str(pScene)+")==================================")
  251. DebugLog("FbxAnimStack.ClassId="+str(FbxAnimStack.ClassId))
  252. pFbxAnimStackClassID=FbxAnimStack.ClassId
  253.  
  254. DebugLog("pFbxAnimStackClassID="+str(pFbxAnimStackClassID))
  255.  
  256. pFbxCriteriaFbxAnimStackClassID=FbxCriteria.ObjectType(FbxAnimStack.ClassId)
  257. DebugLog("pFbxCriteriaFbxAnimStackClassID="+str(pFbxCriteriaFbxAnimStackClassID))
  258. #pFbxCriteriaFbxAnimStackClassID=
  259. #loopCount=pScene.GetSrcObjectCount(pFbxAnimStackClassID)
  260. intSceneAllObjCount=pScene.GetSrcObjectCount(pFbxCriteriaFbxAnimStackClassID)
  261. DebugLog("intSceneAllObjCount="+str(intSceneAllObjCount))
  262. #for i in range(pScene.GetSrcObjectCount(FbxAnimStack.ClassId)):
  263. for i in range(intSceneAllObjCount):
  264. DebugLog("DisplayAnimation i="+str(i))
  265. lAnimStack = pScene.GetSrcObject(pFbxCriteriaFbxAnimStackClassID, i)
  266. DebugLog("lAnimStack ="+str(lAnimStack))
  267.  
  268. lOutputString = "Animation Stack Name: "
  269. lOutputString += lAnimStack.GetName()
  270. lOutputString += "\n"
  271. print(lOutputString)
  272. DisplayAnimationStack(lAnimStack, pScene.GetRootNode(), True)
  273.  
  274.  
  275. """
  276. for i in range(pScene.GetSrcObjectCount(FbxAnimStack.ClassId)):
  277. lAnimStack = pScene.GetSrcObject(FbxAnimStack.ClassId, i)
  278.  
  279. lOutputString = "Animation Stack Name: "
  280. lOutputString += lAnimStack.GetName()
  281. lOutputString += "\n"
  282. print(lOutputString)
  283.  
  284. DisplayAnimationStack(lAnimStack, pScene.GetRootNode(), False)
  285. """
  286. def DisplayAnimationStack(pAnimStack, pNode, isSwitcher):
  287. DebugLog("============DisplayAnimationStack======================")
  288. pFbxCriteria_FbxAnimLayer=FbxCriteria.ObjectType(FbxAnimLayer.ClassId)
  289. DebugLog("pFbxCriteria_FbxAnimLayer="+str(pFbxCriteria_FbxAnimLayer))
  290. nbAnimLayers = pAnimStack.GetSrcObjectCount(pFbxCriteria_FbxAnimLayer)
  291.  
  292. lOutputString = "Animation stack contains "
  293. lOutputString += str(nbAnimLayers)
  294. lOutputString += " Animation Layer(s)"
  295. print(lOutputString)
  296.  
  297. for l in range(nbAnimLayers):
  298.  
  299. lAnimLayer = pAnimStack.GetSrcObject(pFbxCriteria_FbxAnimLayer, l)
  300.  
  301. lOutputString = "AnimLayer "
  302. lOutputString += str(l)
  303. print(lOutputString)
  304.  
  305. DisplayAnimationLayer(lAnimLayer, pNode, isSwitcher)
  306.  
  307. def DisplayAnimationLayer(pAnimLayer, pNode, isSwitcher=False):
  308. lOutputString = " Node Name: "
  309. lOutputString += pNode.GetName()
  310. lOutputString += "\n"
  311. print(lOutputString)
  312. #DisplayCurve
  313. #DisplayCurveKeys(pCurve)
  314. pDisplayCurveKeys=DisplayCurveKeys
  315. DebugLog(" ?????? pDisplayCurveKeys= "+str(pDisplayCurveKeys))
  316. #DebugLog(" ?????? pDisplayCurveKeys= "+str(DisplayCurveKeys))
  317. #DisplayChannels(pNode, pAnimLayer, DisplayCurveKeys, DisplayListCurveKeys, isSwitcher)
  318. #print
  319.  
  320. for lModelCount in range(pNode.GetChildCount()):
  321. DebugLog("lModelCount loop= "+str(lModelCount))
  322.  
  323. DisplayAnimationLayer(pAnimLayer, pNode.GetChild(lModelCount), isSwitcher)
  324.  
  325.  
  326. def DisplayChannels(pNode, pAnimLayer, DisplayCurve, DisplayListCurve, isSwitcher):
  327. DebugLog("DisplayChannels(pNode ="+str(pNode)+", pAnimLayer="+str(pAnimLayer)+", DisplayCurve="+str(DisplayCurve)+", DisplayListCurve="+str(DisplayListCurve)+", isSwitcher="+str(isSwitcher)+")")
  328. lAnimCurve = None
  329.  
  330. KFCURVENODE_T_X = "X"
  331. KFCURVENODE_T_Y = "Y"
  332. KFCURVENODE_T_Z = "Z"
  333.  
  334. KFCURVENODE_R_X = "X"
  335. KFCURVENODE_R_Y = "Y"
  336. KFCURVENODE_R_Z = "Z"
  337. KFCURVENODE_R_W = "W"
  338.  
  339. KFCURVENODE_S_X = "X"
  340. KFCURVENODE_S_Y = "Y"
  341. KFCURVENODE_S_Z = "Z"
  342.  
  343. # Display general curves.
  344. if not isSwitcher:
  345. lAnimCurve = pNode.LclTranslation.GetCurve(pAnimLayer, KFCURVENODE_T_X)
  346. if lAnimCurve:
  347. DebugLog(" TX")
  348. DisplayCurve(lAnimCurve)
  349. lAnimCurve = pNode.LclTranslation.GetCurve(pAnimLayer, KFCURVENODE_T_Y)
  350. if lAnimCurve:
  351. DebugLog(" TY")
  352. DisplayCurve(lAnimCurve)
  353. lAnimCurve = pNode.LclTranslation.GetCurve(pAnimLayer, KFCURVENODE_T_Z)
  354. if lAnimCurve:
  355. DebugLog(" TZ")
  356. DisplayCurve(lAnimCurve)
  357.  
  358. lAnimCurve = pNode.LclRotation.GetCurve(pAnimLayer, KFCURVENODE_R_X)
  359. if lAnimCurve:
  360. DebugLog(" RX")
  361. DisplayCurve(lAnimCurve)
  362. lAnimCurve = pNode.LclRotation.GetCurve(pAnimLayer, KFCURVENODE_R_Y)
  363. if lAnimCurve:
  364. DebugLog(" RY")
  365. DisplayCurve(lAnimCurve)
  366. lAnimCurve = pNode.LclRotation.GetCurve(pAnimLayer, KFCURVENODE_R_Z)
  367. if lAnimCurve:
  368. DebugLog(" RZ")
  369. DisplayCurve(lAnimCurve)
  370.  
  371. lAnimCurve = pNode.LclScaling.GetCurve(pAnimLayer, KFCURVENODE_S_X)
  372. if lAnimCurve:
  373. DebugLog(" SX")
  374. DisplayCurve(lAnimCurve)
  375. lAnimCurve = pNode.LclScaling.GetCurve(pAnimLayer, KFCURVENODE_S_Y)
  376. if lAnimCurve:
  377. DebugLog(" SY")
  378. DisplayCurve(lAnimCurve)
  379. lAnimCurve = pNode.LclScaling.GetCurve(pAnimLayer, KFCURVENODE_S_Z)
  380. if lAnimCurve:
  381. DebugLog(" SZ")
  382. DisplayCurve(lAnimCurve)
  383.  
  384. # Display curves specific to a light or marker.
  385. lNodeAttribute = pNode.GetNodeAttribute()
  386.  
  387. KFCURVENODE_COLOR_RED = "X"
  388. KFCURVENODE_COLOR_GREEN = "Y"
  389. KFCURVENODE_COLOR_BLUE = "Z"
  390.  
  391. if lNodeAttribute:
  392. lAnimCurve = lNodeAttribute.Color.GetCurve(pAnimLayer, KFCURVENODE_COLOR_RED)
  393. if lAnimCurve:
  394. DebugLog(" Red")
  395. DisplayCurve(lAnimCurve)
  396. lAnimCurve = lNodeAttribute.Color.GetCurve(pAnimLayer, KFCURVENODE_COLOR_GREEN)
  397. if lAnimCurve:
  398. DebugLog(" Green")
  399. DisplayCurve(lAnimCurve)
  400. lAnimCurve = lNodeAttribute.Color.GetCurve(pAnimLayer, KFCURVENODE_COLOR_BLUE)
  401. if lAnimCurve:
  402. DebugLog(" Blue")
  403. DisplayCurve(lAnimCurve)
  404.  
  405. # Display curves specific to a light.
  406. light = pNode.GetLight()
  407. if light:
  408. lAnimCurve = light.Intensity.GetCurve(pAnimLayer)
  409. if lAnimCurve:
  410. DebugLog(" Intensity")
  411. DisplayCurve(lAnimCurve)
  412.  
  413. lAnimCurve = light.OuterAngle.GetCurve(pAnimLayer)
  414. if lAnimCurve:
  415. DebugLog(" Cone Angle")
  416. DisplayCurve(lAnimCurve)
  417.  
  418. lAnimCurve = light.Fog.GetCurve(pAnimLayer)
  419. if lAnimCurve:
  420. DebugLog(" Fog")
  421. DisplayCurve(lAnimCurve)
  422.  
  423. # Display curves specific to a camera.
  424. camera = pNode.GetCamera()
  425. if camera:
  426. lAnimCurve = camera.FieldOfView.GetCurve(pAnimLayer)
  427. if lAnimCurve:
  428. DebugLog(" Field of View")
  429. DisplayCurve(lAnimCurve)
  430.  
  431. lAnimCurve = camera.FieldOfViewX.GetCurve(pAnimLayer)
  432. if lAnimCurve:
  433. DebugLog(" Field of View X")
  434. DisplayCurve(lAnimCurve)
  435.  
  436. lAnimCurve = camera.FieldOfViewY.GetCurve(pAnimLayer)
  437. if lAnimCurve:
  438. DebugLog(" Field of View Y")
  439. DisplayCurve(lAnimCurve)
  440.  
  441. lAnimCurve = camera.OpticalCenterX.GetCurve(pAnimLayer)
  442. if lAnimCurve:
  443. DebugLog(" Optical Center X")
  444. DisplayCurve(lAnimCurve)
  445.  
  446. lAnimCurve = camera.OpticalCenterY.GetCurve(pAnimLayer)
  447. if lAnimCurve:
  448. DebugLog(" Optical Center Y")
  449. DisplayCurve(lAnimCurve)
  450.  
  451. lAnimCurve = camera.Roll.GetCurve(pAnimLayer)
  452. if lAnimCurve:
  453. DebugLog(" Roll")
  454. DisplayCurve(lAnimCurve)
  455. """
  456. # Display curves specific to a geometry.
  457. if lNodeAttribute.GetAttributeType() == FbxNodeAttribute.eMesh or \
  458. lNodeAttribute.GetAttributeType() == FbxNodeAttribute.eNurbs or \
  459. lNodeAttribute.GetAttributeType() == FbxNodeAttribute.ePatch:
  460. lGeometry = lNodeAttribute
  461.  
  462. lBlendShapeDeformerCount = lGeometry.GetDeformerCount(FbxDeformer.eBlendShape)
  463. for lBlendShapeIndex in range(lBlendShapeDeformerCount):
  464. lBlendShape = lGeometry.GetDeformer(lBlendShapeIndex, FbxDeformer.eBlendShape)
  465. lBlendShapeChannelCount = lBlendShape.GetBlendShapeChannelCount()
  466. for lChannelIndex in range(lBlendShapeChannelCount):
  467. lChannel = lBlendShape.GetBlendShapeChannel(lChannelIndex)
  468. lChannelName = lChannel.GetName()
  469. lAnimCurve = lGeometry.GetShapeChannel(lBlendShapeIndex, lChannelIndex, pAnimLayer, True)
  470. if lAnimCurve:
  471. DebugLog(" Shape %s" % lChannelName)
  472. DisplayCurve(lAnimCurve)
  473. """
  474. # Display curves specific to properties
  475. lProperty = pNode.GetFirstProperty()
  476.  
  477. GoWhileLoop=lProperty.IsValid()
  478. DebugLog("lProperty.IsValid()==GoWhileLoop=="+str(GoWhileLoop))
  479. while GoWhileLoop:
  480. #DebugLog("GO While Loop")
  481. #"""
  482. if lProperty.GetFlag(FbxPropertyFlags.eUserDefined):
  483. lFbxFCurveNodeName = lProperty.GetName()
  484. lCurveNode = lProperty.GetCurveNode(pAnimLayer)
  485.  
  486. if not lCurveNode:
  487. lProperty = pNode.GetNextProperty(lProperty)
  488. continue
  489.  
  490. lDataType = lProperty.GetPropertyDataType()
  491. if lDataType.GetType() == eFbxBool or lDataType.GetType() == eFbxDouble or lDataType.GetType() == eFbxFloat or lDataType.GetType() == eFbxInt:
  492. lMessage = " Property "
  493. lMessage += lProperty.GetName()
  494. if lProperty.GetLabel().GetLen() > 0:
  495. lMessage += " (Label: "
  496. lMessage += lProperty.GetLabel()
  497. lMessage += ")"
  498.  
  499. DisplayString(lMessage)
  500.  
  501. for c in range(lCurveNode.GetCurveCount(0)):
  502. lAnimCurve = lCurveNode.GetCurve(0, c)
  503. if lAnimCurve:
  504. DisplayCurve(lAnimCurve)
  505. elif lDataType.GetType() == eFbxDouble3 or lDataType.GetType() == eFbxDouble4 or lDataType.Is(FbxColor3DT) or lDataType.Is(FbxColor4DT):
  506. if lDataType.Is(FbxColor3DT) or lDataType.Is(FbxColor4DT):
  507. lComponentName1 = KFCURVENODE_COLOR_RED
  508. lComponentName2 = KFCURVENODE_COLOR_GREEN
  509. lComponentName3 = KFCURVENODE_COLOR_BLUE
  510. else:
  511. lComponentName1 = "X"
  512. lComponentName2 = "Y"
  513. lComponentName3 = "Z"
  514.  
  515. lMessage = " Property "
  516. lMessage += lProperty.GetName()
  517. if lProperty.GetLabel().GetLen() > 0:
  518. lMessage += " (Label: "
  519. lMessage += lProperty.GetLabel()
  520. lMessage += ")"
  521. DisplayString(lMessage)
  522.  
  523. for c in range(lCurveNode.GetCurveCount(0)):
  524. lAnimCurve = lCurveNode.GetCurve(0, c)
  525. if lAnimCurve:
  526. DisplayString(" Component ", lComponentName1)
  527. DisplayCurve(lAnimCurve)
  528.  
  529. for c in range(lCurveNode.GetCurveCount(1)):
  530. lAnimCurve = lCurveNode.GetCurve(1, c)
  531. if lAnimCurve:
  532. DisplayString(" Component ", lComponentName2)
  533. DisplayCurve(lAnimCurve)
  534.  
  535. for c in range(lCurveNode.GetCurveCount(2)):
  536. lAnimCurve = lCurveNode.GetCurve(2, c)
  537. if lAnimCurve:
  538. DisplayString(" Component ", lComponentName3)
  539. DisplayCurve(lAnimCurve)
  540. elif lDataType.GetType() == eFbxEnum:
  541. lMessage = " Property "
  542. lMessage += lProperty.GetName()
  543. if lProperty.GetLabel().GetLen() > 0:
  544. lMessage += " (Label: "
  545. lMessage += lProperty.GetLabel()
  546. lMessage += ")"
  547. DisplayString(lMessage)
  548.  
  549. for c in range(lCurveNode.GetCurveCount(0)):
  550. lAnimCurve = lCurveNode.GetCurve(0, c)
  551. if lAnimCurve:
  552. DisplayListCurve(lAnimCurve, lProperty)
  553.  
  554. #"""
  555. lProperty = pNode.GetNextProperty(lProperty)
  556. GoWhileLoop=lProperty.IsValid()
  557. #while Loop END Indent.
  558.  
  559. def InterpolationFlagToIndex(flags):
  560. #if (flags&KFCURVE_INTERPOLATION_CONSTANT)==KFCURVE_INTERPOLATION_CONSTANT:
  561. # return 1
  562. #if (flags&KFCURVE_INTERPOLATION_LINEAR)==KFCURVE_INTERPOLATION_LINEAR:
  563. # return 2
  564. #if (flags&KFCURVE_INTERPOLATION_CUBIC)==KFCURVE_INTERPOLATION_CUBIC:
  565. # return 3
  566. return 0
  567.  
  568. def ConstantmodeFlagToIndex(flags):
  569. #if (flags&KFCURVE_CONSTANT_STANDARD)==KFCURVE_CONSTANT_STANDARD:
  570. # return 1
  571. #if (flags&KFCURVE_CONSTANT_NEXT)==KFCURVE_CONSTANT_NEXT:
  572. # return 2
  573. return 0
  574.  
  575. def TangeantmodeFlagToIndex(flags):
  576. #if (flags&KFCURVE_TANGEANT_AUTO) == KFCURVE_TANGEANT_AUTO:
  577. # return 1
  578. #if (flags&KFCURVE_TANGEANT_AUTO_BREAK)==KFCURVE_TANGEANT_AUTO_BREAK:
  579. # return 2
  580. #if (flags&KFCURVE_TANGEANT_TCB) == KFCURVE_TANGEANT_TCB:
  581. # return 3
  582. #if (flags&KFCURVE_TANGEANT_USER) == KFCURVE_TANGEANT_USER:
  583. # return 4
  584. #if (flags&KFCURVE_GENERIC_BREAK) == KFCURVE_GENERIC_BREAK:
  585. # return 5
  586. #if (flags&KFCURVE_TANGEANT_BREAK) ==KFCURVE_TANGEANT_BREAK:
  587. # return 6
  588. return 0
  589.  
  590. def TangeantweightFlagToIndex(flags):
  591. #if (flags&KFCURVE_WEIGHTED_NONE) == KFCURVE_WEIGHTED_NONE:
  592. # return 1
  593. #if (flags&KFCURVE_WEIGHTED_RIGHT) == KFCURVE_WEIGHTED_RIGHT:
  594. # return 2
  595. #if (flags&KFCURVE_WEIGHTED_NEXT_LEFT) == KFCURVE_WEIGHTED_NEXT_LEFT:
  596. # return 3
  597. return 0
  598.  
  599. def TangeantVelocityFlagToIndex(flags):
  600. #if (flags&KFCURVE_VELOCITY_NONE) == KFCURVE_VELOCITY_NONE:
  601. # return 1
  602. #if (flags&KFCURVE_VELOCITY_RIGHT) == KFCURVE_VELOCITY_RIGHT:
  603. # return 2
  604. #if (flags&KFCURVE_VELOCITY_NEXT_LEFT) == KFCURVE_VELOCITY_NEXT_LEFT:
  605. # return 3
  606. return 0
  607.  
  608. def DisplayCurveKeys(pCurve):
  609. interpolation = [ "?", "constant", "linear", "cubic"]
  610. constantMode = [ "?", "Standard", "Next" ]
  611. cubicMode = [ "?", "Auto", "Auto break", "Tcb", "User", "Break", "User break" ]
  612. tangentWVMode = [ "?", "None", "Right", "Next left" ]
  613.  
  614. lKeyCount = pCurve.KeyGetCount()
  615.  
  616. for lCount in range(lKeyCount):
  617. lTimeString = ""
  618. lKeyValue = pCurve.KeyGetValue(lCount)
  619. lKeyTime = pCurve.KeyGetTime(lCount)
  620. lKeyTimeStr=lKeyTime.GetTimeString(lTimeString)
  621. #FbxProperty
  622. #lKeyValueStr=pProperty.GetEnumValue(lKeyValue)
  623. lOutputString = " Key Time: "
  624. #lOutputString += lKeyTime.GetTimeString(lTimeString)
  625. lOutputString += str(KeyTimeStr)
  626. lOutputString += ".... Key Value: "
  627. lOutputString += str(lKeyValueStr)
  628. lOutputString += " [ "
  629. lOutputString += interpolation[ InterpolationFlagToIndex(pCurve.KeyGetInterpolation(lCount)) ]
  630. #if (pCurve.KeyGetInterpolation(lCount)&KFCURVE_INTERPOLATION_CONSTANT) == KFCURVE_INTERPOLATION_CONSTANT:
  631. # lOutputString += " | "
  632. # lOutputString += constantMode[ ConstantmodeFlagToIndex(pCurve.KeyGetConstantMode(lCount)) ]
  633. #elif (pCurve.KeyGetInterpolation(lCount)&KFCURVE_INTERPOLATION_CUBIC) == KFCURVE_INTERPOLATION_CUBIC:
  634. # lOutputString += " | "
  635. # lOutputString += cubicMode[ TangeantmodeFlagToIndex(pCurve.KeyGetTangeantMode(lCount)) ]
  636. # lOutputString += " | "
  637. # lOutputString += tangentWVMode[ TangeantweightFlagToIndex(pCurve.KeyGetTangeantWeightMode(lCount)) ]
  638. # lOutputString += " | "
  639. # lOutputString += tangentWVMode[ TangeantVelocityFlagToIndex(pCurve.KeyGetTangeantVelocityMode(lCount)) ]
  640.  
  641. lOutputString += " ]"
  642. print(lOutputString)
  643. def DisplayCurveKeys_pProperty(pCurve,pProperty):
  644. interpolation = [ "?", "constant", "linear", "cubic"]
  645. constantMode = [ "?", "Standard", "Next" ]
  646. cubicMode = [ "?", "Auto", "Auto break", "Tcb", "User", "Break", "User break" ]
  647. tangentWVMode = [ "?", "None", "Right", "Next left" ]
  648.  
  649. lKeyCount = pCurve.KeyGetCount()
  650.  
  651. for lCount in range(lKeyCount):
  652. lTimeString = ""
  653. lKeyValue = pCurve.KeyGetValue(lCount)
  654. lKeyTime = pCurve.KeyGetTime(lCount)
  655. lKeyTimeStr=lKeyTime.GetTimeString(lTimeString)
  656. #FbxProperty
  657. lKeyValueStr=pProperty.GetEnumValue(lKeyValue)
  658. lOutputString = " Key Time: "
  659. #lOutputString += lKeyTime.GetTimeString(lTimeString)
  660. lOutputString += str(KeyTimeStr)
  661. lOutputString += ".... Key Value: "
  662. lOutputString += str(lKeyValueStr)
  663. lOutputString += " [ "
  664. lOutputString += interpolation[ InterpolationFlagToIndex(pCurve.KeyGetInterpolation(lCount)) ]
  665. #if (pCurve.KeyGetInterpolation(lCount)&KFCURVE_INTERPOLATION_CONSTANT) == KFCURVE_INTERPOLATION_CONSTANT:
  666. # lOutputString += " | "
  667. # lOutputString += constantMode[ ConstantmodeFlagToIndex(pCurve.KeyGetConstantMode(lCount)) ]
  668. #elif (pCurve.KeyGetInterpolation(lCount)&KFCURVE_INTERPOLATION_CUBIC) == KFCURVE_INTERPOLATION_CUBIC:
  669. # lOutputString += " | "
  670. # lOutputString += cubicMode[ TangeantmodeFlagToIndex(pCurve.KeyGetTangeantMode(lCount)) ]
  671. # lOutputString += " | "
  672. # lOutputString += tangentWVMode[ TangeantweightFlagToIndex(pCurve.KeyGetTangeantWeightMode(lCount)) ]
  673. # lOutputString += " | "
  674. # lOutputString += tangentWVMode[ TangeantVelocityFlagToIndex(pCurve.KeyGetTangeantVelocityMode(lCount)) ]
  675.  
  676. lOutputString += " ]"
  677. print(lOutputString)
  678.  
  679. def DisplayCurveDefault(pCurve):
  680. lOutputString = " Default Value: "
  681. lOutputString += pCurve.GetValue()
  682.  
  683. print(lOutputString)
  684.  
  685. def DisplayListCurveKeys(pCurve, pProperty):
  686. print ("===606=============DisplayListCurveKeys(pCurve"+str(pCurve)+", pProperty="+str(pProperty)+")=================")
  687. lKeyCount = pCurve.KeyGetCount()
  688. print ("===608=============lKeyCount="+str(lKeyCount)+"=================")
  689.  
  690. for lCount in range(lKeyCount):
  691. lOutputString = " Key Time: "
  692. lKeyValue = int(pCurve.KeyGetValue(lCount))
  693. lKeyTime = pCurve.KeyGetTime(lCount)
  694. #lKeyTimeString
  695. #lKeyValue = static_cast<int>(pCurve.KeyGetValue(lCount))
  696. lOutputString = " Key Time: "
  697. #lOutputString += str(lKeyTime.GetTimeString(lTimeString))
  698. lOutputString += str(lKeyTime)
  699. lOutputString += ".... Key Value: "
  700. lOutputString +=str( lKeyValue)
  701. lOutputString += " ("
  702. lOutputString += str(pProperty.GetEnumValue(lKeyValue))
  703. lOutputString += ")"
  704.  
  705. print(lOutputString)
  706.  
  707. def DisplayListCurveDefault(pCurve, pProperty):
  708. DisplayCurveDefault(pCurve)
  709.  
  710. #===========================引用 D:\work\FBXSDK\FBX\FBX Python SDK\2016.1.1\samples\ImportScene\DisplayAnimation.py
  711.  
  712. #===================GetKeyCurve=========================
  713. class FBXData() :
  714. def DebugLog(strData):
  715. mystr=strData
  716. print(mystr)
  717. def FBXData(self):
  718. print ("==========================FBXData()=========================================")
  719.  
  720. def loadFile(self, filename) :
  721. self.filename = filename
  722. self.root = None
  723. self.load()
  724. def load(self) :
  725. print ("loading ... self.filename= "+self.filename)
  726. #print "loading : %s"%self.filename
  727. manager = FbxManager.Create()
  728. ios = FbxIOSettings.Create(manager, IOSROOT)
  729. manager.SetIOSettings(ios)
  730. importer = FbxImporter.Create(manager, "")
  731. fbxImportSuccesBool=importer.Initialize(self.filename, -1, manager.GetIOSettings())
  732. DebugLog("fbxImportSuccesBool="+str(fbxImportSuccesBool))
  733. if not fbxImportSuccesBool:
  734. print ("==============Failed to load file.=============="+self.filename)
  735. return
  736. scene = FbxScene.Create(manager, "MyScene")
  737. importer.Import(scene)
  738. #importer.Initialize()
  739.  
  740. fbxRoot = scene.GetRootNode()
  741. self.root = Node(fbxRoot.GetName(), None)
  742. getHierarchy(fbxRoot, self.root)
  743. #GetMesh(self.root)
  744. GetKeyCurve(importer,scene)
  745.  
  746.  
  747. print ("==============Succeeded to load file.========="+self.filename)
  748.  
  749.  
  750. print ("==============Destroy All=========")
  751. importer.Destroy()
  752. manager.Destroy()
  753. #//////////////////////////////////////////////////////////////////////////////////////////////////
  754. #//////////////////////////////////// Class Unit Test /////////////////////////////////////////////
  755. #//////////////////////////////////////////////////////////////////////////////////////////////////
  756. def getClassName(self):
  757. DebugLog( u"className= " + self.__class__.__name__)
  758. return self.__class__.__name__
  759.  
  760. Instance = FBXData() # Class export instance.
  761. DebugLog(" FBXData Class __name__="+__name__)
  762. if(__name__ == Instance.getClassName()):
  763. fileWrite(FullPass_DustDataTextFile_TXT,"none...")
  764. DebugLog (u"__name__==self.__class__.__name__ Same!! File Test")
  765. DebugLog (u"=============Simple Single Class Unit Test Start==========")
  766. Instance.FBXData() #Call Method
  767. Instance.loadFile("Solder_Model_FBX_ASCII_2016_2017_settings_.fbx")
  768. elif(__name__ == "fbxsdk00450class"):
  769. DebugLog (u"=============Simple Single Class Unit Test Start=====fbxsdk00300class=====")
  770. Instance.FBXData() #Call Method
  771. Instance.loadFile(FBX_FILE_PATH_AND_NAME_AND_EXT)
  772. else:
  773. DebugLog (u"__name__!=self.__class__.__name__ Othor File Import")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement