【目标】
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;
可以保存了
导入成功!!
4 每个资源有ImportSettings可以配置
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