Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ExodusImport/Source/ExodusImport/Private/ImportedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void ImportedObject::setCompatibleMobility(ImportedObject parentObject) const{
auto newMobility = EComponentMobility::Movable;
UnrealUtilities::processComponentsRecursively(myComponent,
nullptr,
[&](USceneComponent *component){
component->SetMobility(newMobility);
[&](USceneComponent *_component){
_component->SetMobility(newMobility);
}, false
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ template<typename T> class DataPlane2D{

bool loadFromRaw(const FString& filename, int w_, int h_){
resize(w_, h_);
TArray<uint8> data;
if (!FFileHelper::LoadFileToArray(data, *filename)){
TArray<uint8> dataArr;
if (!FFileHelper::LoadFileToArray(dataArr, *filename)){
UE_LOG(JsonLog, Error, TEXT("Could not load file \"%s\""), *filename);
return false;
}
auto byteSize = getByteSize();
if (byteSize != data.Num()){
if (byteSize != dataArr.Num()){
UE_LOG(JsonLog, Error, TEXT("Invalid file size of \"%s\": %d received, %d (%d x %d (%d)) expected"),
*filename, data.Num(), byteSize, getWidth(), getHeight(), sizeof(T));
*filename, dataArr.Num(), byteSize, getWidth(), getHeight(), sizeof(T));
return false;
}
const T* srcPtr = (const T*)data.GetData();
const T* srcPtr = (const T*)dataArr.GetData();
T* dstPtr = getData();
for(auto i = 0; i < getNumElements(); i++){
dstPtr[i] = srcPtr[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace JsonObjects{
template<typename T> void getJsonObjArray(JsonObjPtr jsonData, TArray<T>& result, const char* name, std::function<T(JsonObjPtr, int)> converter){
getJsonValArray<T>(jsonData, result, name,
[&](JsonValPtr val, int idx){
auto jsonObj = jsonVal->AsObject();
auto jsonObj = val->AsObject();
if (!jsonObj.IsValid()){
UE_LOG(JsonLog, Warning, TEXT("Could not retrieve array index %d from \"%s\""), idx, name);
return T();
Expand Down
58 changes: 58 additions & 0 deletions ExodusImport/Source/ExodusImport/Private/UnrealUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,64 @@ FString UnrealUtilities::sanitizePackageName(const FString &arg){
return PackageTools::SanitizePackageName(arg);
}

template <typename T>T* UnrealUtilities::createAssetObject(const FString& objectName, const FString* desiredDir, const JsonImporter *importer,
std::function<void(T* obj)> onCreate, EObjectFlags objectFlags){
return createAssetObject<T>(objectName, desiredDir, importer, onCreate, nullptr, objectFlags);
}

template <typename T>T* UnrealUtilities::createAssetObject(const FString& objectName, const FString* desiredDir, const JsonImporter *importer,
std::function<void(T* obj)> onCreate, std::function<T*(UPackage* pkg, const FString&)> creatorFunc, EObjectFlags objectFlags, bool checkForExistingObjects ){

T* finalResult;
auto sanitizedName = ::sanitizeObjectName(*objectName);
createAssetPackage(objectName, desiredDir, importer,
[&](UPackage* pkg) -> T*{
T* newObj = nullptr;
if (checkForExistingObjects){
auto *oldObj = FindObject<T>(pkg, *sanitizedName);
if (oldObj){
auto uniqueName = MakeUniqueObjectName(pkg, T::StaticClass(), *sanitizedName).ToString();
UE_LOG(JsonLog, Log, TEXT("Unique name created: %s (old obj: %x). Original name: %s"), *uniqueName, oldObj, *sanitizedName);
sanitizedName = uniqueName;
}
}
if (creatorFunc){
newObj = creatorFunc(pkg, sanitizedName);
}
else{
newObj = NewObject<T>(pkg, T::StaticClass(), *sanitizedName, objectFlags);
}
if (onCreate)
onCreate(newObj);
finalResult = newObj;
return newObj;
}
);

return finalResult;
}

template<typename T> UPackage* UnrealUtilities::createPackage(const FString &basePackageName, const FString &srcPackagePath, const FString &objectNameSuffix, const FString *commonAssetPath,
const FString *defaultPackageRoot, FString *outSanitizedPackageName, FString *outSanitizedObjName, T** outExistingObj){

T* existingObj = nullptr;
UPackage* result = createPackage(
basePackageName, srcPackagePath, objectNameSuffix, commonAssetPath, defaultPackageRoot,
outSanitizedPackageName, outSanitizedObjName,
[&](const FString &path) -> UPackage*{
auto obj = Cast<T>(LoadObject<T>(0, *outExistingObj));
if (obj){
existingObj = obj;
return existingObj->GetOutermost();
}
return nullptr;
}
);
if (outExistingObj){
*outExistingObj = existingObj;
}
}

FString UnrealUtilities::buildPackagePath(const FString &desiredName, const FString &desiredDir, const JsonImporter *importer){
return buildPackagePath(desiredName, &desiredDir, importer);
}
Expand Down
57 changes: 3 additions & 54 deletions ExodusImport/Source/ExodusImport/Private/UnrealUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,43 +114,10 @@ namespace UnrealUtilities{

UPackage* createAssetPackage(const FString &objectName, const FString* desiredDir, const JsonImporter *importer, std::function<UObject*(UPackage*)> assetCreator);

template <typename T>T* createAssetObject(const FString& objectName, const FString* desiredDir, const JsonImporter *importer,
std::function<void(T* obj)> onCreate, EObjectFlags objectFlags){
return createAssetObject<T>(objectName, desiredDir, importer, onCreate, nullptr, objectFlags);
}
template <typename T>T* createAssetObject(const FString& objectName, const FString* desiredDir, const JsonImporter *importer, std::function<void(T* obj)> onCreate, EObjectFlags objectFlags);

template <typename T>T* createAssetObject(const FString& objectName, const FString* desiredDir, const JsonImporter *importer,
std::function<void(T* obj)> onCreate, std::function<T*(UPackage* pkg, const FString&)> creatorFunc = nullptr, EObjectFlags objectFlags = RF_NoFlags,
bool checkForExistingObjects = true){

T* finalResult;
auto sanitizedName = sanitizeObjectName(*objectName);
createAssetPackage(objectName, desiredDir, importer,
[&](UPackage* pkg) -> T*{
T* newObj = nullptr;
if (checkForExistingObjects){
auto *oldObj = FindObject<T>(pkg, *sanitizedName);
if (oldObj){
auto uniqueName = MakeUniqueObjectName(pkg, T::StaticClass(), *sanitizedName).ToString();
UE_LOG(JsonLog, Log, TEXT("Unique name created: %s (old obj: %x). Original name: %s"), *uniqueName, oldObj, *sanitizedName);
sanitizedName = uniqueName;
}
}
if (creatorFunc){
newObj = creatorFunc(pkg, sanitizedName);
}
else{
newObj = NewObject<T>(pkg, T::StaticClass(), *sanitizedName, objectFlags);
}
if (onCreate)
onCreate(newObj);
finalResult = newObj;
return newObj;
}
);

return finalResult;
}
std::function<void(T* obj)> onCreate, std::function<T*(UPackage* pkg, const FString&)> creatorFunc = nullptr, EObjectFlags objectFlags = RF_NoFlags, bool checkForExistingObjects = true);

template <typename T>T* createActor(UWorld *world, FTransform transform, bool editorMode, const TCHAR* logName = 0){
T* result = 0;
Expand Down Expand Up @@ -228,25 +195,7 @@ namespace UnrealUtilities{
const FString *defaultPackageRoot = nullptr,
FString *outSanitizedPackageName = nullptr,
FString *outSanitizedObjName = nullptr,
T** outExistingObj = nullptr){

T* existingObj = nullptr;
UPackage* result = createPackage(
basePackageName, srcPackagePath, objectNameSuffix, commonAssetPath, defaultPackageRoot,
outSanitizedPackageName, outSanitizedobjName,
[&](const FString &path) -> UPackage*{
auto obj = Cast<T>(LoadObject<T>(0, *objPath));
if (obj){
existingObj = obj;
return existingObj->GetOutermost();
}
return nullptr;
}
)
if (outExistingObj){
*outExistingObj = existingObj;
}
}
T** outExistingObj = nullptr);

/*
Those were introduced due to mesh api changed over ocurse of 4.22...4.24.
Expand Down