diff --git a/.gitignore b/.gitignore index 4f58714b..2d3ce5e9 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ *.exe *.out *.app +Intermediate +Binaries diff --git a/Content/ImportDataSet/DS_MooaToon.uasset b/Content/ImportDataSet/DS_MooaToon.uasset new file mode 100644 index 00000000..eee0f4f0 Binary files /dev/null and b/Content/ImportDataSet/DS_MooaToon.uasset differ diff --git a/Content/VrmAssetListObjectBP.uasset b/Content/VrmAssetListObjectBP.uasset index d6437fcc..9bb269a4 100644 Binary files a/Content/VrmAssetListObjectBP.uasset and b/Content/VrmAssetListObjectBP.uasset differ diff --git a/Content/VrmAssetListObjectBPUE5.uasset b/Content/VrmAssetListObjectBPUE5.uasset index 4f73823e..e2569cdd 100644 Binary files a/Content/VrmAssetListObjectBPUE5.uasset and b/Content/VrmAssetListObjectBPUE5.uasset differ diff --git a/Source/VRM4U/Private/AnimNode_VrmConstraint.cpp b/Source/VRM4U/Private/AnimNode_VrmConstraint.cpp index 1f825c35..d1d1b46e 100644 --- a/Source/VRM4U/Private/AnimNode_VrmConstraint.cpp +++ b/Source/VRM4U/Private/AnimNode_VrmConstraint.cpp @@ -6,6 +6,7 @@ #include "Animation/AnimInstanceProxy.h" #include "Kismet/KismetSystemLibrary.h" #include "DrawDebugHelpers.h" +#include "SceneManagement.h" #include "VrmMetaObject.h" #include "VrmAssetListObject.h" diff --git a/Source/VRM4U/Private/AnimNode_VrmSpringBone.cpp b/Source/VRM4U/Private/AnimNode_VrmSpringBone.cpp index 08bb5f0a..5c366245 100644 --- a/Source/VRM4U/Private/AnimNode_VrmSpringBone.cpp +++ b/Source/VRM4U/Private/AnimNode_VrmSpringBone.cpp @@ -35,6 +35,7 @@ SOFTWARE. #include "Kismet/KismetSystemLibrary.h" #include "SceneInterface.h" #include "DrawDebugHelpers.h" +#include "SceneManagement.h" #include "VrmMetaObject.h" #include "VrmAssetListObject.h" diff --git a/Source/VRM4U/Private/VrmAssetListObject.cpp b/Source/VRM4U/Private/VrmAssetListObject.cpp index e3d3fd80..4465979a 100644 --- a/Source/VRM4U/Private/VrmAssetListObject.cpp +++ b/Source/VRM4U/Private/VrmAssetListObject.cpp @@ -19,7 +19,8 @@ UVrmAssetListObject::UVrmAssetListObject(const FObjectInitializer& ObjectInitial void UVrmAssetListObject::CopyMember(UVrmAssetListObject *dst) const { dst->bAssetSave = bAssetSave; dst->bSkipMorphTarget = bSkipMorphTarget; - + + dst->MooaToonSet = MooaToonSet; // Mooa VRM dst->MtoonLitSet = MtoonLitSet; dst->MtoonUnlitSet = MtoonUnlitSet; dst->SSSSet = SSSSet; diff --git a/Source/VRM4U/Private/VrmBPFunctionLibrary.cpp b/Source/VRM4U/Private/VrmBPFunctionLibrary.cpp index 8ce813ba..1240a8ba 100644 --- a/Source/VRM4U/Private/VrmBPFunctionLibrary.cpp +++ b/Source/VRM4U/Private/VrmBPFunctionLibrary.cpp @@ -37,6 +37,10 @@ #include "Kismet/KismetRenderingLibrary.h" #endif +#if UE_VERSION_NEWER_THAN(5,6,-1) +#include "MaterialShared.h" +#endif + #if UE_VERSION_OLDER_THAN(5,1,0) #else #if WITH_EDITOR && PLATFORM_WINDOWS diff --git a/Source/VRM4U/Public/VrmAssetListObject.h b/Source/VRM4U/Public/VrmAssetListObject.h index d9f03982..9bf52916 100644 --- a/Source/VRM4U/Public/VrmAssetListObject.h +++ b/Source/VRM4U/Public/VrmAssetListObject.h @@ -38,6 +38,11 @@ class VRM4U_API UVrmAssetListObject : public UObject UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "InOption") bool bSkipMorphTarget=false; + // Mooa VRM + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "InMaterial") + UVrmImportMaterialSet* MooaToonSet; + // Mooa End + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "InMaterial") UVrmImportMaterialSet* MtoonLitSet; diff --git a/Source/VRM4U/Public/VrmUtil.h b/Source/VRM4U/Public/VrmUtil.h index 999f83ef..138ec4a1 100644 --- a/Source/VRM4U/Public/VrmUtil.h +++ b/Source/VRM4U/Public/VrmUtil.h @@ -307,7 +307,7 @@ FORCEINLINE USkeletalMesh *VRMGetSkinnedAsset(const USkinnedMeshComponent* t) { UENUM(BlueprintType) enum class EVRMImportMaterialType : uint8 { - VRMIMT_Auto UMETA(DisplayName = "Auto(MToon Unlit)"), + VRMIMT_Auto UMETA(DisplayName = "MooaToon"), // Mooa VRM VRMIMT_MToon UMETA(DisplayName = "MToon Lit"), VRMIMT_MToonUnlit UMETA(DisplayName = "MToon Unlit"), VRMIMT_SSS UMETA(DisplayName = "Subsurface"), diff --git a/Source/VRM4UCapture/Private/VRM4U_VMCSubsystem.cpp b/Source/VRM4UCapture/Private/VRM4U_VMCSubsystem.cpp index b427d082..9ef02db4 100644 --- a/Source/VRM4UCapture/Private/VRM4U_VMCSubsystem.cpp +++ b/Source/VRM4UCapture/Private/VRM4U_VMCSubsystem.cpp @@ -10,6 +10,10 @@ #include "OSCManager.h" #include "OSCServer.h" +#if WITH_EDITOR + #include "Editor.h" +#endif + bool UVRM4U_VMCSubsystem::CopyVMCData(FVMCData &data, FString ServerAddress, int port) { for (int i = 0; i < VMCObjectList.Num(); ++i) { auto a = VMCObjectList[i].Get(); diff --git a/Source/VRM4UImporter/Private/VRM4UImporterFactory.cpp b/Source/VRM4UImporter/Private/VRM4UImporterFactory.cpp index 71681eae..08396f52 100644 --- a/Source/VRM4UImporter/Private/VRM4UImporterFactory.cpp +++ b/Source/VRM4UImporter/Private/VRM4UImporterFactory.cpp @@ -1,681 +1,681 @@ -// VRM4U Copyright (c) 2021-2024 Haruyoshi Yamamoto. This software is released under the MIT License. - -#include "VRM4UImporterFactory.h" -#include "VRM4UImporterLog.h" - -#include "Misc/EngineVersionComparison.h" - -#include "AssetToolsModule.h" -#if UE_VERSION_OLDER_THAN(4,26,0) -#include "AssetRegistryModule.h" -#else -#include "AssetRegistry/AssetRegistryModule.h" -#endif -#include "PackageTools.h" -#include "Misc/Paths.h" -#include "Engine/SkeletalMesh.h" -#include "EditorFramework/AssetImportData.h" -#include "Components/SkeletalMeshComponent.h" -//#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h" -#include "UObject/ConstructorHelpers.h" -#include "LoaderBPFunctionLibrary.h" -#include "VrmAssetListObject.h" -#include "VrmRuntimeSettings.h" -#include "VrmOptionWindow.h" -#include "Engine/Blueprint.h" -#include "Templates/SharedPointer.h" -#include "Misc/FeedbackContext.h" -#include "FileHelpers.h" -#include "TickableEditorObject.h" - -#include "Interfaces/IMainFrameModule.h" -#include "Widgets/SWindow.h" -#include "Framework/Application/SlateApplication.h" -#include "HAL/PlatformApplicationMisc.h" -#include "VrmOptionWindow.h" -#include "VrmImportUI.h" -#include "VrmConvert.h" -#include "VrmLicenseObject.h" -#include "Vrm1LicenseObject.h" - -#define LOCTEXT_NAMESPACE "VRMImporter" - -// for tick Editor Object -class SWindow2 : public SWindow{ -public: - // bCanTick = false; - SWindow2() : SWindow() { -#if UE_VERSION_OLDER_THAN(4,21,0) - bCanTick = true; -#else - SetCanTick(true); -#endif - } - -public: - virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) { - SWindow::Tick(AllottedGeometry, InCurrentTime, InDeltaTime); - FTickableEditorObject::TickObjects(InDeltaTime); - //FAssetRegistryModule::TickAssetRegistry(-1.0f); - } - bool OnIsActiveChanged(const FWindowActivateEvent& ActivateEvent) { - bool r = SWindow::OnIsActiveChanged(ActivateEvent); -#if UE_VERSION_OLDER_THAN(4,21,0) - bCanTick = true; -#else - SetCanTick(true); -#endif - return r; - } -}; - -/* -UCLASS(config=EditorPerProjectUserSettings, AutoExpandCategories=(FTransform), HideCategories=Object, MinimalAPI) -class UFbxImportUI : public UObject, public IImportSettingsParser -{ -} - -*/ - - -namespace { - void RenameAsset(UObject* Asset, const FString& NewName, FText& ErrorMessage) - { - FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked("AssetTools"); - TArray AssetsAndNames; - const FString PackagePath = FPackageName::GetLongPackagePath(Asset->GetOutermost()->GetName()); - new(AssetsAndNames) FAssetRenameData(Asset, PackagePath, NewName); - AssetToolsModule.Get().RenameAssetsWithDialog(AssetsAndNames); - } -} - -UVRM4UImporterFactory::UVRM4UImporterFactory(const FObjectInitializer& ObjectInitializer) - : Super(ObjectInitializer) -{ - - TArray table = { - TEXT("vrm"), - TEXT("vrma"), - TEXT("glb"), - TEXT("bvh"), - }; - - const UVrmRuntimeSettings* Settings = GetDefault(); - for (auto& a : Settings->extList) { - table.AddUnique(a); - } - - if (Settings->bAllowAllAssimpFormat) { - TArray tmp = { - TEXT("pmx"), - TEXT("obj"), - TEXT("fbx"), - TEXT("dae"), - TEXT("gltf"), - }; - for (auto& a : tmp) { - table.AddUnique(a); - } - } - - for (auto &a : table) { - Formats.Add(a + TEXT(";Model VRM4U")); - } - - bCreateNew = false; - bEditorImport = true; - - ImportPriority = FMath::Max(1, Settings->ImportPriority); -} - - -bool UVRM4UImporterFactory::FactoryCanImport(const FString& Filename) -{ - fullFileName.Empty(); - - const FString Extension = FPaths::GetExtension(Filename); - bool allowAll = false; - - const UVrmRuntimeSettings* Settings = GetDefault(); - if (Settings) { - if (Settings->bAllowAllAssimpFormat) { - allowAll = true; - } - - for (auto& a : Settings->extList) { - if (Extension == a) { - allowAll = true; - } - } - } - - - //if( Extension == TEXT("vrm") || Extension == TEXT("gltf") || Extension == TEXT("glb")) - if(allowAll - || Extension == TEXT("vrm") - || Extension == TEXT("vrma") - || Extension == TEXT("glb") - || Extension == TEXT("bvh")) - { - fullFileName = Filename; - return true; - } - - return false; -} - -UClass* UVRM4UImporterFactory::ResolveSupportedClass() -{ - UClass* ImportClass = USkeletalMesh::StaticClass(); - - return ImportClass; -} - -/* -UObject* UVRMImporterFactory::FactoryCreateFile -( - UClass* Class, - UObject* InParent, - FName Name, - EObjectFlags Flags, - const FString& InFilename, - const TCHAR* Parms, - FFeedbackContext* Warn, - bool& bOutOperationCanceled -) -{ - return nullptr; -} -*/ - -UObject* UVRM4UImporterFactory::FactoryCreateBinary(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const uint8*& Buffer, const uint8* BufferEnd, FFeedbackContext* Warn, bool& bOutOperationCanceled) -{ - if (fullFileName.IsEmpty()) { - return nullptr; - } - - if (VRMConverter::Options::Get().IsDebugIgnoreVRMValidation() == false) { - if (ULoaderBPFunctionLibrary::IsValidVRM4UFile(fullFileName) == false) { - return nullptr; - } - } - - static UVrmImportUI* ImportUI = nullptr; -#if UE_VERSION_OLDER_THAN(5,0,0) - TAssetPtr refPointerToLic; -#else - TSoftObjectPtr refPointerToLic; -#endif - { - if (ImportUI == nullptr) { - ImportUI = NewObject(this, NAME_None, RF_NoFlags); - ImportUI->AddToRoot(); - } - - // to default - { - ImportUI->bRemoveRootBoneRotation = true; - ImportUI->bRemoveRootBonePosition = false; - ImportUI->bVrm10RemoveLocalRotation = false; - - ImportUI->ModelScale = 1.0f; - ImportUI->bMergeMaterial = true; - ImportUI->bMergePrimitive = false; - ImportUI->TitleAuthor.Empty(); - ImportUI->Thumbnail = nullptr; - - ImportUI->TitleAuthor.Empty(); - ImportUI->Thumbnail = nullptr; - ImportUI->allowedUserName.Empty(); - ImportUI->violentUsageName.Empty(); - ImportUI->sexualUsageName.Empty(); - ImportUI->commercialUsageName.Empty(); - ImportUI->otherPermissionUrl.Empty(); - ImportUI->licenseName.Empty(); - ImportUI->otherLicenseUrl.Empty(); - - ImportUI->LicenseString.Empty(); - ImportUI->LicenseBool.Empty(); - ImportUI->LicenseStringArray.Empty(); - } - - if (1) { - UVrmLicenseObject* a = nullptr; - UVrm1LicenseObject* b = nullptr; - ULoaderBPFunctionLibrary::GetVRMMeta(fullFileName, a, b); - if (a) { - ImportUI->TitleAuthor = TEXT("\"") + a->title + TEXT("\"") + TEXT(" / ") + TEXT("\"") + a->author + TEXT("\""); - ImportUI->Thumbnail = a->thumbnail; - ImportUI->allowedUserName = a->allowedUserName; - ImportUI->violentUsageName = a->violentUsageName; - ImportUI->sexualUsageName = a->sexualUsageName; - ImportUI->commercialUsageName = a->commercialUsageName; - ImportUI->otherPermissionUrl = a->otherPermissionUrl; - ImportUI->licenseName = a->licenseName; - ImportUI->otherLicenseUrl = a->otherLicenseUrl; - - refPointerToLic = a; - } - if (b) { - { - auto *p = b->LicenseString.FindByPredicate([](const FLicenseStringDataPair &pair) { - if (pair.key == TEXT("name")) return true; - return false; - }); - if (p) { - ImportUI->TitleAuthor = p->value; - } - } - ImportUI->Thumbnail = b->thumbnail; - ImportUI->LicenseString = b->LicenseString; - ImportUI->LicenseBool = b->LicenseBool; - ImportUI->LicenseStringArray = b->LicenseStringArray; - refPointerToLic = b; - } - { - const FString Extension = FPaths::GetExtension(fullFileName); - if (Extension.ToLower() == TEXT("pmx")) { - ImportUI->ModelScale = 0.1f; - ImportUI->bMergeMaterial = false; - ImportUI->bMergePrimitive = false; - ImportUI->bForceTwoSided = true; - } - if (Extension.ToLower() == TEXT("bvh")) { - ImportUI->ModelScale = 0.01f; - } - } -#if UE_VERSION_OLDER_THAN(5,2,0) - { - ImportUI->bSingleUAssetFile = true; - } -#else - // 5.2でも動くが、デフォルトをOFFにする -#endif - - -#if UE_VERSION_OLDER_THAN(5,0,0) -#else - // for thumbnail update - if (GEditor){ - auto* s = GEditor->GetEditorSubsystem(); - if (s && ImportUI->Thumbnail) { - s->OpenEditorForAsset(ImportUI->Thumbnail); - s->CloseAllEditorsForAsset(ImportUI->Thumbnail); - } - } -#endif - } - - - TSharedPtr ParentWindow; - - if (FModuleManager::Get().IsModuleLoaded("MainFrame")) - { - IMainFrameModule& MainFrame = FModuleManager::LoadModuleChecked("MainFrame"); - ParentWindow = MainFrame.GetParentWindow(); - } - - // Compute centered window position based on max window size, which include when all categories are expanded - const float FbxImportWindowWidth = 410.0f * 2.f; - const float FbxImportWindowHeight = 750.0f; - FVector2D FbxImportWindowSize = FVector2D(FbxImportWindowWidth, FbxImportWindowHeight); // Max window size it can get based on current slate - - - FSlateRect WorkAreaRect = FSlateApplicationBase::Get().GetPreferredWorkArea(); - FVector2D DisplayTopLeft(WorkAreaRect.Left, WorkAreaRect.Top); - FVector2D DisplaySize(WorkAreaRect.Right - WorkAreaRect.Left, WorkAreaRect.Bottom - WorkAreaRect.Top); - - float ScaleFactor = FPlatformApplicationMisc::GetDPIScaleFactorAtPoint(DisplayTopLeft.X, DisplayTopLeft.Y); - FbxImportWindowSize *= ScaleFactor; - - FVector2D WindowPosition = (DisplayTopLeft + (DisplaySize - FbxImportWindowSize) / 2.0f) / ScaleFactor; - - - TSharedRef Window = SNew(SWindow2) - .Title(NSLOCTEXT("UnrealEd", "VRMImportOpionsTitle", "VRM Import Options")) - .SizingRule(ESizingRule::Autosized) - .AutoCenter(EAutoCenter::None) - .ClientSize(FbxImportWindowSize) - .ScreenPosition(WindowPosition); - - TSharedPtr VrmOptionWindow; - Window->SetContent - ( - SAssignNew(VrmOptionWindow, SVrmOptionWindow) - .ImportUI(ImportUI) - .WidgetWindow(Window) - .FullPath(FText::FromString(fullFileName)) - //.ForcedImportType( bForceImportType ? TOptional( ImportType ) : TOptional() ) - //.IsObjFormat( bIsObjFormat ) - .MaxWindowHeight(FbxImportWindowHeight) - .MaxWindowWidth(FbxImportWindowWidth) - ); - - // @todo: we can make this slow as showing progress bar later - FSlateApplication::Get().AddModalWindow(Window, ParentWindow); - - if (VrmOptionWindow->ShouldImport() == false) { - bOutOperationCanceled = true; - - return nullptr; - } - - } - - //static ConstructorHelpers::FObjectFinder MatClass(TEXT("/Game/test/NewMaterial.NewMaterial")); - //static ConstructorHelpers::FObjectFinder MatClass(TEXT("Blueprint'/VRM4U/VrmObjectListBP.VrmObjectListBP_C'")); - //static ConstructorHelpers::FObjectFinder MatClass(TEXT("Blueprint'/VRM4U/VrmObjectListBP'")); - //static ConstructorHelpers::FObjectFinder MatClass(TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP")); - //UVrmAssetListObject *m = Cast(MatClass.Object); - - //UObject* objFinder = StaticLoadObject(UVrmAssetListObject::StaticClass(), nullptr, TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP_C")); - //UObject* objFinder = NewObject(InParent, NAME_None, RF_Transactional); - - auto& importOption = VRMConverter::Options::Get(); - importOption.SetVrmOption(ImportUI->GenerateOptionData()); - - -#if UE_VERSION_OLDER_THAN(5,0,0) - TAssetPtr vrmAssetList; - TArray< TAssetPtr > tt; -#else - TSoftObjectPtr vrmAssetList; - TArray< TSoftObjectPtr > tt; -#endif - tt.Add(InParent); - - //TRefCountPtr m; - //UVrmAssetListObject *m = nullptr; -#if UE_VERSION_OLDER_THAN(5,0,0) - TAssetPtr c; -#else - TSoftObjectPtr c; -#endif - { - const UVrmRuntimeSettings* Settings = GetDefault(); - - { - FSoftObjectPath r = Settings->AssetListObject; //(TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP")); - UObject *u = r.TryLoad(); - if (u) { - if (Cast(u)) { - c = (UClass*)(Cast(u)->GeneratedClass); - } - } - } - if (c == nullptr || VRMConverter::Options::Get().IsUE5Material()) { - FSoftObjectPath r(TEXT("/VRM4U/VrmAssetListObjectBPUE5.VrmAssetListObjectBPUE5")); - UObject *u = r.TryLoad(); - if (u) { - c = (UClass*)(Cast(u)->GeneratedClass); - } - } - if (c == nullptr){ - FSoftObjectPath r(TEXT("/VRM4U/VrmAssetListObjectBP.VrmAssetListObjectBP")); - UObject* u = r.TryLoad(); - if (u) { - c = (UClass*)(Cast(u)->GeneratedClass); - } - } - - if (c == nullptr) { - c = UVrmAssetListObject::StaticClass(); - } - - { - if (ReimportBase) { - vrmAssetList = ReimportBase; - VRMUtil::CloseEditorWindowByFolderPath(vrmAssetList.Get()); - } - if (vrmAssetList) { - vrmAssetList->MarkPackageDirty(); - }else{ - vrmAssetList = NewObject((UObject*)GetTransientPackage(), c.Get()); - } - } - - } - - //UVrmAssetListObject *m = Cast(u); - //FSoftClassPath r(TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP")); - //UObject *u = r.TryLoad(); - //auto aaa = NewObject(c); - - UVrmAssetListObject* mret = nullptr; - if (vrmAssetList) { - //auto a = NewObject(MatClass.Object, NAME_None, RF_Transactional); - //MatClass.Object; - //ULoaderBPFunctionLibrary::LoadVRMFile(nullptr, fullFileName); - - GWarn->BeginSlowTask( NSLOCTEXT("UnrealEd", "ImportVRM", "Importing VRM"), true ); - - int ret = true; - - ULoaderBPFunctionLibrary::SetImportMode(true, Cast(InParent)); - { - ret = ULoaderBPFunctionLibrary::LoadVRMFileLocal(vrmAssetList.Get(), mret, fullFileName); - } - - /* - { - const bool bCheckDirty = false; - const bool bPromptToSave = false; - TArray p; - p.Add(Cast(InParent)); - - p[0]->Modify(); - p[0]->PostEditChange(); - p[0]->FullyLoad(); - p[0]->AddToRoot(); - FEditorFileUtils::PromptForCheckoutAndSave(p, bCheckDirty, bPromptToSave); - - p[0]->SetDirtyFlag(false); - //p[0]->AddToRoot(); - - //p[0]->Rename(*(p[0]->GetName() + TEXT("aatest")), nullptr); - - //ContentBrowserUtils::RenameAsset(p[0], NewName, ErrorMessage); - FText ErrorMessage; - //RenameAsset(p[0], *(p[0]->GetName() + TEXT("aatest")), ErrorMessage); - RenameAsset(p[0], (TEXT("vrm_dummy_to_delete")), ErrorMessage); - - p[0]->Rename(nullptr, GetTransientPackage(), 0); - p[0]->RemoveFromRoot(); - - //FEditorFileUtils::PromptForCheckoutAndSave(p, bCheckDirty, bPromptToSave); - } - */ - - ULoaderBPFunctionLibrary::SetImportMode(false, nullptr); - importOption.SetVrmOption(nullptr); - -#if UE_VERSION_OLDER_THAN(4,22,0) -#else - if (GEditor) { - GEditor->GetEditorSubsystem()->BroadcastAssetPostImport(this, mret); - } -#endif - - - GWarn->EndSlowTask(); - - //bool bDeleteSucceeded = ObjectTools::DeleteSingleObject( ExistingObject ); - CollectGarbage( GARBAGE_COLLECTION_KEEPFLAGS ); - - if (ret == false) { - return nullptr; - } - } - //return InParent; - return mret;// ->GetOuter(); -} -UObject* UVRM4UImporterFactory::FactoryCreateText(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const TCHAR*& Buffer, const TCHAR* BufferEnd, FFeedbackContext* Warn) -{ - return nullptr; -} - -bool UVRM4UImporterFactory::CanReimport(UObject* Obj, TArray& OutFilenames) { - - UVrmAssetListObject* assetList= Cast(Obj); - TArray FactoryExtensions; - GetSupportedFileExtensions(FactoryExtensions); - - if (assetList) - { - if (UAssetImportData* AssetImportData = assetList->GetAssetImportData()) - { - AssetImportData->ExtractFilenames(OutFilenames); - return true; - } - else - { - OutFilenames.Add(TEXT("")); - } - return true; - } - return false; -} -void UVRM4UImporterFactory::SetReimportPaths(UObject* Obj, const TArray& NewReimportPaths) { - UVrmAssetListObject* assetList = Cast(Obj); - if (assetList && ensure(NewReimportPaths.Num() == 1)) - { - assetList->AssetImportData->UpdateFilenameOnly(NewReimportPaths[0]); - } -} -EReimportResult::Type UVRM4UImporterFactory::Reimport(UObject* Obj) { - - UVrmAssetListObject* asset = Cast(Obj); - if (asset == nullptr) - { - return EReimportResult::Failed; - } - if (asset->AssetImportData == nullptr) { - return EReimportResult::Failed; - } -#if UE_VERSION_OLDER_THAN(4,22,0) -#else - if (asset->AssetImportData->GetSourceFileCount() <= 0) { - return EReimportResult::Failed; - } -#endif - -#if UE_VERSION_OLDER_THAN(4,26,0) -#else - ReimportBase = asset; - asset->Package = asset->GetPackage(); - asset->ReimportBase = asset; -#endif - - { - FString str = asset->AssetImportData->GetSourceData().SourceFiles[0].RelativeFilename; - fullFileName = UAssetImportData::ResolveImportFilename(str, asset->Package); - } - - const uint8_t *buf_dummy = nullptr; - bool b_dummy = false; - - UObject* n = FactoryCreateBinary(nullptr, asset->Package, "name", (EObjectFlags)0, nullptr, nullptr, buf_dummy, buf_dummy, nullptr, b_dummy); - - ReimportBase = nullptr; - fullFileName = ""; - - if (n == nullptr) { - return EReimportResult::Failed; - } - return EReimportResult::Succeeded; -} -int32 UVRM4UImporterFactory::GetPriority() const { - return ImportPriority; -} - - -////////////////////////////////////////////////////////////////////////// - - - - - - -//// - -UVrmImportUI::UVrmImportUI(const FObjectInitializer& ObjectInitializer) - : Super(ObjectInitializer) -{ - bIsReimport = false; - //bAutomatedImportShouldDetectType = true; - //Make sure we are transactional to allow undo redo - this->SetFlags(RF_Transactional); - - /* - StaticMeshImportData = CreateDefaultSubobject(TEXT("StaticMeshImportData")); - StaticMeshImportData->SetFlags(RF_Transactional); - StaticMeshImportData->LoadOptions(); - - SkeletalMeshImportData = CreateDefaultSubobject(TEXT("SkeletalMeshImportData")); - SkeletalMeshImportData->SetFlags(RF_Transactional); - SkeletalMeshImportData->LoadOptions(); - - AnimSequenceImportData = CreateDefaultSubobject(TEXT("AnimSequenceImportData")); - AnimSequenceImportData->SetFlags(RF_Transactional); - AnimSequenceImportData->LoadOptions(); - - TextureImportData = CreateDefaultSubobject(TEXT("TextureImportData")); - TextureImportData->SetFlags(RF_Transactional); - TextureImportData->LoadOptions(); - */ -} - -void UVrmImportUI::ParseFromJson(TSharedRef ImportSettingsJson) -{ - /* - // Skip instanced object references. - int64 SkipFlags = CPF_InstancedReference; - FJsonObjectConverter::JsonObjectToUStruct(ImportSettingsJson, GetClass(), this, 0, SkipFlags); - - bAutomatedImportShouldDetectType = true; - if(ImportSettingsJson->TryGetField("MeshTypeToImport").IsValid()) - { - // Import type was specified by the user if MeshTypeToImport exists - bAutomatedImportShouldDetectType = false; - } - - const TSharedPtr* StaticMeshImportJson = nullptr; - ImportSettingsJson->TryGetObjectField(TEXT("StaticMeshImportData"), StaticMeshImportJson); - if(StaticMeshImportJson) - { - FJsonObjectConverter::JsonObjectToUStruct(StaticMeshImportJson->ToSharedRef(), StaticMeshImportData->GetClass(), StaticMeshImportData, 0, 0); - } - - const TSharedPtr* SkeletalMeshImportJson = nullptr; - ImportSettingsJson->TryGetObjectField(TEXT("SkeletalMeshImportData"), SkeletalMeshImportJson); - if (SkeletalMeshImportJson) - { - FJsonObjectConverter::JsonObjectToUStruct(SkeletalMeshImportJson->ToSharedRef(), SkeletalMeshImportData->GetClass(), SkeletalMeshImportData, 0, 0); - } - - const TSharedPtr* AnimImportJson = nullptr; - ImportSettingsJson->TryGetObjectField(TEXT("AnimSequenceImportData"), AnimImportJson); - if (AnimImportJson) - { - FJsonObjectConverter::JsonObjectToUStruct(AnimImportJson->ToSharedRef(), AnimSequenceImportData->GetClass(), AnimSequenceImportData, 0, 0); - } - - const TSharedPtr* TextureImportJson = nullptr; - ImportSettingsJson->TryGetObjectField(TEXT("TextureImportData"), TextureImportJson); - if (TextureImportJson) - { - FJsonObjectConverter::JsonObjectToUStruct(TextureImportJson->ToSharedRef(), TextureImportData->GetClass(), TextureImportData, 0, 0); - } - */ -} - -void UVrmImportUI::ResetToDefault() -{ - ReloadConfig(); -} - - - - - +// VRM4U Copyright (c) 2021-2024 Haruyoshi Yamamoto. This software is released under the MIT License. + +#include "VRM4UImporterFactory.h" +#include "VRM4UImporterLog.h" + +#include "Misc/EngineVersionComparison.h" + +#include "AssetToolsModule.h" +#if UE_VERSION_OLDER_THAN(4,26,0) +#include "AssetRegistryModule.h" +#else +#include "AssetRegistry/AssetRegistryModule.h" +#endif +#include "PackageTools.h" +#include "Misc/Paths.h" +#include "Engine/SkeletalMesh.h" +#include "EditorFramework/AssetImportData.h" +#include "Components/SkeletalMeshComponent.h" +//#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h" +#include "UObject/ConstructorHelpers.h" +#include "LoaderBPFunctionLibrary.h" +#include "VrmAssetListObject.h" +#include "VrmRuntimeSettings.h" +#include "VrmOptionWindow.h" +#include "Engine/Blueprint.h" +#include "Templates/SharedPointer.h" +#include "Misc/FeedbackContext.h" +#include "FileHelpers.h" +#include "TickableEditorObject.h" + +#include "Interfaces/IMainFrameModule.h" +#include "Widgets/SWindow.h" +#include "Framework/Application/SlateApplication.h" +#include "HAL/PlatformApplicationMisc.h" +#include "VrmOptionWindow.h" +#include "VrmImportUI.h" +#include "VrmConvert.h" +#include "VrmLicenseObject.h" +#include "Vrm1LicenseObject.h" + +#define LOCTEXT_NAMESPACE "VRMImporter" + +// for tick Editor Object +class SWindow2 : public SWindow{ +public: + // bCanTick = false; + SWindow2() : SWindow() { +#if UE_VERSION_OLDER_THAN(4,21,0) + bCanTick = true; +#else + SetCanTick(true); +#endif + } + +public: + virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) { + SWindow::Tick(AllottedGeometry, InCurrentTime, InDeltaTime); + FTickableEditorObject::TickObjects(InDeltaTime); + //FAssetRegistryModule::TickAssetRegistry(-1.0f); + } + bool OnIsActiveChanged(const FWindowActivateEvent& ActivateEvent) { + bool r = SWindow::OnIsActiveChanged(ActivateEvent); +#if UE_VERSION_OLDER_THAN(4,21,0) + bCanTick = true; +#else + SetCanTick(true); +#endif + return r; + } +}; + +/* +UCLASS(config=EditorPerProjectUserSettings, AutoExpandCategories=(FTransform), HideCategories=Object, MinimalAPI) +class UFbxImportUI : public UObject, public IImportSettingsParser +{ +} + +*/ + + +namespace { + void RenameAsset(UObject* Asset, const FString& NewName, FText& ErrorMessage) + { + FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked("AssetTools"); + TArray AssetsAndNames; + const FString PackagePath = FPackageName::GetLongPackagePath(Asset->GetOutermost()->GetName()); + new(AssetsAndNames) FAssetRenameData(Asset, PackagePath, NewName); + AssetToolsModule.Get().RenameAssetsWithDialog(AssetsAndNames); + } +} + +UVRM4UImporterFactory::UVRM4UImporterFactory(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + + TArray table = { + TEXT("vrm"), + TEXT("vrma"), + TEXT("glb"), + TEXT("bvh"), + }; + + const UVrmRuntimeSettings* Settings = GetDefault(); + for (auto& a : Settings->extList) { + table.AddUnique(a); + } + + if (Settings->bAllowAllAssimpFormat) { + TArray tmp = { + TEXT("pmx"), + TEXT("obj"), + TEXT("fbx"), + TEXT("dae"), + TEXT("gltf"), + }; + for (auto& a : tmp) { + table.AddUnique(a); + } + } + + for (auto &a : table) { + Formats.Add(a + TEXT(";Model VRM4U")); + } + + bCreateNew = false; + bEditorImport = true; + + ImportPriority = FMath::Max(1, Settings->ImportPriority); +} + + +bool UVRM4UImporterFactory::FactoryCanImport(const FString& Filename) +{ + fullFileName.Empty(); + + const FString Extension = FPaths::GetExtension(Filename); + bool allowAll = false; + + const UVrmRuntimeSettings* Settings = GetDefault(); + if (Settings) { + if (Settings->bAllowAllAssimpFormat) { + allowAll = true; + } + + for (auto& a : Settings->extList) { + if (Extension == a) { + allowAll = true; + } + } + } + + + //if( Extension == TEXT("vrm") || Extension == TEXT("gltf") || Extension == TEXT("glb")) + if(allowAll + || Extension == TEXT("vrm") + || Extension == TEXT("vrma") + || Extension == TEXT("glb") + || Extension == TEXT("bvh")) + { + fullFileName = Filename; + return true; + } + + return false; +} + +UClass* UVRM4UImporterFactory::ResolveSupportedClass() +{ + UClass* ImportClass = USkeletalMesh::StaticClass(); + + return ImportClass; +} + +/* +UObject* UVRMImporterFactory::FactoryCreateFile +( + UClass* Class, + UObject* InParent, + FName Name, + EObjectFlags Flags, + const FString& InFilename, + const TCHAR* Parms, + FFeedbackContext* Warn, + bool& bOutOperationCanceled +) +{ + return nullptr; +} +*/ + +UObject* UVRM4UImporterFactory::FactoryCreateBinary(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const uint8*& Buffer, const uint8* BufferEnd, FFeedbackContext* Warn, bool& bOutOperationCanceled) +{ + if (fullFileName.IsEmpty()) { + return nullptr; + } + + if (VRMConverter::Options::Get().IsDebugIgnoreVRMValidation() == false) { + if (ULoaderBPFunctionLibrary::IsValidVRM4UFile(fullFileName) == false) { + return nullptr; + } + } + + static UVrmImportUI* ImportUI = nullptr; +#if UE_VERSION_OLDER_THAN(5,0,0) + TAssetPtr refPointerToLic; +#else + TSoftObjectPtr refPointerToLic; +#endif + { + if (ImportUI == nullptr) { + ImportUI = NewObject(this, NAME_None, RF_NoFlags); + ImportUI->AddToRoot(); + } + + // to default + { + ImportUI->bRemoveRootBoneRotation = true; + ImportUI->bRemoveRootBonePosition = false; + ImportUI->bVrm10RemoveLocalRotation = false; + + ImportUI->ModelScale = 1.0f; + ImportUI->bMergeMaterial = true; + ImportUI->bMergePrimitive = false; + ImportUI->TitleAuthor.Empty(); + ImportUI->Thumbnail = nullptr; + + ImportUI->TitleAuthor.Empty(); + ImportUI->Thumbnail = nullptr; + ImportUI->allowedUserName.Empty(); + ImportUI->violentUsageName.Empty(); + ImportUI->sexualUsageName.Empty(); + ImportUI->commercialUsageName.Empty(); + ImportUI->otherPermissionUrl.Empty(); + ImportUI->licenseName.Empty(); + ImportUI->otherLicenseUrl.Empty(); + + ImportUI->LicenseString.Empty(); + ImportUI->LicenseBool.Empty(); + ImportUI->LicenseStringArray.Empty(); + } + + if (1) { + UVrmLicenseObject* a = nullptr; + UVrm1LicenseObject* b = nullptr; + ULoaderBPFunctionLibrary::GetVRMMeta(fullFileName, a, b); + if (a) { + ImportUI->TitleAuthor = TEXT("\"") + a->title + TEXT("\"") + TEXT(" / ") + TEXT("\"") + a->author + TEXT("\""); + ImportUI->Thumbnail = a->thumbnail; + ImportUI->allowedUserName = a->allowedUserName; + ImportUI->violentUsageName = a->violentUsageName; + ImportUI->sexualUsageName = a->sexualUsageName; + ImportUI->commercialUsageName = a->commercialUsageName; + ImportUI->otherPermissionUrl = a->otherPermissionUrl; + ImportUI->licenseName = a->licenseName; + ImportUI->otherLicenseUrl = a->otherLicenseUrl; + + refPointerToLic = a; + } + if (b) { + { + auto *p = b->LicenseString.FindByPredicate([](const FLicenseStringDataPair &pair) { + if (pair.key == TEXT("name")) return true; + return false; + }); + if (p) { + ImportUI->TitleAuthor = p->value; + } + } + ImportUI->Thumbnail = b->thumbnail; + ImportUI->LicenseString = b->LicenseString; + ImportUI->LicenseBool = b->LicenseBool; + ImportUI->LicenseStringArray = b->LicenseStringArray; + refPointerToLic = b; + } + { + const FString Extension = FPaths::GetExtension(fullFileName); + if (Extension.ToLower() == TEXT("pmx")) { + ImportUI->ModelScale = 0.1f; + ImportUI->bMergeMaterial = false; + ImportUI->bMergePrimitive = false; + ImportUI->bForceTwoSided = true; + } + if (Extension.ToLower() == TEXT("bvh")) { + ImportUI->ModelScale = 0.01f; + } + } +#if UE_VERSION_OLDER_THAN(5,2,0) + { + ImportUI->bSingleUAssetFile = true; + } +#else + // 5.2縺ァ繧ょ虚縺上′縲√ョ繝輔か繝ォ繝医rOFF縺ォ縺吶k +#endif + + +#if UE_VERSION_OLDER_THAN(5,0,0) +#else + // for thumbnail update + if (GEditor){ + auto* s = GEditor->GetEditorSubsystem(); + if (s && ImportUI->Thumbnail) { + s->OpenEditorForAsset((UObject*)ImportUI->Thumbnail); + s->CloseAllEditorsForAsset((UObject*)ImportUI->Thumbnail); + } + } +#endif + } + + + TSharedPtr ParentWindow; + + if (FModuleManager::Get().IsModuleLoaded("MainFrame")) + { + IMainFrameModule& MainFrame = FModuleManager::LoadModuleChecked("MainFrame"); + ParentWindow = MainFrame.GetParentWindow(); + } + + // Compute centered window position based on max window size, which include when all categories are expanded + const float FbxImportWindowWidth = 410.0f * 2.f; + const float FbxImportWindowHeight = 750.0f; + FVector2D FbxImportWindowSize = FVector2D(FbxImportWindowWidth, FbxImportWindowHeight); // Max window size it can get based on current slate + + + FSlateRect WorkAreaRect = FSlateApplicationBase::Get().GetPreferredWorkArea(); + FVector2D DisplayTopLeft(WorkAreaRect.Left, WorkAreaRect.Top); + FVector2D DisplaySize(WorkAreaRect.Right - WorkAreaRect.Left, WorkAreaRect.Bottom - WorkAreaRect.Top); + + float ScaleFactor = FPlatformApplicationMisc::GetDPIScaleFactorAtPoint(DisplayTopLeft.X, DisplayTopLeft.Y); + FbxImportWindowSize *= ScaleFactor; + + FVector2D WindowPosition = (DisplayTopLeft + (DisplaySize - FbxImportWindowSize) / 2.0f) / ScaleFactor; + + + TSharedRef Window = SNew(SWindow2) + .Title(NSLOCTEXT("UnrealEd", "VRMImportOpionsTitle", "VRM Import Options")) + .SizingRule(ESizingRule::Autosized) + .AutoCenter(EAutoCenter::None) + .ClientSize(FbxImportWindowSize) + .ScreenPosition(WindowPosition); + + TSharedPtr VrmOptionWindow; + Window->SetContent + ( + SAssignNew(VrmOptionWindow, SVrmOptionWindow) + .ImportUI(ImportUI) + .WidgetWindow(Window) + .FullPath(FText::FromString(fullFileName)) + //.ForcedImportType( bForceImportType ? TOptional( ImportType ) : TOptional() ) + //.IsObjFormat( bIsObjFormat ) + .MaxWindowHeight(FbxImportWindowHeight) + .MaxWindowWidth(FbxImportWindowWidth) + ); + + // @todo: we can make this slow as showing progress bar later + FSlateApplication::Get().AddModalWindow(Window, ParentWindow); + + if (VrmOptionWindow->ShouldImport() == false) { + bOutOperationCanceled = true; + + return nullptr; + } + + } + + //static ConstructorHelpers::FObjectFinder MatClass(TEXT("/Game/test/NewMaterial.NewMaterial")); + //static ConstructorHelpers::FObjectFinder MatClass(TEXT("Blueprint'/VRM4U/VrmObjectListBP.VrmObjectListBP_C'")); + //static ConstructorHelpers::FObjectFinder MatClass(TEXT("Blueprint'/VRM4U/VrmObjectListBP'")); + //static ConstructorHelpers::FObjectFinder MatClass(TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP")); + //UVrmAssetListObject *m = Cast(MatClass.Object); + + //UObject* objFinder = StaticLoadObject(UVrmAssetListObject::StaticClass(), nullptr, TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP_C")); + //UObject* objFinder = NewObject(InParent, NAME_None, RF_Transactional); + + auto& importOption = VRMConverter::Options::Get(); + importOption.SetVrmOption(ImportUI->GenerateOptionData()); + + +#if UE_VERSION_OLDER_THAN(5,0,0) + TAssetPtr vrmAssetList; + TArray< TAssetPtr > tt; +#else + TSoftObjectPtr vrmAssetList; + TArray< TSoftObjectPtr > tt; +#endif + tt.Add(InParent); + + //TRefCountPtr m; + //UVrmAssetListObject *m = nullptr; +#if UE_VERSION_OLDER_THAN(5,0,0) + TAssetPtr c; +#else + TSoftObjectPtr c; +#endif + { + const UVrmRuntimeSettings* Settings = GetDefault(); + + { + FSoftObjectPath r = Settings->AssetListObject; //(TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP")); + UObject *u = r.TryLoad(); + if (u) { + if (Cast(u)) { + c = (UClass*)(Cast(u)->GeneratedClass); + } + } + } + if (c == nullptr || VRMConverter::Options::Get().IsUE5Material()) { + FSoftObjectPath r(TEXT("/VRM4U/VrmAssetListObjectBPUE5.VrmAssetListObjectBPUE5")); + UObject *u = r.TryLoad(); + if (u) { + c = (UClass*)(Cast(u)->GeneratedClass); + } + } + if (c == nullptr){ + FSoftObjectPath r(TEXT("/VRM4U/VrmAssetListObjectBP.VrmAssetListObjectBP")); + UObject* u = r.TryLoad(); + if (u) { + c = (UClass*)(Cast(u)->GeneratedClass); + } + } + + if (c == nullptr) { + c = UVrmAssetListObject::StaticClass(); + } + + { + if (ReimportBase) { + vrmAssetList = ReimportBase; + VRMUtil::CloseEditorWindowByFolderPath(vrmAssetList.Get()); + } + if (vrmAssetList) { + vrmAssetList->MarkPackageDirty(); + }else{ + vrmAssetList = NewObject((UObject*)GetTransientPackage(), c.Get()); + } + } + + } + + //UVrmAssetListObject *m = Cast(u); + //FSoftClassPath r(TEXT("/VRM4U/VrmObjectListBP.VrmObjectListBP")); + //UObject *u = r.TryLoad(); + //auto aaa = NewObject(c); + + UVrmAssetListObject* mret = nullptr; + if (vrmAssetList) { + //auto a = NewObject(MatClass.Object, NAME_None, RF_Transactional); + //MatClass.Object; + //ULoaderBPFunctionLibrary::LoadVRMFile(nullptr, fullFileName); + + GWarn->BeginSlowTask( NSLOCTEXT("UnrealEd", "ImportVRM", "Importing VRM"), true ); + + int ret = true; + + ULoaderBPFunctionLibrary::SetImportMode(true, Cast(InParent)); + { + ret = ULoaderBPFunctionLibrary::LoadVRMFileLocal(vrmAssetList.Get(), mret, fullFileName); + } + + /* + { + const bool bCheckDirty = false; + const bool bPromptToSave = false; + TArray p; + p.Add(Cast(InParent)); + + p[0]->Modify(); + p[0]->PostEditChange(); + p[0]->FullyLoad(); + p[0]->AddToRoot(); + FEditorFileUtils::PromptForCheckoutAndSave(p, bCheckDirty, bPromptToSave); + + p[0]->SetDirtyFlag(false); + //p[0]->AddToRoot(); + + //p[0]->Rename(*(p[0]->GetName() + TEXT("aatest")), nullptr); + + //ContentBrowserUtils::RenameAsset(p[0], NewName, ErrorMessage); + FText ErrorMessage; + //RenameAsset(p[0], *(p[0]->GetName() + TEXT("aatest")), ErrorMessage); + RenameAsset(p[0], (TEXT("vrm_dummy_to_delete")), ErrorMessage); + + p[0]->Rename(nullptr, GetTransientPackage(), 0); + p[0]->RemoveFromRoot(); + + //FEditorFileUtils::PromptForCheckoutAndSave(p, bCheckDirty, bPromptToSave); + } + */ + + ULoaderBPFunctionLibrary::SetImportMode(false, nullptr); + importOption.SetVrmOption(nullptr); + +#if UE_VERSION_OLDER_THAN(4,22,0) +#else + if (GEditor) { + GEditor->GetEditorSubsystem()->BroadcastAssetPostImport(this, mret); + } +#endif + + + GWarn->EndSlowTask(); + + //bool bDeleteSucceeded = ObjectTools::DeleteSingleObject( ExistingObject ); + CollectGarbage( GARBAGE_COLLECTION_KEEPFLAGS ); + + if (ret == false) { + return nullptr; + } + } + //return InParent; + return mret;// ->GetOuter(); +} +UObject* UVRM4UImporterFactory::FactoryCreateText(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const TCHAR*& Buffer, const TCHAR* BufferEnd, FFeedbackContext* Warn) +{ + return nullptr; +} + +bool UVRM4UImporterFactory::CanReimport(UObject* Obj, TArray& OutFilenames) { + + UVrmAssetListObject* assetList= Cast(Obj); + TArray FactoryExtensions; + GetSupportedFileExtensions(FactoryExtensions); + + if (assetList) + { + if (UAssetImportData* AssetImportData = assetList->GetAssetImportData()) + { + AssetImportData->ExtractFilenames(OutFilenames); + return true; + } + else + { + OutFilenames.Add(TEXT("")); + } + return true; + } + return false; +} +void UVRM4UImporterFactory::SetReimportPaths(UObject* Obj, const TArray& NewReimportPaths) { + UVrmAssetListObject* assetList = Cast(Obj); + if (assetList && ensure(NewReimportPaths.Num() == 1)) + { + assetList->AssetImportData->UpdateFilenameOnly(NewReimportPaths[0]); + } +} +EReimportResult::Type UVRM4UImporterFactory::Reimport(UObject* Obj) { + + UVrmAssetListObject* asset = Cast(Obj); + if (asset == nullptr) + { + return EReimportResult::Failed; + } + if (asset->AssetImportData == nullptr) { + return EReimportResult::Failed; + } +#if UE_VERSION_OLDER_THAN(4,22,0) +#else + if (asset->AssetImportData->GetSourceFileCount() <= 0) { + return EReimportResult::Failed; + } +#endif + +#if UE_VERSION_OLDER_THAN(4,26,0) +#else + ReimportBase = asset; + asset->Package = asset->GetPackage(); + asset->ReimportBase = asset; +#endif + + { + FString str = asset->AssetImportData->GetSourceData().SourceFiles[0].RelativeFilename; + fullFileName = UAssetImportData::ResolveImportFilename(str, asset->Package); + } + + const uint8_t *buf_dummy = nullptr; + bool b_dummy = false; + + UObject* n = FactoryCreateBinary(nullptr, asset->Package, "name", (EObjectFlags)0, nullptr, nullptr, buf_dummy, buf_dummy, nullptr, b_dummy); + + ReimportBase = nullptr; + fullFileName = ""; + + if (n == nullptr) { + return EReimportResult::Failed; + } + return EReimportResult::Succeeded; +} +int32 UVRM4UImporterFactory::GetPriority() const { + return ImportPriority; +} + + +////////////////////////////////////////////////////////////////////////// + + + + + + +//// + +UVrmImportUI::UVrmImportUI(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + bIsReimport = false; + //bAutomatedImportShouldDetectType = true; + //Make sure we are transactional to allow undo redo + this->SetFlags(RF_Transactional); + + /* + StaticMeshImportData = CreateDefaultSubobject(TEXT("StaticMeshImportData")); + StaticMeshImportData->SetFlags(RF_Transactional); + StaticMeshImportData->LoadOptions(); + + SkeletalMeshImportData = CreateDefaultSubobject(TEXT("SkeletalMeshImportData")); + SkeletalMeshImportData->SetFlags(RF_Transactional); + SkeletalMeshImportData->LoadOptions(); + + AnimSequenceImportData = CreateDefaultSubobject(TEXT("AnimSequenceImportData")); + AnimSequenceImportData->SetFlags(RF_Transactional); + AnimSequenceImportData->LoadOptions(); + + TextureImportData = CreateDefaultSubobject(TEXT("TextureImportData")); + TextureImportData->SetFlags(RF_Transactional); + TextureImportData->LoadOptions(); + */ +} + +void UVrmImportUI::ParseFromJson(TSharedRef ImportSettingsJson) +{ + /* + // Skip instanced object references. + int64 SkipFlags = CPF_InstancedReference; + FJsonObjectConverter::JsonObjectToUStruct(ImportSettingsJson, GetClass(), this, 0, SkipFlags); + + bAutomatedImportShouldDetectType = true; + if(ImportSettingsJson->TryGetField("MeshTypeToImport").IsValid()) + { + // Import type was specified by the user if MeshTypeToImport exists + bAutomatedImportShouldDetectType = false; + } + + const TSharedPtr* StaticMeshImportJson = nullptr; + ImportSettingsJson->TryGetObjectField(TEXT("StaticMeshImportData"), StaticMeshImportJson); + if(StaticMeshImportJson) + { + FJsonObjectConverter::JsonObjectToUStruct(StaticMeshImportJson->ToSharedRef(), StaticMeshImportData->GetClass(), StaticMeshImportData, 0, 0); + } + + const TSharedPtr* SkeletalMeshImportJson = nullptr; + ImportSettingsJson->TryGetObjectField(TEXT("SkeletalMeshImportData"), SkeletalMeshImportJson); + if (SkeletalMeshImportJson) + { + FJsonObjectConverter::JsonObjectToUStruct(SkeletalMeshImportJson->ToSharedRef(), SkeletalMeshImportData->GetClass(), SkeletalMeshImportData, 0, 0); + } + + const TSharedPtr* AnimImportJson = nullptr; + ImportSettingsJson->TryGetObjectField(TEXT("AnimSequenceImportData"), AnimImportJson); + if (AnimImportJson) + { + FJsonObjectConverter::JsonObjectToUStruct(AnimImportJson->ToSharedRef(), AnimSequenceImportData->GetClass(), AnimSequenceImportData, 0, 0); + } + + const TSharedPtr* TextureImportJson = nullptr; + ImportSettingsJson->TryGetObjectField(TEXT("TextureImportData"), TextureImportJson); + if (TextureImportJson) + { + FJsonObjectConverter::JsonObjectToUStruct(TextureImportJson->ToSharedRef(), TextureImportData->GetClass(), TextureImportData, 0, 0); + } + */ +} + +void UVrmImportUI::ResetToDefault() +{ + ReloadConfig(); +} + + + + + #undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/Source/VRM4ULoader/Private/VrmConvertTexture.cpp b/Source/VRM4ULoader/Private/VrmConvertTexture.cpp index c32a9a55..2c62fd26 100644 --- a/Source/VRM4ULoader/Private/VrmConvertTexture.cpp +++ b/Source/VRM4ULoader/Private/VrmConvertTexture.cpp @@ -22,6 +22,10 @@ #include "Misc/FileHelper.h" #include "Misc/Paths.h" +#if UE_VERSION_NEWER_THAN(5,6,-1) +#include "MaterialShared.h" +#endif + #if WITH_EDITOR #include "Factories.h" #include "Factories/TextureFactory.h" @@ -468,6 +472,10 @@ namespace { LocalTextureSet(dm, TEXT("mtoon_tex_MainTex"), vrmAssetList->Textures[n]); LocalTextureSet(dm, TEXT("gltf_tex_diffuse"), vrmAssetList->Textures[n]); LocalTextureSet(dm, TEXT("mtoon_tex_Shade"), vrmAssetList->Textures[n]); + // Mooa VRM + LocalTextureSet(dm, TEXT("Base Color Map"), vrmAssetList->Textures[n]); + LocalTextureSet(dm, TEXT("Shadow Color Map"), vrmAssetList->Textures[n]); + // Mooa End } } @@ -763,7 +771,7 @@ bool VRMConverter::ConvertTextureAndMaterial(UVrmAssetListObject *vrmAssetList) #endif if (NormalBoolTable[i]) { - // UE5.5でクラッシュするので update後に再度更新 + // UE5.5縺ァ繧ッ繝ゥ繝繧キ繝・縺吶k縺ョ縺ァ update蠕後↓蜀榊コヲ譖エ譁ー NewTexture2D->CompressionSettings = TC_Normalmap; NewTexture2D->UpdateResource(); #if WITH_EDITOR @@ -861,7 +869,7 @@ bool VRMConverter::ConvertTextureAndMaterial(UVrmAssetListObject *vrmAssetList) LocalSetOriginalVrmMaterial(true); } - if (Options::Get().GetMaterialType() == EVRMImportMaterialType::VRMIMT_Auto) { + if (Options::Get().GetMaterialType() == EVRMImportMaterialType::VRMIMT_Auto && false) { // Mooa VRM // default unlit MaterialType = EVRMImportMaterialType::VRMIMT_Unlit; @@ -919,6 +927,11 @@ bool VRMConverter::ConvertTextureAndMaterial(UVrmAssetListObject *vrmAssetList) bMToon = false; break; case EVRMImportMaterialType::VRMIMT_Auto: + // Mooa VRM + mset = vrmAssetList->MooaToonSet; + bMToon = false; + break; + // Mooa End default: break; } @@ -1232,27 +1245,36 @@ bool VRMConverter::ConvertTextureAndMaterial(UVrmAssetListObject *vrmAssetList) } } else { // gltf texture - TArray materialParamName; - materialParamName.SetNum(AI_TEXTURE_TYPE_MAX); - materialParamName[aiTextureType::aiTextureType_DIFFUSE] = TEXT("gltf_tex_diffuse"); - materialParamName[aiTextureType::aiTextureType_NORMALS] = TEXT("gltf_tex_normal"); - materialParamName[aiTextureType::aiTextureType_EMISSIVE] = TEXT("gltf_tex_Emission"); - - materialParamName[aiTextureType::aiTextureType_BASE_COLOR] = TEXT("gltf_tex_diffuse"); - materialParamName[aiTextureType::aiTextureType_EMISSION_COLOR] = TEXT("gltf_tex_Emission"); - materialParamName[aiTextureType::aiTextureType_METALNESS] = TEXT("gltf_tex_metalness"); - materialParamName[aiTextureType::aiTextureType_DIFFUSE_ROUGHNESS] = TEXT("gltf_tex_roughness"); + // Mooa VRM + TArray> materialParamNames; + materialParamNames.SetNum(AI_TEXTURE_TYPE_MAX); + materialParamNames[aiTextureType::aiTextureType_DIFFUSE] = { TEXT("gltf_tex_diffuse"), TEXT("Base Color Map"), TEXT("Shadow Color Map") }; + materialParamNames[aiTextureType::aiTextureType_NORMALS] = { TEXT("gltf_tex_normal"), TEXT("Normal Map") }; + materialParamNames[aiTextureType::aiTextureType_AMBIENT_OCCLUSION] = { TEXT("AO Map") }; + materialParamNames[aiTextureType::aiTextureType_EMISSIVE] = { TEXT("gltf_tex_Emission"), TEXT("Emissive Map") }; + + materialParamNames[aiTextureType::aiTextureType_BASE_COLOR] = { TEXT("gltf_tex_diffuse"), TEXT("Base Color Map"), TEXT("Shadow Color Map") }; + materialParamNames[aiTextureType::aiTextureType_EMISSION_COLOR] = { TEXT("gltf_tex_Emission"), TEXT("Emissive Map") }; + materialParamNames[aiTextureType::aiTextureType_METALNESS] = { TEXT("gltf_tex_metalness") }; + materialParamNames[aiTextureType::aiTextureType_DIFFUSE_ROUGHNESS] = { TEXT("gltf_tex_roughness") }; for (uint32_t t = 0; t < AI_TEXTURE_TYPE_MAX; ++t) { - if (materialParamName[t] == "") continue; - int index = TextureTypeToIndex[t]; if (index < 0) continue; if (vrmAssetList->Textures.IsValidIndex(index) == false) continue; if (IsValid(vrmAssetList->Textures[index]) == false) continue; - LocalTextureSet(dm, *(materialParamName[t]), vrmAssetList->Textures[index]); + for (auto MaterialParamName : materialParamNames[t]) + { + if (false) {} + else if (t == aiTextureType::aiTextureType_EMISSIVE || t == aiTextureType::aiTextureType_EMISSION_COLOR) + { + LocalScalarParameterSet(dm, TEXT("Emissive Intensity"), 1.f); + } + LocalTextureSet(dm, *(MaterialParamName), vrmAssetList->Textures[index]); + } } + // Mooa End } LocalMaterialFinishParam(dm);