Torque3D/Engine/lib/assimp/code/MDL/HalfLife/HL1MDLLoader.h
Areloch 6ade6f08ce Updated Assimp
Added initial behavior for ImageAssets to hold a list of GFX resources of different texture profiles to avoid mem leaks with incorrect-typed usages
Added function to ImageAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found
Added function to ShapeAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found
Disabled fields for dynamic and static shadowmap refresh rates
Moved noShape model to core/rendering/shapes to place it in a more logical module position
Added an include to avoid undefined type compile error and removed unneeded semicolon from zone code
Added call to reload probe textures when a reloadTextures call is made
Adjusted default directional light shadowmap settings to not be as extreme
Added utility function to probe manager to allow any class to request a 'best fit' list of probes that would affect a given location, allowing other classes such as fog or particles to utilize IBL. Also updated probeManager's forward rendering to utilize same function to reduce code duplication.
Shifted shape loader code to utilize assimp for loader consistency and testing
Changed render bin used for SSAO postfx so it runs at the right time
Made Core_Rendering module scan for assets
Updated loose file references to a number of assets to follow proper formatting
Refactored asset import code to follow a more consistent object heirarchy structure on importing assets, allowing more reliable cross-referencing between inbound items
Updated asset import logic for materials/images so that they properly utilize ImageType. Images correctly save out the assigned image type, materials reference the images' type to know what map slot they should be used in. Importer logic also updated to better find-and-add associated images based on type.
Cleaned up a bunch of old, outdated code in the asset importer
Added initial handling for in-place importing of files without needing to process them through the UI.
Added ability to edit module script from RMB context menu if torsion path is set
Updated list field code for variable inspector to utilize correct ownerObject field
2020-03-19 09:47:38 -05:00

242 lines
8 KiB
C++

/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file HL1MDLLoader.h
* @brief Declaration of the Half-Life 1 MDL loader.
*/
#ifndef AI_HL1MDLLOADER_INCLUDED
#define AI_HL1MDLLOADER_INCLUDED
#include "HL1FileData.h"
#include "HL1ImportSettings.h"
#include "UniqueNameGenerator.h"
#include <memory>
#include <string>
#include <assimp/types.h>
#include <assimp/scene.h>
#include <assimp/texture.h>
#include <assimp/IOSystem.hpp>
#include <assimp/DefaultIOSystem.h>
#include <assimp/Exceptional.h>
namespace Assimp {
namespace MDL {
namespace HalfLife {
class HL1MDLLoader {
public:
HL1MDLLoader() = delete;
HL1MDLLoader(const HL1MDLLoader &) = delete;
/** See variables descriptions at the end for more details. */
HL1MDLLoader(
aiScene *scene,
IOSystem *io,
const unsigned char *buffer,
const std::string &file_path,
const HL1ImportSettings &import_settings);
~HL1MDLLoader();
void load_file();
protected:
/** \brief Validate the header data structure of a Half-Life 1 MDL file.
* \param[in] header Input header to be validated.
* \param[in] is_texture_header Whether or not we are reading an MDL
* texture file.
*/
void validate_header(const Header_HL1 *header, bool is_texture_header);
void load_texture_file();
void load_sequence_groups_files();
void read_textures();
void read_skins();
void read_bones();
void read_meshes();
void read_animations();
void read_sequence_groups_info();
void read_sequence_infos();
void read_sequence_transitions();
void read_attachments();
void read_hitboxes();
void read_bone_controllers();
void read_global_info();
private:
void release_resources();
/** \brief Load a file and copy it's content to a buffer.
* \param file_path The path to the file to be loaded.
* \param buffer A pointer to a buffer to receive the data.
*/
template <typename MDLFileHeader>
void load_file_into_buffer(const std::string &file_path, unsigned char *&buffer);
/** \brief Read an MDL texture.
* \param[in] ptexture A pointer to an MDL texture.
* \param[in] data A pointer to the data from \p ptexture.
* \param[in] pal A pointer to the texture palette from \p ptexture.
* \param[in,out] pResult A pointer to the output resulting Assimp texture.
* \param[in,out] last_palette_color The last color from the image palette.
*/
void read_texture(const Texture_HL1 *ptexture,
uint8_t *data, uint8_t *pal, aiTexture *pResult,
aiColor3D &last_palette_color);
/** \brief This method reads a compressed anim value.
* \param[in] panimvalue A pointer to the animation data.
* \param[in] frame The frame to look for.
* \param[in] bone_scale The current bone scale to apply to the compressed value.
* \param[in,out] value The decompressed anim value at \p frame.
*/
void extract_anim_value(const AnimValue_HL1 *panimvalue,
int frame, float bone_scale, float &value);
/**
* \brief Given the number of blend animations, determine the number of blend controllers.
*
* \param[in] num_blend_animations The number of blend animations.
* \param[out] num_blend_controllers The number of blend controllers.
* \return True if the number of blend controllers was determined. False otherwise.
*/
static bool get_num_blend_controllers(const int num_blend_animations, int &num_blend_controllers);
/** Output scene to be filled */
aiScene *scene_;
/** Output I/O handler. Required for additional IO operations. */
IOSystem *io_;
/** Buffer from MDLLoader class. */
const unsigned char *buffer_;
/** The full file path to the MDL file we are trying to load.
* Used to locate other MDL files since MDL may store resources
* in external MDL files. */
const std::string &file_path_;
/** Configuration for HL1 MDL */
const HL1ImportSettings &import_settings_;
/** Main MDL header. */
const Header_HL1 *header_;
/** External MDL texture header. */
const Header_HL1 *texture_header_;
/** External MDL animation headers.
* One for each loaded animation file. */
SequenceHeader_HL1 **anim_headers_;
/** Texture file data. */
unsigned char *texture_buffer_;
/** Animation files data. */
unsigned char **anim_buffers_;
/** The number of sequence groups. */
int num_sequence_groups_;
/** The list of children to be appended to the scene's root node. */
std::vector<aiNode *> rootnode_children_;
/** A unique name generator. Used to generate names for MDL values
* that may have empty/duplicate names. */
UniqueNameGenerator unique_name_generator_;
/** The list of unique sequence names. */
std::vector<std::string> unique_sequence_names_;
/** The list of unique sequence groups names. */
std::vector<std::string> unique_sequence_groups_names_;
/** Structure to store temporary bone information. */
struct TempBone {
TempBone() :
node(nullptr),
absolute_transform(),
offset_matrix() {}
aiNode *node;
aiMatrix4x4 absolute_transform;
aiMatrix4x4 offset_matrix;
};
std::vector<TempBone> temp_bones_;
/** The number of available bone controllers in the model. */
int num_blend_controllers_;
/** Self explanatory. */
int total_models_;
};
// ------------------------------------------------------------------------------------------------
template <typename MDLFileHeader>
void HL1MDLLoader::load_file_into_buffer(const std::string &file_path, unsigned char *&buffer) {
if (!io_->Exists(file_path))
throw DeadlyImportError("Missing file " + DefaultIOSystem::fileName(file_path) + ".");
std::unique_ptr<IOStream> file(io_->Open(file_path));
if (file.get() == NULL)
throw DeadlyImportError("Failed to open MDL file " + DefaultIOSystem::fileName(file_path) + ".");
const size_t file_size = file->FileSize();
if (file_size < sizeof(MDLFileHeader))
throw DeadlyImportError("MDL file is too small.");
buffer = new unsigned char[1 + file_size];
file->Read((void *)buffer, 1, file_size);
buffer[file_size] = '\0';
}
} // namespace HalfLife
} // namespace MDL
} // namespace Assimp
#endif // AI_HL1MDLLOADER_INCLUDED