Skip to content

Commit

Permalink
Improvements to help Genesis 8.1 support
Browse files Browse the repository at this point in the history
Improvements to help Genesis 8.1 support
PBRSkin Material for Genesis 8.1
Includes some code for the new Pose transfer feature.
  • Loading branch information
David-Vodhanel committed Jan 21, 2021
1 parent a51b779 commit bb6f6fc
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 38 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "DazToUnrealUtils.h"
#include "DazToUnrealFbx.h"
#include "DazToUnrealEnvironment.h"
#include "DazToUnrealPoses.h"

#include "LevelEditor.h"
#include "Widgets/Docking/SDockTab.h"
Expand Down Expand Up @@ -325,6 +326,8 @@ UObject* FDazToUnrealModule::ImportFromDaz(TSharedPtr<FJsonObject> JsonObject)
AssetType = DazAssetType::Animation;
else if (JsonObject->GetStringField(TEXT("Asset Type")) == TEXT("Environment"))
AssetType = DazAssetType::Environment;
else if (JsonObject->GetStringField(TEXT("Asset Type")) == TEXT("Pose"))
AssetType = DazAssetType::Pose;

// Set up the folder paths
FString ImportDirectory = FPaths::ProjectDir() / TEXT("Import");
Expand Down Expand Up @@ -357,14 +360,14 @@ UObject* FDazToUnrealModule::ImportFromDaz(TSharedPtr<FJsonObject> JsonObject)
FString LocalCharacterMaterialFolder = CharacterMaterialFolder.Replace(TEXT("/Game/"), *ContentDirectory);

// Make any needed folders. If any of these fail, don't continue
if (!MakeDirectoryAndCheck(ImportDirectory)) return false;
if (!MakeDirectoryAndCheck(ImportCharacterFolder)) return false;
if (!MakeDirectoryAndCheck(ImportCharacterTexturesFolder)) return false;
if (!MakeDirectoryAndCheck(LocalDAZImportFolder)) return false;
if (!MakeDirectoryAndCheck(LocalDAZAnimationImportFolder)) return false;
if (!MakeDirectoryAndCheck(LocalCharacterFolder)) return false;
if (!MakeDirectoryAndCheck(LocalCharacterTexturesFolder)) return false;
if (!MakeDirectoryAndCheck(LocalCharacterMaterialFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(ImportDirectory)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(ImportCharacterFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(ImportCharacterTexturesFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(LocalDAZImportFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(LocalDAZAnimationImportFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(LocalCharacterFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(LocalCharacterTexturesFolder)) return false;
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(LocalCharacterMaterialFolder)) return false;

if (AssetType == DazAssetType::Environment)
{
Expand Down Expand Up @@ -477,6 +480,20 @@ UObject* FDazToUnrealModule::ImportFromDaz(TSharedPtr<FJsonObject> JsonObject)
{
Property.Type = TEXT("Color");
}

// Properties that end with Enabled are switches for functionality
if (Property.Name.EndsWith(TEXT(" Enable")))
{
Property.Type = TEXT("Switch");
if (Property.Value == TEXT("0"))
{
Property.Value = TEXT("false");
}
else
{
Property.Value = TEXT("true");
}
}

MaterialProperties[MaterialName].Add(Property);
if (!TextureName.IsEmpty())
Expand Down Expand Up @@ -1017,6 +1034,22 @@ UObject* FDazToUnrealModule::ImportFromDaz(TSharedPtr<FJsonObject> JsonObject)
MorphMappings.Add(MorphName, MorphLabel);
}

// Get a list of morph name mappings
TArray<FString> PoseNameList;
const TArray<TSharedPtr<FJsonValue>>* PoseList;
if (JsonObject->TryGetArrayField(TEXT("Poses"), PoseList))
{
PoseNameList.Add(TEXT("ReferencePose"));
for (int32 i = 0; i < PoseList->Num(); i++)
{
TSharedPtr<FJsonObject> Pose = (*PoseList)[i]->AsObject();
FString PoseName = Pose->GetStringField(TEXT("Name"));
FString PoseLabel = Pose->GetStringField(TEXT("Label"));

PoseNameList.Add(PoseLabel);
}
}

// Combine clothing and body morphs
for (int NodeIndex = 0; NodeIndex < Scene->GetNodeCount(); ++NodeIndex)
{
Expand Down Expand Up @@ -1153,23 +1186,23 @@ UObject* FDazToUnrealModule::ImportFromDaz(TSharedPtr<FJsonObject> JsonObject)
// If this is a character, determine the type.
DazCharacterType CharacterType = DazCharacterType::Unknown;
FString CharacterTypeName = RootBoneName.Replace(TEXT("\0"), TEXT(""));
if (RootBoneName.Contains(TEXT("Genesis3Male")))
if (RootBoneName == TEXT("Genesis3Male"))
{
CharacterType = DazCharacterType::Genesis3Male;
}
else if (RootBoneName.Contains(TEXT("Genesis3Female")))
else if (RootBoneName == TEXT("Genesis3Female"))
{
CharacterType = DazCharacterType::Genesis3Female;
}
else if (RootBoneName.Contains(TEXT("Genesis8Male")))
else if (RootBoneName == TEXT("Genesis8Male"))
{
CharacterType = DazCharacterType::Genesis8Male;
}
else if (RootBoneName.Contains(TEXT("Genesis8Female")))
else if (RootBoneName == TEXT("Genesis8Female"))
{
CharacterType = DazCharacterType::Genesis8Female;
}
else if (RootBoneName.Contains(TEXT("Genesis")))
else if (RootBoneName == TEXT("Genesis"))
{
CharacterType = DazCharacterType::Genesis1;
}
Expand Down Expand Up @@ -1266,14 +1299,19 @@ UObject* FDazToUnrealModule::ImportFromDaz(TSharedPtr<FJsonObject> JsonObject)
}
}

// Create Material Instances
/*if (AssetType == DazAssetType::SkeletalMesh || AssetType == DazAssetType::StaticMesh)
// Import FBX
UObject* NewObject = ImportFBXAsset(UpdatedFBXFile, CharacterFolder, AssetType, CharacterType, CharacterTypeName);

// If this is a Pose transfer, an AnimSequence was created. Make a PoseAsset from it.
if (AssetType == DazAssetType::Pose)
{
CreateMaterials(CharacterMaterialFolder, CharacterTexturesFolder, MaterialNames, MaterialProperties, CharacterType);
}*/
if (UAnimSequence* AnimSequence = Cast<UAnimSequence>(NewObject))
{
FDazToUnrealPoses::CreatePoseAsset(AnimSequence, PoseNameList);
}
}

// Import FBX
return ImportFBXAsset(UpdatedFBXFile, CharacterFolder, AssetType, CharacterType, CharacterTypeName);
return NewObject;
}


Expand Down Expand Up @@ -1419,7 +1457,7 @@ UObject* FDazToUnrealModule::ImportFBXAsset(const FString& SourcePath, const FSt
FbxFactory->ImportUI->bImportMaterials = true;
FbxFactory->ImportUI->MeshTypeToImport = FBXIT_StaticMesh;
}
if (AssetType == DazAssetType::Animation)
if (AssetType == DazAssetType::Animation || AssetType == DazAssetType::Pose)
{
FbxFactory->ImportUI->bImportAsSkeletal = true;
FbxFactory->ImportUI->Skeleton = Skeleton;
Expand All @@ -1436,7 +1474,7 @@ UObject* FDazToUnrealModule::ImportFBXAsset(const FString& SourcePath, const FSt
ImportData->Filenames = FileNames;
ImportData->DestinationPath = ImportLocation;
ImportData->bReplaceExisting = true;
if (AssetType == DazAssetType::Animation)
if (AssetType == DazAssetType::Animation || AssetType == DazAssetType::Pose)
{
ImportData->DestinationPath = CachedSettings->AnimationImportDirectory.Path;
}
Expand Down Expand Up @@ -1501,7 +1539,7 @@ UObject* FDazToUnrealModule::ImportFBXAsset(const FString& SourcePath, const FSt
//EditableSkeleton->Set

CachedSettings->OtherSkeletons.Add(CharacterTypeName, Skeleton);
CachedSettings->SaveConfig();
CachedSettings->SaveConfig(CPF_Config, *CachedSettings->GetDefaultConfigFilename());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,9 @@ UMaterialInstanceConstant* FDazToUnrealMaterials::CreateMaterial(const FString C
}
}
}
/*
// Set the default material type
if (CachedSettings->DefaultShaderMaterials.Contains(ShaderName))
{
BaseMaterialAssetPath = CachedSettings->DefaultShaderMaterials[ShaderName];
}*/

/*if (AssetType == TEXT("Follower/Hair"))
{
BaseMaterialAssetPath = CachedSettings->BaseHairMaterial;
if (MaterialName.EndsWith(TEXT("_scalp")))
{
BaseMaterialAssetPath = CachedSettings->BaseScalpMaterial;
}
}*/
/*else*/ if (AssetType == TEXT("Follower/Attachment/Head/Face/Eyelashes"))
if (AssetType == TEXT("Follower/Attachment/Head/Face/Eyelashes") ||
AssetType == TEXT("Follower/Attachment/Head/Face/Eyes"))
{
if (MaterialName.Contains(TEXT("_EyeMoisture")) || MaterialName.EndsWith(TEXT("_EyeReflection")))
{
Expand All @@ -234,6 +221,13 @@ UMaterialInstanceConstant* FDazToUnrealMaterials::CreateMaterial(const FString C
SetMaterialProperty(MaterialName, TEXT("Diffuse Color"), TEXT("Color"), TEXT("#bababa"), MaterialProperties);
SetMaterialProperty(MaterialName, TEXT("Index of Refraction"), TEXT("Double"), TEXT("1.0"), MaterialProperties);
}
else if (MaterialName.EndsWith(TEXT("_Tear")))
{
//BaseMaterialAssetPath = CachedSettings->BaseCorneaMaterial;
SetMaterialProperty(MaterialName, TEXT("Metallic Weight"), TEXT("Double"), TEXT("1"), MaterialProperties);
SetMaterialProperty(MaterialName, TEXT("Opacity Strength"), TEXT("Double"), TEXT("0.05"), MaterialProperties);
SetMaterialProperty(MaterialName, TEXT("Index of Refraction"), TEXT("Double"), TEXT("1.0"), MaterialProperties);
}
else
{
//BaseMaterialAssetPath = CachedSettings->BaseAlphaMaterial;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "DazToUnrealPoses.h"
#include "DazToUnrealSettings.h"
#include "DazToUnrealTextures.h"
#include "DazToUnrealUtils.h"

#include "Animation/Skeleton.h"
#include "Animation/AnimSequence.h"
#include "Animation/PoseAsset.h"

#include "Factories/PoseAssetFactory.h"
#include "IContentBrowserSingleton.h"
#include "ContentBrowserModule.h"
#include "AssetRegistryModule.h"
#include "PackageTools.h"

// Partially taken from UPoseAssetFactory::FactoryCreateNew
void FDazToUnrealPoses::CreatePoseAsset(UAnimSequence* SourceAnimation, TArray<FString> PoseNames)
{
if (SourceAnimation)
{
const UDazToUnrealSettings* CachedSettings = GetDefault<UDazToUnrealSettings>();

// Make sure the path exists
FString ContentDirectory = FPaths::ProjectContentDir();
FString DAZPoseImportFolder = CachedSettings->PoseImportDirectory.Path.Replace(TEXT("/Game/"), *ContentDirectory);
if (!FDazToUnrealUtils::MakeDirectoryAndCheck(DAZPoseImportFolder))
{
//log error
}

USkeleton* TargetSkeleton = SourceAnimation->GetSkeleton();

TArray<FSmartName> InputPoseNames;
if (PoseNames.Num() > 0)
{
for (int32 Index = 0; Index < PoseNames.Num(); ++Index)
{
FName PoseName = FName(*PoseNames[Index]);
FSmartName NewName;
if (TargetSkeleton->GetSmartNameByName(USkeleton::AnimCurveMappingName, PoseName, NewName) == false)
{
// if failed, add it
TargetSkeleton->AddSmartNameAndModify(USkeleton::AnimCurveMappingName, PoseName, NewName);
}

// we want same names in multiple places
InputPoseNames.AddUnique(NewName);
}
}

FString PackageName = UPackageTools::SanitizePackageName(*(CachedSettings->PoseImportDirectory.Path / FString(SourceAnimation->GetName())));
#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 26
UPackage* Pkg = CreatePackage(nullptr, *PackageName);
#else
UPackage* Pkg = CreatePackage(*PackageName);
#endif
EObjectFlags Flags = RF_Public | RF_Standalone | RF_Transactional;

UPoseAsset* PoseAsset = NewObject<UPoseAsset>(Pkg, FName(*SourceAnimation->GetName()), Flags);
//PoseAsset->bAdditivePose = true;
//PoseAsset->BasePoseIndex = 0;
PoseAsset->CreatePoseFromAnimation(SourceAnimation, &InputPoseNames);
PoseAsset->SetSkeleton(TargetSkeleton);
PoseAsset->ConvertSpace(true, 0);
}
//return NewPose;

//UPoseAssetFactory* Factory = NewObject<UPoseAssetFactory>();
//Factory->TargetSkeleton = Skeleton;
//Factory->PreviewSkeletalMesh = SkeletalMesh;

//FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
//ContentBrowserModule.Get().CreateNewAsset(Name, FPackageName::GetLongPackagePath(PackageName), T::StaticClass(), Factory);

/*UPoseAsset* PoseAsset = NewObject<UPoseAsset>(InParent, Class, Name, Flags);
PoseAsset->CreatePoseFromAnimation(SourceAnimation, &InputPoseNames);
PoseAsset->SetSkeleton(TargetSkeleton);*/
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "DazToUnrealUtils.h"
#include "GenericPlatform/GenericPlatformFile.h"
#include "Misc/Paths.h"

FString FDazToUnrealUtils::SanitizeName(FString OriginalName)
{
Expand All @@ -13,4 +15,18 @@ FString FDazToUnrealUtils::SanitizeName(FString OriginalName)
.Replace(TEXT(">"), TEXT("_"))
.Replace(TEXT("?"), TEXT("_"))
.Replace(TEXT("\\"), TEXT("_"));
}

bool FDazToUnrealUtils::MakeDirectoryAndCheck(FString& Directory)
{
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
if (!FPaths::DirectoryExists(Directory))
{
PlatformFile.CreateDirectory(*Directory);
if (!FPaths::DirectoryExists(Directory))
{
return false;
}
}
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ enum DazAssetType
SkeletalMesh,
StaticMesh,
Animation,
Environment
Environment,
Pose
};


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "CoreMinimal.h"
#include "DazToUnrealEnums.h"


class FDazToUnrealPoses
{
public:
static void CreatePoseAsset(UAnimSequence* SourceAnimation, TArray<FString> PoseNames);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ class DAZTOUNREAL_API UDazToUnrealSettings : public UDeveloperSettings
Port = 32345;
ImportDirectory.Path = TEXT("/Game/DazToUnreal");
AnimationImportDirectory.Path = TEXT("/Game/DazToUnreal/Animation");
PoseImportDirectory.Path = TEXT("/Game/DazToUnreal/Pose");
ShowFBXImportDialog = false;
FrameZeroIsReferencePose = false;
FixBoneRotationsOnImport = false;

Genesis1Skeleton = FSoftObjectPath(TEXT("/DazToUnreal/Genesis1BaseSkeleton.Genesis1BaseSkeleton"));
Genesis3Skeleton = FSoftObjectPath(TEXT("/DazToUnreal/Genesis3BaseSkeleton.Genesis3BaseSkeleton"));
Genesis8Skeleton = FSoftObjectPath(TEXT("/DazToUnreal/Genesis8BaseSkeleton.Genesis8BaseSkeleton"));
OtherSkeletons.Add(TEXT("Genesis8_1Male"), FSoftObjectPath(TEXT("/DazToUnreal/Genesis8BaseSkeleton.Genesis8BaseSkeleton")));
OtherSkeletons.Add(TEXT("Genesis8_1Female"), FSoftObjectPath(TEXT("/DazToUnreal/Genesis8BaseSkeleton.Genesis8BaseSkeleton")));

Genesis1PostProcessAnimation = FSoftClassPath(TEXT("/DazToUnreal/Genesis1JCMPostProcess.Genesis1JCMPostProcess_C"));
Genesis3PostProcessAnimation = FSoftClassPath(TEXT("/DazToUnreal/Genesis3JCMPostProcess.Genesis3JCMPostProcess_C"));
Expand All @@ -34,11 +38,13 @@ class DAZTOUNREAL_API UDazToUnrealSettings : public UDeveloperSettings
BaseShaderMaterials.Add(TEXT("omUberSurface"), FSoftObjectPath(TEXT("/DazToUnreal/omUberBaseMaterial.omUberBaseMaterial")));
BaseShaderMaterials.Add(TEXT("AoA_Subsurface"), FSoftObjectPath(TEXT("/DazToUnreal/AoASubsurfaceBaseMaterial.AoASubsurfaceBaseMaterial")));
BaseShaderMaterials.Add(TEXT("Iray Uber"), FSoftObjectPath(TEXT("/DazToUnreal/IrayUberBaseMaterial.IrayUberBaseMaterial")));
BaseShaderMaterials.Add(TEXT("PBRSkin"), FSoftObjectPath(TEXT("/DazToUnreal/BasePBRSkinMaterial.BasePBRSkinMaterial")));

SkinShaderMaterials.Add(TEXT("Daz Studio Default"), FSoftObjectPath(TEXT("/DazToUnreal/DSDBaseMaterial.DSDBaseMaterial")));
SkinShaderMaterials.Add(TEXT("omUberSurface"), FSoftObjectPath(TEXT("/DazToUnreal/omUberSkinMaterial.omUberSkinMaterial")));
SkinShaderMaterials.Add(TEXT("AoA_Subsurface"), FSoftObjectPath(TEXT("/DazToUnreal/AoASubsurfaceSkinMaterial.AoASubsurfaceSkinMaterial")));
SkinShaderMaterials.Add(TEXT("Iray Uber"), FSoftObjectPath(TEXT("/DazToUnreal/IrayUberSkinMaterial.IrayUberSkinMaterial")));
SkinShaderMaterials.Add(TEXT("PBRSkin"), FSoftObjectPath(TEXT("/DazToUnreal/BasePBRSkinMaterial.BasePBRSkinMaterial")));

BaseMaterial = FSoftObjectPath(TEXT("/DazToUnreal/BaseMaterial.BaseMaterial"));
BaseAlphaMaterial = FSoftObjectPath(TEXT("/DazToUnreal/BaseAlphaMaterial.BaseAlphaMaterial"));
Expand Down Expand Up @@ -95,6 +101,10 @@ class DAZTOUNREAL_API UDazToUnrealSettings : public UDeveloperSettings
UPROPERTY(config, EditAnywhere, Category = PluginSettings, meta = (RelativeToGameContentDir, LongPackageName))
FDirectoryPath AnimationImportDirectory;

/** Directory PoseAssets will be imported to */
UPROPERTY(config, EditAnywhere, Category = PluginSettings, meta = (RelativeToGameContentDir, LongPackageName))
FDirectoryPath PoseImportDirectory;

/** Show the FBX Import dialog when importing the udpated FBX file */
UPROPERTY(config, EditAnywhere, Category = PluginSettings, meta = (RelativeToGameContentDir, LongPackageName))
bool ShowFBXImportDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class FDazToUnrealUtils
{
public:
static FString SanitizeName(FString OriginalName);
static bool MakeDirectoryAndCheck(FString& Directory);
};

0 comments on commit bb6f6fc

Please sign in to comment.