I am trying to import an fbx file and export it as a glTF file using python scripts.
I am trying to use this plugin for the glTF export.
Here is how I import the file into unreal
def import_asset_noncad():
""" Import Non-Cad Asset """
# Bicycle.obj
# Bulk_Filling_Tank.fbx
destination_path = '/Game/NonCad/'
filenames = [input_filename]
editorAssetLibrary = unreal.EditorAssetLibrary()
# delete asset
assets_list = editorAssetLibrary.list_assets(destination_path)
for asset in assets_list:
editorAssetLibrary.delete_asset(asset)
# import asset task
data = unreal.AutomatedAssetImportData()
data.set_editor_property('destination_path', destination_path)
data.set_editor_property('filenames', filenames)
destination_name = os.path.basename(os.path.splitext(filenames[0])[0])
data.set_editor_property('group_name', 'fbx')
data.set_editor_property('replace_existing', True)
# scene import options
scene = unreal.FbxSceneImportOptions()
scene.set_editor_property('create_content_folder_hierarchy', True)
scene.set_editor_property('import_as_dynamic', True)
layer_type = unreal.FBXSceneOptionsCreateHierarchyType.FBXSOCHT_CREATE_LEVEL_ACTORS
scene.set_editor_property('hierarchy_type', layer_type)
# scene import options(static mesh) for factory
static_meshes = unreal.FbxSceneImportOptionsStaticMesh()
# static_meshes.set_editor_property('auto_generate_collision', False)
static_meshes.set_editor_property('generate_lightmap_u_vs', False)
normal_method = unreal.FBXSceneNormalImportMethod.FBX_SCENE_NIM_IMPORT_NORMALS
static_meshes.set_editor_property('normal_import_method', normal_method)
# fbx scene import factory
factory = unreal.FbxSceneImportFactory()
factory.set_editor_property('scene_import_options', scene)
factory.set_editor_property('scene_import_options_static_mesh', static_meshes)
data.set_editor_property('factory', factory)
# run task
asset = unreal.AssetToolsHelpers.get_asset_tools().import_assets_automated(data)
# load asset
assets_list = editorAssetLibrary.list_assets(destination_path)
for asset in assets_list:
editorAssetLibrary.load_asset(asset)
Here is how I trying to export to glTF
def export_gltf_model():
output_filename = ('{}{}{}.{}').format(output_filelocation, "/", model_name, "gltf")
level_actors = unreal.EditorLevelLibrary.get_all_level_actors()
task = unreal.AssetExportTask()
# obj = level_actors[0].get_world()
task.exporter = unreal.GLTFStaticMeshExporter()
task.set_editor_property('options', unreal.GLTFExportOptions())
task.set_editor_property('object', level_actors[0])
task.set_editor_property('filename', output_filename)
# task.set_editor_property('selected', False)
# task.set_editor_property('prompt', False)
task.set_editor_property('automated', True)
task.set_editor_property('replace_identical', True)
result = unreal.Exporter.run_asset_export_task(task)
if (result):
print('DONE! Output {} File Path and name: {}'.format(export_format, output_filename))
else:
print("Export failed")
When I run the above code, the editor crashes.
Question: How would I export a model as a glTF using python in Unreal.
Here is what I get in the crash report.
LoginId:baf048eb204944da5d657396450e0a23
EpicAccountId:5b86c5a63b144d6cae3cce7bbdf5c5ac
Assertion failed: Object->IsA( Exporter->SupportedClass ) [File:/Users/build/Build/++UE4/Sync/Engine/Source/Runtime/Engine/Private/UnrealExporter.cpp] [Line: 167]
FGenericPlatformMisc::RaiseException(unsigned int) Address = 0x10ab5b2b7 (filename not found) [in UE4Editor-Core.dylib]
FMacErrorOutputDevice::Serialize(char16_t const*, ELogVerbosity::Type, FName const&) Address = 0x10ad14e53 (filename not found) [in UE4Editor-Core.dylib]
FOutputDevice::LogfImpl(char16_t const*, ...) Address = 0x10ae2e689 (filename not found) [in UE4Editor-Core.dylib]
AssertFailedImplV(char const*, char const*, int, char16_t const*, __va_list_tag*) Address = 0x10ada0b57 (filename not found) [in UE4Editor-Core.dylib]
FDebug::CheckVerifyFailedImpl(char const*, char const*, int, char16_t const*, ...) Address = 0x10ada09e4 (filename not found) [in UE4Editor-Core.dylib]
UExporter::RunAssetExportTask(UAssetExportTask*) Address = 0x1141d1037 (filename not found) [in UE4Editor-Engine.dylib]
UExporter::execRunAssetExportTask(UObject*, FFrame&, void*) Address = 0x114482c7e (filename not found) [in UE4Editor-Engine.dylib]
UFunction::Invoke(UObject*, FFrame&, void*) Address = 0x109848c3c (filename not found) [in UE4Editor-CoreUObject.dylib]
UObject::ProcessEvent(UFunction*, void*) Address = 0x109b157bc (filename not found) [in UE4Editor-CoreUObject.dylib]
PyUtil::InvokeFunctionCall(UObject*, UFunction const*, void*, char16_t const*) Address = 0x285cabdbd (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPyWrapperObject::CallFunction_Impl(UObject*, _object*, _object*, PyGenUtil::FGeneratedWrappedFunction const&, char const*, char16_t const*) Address = 0x285d1f626 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPyWrapperObject::CallFunction(_typeobject*, _object*, _object*, PyGenUtil::FGeneratedWrappedFunction const&, char const*) Address = 0x285d1f2ee (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
_PyObject_FastCallKeywords Address = 0x285fee24f (filename not found) [in libpython3.7.dylib]
call_function Address = 0x2860bca20 (filename not found) [in libpython3.7.dylib]
_PyEval_EvalFrameDefault Address = 0x2860b9551 (filename not found) [in libpython3.7.dylib]
function_code_fastcall Address = 0x285fee91d (filename not found) [in libpython3.7.dylib]
call_function Address = 0x2860bca27 (filename not found) [in libpython3.7.dylib]
_PyEval_EvalFrameDefault Address = 0x2860b95fb (filename not found) [in libpython3.7.dylib]
function_code_fastcall Address = 0x285fee91d (filename not found) [in libpython3.7.dylib]
call_function Address = 0x2860bca27 (filename not found) [in libpython3.7.dylib]
_PyEval_EvalFrameDefault Address = 0x2860b95fb (filename not found) [in libpython3.7.dylib]
_PyEval_EvalCodeWithName Address = 0x2860bd5df (filename not found) [in libpython3.7.dylib]
PyEval_EvalCode Address = 0x2860b27d0 (filename not found) [in libpython3.7.dylib]
FPythonScriptPlugin::EvalString(char16_t const*, char16_t const*, int, _object*, _object*) Address = 0x285cc42b1 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonScriptPlugin::RunFile(char16_t const*, char16_t const*, FPythonCommandEx&) Address = 0x285cbc201 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonScriptPlugin::ExecPythonCommandEx(FPythonCommandEx&) Address = 0x285cbb9c0 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonScriptPlugin::ExecPythonCommand(char16_t const*) Address = 0x285cbb7ac (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonCommandExecutor::Exec(char16_t const*) Address = 0x285cbb1eb (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
SConsoleInputBox::OnTextCommitted(FText const&, ETextCommit::Type) Address = 0x261d3b6f5 (filename not found) [in UE4Editor-OutputLog.dylib]
TBaseSPMethodDelegateInstance<false, SConsoleInputBox, (ESPMode)0, void (FText const&, ETextCommit::Type), FDefaultDelegateUserPolicy>::ExecuteIfSafe(FText const&, ETextCommit::Type) const Address = 0x261d6238f (filename not found) [in UE4Editor-OutputLog.dylib]
FSlateEditableTextLayout::HandleCarriageReturn(bool) Address = 0x10d238dfb (filename not found) [in UE4Editor-Slate.dylib]
FSlateEditableTextLayout::HandleKeyDown(FKeyEvent const&) Address = 0x10d237161 (filename not found) [in UE4Editor-Slate.dylib]
SMultiLineEditableText::OnKeyDown(FGeometry const&, FKeyEvent const&) Address = 0x10d24cff7 (filename not found) [in UE4Editor-Slate.dylib]
FSlateApplication::ProcessKeyDownEvent(FKeyEvent const&) Address = 0x10cf0fc2f (filename not found) [in UE4Editor-Slate.dylib]
FSlateApplication::OnKeyDown(int, unsigned int, bool) Address = 0x10cf0e3aa (filename not found) [in UE4Editor-Slate.dylib]
FMacApplication::ProcessKeyDownEvent(FDeferredMacEvent const&, TSharedPtr<FMacWindow, (ESPMode)0>) Address = 0x108eaba46 (filename not found) [in UE4Editor-ApplicationCore.dylib]
FMacApplication::ProcessEvent(FDeferredMacEvent const&) Address = 0x108ea52b4 (filename not found) [in UE4Editor-ApplicationCore.dylib]
FMacApplication::ProcessDeferredEvents(float) Address = 0x108ea4eaf (filename not found) [in UE4Editor-ApplicationCore.dylib]
FSlateApplication::TickPlatform(float) Address = 0x10ceee590 (filename not found) [in UE4Editor-Slate.dylib]
FSlateApplication::Tick(ESlateTickType) Address = 0x10ceedc11 (filename not found) [in UE4Editor-Slate.dylib]
FEngineLoop::Tick() Address = 0x108961254 (filename not found) [in UE4Editor]
GuardedMain(char16_t const*) Address = 0x10896e92e (filename not found) [in UE4Editor]
-[UE4AppDelegate runGameThread:] Address = 0x10898d413 (filename not found) [in UE4Editor]
-[FCocoaGameThread main] Address = 0x10ad13fc1 (filename not found) [in UE4Editor-Core.dylib]
Unknown() Address = 0x7ff8095442d9 (filename not found) [in Foundation]
_pthread_start Address = 0x7ff80861f4f4 (filename not found) [in libsystem_pthread.dylib]
thread_start Address = 0x7ff80861b00f (filename not found) [in libsystem_pthread.dylib]