【目標】
UE4的Import
【思路】
1 FNewAssetOrClassContextMenu.MakeContextMenu

FNewAssetOrClassContextMenu.ExecuteImportAsset
2 UFactory.StaticImportObject

3 居然有自動Import

在自動測試的時候可以自動導入
FAssetTools.ImportAssetsAutomated
還有Commandlet
UImportAssetsCommandlet.Main

試一下指令
UE4Editor.exe DemonHunter.uproject ImportAssets
發現 UE4的Commandlet參數不同
eg.

試一下指令
UE4Editor.exe DemonHunter.uproject -run=ImportAssets
出來了
如果有importsttings,就不需要用-source -dest來指定單個文件路徑
問:那么importsettings如何去配置?
答:是將UAutomatedAssetImportData 類轉成Json來配置
/**
* Contains data for a group of assets to import
*/
UCLASS(Transient)
class UNREALED_API UAutomatedAssetImportData : public UObject
{
GENERATED_BODY()
public:
UAutomatedAssetImportData();
/** @return true if this group contains enough valid data to import*/
bool IsValid() const;
/** Initalizes the group */
void Initialize(TSharedPtr<FJsonObject> InImportGroupJsonData);
/** @return the display name of the group */
FString GetDisplayName() const;
public:
/** Display name of the group. This is for logging purposes only. */
UPROPERTY()
FString GroupName;
/** Filenames to import */
UPROPERTY()
TArray<FString> Filenames;
/** Content path in the projects content directory where assets will be imported */
UPROPERTY()
FString DestinationPath;
/** Name of the factory to use when importing these assets. If not specified the factory type will be auto detected */
UPROPERTY()
FString FactoryName;
/** Whether or not to replace existing assets */
UPROPERTY()
bool bReplaceExisting;
/** Whether or not to skip importing over read only assets that could not be checked out */
UPROPERTY()
bool bSkipReadOnly;
/** Pointer to the factory currently being sued */
UPROPERTY()
UFactory* Factory;
/** Json data to be read when importing this group */
TSharedPtr<FJsonObject> ImportGroupJsonData;
};
那嘗試新建一個json文件
{
"ImportGroups":[
{
"GroupName":
"Filenames":"F:\A_Works\trunk_C\DevEnv\ue3\Binaries\Win32\EEE\ExampleGame\Content\Characters\daoju\daoju_rw_092\daoju_rw_092.fbx"
"DestinationPath":"ttt"
"FactoryName":"ReimportFbxStaticMeshFactory"
"bReplaceExisting":1
"bSkipReadOnly":0
}
]
}

查找到錯誤
{
"ImportGroups": [
{
"GroupName": "Group11",
"Filenames": [
"F:\\A_Works\\trunk_C\\DevEnv\\ue3\\Binaries\\Win32\\EEE\\ExampleGame\\Content\\Characters\\daoju\\daoju_rw_092\\daoju_rw_092.fbx"
],
"DestinationPath": "ttt",
"FactoryName": "FbxFactory",
"bReplaceExisting": 1,
"bSkipReadOnly": 0
}
]
}
測試指令
DemonHunter.uproject -run=ImportAssets -importsettings=G:\Import.json
跟蹤發現可以生成資源,但是沒保存到文件
修改一下UImportAssetsCommandlet.ImportAndSave.
bool bIsReadOnly = IFileManager::Get().IsReadOnly(*PackageFilename);
if(bIsReadOnly && ImportData->bSkipReadOnly)
{
bShouldAttemptToSave = ImportData->bSkipReadOnly;
if(bIsReadOnly)
{
UE_LOG(LogAutomatedImport, Error, TEXT("%s is read only and -skipreadonly was specified. Will not save"), *PackageFilename);
bImportAndSaveSucceeded = false;
}
}
else if (bIsReadOnly)
{
bShouldAttemptToSave = FPlatformFileManager::Get().GetPlatformFile().SetReadOnly(*PackageFilename, false);
if (!bShouldAttemptToSave)
{
UE_LOG(LogAutomatedImport, Error, TEXT("%s is read only and could not be made writable. Will not save"), *PackageFilename);
bImportAndSaveSucceeded = false;
}
}
else
bShouldAttemptToSave = true;
可以保存了
導入成功!!

UFbxImportUI
/** Type of asset to import from the FBX file */
UPROPERTY()
TEnumAsByte<enum EFBXImportType> MeshTypeToImport;
....
- 如果是骨骼動畫的就設置成SkeletalMesh
- 在UE3導出時就需要生成json配置文件
5 試一下配置ImportSettings
修改Json文件
{
"ImportGroups": [
{
"GroupName": "Group11",
"Filenames": [
"F:\\A_Works\\trunk_C\\DevEnv\\ue3\\Binaries\\Win32\\EEE\\ExampleGame\\Content\\Characters\\daoju\\daoju_rw_092\\daoju_rw_092.fbx"
],
"DestinationPath": "ttt",
"FactoryName": "FbxFactory",
"bReplaceExisting": 1,
"bSkipReadOnly": 0,
"ImportSettings": {
"MeshTypeToImport": 1
}
}
]
}
運行導入成功
6 問:如果是導入動畫如何來關聯骨骼?
手動導入動畫時會彈出以下界面
如果不選擇是Import不了的
導入動畫時Option的內容
ImportUI(也就是可配置的ImportSettings)的內容
數據流
UnFbx.ApplyImportUIToImportOptions 中
UFbxImportUI ->FBXImportOptions
問:這個Skeleton內容是否可以由Json創建呢?
嘗試配置一個路徑,需要注意路徑格式
{
"ImportGroups": [
{
"GroupName": "Group11",
"Filenames": [
"F:\\A_Works\\trunk_C\\DevEnv\\ue3\\Binaries\\Win32\\EEE\\ExampleGame\\Content\\Characters\\daoju\\daoju_rw_092\\Mesh\\Anim\\skill01.fbx"
],
"DestinationPath": "ttt",
"FactoryName": "FbxFactory",
"bReplaceExisting": 1,
"bSkipReadOnly": 0,
"ImportSettings": {
"OriginalImportType": 2,
"MeshTypeToImport": 2,
"Skeleton": "
/Game/ttt/daoju_rw_092_Skeleton.daoju_rw_092_Skeleton
"
}
}
]
}
結果是可以構建
Skeleton
但是測試下來沒有保存資源文件,原來是骨骼不匹配
測試一下多文件同時導入
{
"ImportGroups": [
{
"GroupName": "Group1",
"Filenames": [
"F:\\A_Works\\trunk_C\\DevEnv\\ue3\\Binaries\\Win32\\EEE\\ExampleGame\\Content\\Characters\\daoju\\daoju_rw_092\\Mesh\\daoju_rw_092.fbx"
],
"DestinationPath": "ttt",
"FactoryName": "FbxFactory",
"bReplaceExisting": 1,
"bSkipReadOnly": 0,
"ImportSettings": {
"MeshTypeToImport": 1
}
},
{
"GroupName": "Group11",
"Filenames": [
"F:\\A_Works\\trunk_C\\DevEnv\\ue3\\Binaries\\Win32\\EEE\\ExampleGame\\Content\\Characters\\daoju\\daoju_rw_092\\Mesh\\Anim\\skill01.fbx"
],
"DestinationPath": "/Game/ttt/Anim",
"FactoryName": "FbxFactory",
"bReplaceExisting": 1,
"bSkipReadOnly": 0,
"ImportSettings": {
"OriginalImportType": 2,
"MeshTypeToImport": 2,
"Skeleton": "/Game/ttt/daoju_rw_092_Skeleton.daoju_rw_092_Skeleton"
}
}
]
}
如果原來有文件就會彈出確認框 確認是否合並骨骼
點擊確認之后還是動畫有問題,打開編輯器查看是有模型了,但是骨骼數還是沒有變化
刪掉重新導入試下
生成的資源有這些
【步驟】
1 修改
ErrorWarningList
-
>InsertColumn(
3,
*LocalizeUnrealEd(
"FullName"), wxLIST_FORMAT_LEFT,
100 );...
....
2 修改
if (ewi
-
>Object)
...
ErrorWarningList->SetItem( Index, 3, *ObjectName );
3
void USkelControlHitPlacement
:
:CalculateNewBoneTransforms(INT BoneIndex, USkeletalMeshComponent
* SkelComp, TArray
<FBoneAtom
>
& OutBoneTransforms)
{
....
}
【運行】
3
