Static Meshes
Static Mesh assets are the basic unit used to create world geometry for levels. These 3D models are created in external modeling applications (such as 3dsMax, Maya, Blender, and so on) that are imported into the Unreal Editor through the Content Browser. The vast majority of any level made with Unreal Engine will consist of Static Meshes, generally in the form of Static Mesh Actors
.
Instanced Static Mesh
Import Static Mesh - .fbx file
#include "Kismet/BlueprintFunctionLibrary.h" // Engine, Editor only
/**
* Editor Only - Will not work in packaged build.
*
* Create and process a StaticMesh import task.
*
* @param SourcePath The path of the source file: "C:/Temp/MyStaticMesh.fbx"
* @param DestinationPath The path of the imported asset: "/Game/Folder/MyStaticMesh"
* @param bOutSuccess If the action was a success or not
* @param OutInfoMessage More information about the action's result
*
* @return The imported StaticMesh
*/
UFUNCTION(BlueprintCallable, Category = "")
static class UStaticMesh* ImportStaticMesh(FString SourcePath, FString DestinationPath, bool& bOutSuccess, FString& OutInfoMsg);
.cpp file
#include "Factories/FbxImportUI.h" // UnrealEd (Editor Only)
#include "Factories/FbxStaticMeshImportData.h" // UnrealEd (Editor Only)
UStaticMesh* UExampleClass::ImportStaticMesh(FString SourcePath, FString DestinationPath, bool& bOutSuccess, FString& OutInfoMsg)
{
UFbxImportUI* Options = NewObject<UFbxImportUI>();
// Required options to specify that we're importing a static mesh
Options->bAutomatedImportShouldDetectType = false;
Options->MeshTypeToImport = EFBXImportType::FBXIT_StaticMesh;
Options->bImportMesh = true;
// No skeletal mesh or animations
Options->bImportAsSkeletal = false;
Options->bImportAnimations = false;
Options->bCreatePhysicsAsset = false;
// More options
Options->bImportTextures = true;
Options->bImportMaterials = true;
Options->bResetToFbxOnMaterialConflict = true;
Options->LodNumber = 0;
// UFbxAssetImportData
Options->StaticMeshImportData->ImportTranslation = FVector(0.0f);
Options->StaticMeshImportData->ImportRotation = FRotator(0.0f);
Options->StaticMeshImportData->ImportUniformScale = 1.0f;
Options->StaticMeshImportData->bConvertScene = true;
Options->StaticMeshImportData->bForceFrontXAxis = true;
Options->StaticMeshImportData->bConvertSceneUnit = true;
// UFbxMeshImportData
Options->StaticMeshImportData->bTransformVertexToAbsolute = false;
Options->StaticMeshImportData->bBakePivotInVertex = false;
Options->StaticMeshImportData->bImportMeshLODs = true;
Options->StaticMeshImportData->NormalImportMethod = EFBXNormalImportMethod::FBXNIM_ComputeNormals;
Options->StaticMeshImportData->NormalGenerationMethod = EFBXNormalGenerationMethod::BuiltIn;
Options->StaticMeshImportData->bComputeWeightedNormals = true;
Options->StaticMeshImportData->bReorderMaterialToFbxOrder = false;
// UFbxStaticMeshImportData
Options->StaticMeshImportData->StaticMeshLODGroup = FName();
Options->StaticMeshImportData->VertexColorImportOption = EVertexColorImportOption::Replace;
Options->StaticMeshImportData->bRemoveDegenerates = true;
Options->StaticMeshImportData->bBuildReversedIndexBuffer = true;
Options->StaticMeshImportData->bBuildNanite = true;
Options->StaticMeshImportData->bGenerateLightmapUVs = true;
Options->StaticMeshImportData->bOneConvexHullPerUCX = true;
Options->StaticMeshImportData->bAutoGenerateCollision = true;
Options->StaticMeshImportData->bCombineMeshes = true;
Options->StaticMeshImportData->DistanceFieldResolutionScale = 0.0f;
// Create the import task
UAssetImportTask* Task = UExampleClass::CreateImportTask(SourcePath, DestinationPath, nullptr, Options, bOutSuccess, OutInfoMsg);
if (!bOutSuccess) return nullptr;
// Import the asset
UStaticMesh* RetAsset = Cast<UStaticMesh>(UExampleClass::ProcessImportTask(Task, bOutSuccess, OutInfoMsg));
if (!bOutSuccess) return nullptr;
// Return the imported asset
bOutSuccess = true;
OutInfoMessage = FString::Printf(TEXT("Import Static Mesh Succeeded - '%s'"), *DestinationPath);
return RetAsset;
}