def fbxImport(fbx, scale=1): fbx_factory = PyFbxFactory() # build the path for the fbx file # configure the factory fbx_factory.ImportUI.bCreatePhysicsAsset = False fbx_factory.ImportUI.bImportMaterials = False fbx_factory.ImportUI.bImportTextures = False fbx_factory.ImportUI.bImportAnimations = False # scale the mesh (the Kaiju is 30 meters high !) fbx_factory.ImportUI.SkeletalMeshImportData.ImportUniformScale = scale # import the mesh slicer_mesh = fbx_factory.factory_import_object(fbx, '/Game/Kaiju/Slicer')
def CreateTask_Anim_Armature_ArmatureAction003(): ################[ Import Armature as Action type ]################ print( '================[ New import task : Armature as Action type ]================' ) FilePath = os.path.join( r'D:\Repos\Piroots2\Other Files\ExportedFbx\SkeletalMesh\Armature\Anim\Anim_Armature_ArmatureAction003.fbx' ) AdditionalParameterLoc = os.path.join( r'D:\Repos\Piroots2\Other Files\ExportedFbx\SkeletalMesh\Armature\Anim\SK_Armature_AdditionalParameter.ini' ) AssetImportPath = (os.path.join(unrealImportLocation, r'Anim').replace('\\', '/')).rstrip('/') SkeletonLocation = os.path.join( unrealImportLocation, r'SK_Armature_Skeleton.SK_Armature_Skeleton').replace('\\', '/') OriginSkeleton = ue.find_asset(SkeletonLocation) task = PyFbxFactory() if OriginSkeleton: task.ImportUI.Skeleton = OriginSkeleton else: ImportFailList.append('Skeleton "' + SkeletonLocation + '" Not found for "Armature" asset ') return task.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_Animation task.ImportUI.bImportMaterials = False task.ImportUI.bImportTextures = False task.ImportUI.bImportAnimations = True task.ImportUI.bImportMesh = False task.ImportUI.bCreatePhysicsAsset = False task.ImportUI.SkeletalMeshImportData.bImportMorphTargets = True print('================[ import asset : Armature ]================') try: asset = task.factory_import_object(FilePath, AssetImportPath) except: asset = None if asset == None: ImportFailList.append( 'Asset "Armature" not found for after inport') return print( '========================= Imports of Armature completed ! Post treatment started... =========================' ) print( '========================= Post treatment of Armature completed ! =========================' ) asset.save_package() asset.post_edit_change() ImportedList.append([asset, 'Action'])
def CreateTask_SM_Goal_Ring1(): ################[ Import Goal_Ring1 as StaticMesh type ]################ print( '================[ New import task : Goal_Ring1 as StaticMesh type ]================' ) FilePath = os.path.join( r'D:\Projects\Git\RetroTowerDefense\ExportedFbx\StaticMesh\SM_Goal_Ring1.fbx' ) AdditionalParameterLoc = os.path.join( r'D:\Projects\Git\RetroTowerDefense\ExportedFbx\StaticMesh\SM_Goal_Ring1_AdditionalParameter.ini' ) AssetImportPath = (os.path.join(unrealImportLocation, r'').replace('\\', '/')).rstrip('/') task = PyFbxFactory() task.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_StaticMesh task.ImportUI.bImportMaterials = True task.ImportUI.bImportTextures = False task.ImportUI.bImportAnimations = False task.ImportUI.bImportMesh = True task.ImportUI.bCreatePhysicsAsset = True task.ImportUI.TextureImportData.MaterialSearchLocation = EMaterialSearchLocation.Local task.ImportUI.StaticMeshImportData.bCombineMeshes = True task.ImportUI.StaticMeshImportData.bAutoGenerateCollision = True task.ImportUI.StaticMeshImportData.bGenerateLightmapUVs = True print('================[ import asset : Goal_Ring1 ]================') try: asset = task.factory_import_object(FilePath, AssetImportPath) except: asset = None if asset == None: ImportFailList.append( 'Asset "Goal_Ring1" not found for after inport') return print( '========================= Imports of Goal_Ring1 completed ! Post treatment started... =========================' ) asset.BodySetup.CollisionTraceFlag = ECollisionTraceFlag.CTF_UseDefault lods_to_add = GetOptionByIniFile(AdditionalParameterLoc, 'LevelOfDetail') for x, lod in enumerate(lods_to_add): pass asset.static_mesh_import_lod(lod, x + 1) print( '========================= Post treatment of Goal_Ring1 completed ! =========================' ) asset.save_package() asset.post_edit_change() ImportedList.append([asset, 'StaticMesh'])
def CreateTask_SK_Armature(): ################[ Import Armature as SkeletalMesh type ]################ print( '================[ New import task : Armature as SkeletalMesh type ]================' ) FilePath = os.path.join( r'D:\Repos\Piroots2\Other Files\ExportedFbx\SkeletalMesh\Armature\SK_Armature.fbx' ) AdditionalParameterLoc = os.path.join( r'D:\Repos\Piroots2\Other Files\ExportedFbx\SkeletalMesh\Armature\SK_Armature_AdditionalParameter.ini' ) AssetImportPath = (os.path.join(unrealImportLocation, r'').replace('\\', '/')).rstrip('/') task = PyFbxFactory() task.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_SkeletalMesh task.ImportUI.bImportMaterials = True task.ImportUI.bImportTextures = False task.ImportUI.bImportAnimations = False task.ImportUI.bCreatePhysicsAsset = True task.ImportUI.bImportAnimations = False task.ImportUI.bImportMesh = True task.ImportUI.bCreatePhysicsAsset = True task.ImportUI.TextureImportData.MaterialSearchLocation = EMaterialSearchLocation.Local task.ImportUI.SkeletalMeshImportData.bImportMorphTargets = True print('================[ import asset : Armature ]================') try: asset = task.factory_import_object(FilePath, AssetImportPath) except: asset = None if asset == None: ImportFailList.append( 'Asset "Armature" not found for after inport') return print( '========================= Imports of Armature completed ! Post treatment started... =========================' ) skeleton = asset.skeleton current_sockets = skeleton.Sockets new_sockets = [] sockets_to_add = GetOptionByIniFile(AdditionalParameterLoc, 'Sockets', True) for socket in sockets_to_add: #Create socket new_socket = SkeletalMeshSocket('', skeleton) new_socket.SocketName = socket[0] print(socket[0]) new_socket.BoneName = socket[1] l = socket[2] r = socket[3] s = socket[4] new_socket.RelativeLocation = FVector(l[0], l[1], l[2]) new_socket.RelativeRotation = FRotator(r[0], r[1], r[2]) new_socket.RelativeScale = FVector(s[0], s[1], s[2]) new_sockets.append(new_socket) skeleton.Sockets = new_sockets lods_to_add = GetOptionByIniFile(AdditionalParameterLoc, 'LevelOfDetail') for x, lod in enumerate(lods_to_add): pass print( '========================= Post treatment of Armature completed ! =========================' ) asset.save_package() asset.post_edit_change() ImportedList.append([asset, 'SkeletalMesh'])
import unreal_engine as ue from unreal_engine.classes import PyFbxFactory, Skeleton from unreal_engine.enums import EFBXImportType import os base_directory = 'D:/Users/rober/Downloads/mixamo' # get a reference to the skeleton skeleton = ue.load_object(Skeleton, '/Game/run_Skeleton') factory = PyFbxFactory() factory.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_Animation factory.ImportUI.Skeleton = skeleton for item in os.listdir(base_directory): if item.endswith('.fbx'): animation = factory.factory_import_object(os.path.join(base_directory, item), '/Game/Mixamo002')
# build the path for the fbx file kaiju_assets_dir = os.path.join(os.path.expanduser('~/Desktop'), 'Kaiju_Assets/Slicer') slicer_fbx = os.path.join(kaiju_assets_dir, 'slicer.fbx') # configure the factory fbx_factory.ImportUI.bCreatePhysicsAsset = False fbx_factory.ImportUI.bImportMaterials = False fbx_factory.ImportUI.bImportTextures = False fbx_factory.ImportUI.bImportAnimations = False # scale the mesh (the Kaiju is 30 meters high !) fbx_factory.ImportUI.SkeletalMeshImportData.ImportUniformScale = 0.1; # import the mesh slicer_mesh = fbx_factory.factory_import_object(slicer_fbx, '/Game/Kaiju/Slicer') from unreal_engine.classes import MaterialFactoryNew material_factory = MaterialFactoryNew() material_blades = material_factory.factory_create_new('/Game/Kaiju/Slicer/Blades_Material') material_body = material_factory.factory_create_new('/Game/Kaiju/Slicer/Body_Material') from unreal_engine.classes import TextureFactory # instantiate a factory for importing textures texture_factory = TextureFactory() # ensures textures are overwritten (2 means, YesAll, defined in Engine/Source/Runtime/Core/Public/GenericPlatform/GenericPlatformMisc.h, EAppReturnType::YesAll) texture_factory.OverwriteYesOrNoToAllState = 2
import unreal_engine as ue from unreal_engine.classes import PyFbxFactory, Skeleton from unreal_engine.enums import EFBXImportType import os base_directory = 'D:/Users/rober/Downloads/mixamo' # get a reference to the skeleton skeleton = ue.load_object(Skeleton, '/Game/run_Skeleton') factory = PyFbxFactory() factory.ImportUI.MeshTypeToImport = EFBXImportType.FBXIT_Animation factory.ImportUI.Skeleton = skeleton for item in os.listdir(base_directory): if item.endswith('.fbx'): animation = factory.factory_import_object(os.path.join(base_directory, item), '/Game/Mixamo002')
obj = os.path.join(assets_dir, error_object) else: assets_dir = os.path.join(os.path.expanduser(xmodels_directory), model["Name"]) obj = os.path.join(assets_dir, model["Name"] + LOD0 + ".obj") # configure the factory fbx_factory.ImportUI.bCreatePhysicsAsset = False fbx_factory.ImportUI.bImportMaterials = False fbx_factory.ImportUI.bImportTextures = False fbx_factory.ImportUI.bImportAnimations = False fbx_factory.ImportUI.StaticMeshImportData.bCombineMeshes = True fbx_factory.ImportUI.SkeletalMeshImportData.ImportUniformScale = 1; # import the mesh mesh = fbx_factory.factory_import_object(obj, xmodels_path + "xmodels") if model["Name"].endswith("_missing"): ue.rename_asset(xmodels_path + "xmodels/" + error_object_name[0] + "." + error_object_name[0], prop_name) else: ue.rename_asset(xmodels_path + "xmodels/" + prop_name + LOD0 + "." + prop_name + LOD0, prop_name) props.append(prop) #3. Materials model_names = [] slot_names = [] diffuse_names = [] normal_names = []
print('========================= Import started ! =========================') ################[ Import Cube as StaticMesh type ]################ fbx_factory = PyFbxFactory() fbx_factory.ImportUI.bImportMaterials = True fbx_factory.ImportUI.bImportTextures = False fbx_factory.ImportUI.TextureImportData.MaterialSearchLocation = EMaterialSearchLocation.Local fbx_factory.ImportUI.StaticMeshImportData.bCombineMeshes = True fbx_factory.ImportUI.StaticMeshImportData.bAutoGenerateCollision = True FbxLoc = os.path.join(r'C:\Users\hichu\Documents\GitHub\Blender-Rigging\ExportedFbx\StaticMesh\SM_Cube.fbx') AdditionalParameterLoc = os.path.join(r'C:\Users\hichu\Documents\GitHub\Blender-Rigging\ExportedFbx\StaticMesh\SM_Cube_AdditionalParameter.ini') AssetImportLocation = (os.path.join(UnrealImportLocation, r'').replace('\\','/')).rstrip('/') try: asset = fbx_factory.factory_import_object(FbxLoc, AssetImportLocation) lods_to_add = GetOptionByIniFile(AdditionalParameterLoc, 'LevelOfDetail') for x, lod in enumerate(lods_to_add): asset.static_mesh_import_lod(lod, x+1) asset.save_package() asset.post_edit_change() ImportedAsset.append(asset) except: ImportedAsset.append('Import error for asset named "Cube" ') print('========================= Imports completed ! =========================') for asset in ImportedAsset: print(asset)
# textures (from substance designer) kaiju_textures = ['slicer_BaseColor.tga', 'slicer_Emissive.tga', 'slicer_Normal.tga', 'slicer_OcclusionRoughnessMetallic.tga'] # an fbx skeletal animation kaiju_animation = 'slicer_walking.fbx' # start configuring the mesh importer factory = PyFbxFactory() factory.ImportUI.bCreatePhysicsAsset = False factory.ImportUI.bImportMaterials = False factory.ImportUI.bImportTextures = False factory.ImportUI.bImportAnimations = False # scale the mesh factory.ImportUI.SkeletalMeshImportData.ImportUniformScale = 0.1; # import the mesh mesh = factory.factory_import_object(os.path.join(kaiju_source, kaiju_mesh), kaiju_destination) # start configurint the texture importer texture_factory = TextureFactory() imported_textures = [] for texture in kaiju_textures: imported_texture = texture_factory.factory_import_object(os.path.join(kaiju_source, texture), kaiju_destination) imported_textures.append(imported_texture) mat = Material() #mat.set_name('kaiju_Material_' + str(time.time())) mat.save_package(kaiju_destination + '/kaiju_Material')