mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
update assimp to 6.0.5
This commit is contained in:
parent
2d2eb57e2e
commit
f5cf21cfeb
941 changed files with 22718 additions and 12240 deletions
182
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1DataBuffer.h
Normal file
182
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1DataBuffer.h
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2026, 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 HL1DataBuffer.h
|
||||
* @brief Declaration of the Half-Life 1 data buffer.
|
||||
*/
|
||||
|
||||
#ifndef AI_HL1DATABUFFER_INCLUDED
|
||||
#define AI_HL1DATABUFFER_INCLUDED
|
||||
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/defs.h>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
/**
|
||||
* \brief Lightweight byte buffer wrapper for HL1 binary parsing.
|
||||
*
|
||||
* Acts as either:
|
||||
* - a non-owning view into external memory, or
|
||||
* - an owning buffer backed by a unique_ptr.
|
||||
*
|
||||
* Copy is disabled to avoid accidental double-ownership; move is supported.
|
||||
*/
|
||||
class HL1DataBuffer {
|
||||
public:
|
||||
/** \brief Construct an empty buffer (null view). */
|
||||
HL1DataBuffer() AI_NO_EXCEPT : data_(nullptr),
|
||||
length_(0),
|
||||
owner_(nullptr) {}
|
||||
|
||||
/** \brief Non-copyable (buffer may own memory). */
|
||||
HL1DataBuffer(const HL1DataBuffer &) = delete;
|
||||
|
||||
/** \brief Non-copyable (buffer may own memory). */
|
||||
HL1DataBuffer &operator=(const HL1DataBuffer &) = delete;
|
||||
|
||||
/** \brief Move-construct, transferring ownership/view state. */
|
||||
HL1DataBuffer(HL1DataBuffer &&other) AI_NO_EXCEPT : data_(other.data_),
|
||||
length_(other.length_),
|
||||
owner_(std::move(other.owner_)) {
|
||||
other.data_ = nullptr;
|
||||
other.length_ = 0;
|
||||
other.owner_ = nullptr;
|
||||
}
|
||||
|
||||
/** \brief Move-assign, transferring ownership/view state. */
|
||||
HL1DataBuffer &operator=(HL1DataBuffer &&other) AI_NO_EXCEPT {
|
||||
if (this != &other) {
|
||||
data_ = other.data_;
|
||||
length_ = other.length_;
|
||||
owner_ = std::move(other.owner_);
|
||||
|
||||
other.data_ = nullptr;
|
||||
other.length_ = 0;
|
||||
other.owner_ = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a non-owning view into external bytes.
|
||||
*
|
||||
* \param[in] data Pointer to raw bytes (must outlive the view).
|
||||
* \param[in] length Size in bytes.
|
||||
*/
|
||||
static HL1DataBuffer view(const unsigned char *data, size_t length) {
|
||||
HL1DataBuffer b;
|
||||
b.data_ = data;
|
||||
b.length_ = length;
|
||||
b.owner_ = nullptr;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create a non-owning view of another buffer.
|
||||
*
|
||||
* \param[in] other Source buffer.
|
||||
*/
|
||||
static HL1DataBuffer view(const HL1DataBuffer &other) {
|
||||
HL1DataBuffer b;
|
||||
b.data_ = other.data_;
|
||||
b.length_ = other.length_;
|
||||
b.owner_ = nullptr;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Create an owning buffer by taking ownership of allocated storage.
|
||||
*
|
||||
* \param[in] buffer Unique buffer storage.
|
||||
* \param[in] length Size in bytes.
|
||||
*/
|
||||
static HL1DataBuffer owning(std::unique_ptr<unsigned char[]> buffer, size_t length) {
|
||||
HL1DataBuffer b;
|
||||
b.data_ = buffer.get();
|
||||
b.length_ = length;
|
||||
b.owner_ = std::move(buffer);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Return a typed pointer into the buffer with bounds checks.
|
||||
*
|
||||
* \param[in] offset Byte offset from the start of the buffer.
|
||||
* \param[in] elements Number of elements to access.
|
||||
* \return Pointer to the requested typed data inside the buffer.
|
||||
* \throws DeadlyImportError if the request is out of range.
|
||||
*/
|
||||
template <typename DataType>
|
||||
const DataType *get_data(int offset, int elements) const {
|
||||
if (offset < 0 || elements < 0) {
|
||||
throw DeadlyImportError("MDL file contains invalid data");
|
||||
}
|
||||
|
||||
const size_t uoffset = static_cast<size_t>(offset);
|
||||
const size_t uelements = static_cast<size_t>(elements);
|
||||
|
||||
if (uoffset > length_ || uelements > (length_ - uoffset) / sizeof(DataType)) {
|
||||
throw DeadlyImportError("MDL file contains invalid data");
|
||||
}
|
||||
|
||||
return reinterpret_cast<const DataType *>(data_ + uoffset);
|
||||
}
|
||||
|
||||
private:
|
||||
/** Raw byte pointer (points to owner_.get() when owning, otherwise external). */
|
||||
const unsigned char *data_;
|
||||
/** Buffer length in bytes. */
|
||||
size_t length_;
|
||||
/** Owning storage (null for views). */
|
||||
std::unique_ptr<unsigned char[]> owner_;
|
||||
};
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // AI_HL1DATABUFFER_INCLUDED
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -78,18 +78,19 @@ HL1MDLLoader::HL1MDLLoader(
|
|||
aiScene *scene,
|
||||
IOSystem *io,
|
||||
const unsigned char *buffer,
|
||||
size_t buffer_length,
|
||||
const std::string &file_path,
|
||||
const HL1ImportSettings &import_settings) :
|
||||
scene_(scene),
|
||||
io_(io),
|
||||
buffer_(buffer),
|
||||
buffer_(HL1DataBuffer::view(buffer, buffer_length)),
|
||||
file_path_(file_path),
|
||||
import_settings_(import_settings),
|
||||
header_(nullptr),
|
||||
texture_header_(nullptr),
|
||||
anim_headers_(nullptr),
|
||||
texture_buffer_(nullptr),
|
||||
anim_buffers_(nullptr),
|
||||
anim_headers_(),
|
||||
texture_buffer_(),
|
||||
anim_buffers_(),
|
||||
num_sequence_groups_(0),
|
||||
rootnode_children_(),
|
||||
unique_name_generator_(),
|
||||
|
|
@ -108,28 +109,6 @@ HL1MDLLoader::~HL1MDLLoader() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HL1MDLLoader::release_resources() {
|
||||
if (buffer_ != texture_buffer_) {
|
||||
delete[] texture_buffer_;
|
||||
texture_buffer_ = nullptr;
|
||||
}
|
||||
|
||||
if (num_sequence_groups_ && anim_buffers_) {
|
||||
for (int i = 1; i < num_sequence_groups_; ++i) {
|
||||
if (anim_buffers_[i]) {
|
||||
delete[] anim_buffers_[i];
|
||||
anim_buffers_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] anim_buffers_;
|
||||
anim_buffers_ = nullptr;
|
||||
}
|
||||
|
||||
if (anim_headers_) {
|
||||
delete[] anim_headers_;
|
||||
anim_headers_ = nullptr;
|
||||
}
|
||||
|
||||
// Root has some children nodes. so let's proceed them
|
||||
if (!rootnode_children_.empty()) {
|
||||
// Here, it means that the nodes were not added to the
|
||||
|
|
@ -147,7 +126,7 @@ void HL1MDLLoader::release_resources() {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
void HL1MDLLoader::load_file() {
|
||||
try {
|
||||
header_ = (const Header_HL1 *)buffer_;
|
||||
header_ = get_buffer_data<Header_HL1>(0, 1);
|
||||
validate_header(header_, false);
|
||||
|
||||
// Create the root scene node.
|
||||
|
|
@ -286,10 +265,10 @@ void HL1MDLLoader::load_texture_file() {
|
|||
load_file_into_buffer<Header_HL1>(texture_file_path, texture_buffer_);
|
||||
} else {
|
||||
// Model has no external texture file. This means the texture is stored inside the main MDL file.
|
||||
texture_buffer_ = const_cast<unsigned char *>(buffer_);
|
||||
texture_buffer_ = HL1DataBuffer::view(buffer_);
|
||||
}
|
||||
|
||||
texture_header_ = (const Header_HL1 *)texture_buffer_;
|
||||
texture_header_ = get_texture_buffer_data<Header_HL1>(0, 1);
|
||||
|
||||
// Validate texture header.
|
||||
validate_header(texture_header_, true);
|
||||
|
|
@ -318,12 +297,8 @@ void HL1MDLLoader::load_sequence_groups_files() {
|
|||
|
||||
num_sequence_groups_ = header_->numseqgroups;
|
||||
|
||||
anim_buffers_ = new unsigned char *[num_sequence_groups_];
|
||||
anim_headers_ = new SequenceHeader_HL1 *[num_sequence_groups_];
|
||||
for (int i = 0; i < num_sequence_groups_; ++i) {
|
||||
anim_buffers_[i] = nullptr;
|
||||
anim_headers_[i] = nullptr;
|
||||
}
|
||||
anim_buffers_.resize(num_sequence_groups_);
|
||||
anim_headers_.resize(num_sequence_groups_, nullptr);
|
||||
|
||||
std::string file_path_without_extension =
|
||||
DefaultIOSystem::absolutePath(file_path_) +
|
||||
|
|
@ -340,14 +315,14 @@ void HL1MDLLoader::load_sequence_groups_files() {
|
|||
|
||||
load_file_into_buffer<SequenceHeader_HL1>(sequence_file_path, anim_buffers_[i]);
|
||||
|
||||
anim_headers_[i] = (SequenceHeader_HL1 *)anim_buffers_[i];
|
||||
anim_headers_[i] = get_anim_buffer_data<SequenceHeader_HL1>(i, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Read an MDL texture.
|
||||
void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture,
|
||||
uint8_t *data, uint8_t *pal, aiTexture *pResult,
|
||||
const uint8_t *data, const uint8_t *pal, aiTexture *pResult,
|
||||
aiColor3D &last_palette_color) {
|
||||
pResult->mFilename = ptexture->name;
|
||||
pResult->mWidth = static_cast<unsigned int>(ptexture->width);
|
||||
|
|
@ -381,24 +356,24 @@ void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture,
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void HL1MDLLoader::read_textures() {
|
||||
const Texture_HL1 *ptexture = (const Texture_HL1 *)((uint8_t *)texture_header_ + texture_header_->textureindex);
|
||||
unsigned char *pin = texture_buffer_;
|
||||
scene_->mTextures = new aiTexture *[texture_header_->numtextures];
|
||||
scene_->mMaterials = new aiMaterial *[texture_header_->numtextures];
|
||||
|
||||
scene_->mNumTextures = scene_->mNumMaterials = texture_header_->numtextures;
|
||||
scene_->mTextures = new aiTexture *[scene_->mNumTextures];
|
||||
scene_->mMaterials = new aiMaterial *[scene_->mNumMaterials];
|
||||
const Texture_HL1 *ptexture = get_texture_buffer_data<Texture_HL1>(texture_header_->textureindex, texture_header_->numtextures);
|
||||
|
||||
for (int i = 0; i < texture_header_->numtextures; ++i) {
|
||||
scene_->mTextures[i] = new aiTexture();
|
||||
++scene_->mNumTextures;
|
||||
|
||||
const uint8_t *data = get_texture_buffer_data<uint8_t>(ptexture[i].index, ptexture[i].width * ptexture[i].height);
|
||||
const uint8_t *pal = get_texture_buffer_data<uint8_t>(ptexture[i].index + ptexture[i].width * ptexture[i].height, 256 * 3);
|
||||
|
||||
aiColor3D last_palette_color;
|
||||
read_texture(&ptexture[i],
|
||||
pin + ptexture[i].index,
|
||||
pin + ptexture[i].width * ptexture[i].height + ptexture[i].index,
|
||||
scene_->mTextures[i],
|
||||
last_palette_color);
|
||||
read_texture(&ptexture[i], data, pal, scene_->mTextures[i], last_palette_color);
|
||||
|
||||
aiMaterial *scene_material = scene_->mMaterials[i] = new aiMaterial();
|
||||
aiMaterial *scene_material = new aiMaterial();
|
||||
scene_->mMaterials[i] = scene_material;
|
||||
++scene_->mNumMaterials;
|
||||
|
||||
const aiTextureType texture_type = aiTextureType_DIFFUSE;
|
||||
aiString texture_name(ptexture[i].name);
|
||||
|
|
@ -435,10 +410,14 @@ void HL1MDLLoader::read_skins() {
|
|||
}
|
||||
|
||||
// Pointer to base texture index.
|
||||
short *default_skin_ptr = (short *)((uint8_t *)texture_header_ + texture_header_->skinindex);
|
||||
const short *default_skin_ptr = get_texture_buffer_data<short>(
|
||||
texture_header_->skinindex,
|
||||
texture_header_->numskinref);
|
||||
|
||||
// Start at first replacement skin.
|
||||
short *replacement_skin_ptr = default_skin_ptr + texture_header_->numskinref;
|
||||
const short *replacement_skin_ptr = get_texture_buffer_data<short>(
|
||||
texture_header_->skinindex + texture_header_->numskinref * sizeof(short),
|
||||
(texture_header_->numskinfamilies - 1) * texture_header_->numskinref);
|
||||
|
||||
for (int i = 1; i < texture_header_->numskinfamilies; ++i, replacement_skin_ptr += texture_header_->numskinref) {
|
||||
for (int j = 0; j < texture_header_->numskinref; ++j) {
|
||||
|
|
@ -457,7 +436,7 @@ void HL1MDLLoader::read_bones() {
|
|||
return;
|
||||
}
|
||||
|
||||
const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex);
|
||||
const Bone_HL1 *pbone = get_buffer_data<Bone_HL1>(header_->boneindex, header_->numbones);
|
||||
|
||||
std::vector<std::string> unique_bones_names(header_->numbones);
|
||||
for (int i = 0; i < header_->numbones; ++i) {
|
||||
|
|
@ -589,12 +568,12 @@ void HL1MDLLoader::read_meshes() {
|
|||
int total_triangles = 0;
|
||||
total_models_ = 0;
|
||||
|
||||
const Bodypart_HL1 *pbodypart = (const Bodypart_HL1 *)((uint8_t *)header_ + header_->bodypartindex);
|
||||
const Bodypart_HL1 *pbodypart = get_buffer_data<Bodypart_HL1>(header_->bodypartindex, header_->numbodyparts);
|
||||
const Model_HL1 *pmodel = nullptr;
|
||||
const Mesh_HL1 *pmesh = nullptr;
|
||||
|
||||
const Texture_HL1 *ptexture = (const Texture_HL1 *)((uint8_t *)texture_header_ + texture_header_->textureindex);
|
||||
short *pskinref = (short *)((uint8_t *)texture_header_ + texture_header_->skinindex);
|
||||
const Texture_HL1 *ptexture = get_texture_buffer_data<Texture_HL1>(texture_header_->textureindex, texture_header_->numtextures);
|
||||
const short *pskinref = get_texture_buffer_data<short>(texture_header_->skinindex, texture_header_->numskinref);
|
||||
|
||||
scene_->mNumMeshes = 0;
|
||||
|
||||
|
|
@ -606,7 +585,7 @@ void HL1MDLLoader::read_meshes() {
|
|||
for (int i = 0; i < header_->numbodyparts; ++i, ++pbodypart) {
|
||||
unique_bodyparts_names[i] = pbodypart->name;
|
||||
|
||||
pmodel = (Model_HL1 *)((uint8_t *)header_ + pbodypart->modelindex);
|
||||
pmodel = get_buffer_data<Model_HL1>(pbodypart->modelindex, pbodypart->nummodels);
|
||||
for (int j = 0; j < pbodypart->nummodels; ++j, ++pmodel) {
|
||||
scene_->mNumMeshes += pmodel->nummesh;
|
||||
total_verts += pmodel->numverts;
|
||||
|
|
@ -633,7 +612,7 @@ void HL1MDLLoader::read_meshes() {
|
|||
unique_name_generator_.make_unique(unique_bodyparts_names);
|
||||
|
||||
// Now do the same for each model.
|
||||
pbodypart = (const Bodypart_HL1 *)((uint8_t *)header_ + header_->bodypartindex);
|
||||
pbodypart = get_buffer_data<Bodypart_HL1>(header_->bodypartindex, header_->numbodyparts);
|
||||
|
||||
// Prepare template name for bodypart models.
|
||||
std::vector<std::string> unique_models_names;
|
||||
|
|
@ -642,7 +621,7 @@ void HL1MDLLoader::read_meshes() {
|
|||
unsigned int model_index = 0;
|
||||
|
||||
for (int i = 0; i < header_->numbodyparts; ++i, ++pbodypart) {
|
||||
pmodel = (Model_HL1 *)((uint8_t *)header_ + pbodypart->modelindex);
|
||||
pmodel = get_buffer_data<Model_HL1>(pbodypart->modelindex, pbodypart->nummodels);
|
||||
for (int j = 0; j < pbodypart->nummodels; ++j, ++pmodel, ++model_index)
|
||||
unique_models_names[model_index] = pmodel->name;
|
||||
}
|
||||
|
|
@ -654,7 +633,7 @@ void HL1MDLLoader::read_meshes() {
|
|||
|
||||
scene_->mMeshes = new aiMesh *[scene_->mNumMeshes];
|
||||
|
||||
pbodypart = (const Bodypart_HL1 *)((uint8_t *)header_ + header_->bodypartindex);
|
||||
pbodypart = get_buffer_data<Bodypart_HL1>(header_->bodypartindex, header_->numbodyparts);
|
||||
|
||||
/* Create a node that will represent the mesh hierarchy.
|
||||
|
||||
|
|
@ -738,7 +717,7 @@ void HL1MDLLoader::read_meshes() {
|
|||
model_index = 0;
|
||||
|
||||
for (int i = 0; i < header_->numbodyparts; ++i, ++pbodypart, ++bodyparts_node_ptr) {
|
||||
pmodel = (const Model_HL1 *)((uint8_t *)header_ + pbodypart->modelindex);
|
||||
pmodel = get_buffer_data<Model_HL1>(pbodypart->modelindex, pbodypart->nummodels);
|
||||
|
||||
// Create bodypart node for the mesh tree hierarchy.
|
||||
aiNode *bodypart_node = (*bodyparts_node_ptr) = new aiNode(unique_bodyparts_names[i]);
|
||||
|
|
@ -753,12 +732,12 @@ void HL1MDLLoader::read_meshes() {
|
|||
for (int j = 0; j < pbodypart->nummodels;
|
||||
++j, ++pmodel, ++bodypart_models_ptr, ++model_index) {
|
||||
|
||||
pmesh = (const Mesh_HL1 *)((uint8_t *)header_ + pmodel->meshindex);
|
||||
pmesh = get_buffer_data<Mesh_HL1>(pmodel->meshindex, pmodel->nummesh);
|
||||
|
||||
uint8_t *pvertbone = ((uint8_t *)header_ + pmodel->vertinfoindex);
|
||||
uint8_t *pnormbone = ((uint8_t *)header_ + pmodel->norminfoindex);
|
||||
vec3_t *pstudioverts = (vec3_t *)((uint8_t *)header_ + pmodel->vertindex);
|
||||
vec3_t *pstudionorms = (vec3_t *)((uint8_t *)header_ + pmodel->normindex);
|
||||
const uint8_t *pvertbone = get_buffer_data<uint8_t>(pmodel->vertinfoindex, pmodel->numverts);
|
||||
const uint8_t *pnormbone = get_buffer_data<uint8_t>(pmodel->norminfoindex, pmodel->numnorms);
|
||||
const vec3_t *pstudioverts = get_buffer_data<vec3_t>(pmodel->vertindex, pmodel->numverts);
|
||||
const vec3_t *pstudionorms = get_buffer_data<vec3_t>(pmodel->normindex, pmodel->numnorms);
|
||||
|
||||
// Each vertex and normal is in local space, so transform
|
||||
// each of them to bring them in bind pose.
|
||||
|
|
@ -964,7 +943,7 @@ void HL1MDLLoader::read_animations() {
|
|||
return;
|
||||
}
|
||||
|
||||
const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex);
|
||||
const SequenceDesc_HL1 *pseqdesc = get_buffer_data<SequenceDesc_HL1>(header_->seqindex, header_->numseq);
|
||||
const SequenceGroup_HL1 *pseqgroup = nullptr;
|
||||
const AnimValueOffset_HL1 *panim = nullptr;
|
||||
const AnimValue_HL1 *panimvalue = nullptr;
|
||||
|
|
@ -990,22 +969,22 @@ void HL1MDLLoader::read_animations() {
|
|||
// Get the number of available blend controllers for global info.
|
||||
get_num_blend_controllers(highest_num_blend_animations, num_blend_controllers_);
|
||||
|
||||
pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex);
|
||||
pseqdesc = get_buffer_data<SequenceDesc_HL1>(header_->seqindex, header_->numseq);
|
||||
|
||||
aiAnimation **scene_animations_ptr = scene_->mAnimations = new aiAnimation *[scene_->mNumAnimations];
|
||||
aiAnimation **scene_animations_ptr = scene_->mAnimations = new aiAnimation *[scene_->mNumAnimations]();
|
||||
|
||||
for (int sequence = 0; sequence < header_->numseq; ++sequence, ++pseqdesc) {
|
||||
pseqgroup = (const SequenceGroup_HL1 *)((uint8_t *)header_ + header_->seqgroupindex) + pseqdesc->seqgroup;
|
||||
pseqgroup = get_buffer_data<SequenceGroup_HL1>(header_->seqgroupindex + pseqdesc->seqgroup * sizeof(SequenceGroup_HL1), 1);
|
||||
|
||||
if (pseqdesc->seqgroup == 0) {
|
||||
panim = (const AnimValueOffset_HL1 *)((uint8_t *)header_ + pseqgroup->unused2 + pseqdesc->animindex);
|
||||
panim = get_buffer_data<AnimValueOffset_HL1>(pseqgroup->unused2 + pseqdesc->animindex, pseqdesc->numblends * header_->numbones);
|
||||
} else {
|
||||
panim = (const AnimValueOffset_HL1 *)((uint8_t *)anim_headers_[pseqdesc->seqgroup] + pseqdesc->animindex);
|
||||
panim = get_anim_buffer_data<AnimValueOffset_HL1>(pseqdesc->seqgroup, pseqdesc->animindex, pseqdesc->numblends * header_->numbones);
|
||||
}
|
||||
|
||||
for (int blend = 0; blend < pseqdesc->numblends; ++blend, ++scene_animations_ptr) {
|
||||
|
||||
const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex);
|
||||
const Bone_HL1 *pbone = get_buffer_data<Bone_HL1>(header_->boneindex, header_->numbones);
|
||||
|
||||
aiAnimation *scene_animation = (*scene_animations_ptr) = new aiAnimation();
|
||||
|
||||
|
|
@ -1013,7 +992,7 @@ void HL1MDLLoader::read_animations() {
|
|||
scene_animation->mTicksPerSecond = pseqdesc->fps;
|
||||
scene_animation->mDuration = static_cast<double>(pseqdesc->fps) * pseqdesc->numframes;
|
||||
scene_animation->mNumChannels = static_cast<unsigned int>(header_->numbones);
|
||||
scene_animation->mChannels = new aiNodeAnim *[scene_animation->mNumChannels];
|
||||
scene_animation->mChannels = new aiNodeAnim *[scene_animation->mNumChannels]();
|
||||
|
||||
for (int bone = 0; bone < header_->numbones; bone++, ++pbone, ++panim) {
|
||||
aiNodeAnim *node_anim = scene_animation->mChannels[bone] = new aiNodeAnim();
|
||||
|
|
@ -1074,7 +1053,7 @@ void HL1MDLLoader::read_sequence_groups_info() {
|
|||
sequence_groups_node->mNumChildren = static_cast<unsigned int>(header_->numseqgroups);
|
||||
sequence_groups_node->mChildren = new aiNode *[sequence_groups_node->mNumChildren];
|
||||
|
||||
const SequenceGroup_HL1 *pseqgroup = (const SequenceGroup_HL1 *)((uint8_t *)header_ + header_->seqgroupindex);
|
||||
const SequenceGroup_HL1 *pseqgroup = get_buffer_data<SequenceGroup_HL1>(header_->seqgroupindex, header_->numseqgroups);
|
||||
|
||||
unique_sequence_groups_names_.resize(header_->numseqgroups);
|
||||
for (int i = 0; i < header_->numseqgroups; ++i) {
|
||||
|
|
@ -1106,7 +1085,7 @@ void HL1MDLLoader::read_sequence_infos() {
|
|||
return;
|
||||
}
|
||||
|
||||
const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex);
|
||||
const SequenceDesc_HL1 *pseqdesc = get_buffer_data<SequenceDesc_HL1>(header_->seqindex, header_->numseq);
|
||||
|
||||
aiNode *sequence_infos_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_INFOS);
|
||||
rootnode_children_.push_back(sequence_infos_node);
|
||||
|
|
@ -1178,7 +1157,7 @@ void HL1MDLLoader::read_sequence_infos() {
|
|||
pseqdesc->numevents, "animation events");
|
||||
}
|
||||
|
||||
const AnimEvent_HL1 *pevent = (const AnimEvent_HL1 *)((uint8_t *)header_ + pseqdesc->eventindex);
|
||||
const AnimEvent_HL1 *pevent = get_buffer_data<AnimEvent_HL1>(pseqdesc->eventindex, pseqdesc->numevents);
|
||||
|
||||
aiNode *pEventsNode = new aiNode(AI_MDL_HL1_NODE_ANIMATION_EVENTS);
|
||||
sequence_info_node_children.push_back(pEventsNode);
|
||||
|
|
@ -1215,7 +1194,7 @@ void HL1MDLLoader::read_sequence_transitions() {
|
|||
aiNode *transition_graph_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_TRANSITION_GRAPH);
|
||||
rootnode_children_.push_back(transition_graph_node);
|
||||
|
||||
uint8_t *ptransitions = ((uint8_t *)header_ + header_->transitionindex);
|
||||
const uint8_t *ptransitions = get_buffer_data<uint8_t>(header_->transitionindex, header_->numtransitions * header_->numtransitions);
|
||||
aiMetadata *md = transition_graph_node->mMetaData = aiMetadata::Alloc(header_->numtransitions * header_->numtransitions);
|
||||
for (unsigned int i = 0; i < md->mNumProperties; ++i)
|
||||
md->Set(i, std::to_string(i), static_cast<int>(ptransitions[i]));
|
||||
|
|
@ -1226,7 +1205,7 @@ void HL1MDLLoader::read_attachments() {
|
|||
return;
|
||||
}
|
||||
|
||||
const Attachment_HL1 *pattach = (const Attachment_HL1 *)((uint8_t *)header_ + header_->attachmentindex);
|
||||
const Attachment_HL1 *pattach = get_buffer_data<Attachment_HL1>(header_->attachmentindex, header_->numattachments);
|
||||
|
||||
aiNode *attachments_node = new aiNode(AI_MDL_HL1_NODE_ATTACHMENTS);
|
||||
rootnode_children_.push_back(attachments_node);
|
||||
|
|
@ -1250,7 +1229,7 @@ void HL1MDLLoader::read_hitboxes() {
|
|||
return;
|
||||
}
|
||||
|
||||
const Hitbox_HL1 *phitbox = (const Hitbox_HL1 *)((uint8_t *)header_ + header_->hitboxindex);
|
||||
const Hitbox_HL1 *phitbox = get_buffer_data<Hitbox_HL1>(header_->hitboxindex, header_->numhitboxes);
|
||||
|
||||
aiNode *hitboxes_node = new aiNode(AI_MDL_HL1_NODE_HITBOXES);
|
||||
rootnode_children_.push_back(hitboxes_node);
|
||||
|
|
@ -1277,7 +1256,9 @@ void HL1MDLLoader::read_bone_controllers() {
|
|||
return;
|
||||
}
|
||||
|
||||
const BoneController_HL1 *pbonecontroller = (const BoneController_HL1 *)((uint8_t *)header_ + header_->bonecontrollerindex);
|
||||
const BoneController_HL1 *pbonecontroller = get_buffer_data<BoneController_HL1>(
|
||||
header_->bonecontrollerindex,
|
||||
header_->numbonecontrollers);
|
||||
|
||||
aiNode *bones_controller_node = new aiNode(AI_MDL_HL1_NODE_BONE_CONTROLLERS);
|
||||
rootnode_children_.push_back(bones_controller_node);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define AI_HL1MDLLOADER_INCLUDED
|
||||
|
||||
#include "HL1FileData.h"
|
||||
#include "HL1DataBuffer.h"
|
||||
#include "HL1ImportSettings.h"
|
||||
#include "UniqueNameGenerator.h"
|
||||
|
||||
|
|
@ -74,6 +75,7 @@ public:
|
|||
aiScene *scene,
|
||||
IOSystem *io,
|
||||
const unsigned char *buffer,
|
||||
size_t buffer_length,
|
||||
const std::string &file_path,
|
||||
const HL1ImportSettings &import_settings);
|
||||
|
||||
|
|
@ -109,10 +111,32 @@ private:
|
|||
|
||||
/** \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.
|
||||
* \param buffer A buffer to receive the data.
|
||||
*/
|
||||
template <typename MDLFileHeader>
|
||||
void load_file_into_buffer(const std::string &file_path, unsigned char *&buffer);
|
||||
void load_file_into_buffer(const std::string &file_path, HL1DataBuffer &buffer);
|
||||
|
||||
/** \brief Get a pointer to the specified data type in texture buffer.
|
||||
* \param offset Offset in bytes.
|
||||
* \param elements Elements count.
|
||||
*/
|
||||
template <typename DataType>
|
||||
const DataType *get_texture_buffer_data(int offset, int elements);
|
||||
|
||||
/** \brief Get a pointer to the specified data type in animation buffer.
|
||||
* \param animation Animation index.
|
||||
* \param offset Offset in bytes.
|
||||
* \param elements Elements count.
|
||||
*/
|
||||
template <typename DataType>
|
||||
const DataType *get_anim_buffer_data(int animation, int offset, int elements);
|
||||
|
||||
/** \brief Get a pointer to the specified data type in MDL buffer.
|
||||
* \param offset Offset in bytes.
|
||||
* \param elements Elements count.
|
||||
*/
|
||||
template <typename DataType>
|
||||
const DataType *get_buffer_data(int offset, int elements);
|
||||
|
||||
/** \brief Read an MDL texture.
|
||||
* \param[in] ptexture A pointer to an MDL texture.
|
||||
|
|
@ -122,7 +146,7 @@ private:
|
|||
* \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,
|
||||
const uint8_t *data, const uint8_t *pal, aiTexture *pResult,
|
||||
aiColor3D &last_palette_color);
|
||||
|
||||
/** \brief This method reads a compressed anim value.
|
||||
|
|
@ -158,7 +182,7 @@ private:
|
|||
IOSystem *io_;
|
||||
|
||||
/** Buffer from MDLLoader class. */
|
||||
const unsigned char *buffer_;
|
||||
const HL1DataBuffer 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
|
||||
|
|
@ -176,13 +200,13 @@ private:
|
|||
|
||||
/** External MDL animation headers.
|
||||
* One for each loaded animation file. */
|
||||
SequenceHeader_HL1 **anim_headers_;
|
||||
std::vector<const SequenceHeader_HL1*> anim_headers_;
|
||||
|
||||
/** Texture file data. */
|
||||
unsigned char *texture_buffer_;
|
||||
HL1DataBuffer texture_buffer_;
|
||||
|
||||
/** Animation files data. */
|
||||
unsigned char **anim_buffers_;
|
||||
std::vector<HL1DataBuffer> anim_buffers_;
|
||||
|
||||
/** The number of sequence groups. */
|
||||
int num_sequence_groups_;
|
||||
|
|
@ -226,7 +250,7 @@ private:
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename MDLFileHeader>
|
||||
void HL1MDLLoader::load_file_into_buffer(const std::string &file_path, unsigned char *&buffer) {
|
||||
void HL1MDLLoader::load_file_into_buffer(const std::string &file_path, HL1DataBuffer &buffer) {
|
||||
if (!io_->Exists(file_path))
|
||||
throw DeadlyImportError("Missing file ", DefaultIOSystem::fileName(file_path), ".");
|
||||
|
||||
|
|
@ -241,9 +265,30 @@ void HL1MDLLoader::load_file_into_buffer(const std::string &file_path, unsigned
|
|||
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';
|
||||
std::unique_ptr<unsigned char[]> data(new unsigned char[1 + file_size]);
|
||||
file->Read(data.get(), 1, file_size);
|
||||
data[file_size] = '\0';
|
||||
|
||||
buffer = HL1DataBuffer::owning(std::move(data), file_size);
|
||||
}
|
||||
|
||||
template <typename DataType>
|
||||
const DataType *HL1MDLLoader::get_texture_buffer_data(int offset, int elements) {
|
||||
return texture_buffer_.get_data<DataType>(offset, elements);
|
||||
}
|
||||
|
||||
template <typename DataType>
|
||||
const DataType *HL1MDLLoader::get_anim_buffer_data(int animation, int offset, int elements) {
|
||||
if (animation < 0 || animation >= num_sequence_groups_) {
|
||||
throw DeadlyImportError("MDL file contains invalid sequence group index (", animation, ")");
|
||||
}
|
||||
|
||||
return anim_buffers_[animation].get_data<DataType>(offset, elements);
|
||||
}
|
||||
|
||||
template <typename DataType>
|
||||
const DataType *HL1MDLLoader::get_buffer_data(int offset, int elements) {
|
||||
return buffer_.get_data<DataType>(offset, elements);
|
||||
}
|
||||
|
||||
} // namespace HalfLife
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -63,8 +62,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
struct aiMaterial;
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// to make it easier for us, we test the magic word against both "endiannesses"
|
||||
|
|
@ -603,7 +602,7 @@ struct Vertex_MDL7
|
|||
union {
|
||||
uint8_t norm162index;
|
||||
float norm[3];
|
||||
};
|
||||
} PACK_STRUCT;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
|
@ -876,7 +875,7 @@ struct IntSharedData_MDL7 {
|
|||
: apcOutBones(),
|
||||
iNum()
|
||||
{
|
||||
abNeedMaterials.reserve(10);
|
||||
abNeedMaterials.reserve(12);
|
||||
}
|
||||
|
||||
//! Destruction: properly delete all allocated resources
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,10 +48,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_MDL_IMPORTER
|
||||
|
||||
#include "AssetLib/MDL/MDLLoader.h"
|
||||
#include "MDLLoader.h"
|
||||
#include "AssetLib/MD2/MD2FileData.h"
|
||||
#include "AssetLib/MDL/HalfLife/HL1MDLLoader.h"
|
||||
#include "AssetLib/MDL/MDLDefaultColorMap.h"
|
||||
#include "HalfLife/HL1MDLLoader.h"
|
||||
#include "HalfLife/HL1FileData.h"
|
||||
#include "MDLDefaultColorMap.h"
|
||||
|
||||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
|
|
@ -268,8 +269,8 @@ void MDLImporter::InternReadFile(const std::string &pFile,
|
|||
// Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
|
||||
pScene->mRootNode->mTransformation = aiMatrix4x4(
|
||||
1.f, 0.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, -1.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, -1.f, 0.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
}
|
||||
|
||||
|
|
@ -325,13 +326,13 @@ void MDLImporter::SizeCheck(const void *szPos, const char *szFile, unsigned int
|
|||
// Validate a quake file header
|
||||
void MDLImporter::ValidateHeader_Quake1(const MDL::Header *pcHeader) {
|
||||
// some values may not be nullptr
|
||||
if (!pcHeader->num_frames)
|
||||
if (pcHeader->num_frames <= 0)
|
||||
throw DeadlyImportError("[Quake 1 MDL] There are no frames in the file");
|
||||
|
||||
if (!pcHeader->num_verts)
|
||||
if (pcHeader->num_verts <= 0)
|
||||
throw DeadlyImportError("[Quake 1 MDL] There are no vertices in the file");
|
||||
|
||||
if (!pcHeader->num_tris)
|
||||
if (pcHeader->num_tris <= 0)
|
||||
throw DeadlyImportError("[Quake 1 MDL] There are no triangles in the file");
|
||||
|
||||
// check whether the maxima are exceeded ...however, this applies for Quake 1 MDLs only
|
||||
|
|
@ -420,7 +421,7 @@ void MDLImporter::InternReadFile_Quake1() {
|
|||
}
|
||||
// go to the end of the skin section / the beginning of the next skin
|
||||
bool overflow = false;
|
||||
if (pcHeader->skinwidth != 0 || pcHeader->skinheight != 0) {
|
||||
if (pcHeader->skinwidth != 0 && pcHeader->skinheight != 0) {
|
||||
if ((pcHeader->skinheight > INT_MAX / pcHeader->skinwidth) || (pcHeader->skinwidth > INT_MAX / pcHeader->skinheight)){
|
||||
overflow = true;
|
||||
}
|
||||
|
|
@ -449,12 +450,14 @@ void MDLImporter::InternReadFile_Quake1() {
|
|||
BE_NCONST MDL::Frame *pcFrames = (BE_NCONST MDL::Frame *)szCurrent;
|
||||
MDL::SimpleFrame *pcFirstFrame;
|
||||
|
||||
VALIDATE_FILE_SIZE((const unsigned char *)(pcFrames + 1));
|
||||
if (0 == pcFrames->type) {
|
||||
// get address of single frame
|
||||
pcFirstFrame = (MDL::SimpleFrame *)&pcFrames->frame;
|
||||
} else {
|
||||
// get the first frame in the group
|
||||
BE_NCONST MDL::GroupFrame *pcFrames2 = (BE_NCONST MDL::GroupFrame *)szCurrent;
|
||||
VALIDATE_FILE_SIZE((const unsigned char *)(pcFrames2 + 1));
|
||||
pcFirstFrame = (MDL::SimpleFrame *)( szCurrent + sizeof(MDL::GroupFrame::type) + sizeof(MDL::GroupFrame::numframes)
|
||||
+ sizeof(MDL::GroupFrame::min) + sizeof(MDL::GroupFrame::max) + sizeof(*MDL::GroupFrame::times) * pcFrames2->numframes );
|
||||
}
|
||||
|
|
@ -601,6 +604,9 @@ void MDLImporter::SetupMaterialProperties_3DGS_MDL5_Quake1() {
|
|||
// Read a MDL 3,4,5 file
|
||||
void MDLImporter::InternReadFile_3DGS_MDL345() {
|
||||
ai_assert(nullptr != pScene);
|
||||
if (pScene == nullptr) {
|
||||
throw DeadlyImportError("INvalid scene pointer detected.");
|
||||
}
|
||||
|
||||
// the header of MDL 3/4/5 is nearly identical to the original Quake1 header
|
||||
BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header *)this->mBuffer;
|
||||
|
|
@ -609,6 +615,10 @@ void MDLImporter::InternReadFile_3DGS_MDL345() {
|
|||
#endif
|
||||
ValidateHeader_Quake1(pcHeader);
|
||||
|
||||
if (pcHeader->synctype < 0) {
|
||||
throw DeadlyImportError("Invalid synctype value in MDL header; possible corrupt file.");
|
||||
}
|
||||
|
||||
// current cursor position in the file
|
||||
const unsigned char *szCurrent = (const unsigned char *)(pcHeader + 1);
|
||||
const unsigned char *szEnd = mBuffer + iFileSize;
|
||||
|
|
@ -618,8 +628,7 @@ void MDLImporter::InternReadFile_3DGS_MDL345() {
|
|||
if (szCurrent + sizeof(uint32_t) > szEnd) {
|
||||
throw DeadlyImportError("Texture data past end of file.");
|
||||
}
|
||||
BE_NCONST MDL::Skin *pcSkin;
|
||||
pcSkin = (BE_NCONST MDL::Skin *)szCurrent;
|
||||
BE_NCONST MDL::Skin *pcSkin = (BE_NCONST MDL::Skin *)szCurrent;
|
||||
AI_SWAP4(pcSkin->group);
|
||||
// create one output image
|
||||
unsigned int iSkip = i ? UINT_MAX : 0;
|
||||
|
|
@ -696,6 +705,7 @@ void MDLImporter::InternReadFile_3DGS_MDL345() {
|
|||
|
||||
// now get a pointer to the first frame in the file
|
||||
BE_NCONST MDL::Frame *pcFrames = (BE_NCONST MDL::Frame *)szCurrent;
|
||||
VALIDATE_FILE_SIZE((const unsigned char *)(pcFrames + 1));
|
||||
AI_SWAP4(pcFrames->type);
|
||||
|
||||
// byte packed vertices
|
||||
|
|
@ -1166,6 +1176,7 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7 &groupInf
|
|||
for (unsigned int iFrame = 0; iFrame < (unsigned int)groupInfo.pcGroup->numframes; ++iFrame) {
|
||||
MDL::IntFrameInfo_MDL7 frame((BE_NCONST MDL::Frame_MDL7 *)szCurrent, iFrame);
|
||||
|
||||
VALIDATE_FILE_SIZE((const unsigned char *)(frame.pcFrame + 1));
|
||||
AI_SWAP4(frame.pcFrame->vertices_count);
|
||||
AI_SWAP4(frame.pcFrame->transmatrix_count);
|
||||
|
||||
|
|
@ -1837,6 +1848,10 @@ void MDLImporter::GenerateOutputMeshes_3DGS_MDL7(
|
|||
const unsigned int iNumOutBones = pcHeader->bones_num;
|
||||
|
||||
for (std::vector<aiMaterial *>::size_type i = 0; i < shared.pcMats.size(); ++i) {
|
||||
if (splitGroupData.aiSplit == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!splitGroupData.aiSplit[i]->empty()) {
|
||||
|
||||
// allocate the output mesh
|
||||
|
|
@ -1980,11 +1995,17 @@ void MDLImporter::InternReadFile_HL1(const std::string &pFile, const uint32_t iM
|
|||
if (iMagicWord == AI_MDL_MAGIC_NUMBER_BE_HL2b || iMagicWord == AI_MDL_MAGIC_NUMBER_LE_HL2b)
|
||||
throw DeadlyImportError("Impossible to properly load a model from an MDL sequence file.");
|
||||
|
||||
// Check if the buffer is large enough to hold the header
|
||||
if (iFileSize < sizeof(HalfLife::Header_HL1)) {
|
||||
throw DeadlyImportError("HL1 MDL file is too small to contain header.");
|
||||
}
|
||||
|
||||
// Read the MDL file.
|
||||
HalfLife::HL1MDLLoader loader(
|
||||
pScene,
|
||||
mIOHandler,
|
||||
mBuffer,
|
||||
iFileSize,
|
||||
pFile,
|
||||
mHL1ImportSettings);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/BaseImporter.h>
|
||||
#include "MDLFileData.h"
|
||||
#include "AssetLib/HMP/HalfLifeFileData.h"
|
||||
#include "AssetLib/MDL/HalfLife/HL1ImportSettings.h"
|
||||
#include "HalfLife/HL1ImportSettings.h"
|
||||
|
||||
struct aiNode;
|
||||
struct aiTexture;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -209,6 +209,8 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char *szData,
|
|||
return;
|
||||
}
|
||||
|
||||
static const uint32_t MaxTextureSize = 4096;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Load color data of a texture and convert it to our output format
|
||||
void MDLImporter::ParseTextureColorData(const unsigned char *szData,
|
||||
|
|
@ -219,6 +221,11 @@ void MDLImporter::ParseTextureColorData(const unsigned char *szData,
|
|||
|
||||
// allocate storage for the texture image
|
||||
if (do_read) {
|
||||
// check for max texture sizes
|
||||
if (pcNew->mWidth > MaxTextureSize || pcNew->mHeight > MaxTextureSize) {
|
||||
throw DeadlyImportError("Invalid MDL file. A texture is too big.");
|
||||
}
|
||||
|
||||
if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
|
||||
throw DeadlyImportError("Invalid MDL file. A texture is too big.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue