Skip to content

Commit

Permalink
Exporters:
Browse files Browse the repository at this point in the history
- saving material's properties next to .mat file, as .props.txt
- added file flags option for CreateExportArchive(), now can correctly save text files
- used this option in all appropriate places
  • Loading branch information
gildor2 committed Jul 11, 2018
1 parent e10ebbf commit 3abe49b
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Exporters/Export3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ void Export3D(const UVertMesh *Mesh)
// export script file
if (GExportScripts)
{
Ar = CreateExportArchive(Mesh, "%s.uc", Mesh->Name);
Ar = CreateExportArchive(Mesh, FAO_TextFile, "%s.uc", Mesh->Name);
if (Ar)
{
ExportScript(Mesh, *Ar);
delete Ar;
}
}
// export mesh data
Ar = CreateExportArchive(Mesh, "%s_d.3d", Mesh->Name);
Ar = CreateExportArchive(Mesh, 0, "%s_d.3d", Mesh->Name);
if (Ar)
{
ExportMesh(Mesh, *Ar);
delete Ar;
}
// export animation frames
Ar = CreateExportArchive(Mesh, "%s_a.3d", Mesh->Name);
Ar = CreateExportArchive(Mesh, 0, "%s_a.3d", Mesh->Name);
if (Ar)
{
ExportAnims(Mesh, *Ar);
Expand Down
22 changes: 21 additions & 1 deletion Exporters/ExportMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "UnObject.h"
#include "UnMaterial.h"
#include "UnMaterial3.h"

#include "Exporters.h"

Expand All @@ -27,7 +28,7 @@ void ExportMaterial(const UUnrealMaterial *Mat)
return;
}

FArchive *Ar = CreateExportArchive(Mat, "%s.mat", Mat->Name);
FArchive* Ar = CreateExportArchive(Mat, FAO_TextFile, "%s.mat", Mat->Name);
if (!Ar) return;

#define PROC(Arg) \
Expand All @@ -46,6 +47,7 @@ void ExportMaterial(const UUnrealMaterial *Mat)
PROC(Cube);
PROC(Mask);

#if 0
// collect all textures - already exported ones and everything else
TArray<UUnrealMaterial*> ExportedTextures;
Params.AppendAllTextures(ExportedTextures);
Expand All @@ -60,6 +62,24 @@ void ExportMaterial(const UUnrealMaterial *Mat)
ExportObject(Tex);
}
}
#else
// Dump material properties to a separate file
FArchive* PropAr = CreateExportArchive(Mat, FAO_TextFile, "%s.props.txt", Mat->Name);
if (PropAr)
{
Mat->GetTypeinfo()->SaveProps(Mat, *PropAr);
delete PropAr;
}
#endif

if (Mat->IsA("MaterialInstanceConstant"))
{
const UMaterialInstanceConstant* Inst = static_cast<const UMaterialInstanceConstant*>(Mat);
if (Inst->Parent)
{
ExportMaterial(Inst->Parent);
}
}

delete Ar;

Expand Down
4 changes: 2 additions & 2 deletions Exporters/ExportMd5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void ExportMd5Mesh(const CSkeletalMesh *Mesh)
return;
}

FArchive *Ar = CreateExportArchive(OriginalMesh, "%s.md5mesh", OriginalMesh->Name);
FArchive *Ar = CreateExportArchive(OriginalMesh, FAO_TextFile, "%s.md5mesh", OriginalMesh->Name);
if (!Ar) return;

const CSkelMeshLod &Lod = Mesh->Lods[0];
Expand Down Expand Up @@ -303,7 +303,7 @@ void ExportMd5Anim(const CAnimSet *Anim)
int i;
const CAnimSequence &S = *Anim->Sequences[AnimIndex];

FArchive *Ar = CreateExportArchive(OriginalAnim, "%s/%s.md5anim", OriginalAnim->Name, *S.Name);
FArchive *Ar = CreateExportArchive(OriginalAnim, FAO_TextFile, "%s/%s.md5anim", OriginalAnim->Name, *S.Name);
if (!Ar) continue;

Ar->Printf(
Expand Down
10 changes: 5 additions & 5 deletions Exporters/ExportPsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void ExportPsk(const CSkeletalMesh *Mesh)
// export script file
if (GExportScripts)
{
FArchive *Ar = CreateExportArchive(OriginalMesh, "%s.uc", OriginalMesh->Name);
FArchive *Ar = CreateExportArchive(OriginalMesh, FAO_TextFile, "%s.uc", OriginalMesh->Name);
if (Ar)
{
ExportScript(Mesh, *Ar);
Expand All @@ -400,7 +400,7 @@ void ExportPsk(const CSkeletalMesh *Mesh)
else
appSprintf(ARRAY_ARG(filename), "%s_Lod%d.%s", OriginalMesh->Name, Lod, Ext);

FArchive *Ar = CreateExportArchive(OriginalMesh, "%s", filename);
FArchive *Ar = CreateExportArchive(OriginalMesh, 0, "%s", filename);
if (Ar)
{
ExportSkeletalMeshLod(*Mesh, MeshLod, *Ar);
Expand All @@ -422,7 +422,7 @@ void ExportPsa(const CAnimSet *Anim)

UObject *OriginalAnim = Anim->OriginalAnim;

FArchive *Ar0 = CreateExportArchive(OriginalAnim, "%s.psa", OriginalAnim->Name);
FArchive *Ar0 = CreateExportArchive(OriginalAnim, 0, "%s.psa", OriginalAnim->Name);
if (!Ar0) return;
FArchive &Ar = *Ar0; // use "Ar << obj" instead of "(*Ar) << obj"

Expand Down Expand Up @@ -523,7 +523,7 @@ void ExportPsa(const CAnimSet *Anim)
return;
}

FArchive *Ar1 = CreateExportArchive(OriginalAnim, "%s.config", OriginalAnim->Name);
FArchive *Ar1 = CreateExportArchive(OriginalAnim, FAO_TextFile, "%s.config", OriginalAnim->Name);
if (!Ar1) return;

// we are using UE3 property names here
Expand Down Expand Up @@ -636,7 +636,7 @@ void ExportStaticMesh(const CStaticMesh *Mesh)
else
appSprintf(ARRAY_ARG(filename), "%s_Lod%d.pskx", OriginalMesh->Name, Lod);

FArchive *Ar = CreateExportArchive(OriginalMesh, "%s", filename);
FArchive *Ar = CreateExportArchive(OriginalMesh, 0, "%s", filename);
if (Ar)
{
ExportStaticMeshLod(Mesh->Lods[Lod], *Ar);
Expand Down
6 changes: 3 additions & 3 deletions Exporters/ExportSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void SaveSound(const UObject *Obj, void *Data, int DataSize, const char *
else if (!memcmp(Data, "MSFC", 4))
ext = "mp3"; // PS3 MP3 codec

FArchive *Ar = CreateExportArchive(Obj, "%s.%s", Obj->Name, ext);
FArchive *Ar = CreateExportArchive(Obj, 0, "%s.%s", Obj->Name, ext);
if (Ar)
{
Ar->Serialize(Data, DataSize);
Expand Down Expand Up @@ -156,7 +156,7 @@ static bool SaveXMASound(const UObject *Obj, void *Data, int DataSize, const cha

if (Hdr.WaveFormatLength == 0x34) // sizeof(XMA2WAVEFORMATEX)
{
Ar = CreateExportArchive(Obj, "%s.%s", Obj->Name, DefExt);
Ar = CreateExportArchive(Obj, 0, "%s.%s", Obj->Name, DefExt);
if (!Ar) return false;

WriteRiffHeader(*Ar, ResultFileSize);
Expand All @@ -170,7 +170,7 @@ static bool SaveXMASound(const UObject *Obj, void *Data, int DataSize, const cha
}
else if (Hdr.WaveFormatLength == 0x2C) // sizeof(XMA2WAVEFORMAT)
{
Ar = CreateExportArchive(Obj, "%s.%s", Obj->Name, DefExt);
Ar = CreateExportArchive(Obj, 0, "%s.%s", Obj->Name, DefExt);
if (!Ar) return false;

WriteRiffHeader(*Ar, ResultFileSize);
Expand Down
4 changes: 2 additions & 2 deletions Exporters/ExportTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void ExportTexture(const UUnrealMaterial *Tex)
// For HDR textures use Radiance format
if (PixelFormatInfo[TexData.Format].Float)
{
FArchive *Ar = CreateExportArchive(Tex, "%s.hdr", Tex->Name);
FArchive *Ar = CreateExportArchive(Tex, 0, "%s.hdr", Tex->Name);
if (Ar)
{
WriteHDR(*Ar, width, height, pic);
Expand All @@ -340,7 +340,7 @@ void ExportTexture(const UUnrealMaterial *Tex)
}
#endif

FArchive *Ar = CreateExportArchive(Tex, "%s.tga", Tex->Name);
FArchive *Ar = CreateExportArchive(Tex, 0, "%s.tga", Tex->Name);
if (Ar)
{
WriteTGA(*Ar, width, height, pic);
Expand Down
6 changes: 3 additions & 3 deletions Exporters/ExportThirdParty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

void ExportGfx(const USwfMovie *Swf)
{
FArchive *Ar = CreateExportArchive(Swf, "%s.gfx", Swf->Name);
FArchive *Ar = CreateExportArchive(Swf, 0, "%s.gfx", Swf->Name);
if (Ar)
{
Ar->Serialize((void*)&Swf->RawData[0], Swf->RawData.Num());
Expand All @@ -21,7 +21,7 @@ void ExportGfx(const USwfMovie *Swf)

void ExportFaceFXAnimSet(const UFaceFXAnimSet *Fx)
{
FArchive *Ar = CreateExportArchive(Fx, "%s.fxa", Fx->Name);
FArchive *Ar = CreateExportArchive(Fx, 0, "%s.fxa", Fx->Name);
if (Ar)
{
Ar->Serialize((void*)&Fx->RawFaceFXAnimSetBytes[0], Fx->RawFaceFXAnimSetBytes.Num());
Expand All @@ -31,7 +31,7 @@ void ExportFaceFXAnimSet(const UFaceFXAnimSet *Fx)

void ExportFaceFXAsset(const UFaceFXAsset *Fx)
{
FArchive *Ar = CreateExportArchive(Fx, "%s.fxa", Fx->Name);
FArchive *Ar = CreateExportArchive(Fx, 0, "%s.fxa", Fx->Name);
if (Ar)
{
Ar->Serialize((void*)&Fx->RawFaceFXActorBytes[0], Fx->RawFaceFXActorBytes.Num());
Expand Down
4 changes: 2 additions & 2 deletions Exporters/Exporters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ bool CheckExportFilePresence(const UObject *Obj, const char *fmt, ...)
}


FArchive *CreateExportArchive(const UObject *Obj, const char *fmt, ...)
FArchive *CreateExportArchive(const UObject *Obj, unsigned FileOptions, const char *fmt, ...)
{
guard(CreateExportArchive);

Expand All @@ -358,7 +358,7 @@ FArchive *CreateExportArchive(const UObject *Obj, const char *fmt, ...)
// appPrintf("... writing %s'%s' to %s ...\n", Obj->GetClassName(), Obj->Name, filename);

appMakeDirectoryForFile(filename);
FFileWriter *Ar = new FFileWriter(filename, FAO_NoOpenError);
FFileWriter *Ar = new FFileWriter(filename, FAO_NoOpenError | FileOptions);
if (!Ar->IsOpen())
{
appPrintf("Error creating file \"%s\" ...\n", filename);
Expand Down
2 changes: 1 addition & 1 deletion Exporters/Exporters.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool CheckExportFilePresence(const UObject *Obj, const char *fmt, ...);
// Create file for saving UObject.
// File will be placed in directory selected by GetExportPath(), name is computed from fmt+varargs.
// Function may return NULL.
FArchive *CreateExportArchive(const UObject *Obj, const char *fmt, ...);
FArchive *CreateExportArchive(const UObject *Obj, unsigned FileOptions, const char *fmt, ...);

// configuration
extern bool GExportScripts;
Expand Down
15 changes: 8 additions & 7 deletions makefile-linux
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,10 @@ DEPENDS_28 = \
Unreal/UnCore.h \
Unreal/UnMaterial.h \
Unreal/UnMaterial3.h \
Unreal/UnObject.h \
Unreal/UnTextureNVTT.h
Unreal/UnObject.h

$(OUT_1)/ExportTexture.o : Exporters/ExportTexture.cpp $(DEPENDS_28)
$(CPP) $(OPT_MAIN) -o $(OUT_1)/ExportTexture.o Exporters/ExportTexture.cpp
$(OUT_1)/ExportMaterial.o : Exporters/ExportMaterial.cpp $(DEPENDS_28)
$(CPP) $(OPT_MAIN) -o $(OUT_1)/ExportMaterial.o Exporters/ExportMaterial.cpp

DEPENDS_29 = \
Core/Core.h \
Expand All @@ -867,10 +866,12 @@ DEPENDS_29 = \
Unreal/TypeInfo.h \
Unreal/UnCore.h \
Unreal/UnMaterial.h \
Unreal/UnObject.h
Unreal/UnMaterial3.h \
Unreal/UnObject.h \
Unreal/UnTextureNVTT.h

$(OUT_1)/ExportMaterial.o : Exporters/ExportMaterial.cpp $(DEPENDS_29)
$(CPP) $(OPT_MAIN) -o $(OUT_1)/ExportMaterial.o Exporters/ExportMaterial.cpp
$(OUT_1)/ExportTexture.o : Exporters/ExportTexture.cpp $(DEPENDS_29)
$(CPP) $(OPT_MAIN) -o $(OUT_1)/ExportTexture.o Exporters/ExportTexture.cpp

DEPENDS_30 = \
Core/Core.h \
Expand Down
15 changes: 8 additions & 7 deletions makefile-vc-win32
Original file line number Diff line number Diff line change
Expand Up @@ -850,11 +850,10 @@ DEPENDS = \
Unreal/UnCore.h \
Unreal/UnMaterial.h \
Unreal/UnMaterial3.h \
Unreal/UnObject.h \
Unreal/UnTextureNVTT.h
Unreal/UnObject.h

$(OUT_1)/ExportTexture.obj : Exporters/ExportTexture.cpp $(DEPENDS)
$(CPP) -MD $(OPT_MAIN) -Fo"$(OUT_1)/ExportTexture.obj" Exporters/ExportTexture.cpp
$(OUT_1)/ExportMaterial.obj : Exporters/ExportMaterial.cpp $(DEPENDS)
$(CPP) -MD $(OPT_MAIN) -Fo"$(OUT_1)/ExportMaterial.obj" Exporters/ExportMaterial.cpp

DEPENDS = \
Core/Core.h \
Expand All @@ -868,10 +867,12 @@ DEPENDS = \
Unreal/TypeInfo.h \
Unreal/UnCore.h \
Unreal/UnMaterial.h \
Unreal/UnObject.h
Unreal/UnMaterial3.h \
Unreal/UnObject.h \
Unreal/UnTextureNVTT.h

$(OUT_1)/ExportMaterial.obj : Exporters/ExportMaterial.cpp $(DEPENDS)
$(CPP) -MD $(OPT_MAIN) -Fo"$(OUT_1)/ExportMaterial.obj" Exporters/ExportMaterial.cpp
$(OUT_1)/ExportTexture.obj : Exporters/ExportTexture.cpp $(DEPENDS)
$(CPP) -MD $(OPT_MAIN) -Fo"$(OUT_1)/ExportTexture.obj" Exporters/ExportTexture.cpp

DEPENDS = \
Core/Core.h \
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ detex

Changes
~~~~~~~
11.07.2018
- exporting a .props.txt file next to .mat, it contains all material's properties

28.06.2018
- heavily optimized memory used by animations

Expand Down
Binary file modified umodel
Binary file not shown.
Binary file modified umodel.exe
Binary file not shown.

0 comments on commit 3abe49b

Please sign in to comment.