diff --git a/niflib.cpp b/niflib.cpp index bea78575d1b42244eeca40ab588ca4afbc325ba5..9ea759963cf057a8d608beebbd2f8d849fd1f5d6 100644 --- a/niflib.cpp +++ b/niflib.cpp @@ -786,4 +786,15 @@ unsigned int GetVersion(string version){ return outver; } +Ref<NiObject> CloneNifTree( Ref<NiObject> const & root, unsigned int version, unsigned int user_version ) { + //Create a string stream to temporarily hold the state-save of this tree + stringstream tmp; + + //Write the existing tree into the stringstream + WriteNifTree( tmp, root, version, user_version ); + + //Read the data back out of the stringstream, returning the new tree + return ReadNifTree( tmp ); +} + } // namespace NifLib \ No newline at end of file diff --git a/niflib.h b/niflib.h index 9639e0f357c3492a240616354eb91f63684d5066..86409a7d6faaaecbafb395b267b21d0239e5054f 100644 --- a/niflib.h +++ b/niflib.h @@ -199,7 +199,6 @@ NIFLIB_API void WriteNifTree( string const & file_name, Ref<NiObject> const & ro */ NIFLIB_API void WriteNifTree( ostream & stream, Ref<NiObject> const & root, unsigned int version = VER_4_0_0_2, unsigned int user_version = 0 ); -//TODO: This was written by Amorilia. Figure out how to fix it. /*! * Writes a bunch of files given a base file name, and a pointer to the root block of the Nif file tree. * \param file_name The desired file name for the base NIF file. This name serves as the basis for the names of any Kf files and Kfm files as well. The path is relative to the working directory unless a full path is specified. @@ -210,6 +209,16 @@ NIFLIB_API void WriteNifTree( ostream & stream, Ref<NiObject> const & root, unsi */ NIFLIB_API void WriteFileGroup( string const & file_name, Ref<NiObject> const & root, unsigned int version, ExportOptions export_files, NifGame kf_type ); +/*! + * Creates a clone of an entire tree of objects. + * \param root The root block to start from when cloning the NIF data. All referenced objects will be included in the new tree. + * \param version The version of the NIF format to use when writing a file. Default is version 4.0.0.2. + * \param user_version The user version of the NIF format to use when writing a file. Default is user version 0. + * \return The root of the new cloned tree. + */ +NIFLIB_API Ref<NiObject> CloneNifTree( Ref<NiObject> const & root, unsigned int version = VER_4_0_0_2, unsigned int user_version = 0 ); + + //TODO: Figure out how to fix this to work with the new system /*! * Merges two Nif trees into one. For standard Nif files, any blocks with the same name are merged. For Kf files, blocks are attatched to those that match the name specified in the KF root block. The data stored in a NIF file varies from version to version. Usually you are safe with the default option (the highest availiable version) but you may need to use an earlier version if you need to clone an obsolete piece of information.