|
| 1 | +from fbx import * |
| 2 | +import sys |
| 3 | + |
| 4 | +def InitializeSdkObjects(): |
| 5 | + # The first thing to do is to create the FBX SDK manager which is the |
| 6 | + # object allocator for almost all the classes in the SDK. |
| 7 | + lSdkManager = FbxManager.Create() |
| 8 | + if not lSdkManager: |
| 9 | + sys.exit(0) |
| 10 | + |
| 11 | + # Create an IOSettings object |
| 12 | + ios = FbxIOSettings.Create(lSdkManager, IOSROOT) |
| 13 | + lSdkManager.SetIOSettings(ios) |
| 14 | + |
| 15 | + # Create the entity that will hold the scene. |
| 16 | + lScene = FbxScene.Create(lSdkManager, "") |
| 17 | + |
| 18 | + return (lSdkManager, lScene) |
| 19 | + |
| 20 | +def SaveScene(pSdkManager, pScene, pFilename, pFileFormat = -1, pEmbedMedia = False): |
| 21 | + lExporter = FbxExporter.Create(pSdkManager, "") |
| 22 | + if pFileFormat < 0 or pFileFormat >= pSdkManager.GetIOPluginRegistry().GetWriterFormatCount(): |
| 23 | + pFileFormat = pSdkManager.GetIOPluginRegistry().GetNativeWriterFormat() |
| 24 | + if not pEmbedMedia: |
| 25 | + lFormatCount = pSdkManager.GetIOPluginRegistry().GetWriterFormatCount() |
| 26 | + for lFormatIndex in range(lFormatCount): |
| 27 | + if pSdkManager.GetIOPluginRegistry().WriterIsFBX(lFormatIndex): |
| 28 | + lDesc = pSdkManager.GetIOPluginRegistry().GetWriterFormatDescription(lFormatIndex) |
| 29 | + if "ascii" in lDesc: |
| 30 | + pFileFormat = lFormatIndex |
| 31 | + break |
| 32 | + |
| 33 | + if not pSdkManager.GetIOSettings(): |
| 34 | + ios = FbxIOSettings.Create(pSdkManager, IOSROOT) |
| 35 | + pSdkManager.SetIOSettings(ios) |
| 36 | + |
| 37 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_MATERIAL, True) |
| 38 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_TEXTURE, True) |
| 39 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_EMBEDDED, pEmbedMedia) |
| 40 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_SHAPE, True) |
| 41 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_GOBO, True) |
| 42 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_ANIMATION, True) |
| 43 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, True) |
| 44 | + |
| 45 | + result = lExporter.Initialize(pFilename, pFileFormat, pSdkManager.GetIOSettings()) |
| 46 | + if result == True: |
| 47 | + result = lExporter.Export(pScene) |
| 48 | + |
| 49 | + lExporter.Destroy() |
| 50 | + return result |
| 51 | + |
| 52 | +def LoadScene(pSdkManager, pScene, pFileName): |
| 53 | + lImporter = FbxImporter.Create(pSdkManager, "") |
| 54 | + result = lImporter.Initialize(pFileName, -1, pSdkManager.GetIOSettings()) |
| 55 | + if not result: |
| 56 | + return False |
| 57 | + |
| 58 | + if lImporter.IsFBX(): |
| 59 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_MATERIAL, True) |
| 60 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_TEXTURE, True) |
| 61 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_EMBEDDED, True) |
| 62 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_SHAPE, True) |
| 63 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_GOBO, True) |
| 64 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_ANIMATION, True) |
| 65 | + pSdkManager.GetIOSettings().SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, True) |
| 66 | + |
| 67 | + result = lImporter.Import(pScene) |
| 68 | + lImporter.Destroy() |
| 69 | + return result |
0 commit comments