17072802(UE4的批量Import)

【目标】

UE4的Import

【思路】

1 FNewAssetOrClassContextMenu.MakeContextMenu

442386-20170906103624272-1574858930.png

 

FNewAssetOrClassContextMenu.ExecuteImportAsset 


2 UFactory.StaticImportObject 


442386-20170906103626132-946938369.png

 


3 居然有自动Import

442386-20170906103626413-175070187.png

在自动测试的时候可以自动导入


FAssetTools.ImportAssetsAutomated 


还有Commandlet

UImportAssetsCommandlet.Main 

442386-20170906103626741-416974873.png




试一下指令

UE4Editor.exe DemonHunter.uproject ImportAssets


发现 UE4的Commandlet参数不同

eg.

442386-20170906103627022-1973459582.png


试一下指令

UE4Editor.exe DemonHunter.uproject -run=ImportAssets

出来了
442386-20170906103627647-1191011660.png

 
442386-20170906103628163-1515669112.png
如果有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<FJsonObjectInImportGroupJsonData);
    /** @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<FStringFilenames;
    /** 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()
    UFactoryFactory;
    /** Json data to be read when importing this group */
    TSharedPtr<FJsonObjectImportGroupJsonData;
};



那尝试新建一个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
}
  ]
}


http://www.sojson.com/ 检测一下

442386-20170906103628929-1695820061.png

查找到错误

 
{
    "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, ErrorTEXT("%s is read only and -skipreadonly was specified.  Will not save"), *PackageFilename);
                            bImportAndSaveSucceeded = false;
                        }
                    }
                    else if (bIsReadOnly)
                    {
                        bShouldAttemptToSave = FPlatformFileManager::Get().GetPlatformFile().SetReadOnly(*PackageFilenamefalse);
                        if (!bShouldAttemptToSave)
                        {
                            UE_LOG(LogAutomatedImport, ErrorTEXT("%s is read only and could not be made writable.  Will not save"), *PackageFilename);
                            bImportAndSaveSucceeded = false;
                        }
                    }
                    else
                        bShouldAttemptToSave = true;

可以保存了

导入成功!!

442386-20170906103629351-743367234.png

 


4 每个资源有ImportSettings可以配置
UFbxImportUI 

    /** Type of asset to import from the FBX file */
    UPROPERTY()
    TEnumAsByte<enum EFBXImportTypeMeshTypeToImport;
....


  • 如果是骨骼动画的就设置成SkeletalMesh
  • 在UE3导出时就需要生成json配置文件


试一下配置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
            }
        }
    ]
}


442386-20170906103629804-1489611905.png


运行导入成功
442386-20170906103630413-1554663301.png

 
6 问:如果是导入动画如何来关联骨骼?
手动导入动画时会弹出以下界面
442386-20170906103631116-437547257.png
如果不选择是Import不了的
导入动画时Option的内容

442386-20170906103631663-113544429.png

ImportUI(也就是可配置的ImportSettings)的内容
442386-20170906103632163-1922102257.png
数据流
UnFbx.ApplyImportUIToImportOptions 中

UFbxImportUI ->FBXImportOptions

442386-20170906103632913-395099693.png

442386-20170906103633226-749577263.png
 


问:这个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"
            }
        }
    ]
}


如果原来有文件就会弹出确认框 确认是否合并骨骼
点击确认之后还是动画有问题,打开编辑器查看是有模型了,但是骨骼数还是没有变化
删掉重新导入试下
442386-20170906103641757-1442484476.gif
生成的资源有这些
442386-20170906103644163-2127703309.png
 





【步骤】

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






转载于:https://www.cnblogs.com/username/p/7483340.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值