From 80e17db6023cb34ccf39238ea11b76350d99588f Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 27 Aug 2012 17:16:16 +0200 Subject: [PATCH] Added: #1440 Initial tool to fix asset paths --HG-- branch : build_pipeline_v3 --- code/nel/tools/pipeline/CMakeLists.txt | 1 + .../tools/pipeline/max/class_directory_3.cpp | 4 +- code/nel/tools/pipeline/max/dll_directory.cpp | 4 +- .../nel/tools/pipeline/max/storage_stream.cpp | 9 +- code/nel/tools/pipeline/max_dump/info.txt | 2 +- .../tools/pipeline/max_dump/scene_graph_5.txt | 172 ++++++++++++ .../max_rewrite_assets/CMakeLists.txt | 36 +++ .../pipeline/max_rewrite_assets/main.cpp | 248 ++++++++++++++++++ 8 files changed, 469 insertions(+), 7 deletions(-) create mode 100644 code/nel/tools/pipeline/max_dump/scene_graph_5.txt create mode 100644 code/nel/tools/pipeline/max_rewrite_assets/CMakeLists.txt create mode 100644 code/nel/tools/pipeline/max_rewrite_assets/main.cpp diff --git a/code/nel/tools/pipeline/CMakeLists.txt b/code/nel/tools/pipeline/CMakeLists.txt index 719c0a6e3..323ca391c 100644 --- a/code/nel/tools/pipeline/CMakeLists.txt +++ b/code/nel/tools/pipeline/CMakeLists.txt @@ -1,6 +1,7 @@ SUBDIRS( max max_dump + max_rewrite_assets plugin_library plugin_nel plugin_max diff --git a/code/nel/tools/pipeline/max/class_directory_3.cpp b/code/nel/tools/pipeline/max/class_directory_3.cpp index 5fa11cebb..bbe46eefe 100644 --- a/code/nel/tools/pipeline/max/class_directory_3.cpp +++ b/code/nel/tools/pipeline/max/class_directory_3.cpp @@ -222,13 +222,15 @@ void CClassDirectory3::build(uint16 version, uint filter) // Parallel to CDllDirectory void CClassDirectory3::disown() { - CStorageContainer::disown(); m_ChunkCache.clear(); m_Entries.clear(); m_ClassIdToIndex.clear(); // Ownership goes back to m_Chunks m_ChunksOwnsPointers = true; + + // Disown child chunks + CStorageContainer::disown(); } // Parallel to CDllDirectory diff --git a/code/nel/tools/pipeline/max/dll_directory.cpp b/code/nel/tools/pipeline/max/dll_directory.cpp index 071371cb1..8f60c459c 100644 --- a/code/nel/tools/pipeline/max/dll_directory.cpp +++ b/code/nel/tools/pipeline/max/dll_directory.cpp @@ -221,13 +221,15 @@ void CDllDirectory::build(uint16 version, uint filter) // Parallel to CClassDirectory3 void CDllDirectory::disown() { - CStorageContainer::disown(); m_ChunkCache.clear(); m_Entries.clear(); m_InternalNameToIndex.clear(); // Ownership goes back to m_Chunks m_ChunksOwnsPointers = true; + + // Disown child chunks + CStorageContainer::disown(); } // Parallel to CClassDirectory3 diff --git a/code/nel/tools/pipeline/max/storage_stream.cpp b/code/nel/tools/pipeline/max/storage_stream.cpp index e0651d826..d9e27153e 100644 --- a/code/nel/tools/pipeline/max/storage_stream.cpp +++ b/code/nel/tools/pipeline/max/storage_stream.cpp @@ -59,7 +59,10 @@ CStorageStream::CStorageStream(GsfOutput *output) : NLMISC::IStream(false), m_In CStorageStream::~CStorageStream() { - + if (m_Output) + { + gsf_output_seek(m_Output, 0, G_SEEK_END); + } } bool CStorageStream::seek(sint32 offset, NLMISC::IStream::TSeekOrigin origin) const @@ -131,9 +134,7 @@ void CStorageStream::serialBuffer(uint8 *buf, uint len) { if (!gsf_output_write(m_Output, len, buf)) { -#ifdef NL_DEBUG_STORAGE - nldebug("Cannot write to output, throw exception"); -#endif + nlwarning("Cannot write %i bytes to output at pos %i, throw exception", len, getPos()); throw NLMISC::EStream(); } } diff --git a/code/nel/tools/pipeline/max_dump/info.txt b/code/nel/tools/pipeline/max_dump/info.txt index d5e65b49f..db3130509 100644 --- a/code/nel/tools/pipeline/max_dump/info.txt +++ b/code/nel/tools/pipeline/max_dump/info.txt @@ -1173,7 +1173,7 @@ bitfield 01 00 00 00 05 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 03 00 00 00 21 00 01 00 01 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 // selected -01 00 00 00 05 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 03 00 00 00 21 00 00 00 01 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 // unselected - no difference +01 00 00 00 05 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 03 00 00 00 21 00 00 00 01 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 // unselected - no difference *** byte changed from 1 to 0 ??? 01 00 00 00 05 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 03 00 00 00 29 00 01 00 01 00 04 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 // material id changed to '5', 08 00 01 00 00 00 05 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 03 00 00 00 29 00 01 00 01 00 04 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 // clear selection unselected -- no diff 01 00 00 00 05 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 03 00 00 00 29 00 01 00 01 00 04 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 // use subdiv -- no diff diff --git a/code/nel/tools/pipeline/max_dump/scene_graph_5.txt b/code/nel/tools/pipeline/max_dump/scene_graph_5.txt new file mode 100644 index 000000000..e206e14fc --- /dev/null +++ b/code/nel/tools/pipeline/max_dump/scene_graph_5.txt @@ -0,0 +1,172 @@ +Scene Graph +Version R3 + + Root Node [8] { +0: TR_HOF_civil01_armpad [0] { + Object: OSM Derived } +1: TR_HOF_civil01_gilet [0] { + Object: OSM Derived } +2: TR_HOF_Civil01_bottes [0] { + Object: OSM Derived } +3: TR_HOF_civil01_pantabottes [0] { + Object: OSM Derived } +4: Bip01 [3] { + Object: Biped Object + 0: Bip01 Footsteps [0] { + Object: Biped Object } + 1: Bip01 Pelvis [3] { + Object: Biped Object + 0: Bip01 Spine [1] { + Object: Biped Object + 0: Bip01 Spine1 [1] { + Object: Biped Object + 0: Bip01 Spine2 [1] { + Object: Biped Object + 0: Bip01 Neck [3] { + Object: Biped Object + 0: Bip01 Head [2] { + Object: Biped Object + 0: Bip01 Head [0] { + Object: Dummy } + 1: Bip01 hair1 [1] { + Object: Biped Object + 0: Bip01 hair11 [1] { + Object: Biped Object + 0: Bip01 hair1 [0] { + Object: Dummy } } } } + 1: Bip01 L Clavicle [1] { + Object: Biped Object + 0: Bip01 L UpperArm [1] { + Object: Biped Object + 0: Bip01 L Forearm [2] { + Object: Biped Object + 0: Bip01 L Hand [6] { + Object: Biped Object + 0: Bip01 L Finger0 [1] { + Object: Biped Object + 0: Bip01 L Finger01 [1] { + Object: Biped Object + 0: Bip01 L Finger02 [1] { + Object: Biped Object + 0: Bip01 L Finger0 [0] { + Object: Dummy } } } } + 1: Bip01 L Finger1 [1] { + Object: Biped Object + 0: Bip01 L Finger11 [1] { + Object: Biped Object + 0: Bip01 L Finger12 [1] { + Object: Biped Object + 0: Bip01 L Finger1 [0] { + Object: Dummy } } } } + 2: Bip01 L Finger2 [1] { + Object: Biped Object + 0: Bip01 L Finger21 [1] { + Object: Biped Object + 0: Bip01 L Finger22 [1] { + Object: Biped Object + 0: Bip01 L Finger2 [0] { + Object: Dummy } } } } + 3: Bip01 L Finger3 [1] { + Object: Biped Object + 0: Bip01 L Finger31 [1] { + Object: Biped Object + 0: Bip01 L Finger32 [1] { + Object: Biped Object + 0: Bip01 L Finger3 [0] { + Object: Dummy } } } } + 4: Bip01 L Finger4 [1] { + Object: Biped Object + 0: Bip01 L Finger41 [1] { + Object: Biped Object + 0: Bip01 L Finger42 [1] { + Object: Biped Object + 0: Bip01 L Finger4 [0] { + Object: Dummy } } } } + 5: box_arme_gauche [0] { + Object: Editable Mesh } } + 1: Box_bouclier [0] { + Object: Editable Mesh } } } } + 2: Bip01 R Clavicle [1] { + Object: Biped Object + 0: Bip01 R UpperArm [1] { + Object: Biped Object + 0: Bip01 R Forearm [1] { + Object: Biped Object + 0: Bip01 R Hand [6] { + Object: Biped Object + 0: Bip01 R Finger0 [1] { + Object: Biped Object + 0: Bip01 R Finger01 [1] { + Object: Biped Object + 0: Bip01 R Finger02 [1] { + Object: Biped Object + 0: Bip01 R Finger0R [0] { + Object: Dummy } } } } + 1: Bip01 R Finger1 [1] { + Object: Biped Object + 0: Bip01 R Finger11 [1] { + Object: Biped Object + 0: Bip01 R Finger12 [1] { + Object: Biped Object + 0: Bip01 R Finger1R [0] { + Object: Dummy } } } } + 2: Bip01 R Finger2 [1] { + Object: Biped Object + 0: Bip01 R Finger21 [1] { + Object: Biped Object + 0: Bip01 R Finger22 [1] { + Object: Biped Object + 0: Bip01 R Finger2R [0] { + Object: Dummy } } } } + 3: Bip01 R Finger3 [1] { + Object: Biped Object + 0: Bip01 R Finger31 [1] { + Object: Biped Object + 0: Bip01 R Finger32 [1] { + Object: Biped Object + 0: Bip01 R Finger3R [0] { + Object: Dummy } } } } + 4: Bip01 R Finger4 [1] { + Object: Biped Object + 0: Bip01 R Finger41 [1] { + Object: Biped Object + 0: Bip01 R Finger42 [1] { + Object: Biped Object + 0: Bip01 R Finger4R [0] { + Object: Dummy } } } } + 5: box_arme [0] { + Object: Editable Mesh } } } } } } } } } + 1: Bip01 L Thigh [1] { + Object: Biped Object + 0: Bip01 L Calf [1] { + Object: Biped Object + 0: Bip01 L Foot [1] { + Object: Biped Object + 0: Bip01 L Toe0 [1] { + Object: Biped Object + 0: Bip01 L Toe0 [0] { + Object: Dummy } } } } } + 2: Bip01 R Thigh [1] { + Object: Biped Object + 0: Bip01 R Calf [1] { + Object: Biped Object + 0: Bip01 R Foot [1] { + Object: Biped Object + 0: Bip01 R Toe0 [1] { + Object: Biped Object + 0: Bip01 R Toe0 [0] { + Object: Dummy } } } } } } + 2: name [0] { + Object: Dummy } } +5: visage01 [0] { + Object: OSM Derived } +6: Object02 [0] { + Object: OSM Derived } +7: TR_HOF_underwear_hand [0] { + Object: OSM Derived } } + + +------------------ +(program exited with code: 0) +Press return to continue + diff --git a/code/nel/tools/pipeline/max_rewrite_assets/CMakeLists.txt b/code/nel/tools/pipeline/max_rewrite_assets/CMakeLists.txt new file mode 100644 index 000000000..9a5eb7d91 --- /dev/null +++ b/code/nel/tools/pipeline/max_rewrite_assets/CMakeLists.txt @@ -0,0 +1,36 @@ + +FIND_PACKAGE(LIBGSF) + +IF (NOT (LIBGSF_INCLUDE_DIR AND LIBGSF_LIBRARIES)) + MESSAGE(FATAL_ERROR "LIBGSF not found!") +ENDIF (NOT (LIBGSF_INCLUDE_DIR AND LIBGSF_LIBRARIES)) + +FIND_PACKAGE(GLIB2) + +if (NOT GLIB2_FOUND) + MESSAGE(FATAL_ERROR "GLIB2 not found!") +ENDIF (NOT GLIB2_FOUND) + +INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(${LIBGSF_INCLUDE_DIR}) + +FILE(GLOB SRCS *.cpp) +FILE(GLOB HDRS *.h) + +ADD_EXECUTABLE(pipeline_max_rewrite_assets + ${SRCS} + ${HDRS} + ) + +TARGET_LINK_LIBRARIES(pipeline_max_rewrite_assets + ${LIBGSF_LIBRARIES} + ${GLIB2_LIBRARIES} + pipeline_max + nelmisc +) + +NL_DEFAULT_PROPS(pipeline_max_dump "NeL, Tools, Pipeline: Max Rewrite Assets") +NL_ADD_RUNTIME_FLAGS(pipeline_max_rewrite_assets) + +INSTALL(TARGETS pipeline_max_rewrite_assets RUNTIME DESTINATION bin COMPONENT toolsmisc) + diff --git a/code/nel/tools/pipeline/max_rewrite_assets/main.cpp b/code/nel/tools/pipeline/max_rewrite_assets/main.cpp new file mode 100644 index 000000000..2a36de4e4 --- /dev/null +++ b/code/nel/tools/pipeline/max_rewrite_assets/main.cpp @@ -0,0 +1,248 @@ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "../max/storage_stream.h" +#include "../max/storage_object.h" +#include "../max/dll_directory.h" +#include "../max/class_directory_3.h" +#include "../max/class_data.h" +#include "../max/config.h" +#include "../max/scene.h" +#include "../max/scene_class_registry.h" + +// Testing +#include "../max/builtin/builtin.h" +#include "../max/update1/update1.h" +#include "../max/epoly/epoly.h" + +#include "../max/builtin/storage/app_data.h" +#include "../max/builtin/storage/geom_buffers.h" +#include "../max/builtin/scene_impl.h" +#include "../max/builtin/i_node.h" +#include "../max/update1/editable_mesh.h" +#include "../max/epoly/editable_poly.h" + +using namespace PIPELINE::MAX; +using namespace PIPELINE::MAX::BUILTIN; +using namespace PIPELINE::MAX::BUILTIN::STORAGE; +using namespace PIPELINE::MAX::UPDATE1; +using namespace PIPELINE::MAX::EPOLY; + +CSceneClassRegistry SceneClassRegistry; + +bool DisplayStream = false; +bool WriteModified = false; +bool WriteDummy = true; + +void serializeStorageContainer(PIPELINE::MAX::CStorageContainer *storageContainer, GsfInfile *infile, const char *streamName) +{ + GsfInput *input = gsf_infile_child_by_name(infile, streamName); + if (!input) + { + nlerror("GSF Could not read stream %s", streamName); + return; + } + { + PIPELINE::MAX::CStorageStream instream(input); + storageContainer->serial(instream); + } + g_object_unref(input); +} + +void serializeStorageContainer(PIPELINE::MAX::CStorageContainer *storageContainer, GsfOutfile *outfile, const char *streamName) +{ + //nldebug("write"); + GsfOutput *output = GSF_OUTPUT(gsf_outfile_new_child(outfile, streamName, false)); + if (!output) + { + nlerror("GSF Could not write stream %s", streamName); + return; + } + { + PIPELINE::MAX::CStorageStream outstream(output); + storageContainer->serial(outstream); + } + gsf_output_close(output); + g_object_unref(G_OBJECT(output)); +} + +void serializeRaw(std::vector &rawOutput, GsfInfile *infile, const char *streamName) +{ + GsfInput *input = gsf_infile_child_by_name(infile, streamName); + if (!input) + { + nlerror("GSF Could not read stream %s", streamName); + return; + } + { + PIPELINE::MAX::CStorageStream instream(input); + rawOutput.resize(instream.size()); + instream.serialBuffer(&rawOutput[0], rawOutput.size()); + } + g_object_unref(input); +} + +void serializeRaw(std::vector &rawOutput, GsfOutfile *outfile, const char *streamName) +{ + GsfOutput *output = GSF_OUTPUT(gsf_outfile_new_child(outfile, streamName, false)); + if (!output) + { + nlerror("GSF Could not write stream %s", streamName); + return; + } + { + PIPELINE::MAX::CStorageStream outstream(output); + outstream.serialBuffer(&rawOutput[0], rawOutput.size()); + } + gsf_output_close(output); + g_object_unref(G_OBJECT(output)); +} + +void handleFile(const std::string &path) +{ + GError *err = NULL; + + GsfDocMetaData *metadata = gsf_doc_meta_data_new(); + nlassert(metadata); + + GsfInput *src = gsf_input_stdio_new(path.c_str(), &err); + if (err) { nlerror("GSF Failed to open %s", path.c_str()); return; } + + GsfInfile *infile = gsf_infile_msole_new(src, NULL); + if (!infile) { nlerror("GSF Failed to recognize %s", path.c_str()); return; } + g_object_unref(src); + + uint8 classId[16]; + if (!gsf_infile_msole_get_class_id((GsfInfileMSOle *)infile, classId)) + nlerror("GSF Did not find classId"); + + PIPELINE::MAX::CStorageContainer videoPostQueue; + serializeStorageContainer(&videoPostQueue, infile, "VideoPostQueue"); + PIPELINE::MAX::CStorageContainer config; + serializeStorageContainer(&config, infile, "Config"); + PIPELINE::MAX::CStorageContainer classData; + serializeStorageContainer(&classData, infile, "ClassData"); + + std::vector summaryInformation; + serializeRaw(summaryInformation, infile, "\05SummaryInformation"); + + std::vector documentSummaryInformation; + serializeRaw(documentSummaryInformation, infile, "\05DocumentSummaryInformation"); // Can't read this, don't care. + + PIPELINE::MAX::CDllDirectory dllDirectory; + serializeStorageContainer(&dllDirectory, infile, "DllDirectory"); + dllDirectory.parse(VersionUnknown); + + PIPELINE::MAX::CClassDirectory3 classDirectory3(&dllDirectory); + serializeStorageContainer(&classDirectory3, infile, "ClassDirectory3"); + classDirectory3.parse(VersionUnknown); + + PIPELINE::MAX::CScene scene(&SceneClassRegistry, &dllDirectory, &classDirectory3); + serializeStorageContainer(&scene, infile, "Scene"); + + /* + // Not parsing the scene for this function. + scene.parse(VersionUnknown); + scene.clean(); + scene.build(VersionUnknown); + scene.disown(); + */ + + /* + PIPELINE::MAX::CStorageContainer dllDirectory; + serializeStorageContainer(&dllDirectory, infile, "DllDirectory"); + + PIPELINE::MAX::CStorageContainer classDirectory3; + serializeStorageContainer(&classDirectory3, infile, "ClassDirectory3"); + + PIPELINE::MAX::CStorageContainer scene; + serializeStorageContainer(&scene, infile, "Scene"); + */ + + if (DisplayStream) + { + videoPostQueue.toString(std::cout); + config.toString(std::cout); + classData.toString(std::cout); + dllDirectory.toString(std::cout); + classDirectory3.toString(std::cout); + scene.toString(std::cout); + } + + g_object_unref(infile); + + dllDirectory.disown(); + classDirectory3.disown(); + if (WriteModified) + { + const char *outpath = (WriteDummy ? "testdummy.max" : path.c_str()); + GsfOutput *output; + GsfOutfile *outfile; + + output = gsf_output_stdio_new(outpath, &err); + if (err) { nlerror("GSF Failed to create %s", outpath); return; } + outfile = gsf_outfile_msole_new(output); + g_object_unref(G_OBJECT(output)); + + serializeStorageContainer(&videoPostQueue, outfile, "VideoPostQueue"); + serializeStorageContainer(&scene, outfile, "Scene"); + serializeStorageContainer(&dllDirectory, outfile, "DllDirectory"); + serializeStorageContainer(&config, outfile, "Config"); + serializeStorageContainer(&classDirectory3, outfile, "ClassDirectory3"); + serializeStorageContainer(&classData, outfile, "ClassData"); + serializeRaw(summaryInformation, outfile, "\05SummaryInformation"); + serializeRaw(documentSummaryInformation, outfile, "\05DocumentSummaryInformation"); + + if (!gsf_outfile_msole_set_class_id((GsfOutfileMSOle *)outfile, classId)) + nlerror("GSF Cannot write class id"); + + gsf_output_close(GSF_OUTPUT(outfile)); + g_object_unref(G_OBJECT(outfile)); + } + + g_object_unref(metadata); +} + +// int __stdcall WinMain(void *, void *, void *, int) +int main(int argc, char **argv) +{ + // Initialise gsf + printf("Pipeline Max Rewrite Assets\n"); + char const *me = (argv[0] ? argv[0] : "pipeline_max_rewrite_assets"); + g_set_prgname(me); + gsf_init(); + + // Register all plugin classes + CBuiltin::registerClasses(&SceneClassRegistry); + CUpdate1::registerClasses(&SceneClassRegistry); + CEPoly::registerClasses(&SceneClassRegistry); + + handleFile("/srv/work/database/interfaces/anims_max/cp_fy_hof_species.max"); + + gsf_shutdown(); + + return 0; +} +