mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
update assimp to 5.2.3 Bugfix-Release
This commit is contained in:
parent
3f796d2a06
commit
f297476092
1150 changed files with 165834 additions and 112019 deletions
600
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1FileData.h
Normal file
600
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1FileData.h
Normal file
|
|
@ -0,0 +1,600 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 HL1FileData.h
|
||||
* @brief Definition of in-memory structures for the
|
||||
* Half-Life 1 MDL file format.
|
||||
*/
|
||||
|
||||
#ifndef AI_HL1FILEDATA_INCLUDED
|
||||
#define AI_HL1FILEDATA_INCLUDED
|
||||
|
||||
#include "HalfLifeMDLBaseHeader.h"
|
||||
|
||||
#include <assimp/Compiler/pushpack1.h>
|
||||
#include <assimp/types.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
using vec3_t = float[3];
|
||||
|
||||
/** \struct Header_HL1
|
||||
* \brief Data structure for the HL1 MDL file header.
|
||||
*/
|
||||
struct Header_HL1 : HalfLifeMDLBaseHeader {
|
||||
//! The model name.
|
||||
char name[64];
|
||||
|
||||
//! The total file size in bytes.
|
||||
int32_t length;
|
||||
|
||||
//! Ideal eye position.
|
||||
vec3_t eyeposition;
|
||||
|
||||
//! Ideal movement hull size.
|
||||
vec3_t min;
|
||||
vec3_t max;
|
||||
|
||||
//! Clipping bounding box.
|
||||
vec3_t bbmin;
|
||||
vec3_t bbmax;
|
||||
|
||||
//! Was "flags".
|
||||
int32_t unused;
|
||||
|
||||
//! The number of bones.
|
||||
int32_t numbones;
|
||||
|
||||
//! Offset to the first bone chunk.
|
||||
int32_t boneindex;
|
||||
|
||||
//! The number of bone controllers.
|
||||
int32_t numbonecontrollers;
|
||||
|
||||
//! Offset to the first bone controller chunk.
|
||||
int32_t bonecontrollerindex;
|
||||
|
||||
//! The number of hitboxes.
|
||||
int32_t numhitboxes;
|
||||
|
||||
//! Offset to the first hitbox chunk.
|
||||
int32_t hitboxindex;
|
||||
|
||||
//! The number of sequences.
|
||||
int32_t numseq;
|
||||
|
||||
//! Offset to the first sequence description chunk.
|
||||
int32_t seqindex;
|
||||
|
||||
//! The number of sequence groups.
|
||||
int32_t numseqgroups;
|
||||
|
||||
//! Offset to the first sequence group chunk.
|
||||
int32_t seqgroupindex;
|
||||
|
||||
//! The number of textures.
|
||||
int32_t numtextures;
|
||||
|
||||
//! Offset to the first texture chunk.
|
||||
int32_t textureindex;
|
||||
|
||||
//! Offset to the first texture's image data.
|
||||
int32_t texturedataindex;
|
||||
|
||||
//! The number of replaceable textures.
|
||||
int32_t numskinref;
|
||||
|
||||
//! The number of skin families.
|
||||
int32_t numskinfamilies;
|
||||
|
||||
//! Offset to the first replaceable texture.
|
||||
int32_t skinindex;
|
||||
|
||||
//! The number of bodyparts.
|
||||
int32_t numbodyparts;
|
||||
|
||||
//! Offset the the first bodypart.
|
||||
int32_t bodypartindex;
|
||||
|
||||
//! The number of attachments.
|
||||
int32_t numattachments;
|
||||
|
||||
//! Offset the the first attachment chunk.
|
||||
int32_t attachmentindex;
|
||||
|
||||
//! Was "soundtable".
|
||||
int32_t unused2;
|
||||
|
||||
//! Was "soundindex".
|
||||
int32_t unused3;
|
||||
|
||||
//! Was "soundgroups".
|
||||
int32_t unused4;
|
||||
|
||||
//! Was "soundgroupindex".
|
||||
int32_t unused5;
|
||||
|
||||
//! The number of nodes in the sequence transition graph.
|
||||
int32_t numtransitions;
|
||||
|
||||
//! Offset the the first sequence transition.
|
||||
int32_t transitionindex;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct SequenceHeader_HL1
|
||||
* \brief Data structure for the file header of a demand loaded
|
||||
* HL1 MDL sequence group file.
|
||||
*/
|
||||
struct SequenceHeader_HL1 : HalfLifeMDLBaseHeader {
|
||||
//! The sequence group file name.
|
||||
char name[64];
|
||||
|
||||
//! The total file size in bytes.
|
||||
int32_t length;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Bone_HL1
|
||||
* \brief Data structure for a bone in HL1 MDL files.
|
||||
*/
|
||||
struct Bone_HL1 {
|
||||
//! The bone name.
|
||||
char name[32];
|
||||
|
||||
//! The parent bone index. (-1) If it has no parent.
|
||||
int32_t parent;
|
||||
|
||||
//! Was "flags".
|
||||
int32_t unused;
|
||||
|
||||
//! Available bone controller per motion type.
|
||||
//! (-1) if no controller is available.
|
||||
int32_t bonecontroller[6];
|
||||
|
||||
/*! Default position and rotation values where
|
||||
* scale[0] = position.X
|
||||
* scale[1] = position.Y
|
||||
* scale[2] = position.Z
|
||||
* scale[3] = rotation.X
|
||||
* scale[4] = rotation.Y
|
||||
* scale[5] = rotation.Z
|
||||
*/
|
||||
float value[6];
|
||||
|
||||
/*! Compressed scale values where
|
||||
* scale[0] = position.X scale
|
||||
* scale[1] = position.Y scale
|
||||
* scale[2] = position.Z scale
|
||||
* scale[3] = rotation.X scale
|
||||
* scale[4] = rotation.Y scale
|
||||
* scale[5] = rotation.Z scale
|
||||
*/
|
||||
float scale[6];
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct BoneController_HL1
|
||||
* \brief Data structure for a bone controller in HL1 MDL files.
|
||||
*/
|
||||
struct BoneController_HL1 {
|
||||
//! Bone affected by this controller.
|
||||
int32_t bone;
|
||||
|
||||
//! The motion type.
|
||||
int32_t type;
|
||||
|
||||
//! The minimum and maximum values.
|
||||
float start;
|
||||
float end;
|
||||
|
||||
// Was "rest".
|
||||
int32_t unused;
|
||||
|
||||
// The bone controller channel.
|
||||
int32_t index;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Hitbox_HL1
|
||||
* \brief Data structure for a hitbox in HL1 MDL files.
|
||||
*/
|
||||
struct Hitbox_HL1 {
|
||||
//! The bone this hitbox follows.
|
||||
int32_t bone;
|
||||
|
||||
//! The hit group.
|
||||
int32_t group;
|
||||
|
||||
//! The hitbox minimum and maximum extents.
|
||||
vec3_t bbmin;
|
||||
vec3_t bbmax;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct SequenceGroup_HL1
|
||||
* \brief Data structure for a sequence group in HL1 MDL files.
|
||||
*/
|
||||
struct SequenceGroup_HL1 {
|
||||
//! A textual name for this sequence group.
|
||||
char label[32];
|
||||
|
||||
//! The file name.
|
||||
char name[64];
|
||||
|
||||
//! Was "cache".
|
||||
int32_t unused;
|
||||
|
||||
//! Was "data".
|
||||
int32_t unused2;
|
||||
} PACK_STRUCT;
|
||||
|
||||
//! The type of blending for a sequence.
|
||||
enum SequenceBlendMode_HL1 {
|
||||
NoBlend = 1,
|
||||
TwoWayBlending = 2,
|
||||
FourWayBlending = 4,
|
||||
};
|
||||
|
||||
/** \struct SequenceDesc_HL1
|
||||
* \brief Data structure for a sequence description in HL1 MDL files.
|
||||
*/
|
||||
struct SequenceDesc_HL1 {
|
||||
//! The sequence name.
|
||||
char label[32];
|
||||
|
||||
//! Frames per second.
|
||||
float fps;
|
||||
|
||||
//! looping/non-looping flags.
|
||||
int32_t flags;
|
||||
|
||||
//! The sequence activity.
|
||||
int32_t activity;
|
||||
|
||||
//! The sequence activity weight.
|
||||
int32_t actweight;
|
||||
|
||||
//! The number of animation events.
|
||||
int32_t numevents;
|
||||
|
||||
//! Offset the the first animation event chunk.
|
||||
int32_t eventindex;
|
||||
|
||||
//! The number of frames in the sequence.
|
||||
int32_t numframes;
|
||||
|
||||
//! Was "numpivots".
|
||||
int32_t unused;
|
||||
|
||||
//! Was "pivotindex".
|
||||
int32_t unused2;
|
||||
|
||||
//! Linear motion type.
|
||||
int32_t motiontype;
|
||||
|
||||
//! Linear motion bone.
|
||||
int32_t motionbone;
|
||||
|
||||
//! Linear motion.
|
||||
vec3_t linearmovement;
|
||||
|
||||
//! Was "automoveposindex".
|
||||
int32_t unused3;
|
||||
|
||||
//! Was "automoveangleindex".
|
||||
int32_t unused4;
|
||||
|
||||
//! The sequence minimum and maximum extents.
|
||||
vec3_t bbmin;
|
||||
vec3_t bbmax;
|
||||
|
||||
//! The number of blend animations.
|
||||
int32_t numblends;
|
||||
|
||||
//! Offset to first the AnimValueOffset_HL1 chunk.
|
||||
//! This offset is relative to the SequenceHeader_HL1 of the file
|
||||
//! that contains the animation data.
|
||||
int32_t animindex;
|
||||
|
||||
//! The motion type of each blend controller.
|
||||
int32_t blendtype[2];
|
||||
|
||||
//! The starting value of each blend controller.
|
||||
float blendstart[2];
|
||||
|
||||
//! The ending value of each blend controller.
|
||||
float blendend[2];
|
||||
|
||||
//! Was "blendparent".
|
||||
int32_t unused5;
|
||||
|
||||
//! The sequence group.
|
||||
int32_t seqgroup;
|
||||
|
||||
//! The node at entry in the sequence transition graph.
|
||||
int32_t entrynode;
|
||||
|
||||
//! The node at exit in the sequence transition graph.
|
||||
int32_t exitnode;
|
||||
|
||||
//! Transition rules.
|
||||
int32_t nodeflags;
|
||||
|
||||
//! Was "nextseq"
|
||||
int32_t unused6;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct AnimEvent_HL1
|
||||
* \brief Data structure for an animation event in HL1 MDL files.
|
||||
*/
|
||||
struct AnimEvent_HL1 {
|
||||
//! The frame at which this animation event occurs.
|
||||
int32_t frame;
|
||||
|
||||
//! The script event type.
|
||||
int32_t event;
|
||||
|
||||
//! was "type"
|
||||
int32_t unused;
|
||||
|
||||
//! Options. Could be path to sound WAVE files.
|
||||
char options[64];
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Attachment_HL1
|
||||
* \brief Data structure for an attachment in HL1 MDL files.
|
||||
*/
|
||||
struct Attachment_HL1 {
|
||||
//! Was "name".
|
||||
char unused[32];
|
||||
|
||||
//! Was "type".
|
||||
int32_t unused2;
|
||||
|
||||
//! The bone this attachment follows.
|
||||
int32_t bone;
|
||||
|
||||
//! The attachment origin.
|
||||
vec3_t org;
|
||||
|
||||
//! Was "vectors"
|
||||
vec3_t unused3[3];
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct AnimValueOffset_HL1
|
||||
* \brief Data structure to hold offsets (one per motion type)
|
||||
* to the first animation frame value for a single bone
|
||||
* in HL1 MDL files.
|
||||
*/
|
||||
struct AnimValueOffset_HL1 {
|
||||
unsigned short offset[6];
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct AnimValue_HL1
|
||||
* \brief Data structure for an animation frame in HL1 MDL files.
|
||||
*/
|
||||
union AnimValue_HL1 {
|
||||
struct {
|
||||
uint8_t valid;
|
||||
uint8_t total;
|
||||
} num;
|
||||
short value;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Bodypart_HL1
|
||||
* \brief Data structure for a bodypart in HL1 MDL files.
|
||||
*/
|
||||
struct Bodypart_HL1 {
|
||||
//! The bodypart name.
|
||||
char name[64];
|
||||
|
||||
//! The number of available models for this bodypart.
|
||||
int32_t nummodels;
|
||||
|
||||
//! Used to convert from a global model index
|
||||
//! to a local bodypart model index.
|
||||
int32_t base;
|
||||
|
||||
//! The offset to the first model chunk.
|
||||
int32_t modelindex;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Texture_HL1
|
||||
* \brief Data structure for a texture in HL1 MDL files.
|
||||
*/
|
||||
struct Texture_HL1 {
|
||||
//! Texture file name.
|
||||
char name[64];
|
||||
|
||||
//! Texture flags.
|
||||
int32_t flags;
|
||||
|
||||
//! Texture width in pixels.
|
||||
int32_t width;
|
||||
|
||||
//! Texture height in pixels.
|
||||
int32_t height;
|
||||
|
||||
//! Offset to the image data.
|
||||
//! This offset is relative to the texture file header.
|
||||
int32_t index;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Model_HL1
|
||||
* \brief Data structure for a model in HL1 MDL files.
|
||||
*/
|
||||
struct Model_HL1 {
|
||||
//! Model name.
|
||||
char name[64];
|
||||
|
||||
//! Was "type".
|
||||
int32_t unused;
|
||||
|
||||
//! Was "boundingradius".
|
||||
float unused2;
|
||||
|
||||
//! The number of meshes in the model.
|
||||
int32_t nummesh;
|
||||
|
||||
//! Offset to the first mesh chunk.
|
||||
int32_t meshindex;
|
||||
|
||||
//! The number of unique vertices.
|
||||
int32_t numverts;
|
||||
|
||||
//! Offset to the vertex bone array.
|
||||
int32_t vertinfoindex;
|
||||
|
||||
//! Offset to the vertex array.
|
||||
int32_t vertindex;
|
||||
|
||||
//! The number of unique normals.
|
||||
int32_t numnorms;
|
||||
|
||||
//! Offset to the normal bone array.
|
||||
int32_t norminfoindex;
|
||||
|
||||
//! Offset to the normal array.
|
||||
int32_t normindex;
|
||||
|
||||
//! Was "numgroups".
|
||||
int32_t unused3;
|
||||
|
||||
//! Was "groupindex".
|
||||
int32_t unused4;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Mesh_HL1
|
||||
* \brief Data structure for a mesh in HL1 MDL files.
|
||||
*/
|
||||
struct Mesh_HL1 {
|
||||
//! Can be interpreted as the number of triangles in the mesh.
|
||||
int32_t numtris;
|
||||
|
||||
//! Offset to the start of the tris sequence.
|
||||
int32_t triindex;
|
||||
|
||||
//! The skin index.
|
||||
int32_t skinref;
|
||||
|
||||
//! The number of normals in the mesh.
|
||||
int32_t numnorms;
|
||||
|
||||
//! Was "normindex".
|
||||
int32_t unused;
|
||||
} PACK_STRUCT;
|
||||
|
||||
/** \struct Trivert
|
||||
* \brief Data structure for a trivert in HL1 MDL files.
|
||||
*/
|
||||
struct Trivert {
|
||||
//! Index into Model_HL1 vertex array.
|
||||
short vertindex;
|
||||
|
||||
//! Index into Model_HL1 normal array.
|
||||
short normindex;
|
||||
|
||||
//! Texture coordinates in absolute space (unnormalized).
|
||||
short s, t;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#include <assimp/Compiler/poppack1.h>
|
||||
|
||||
#if (!defined AI_MDL_HL1_VERSION)
|
||||
#define AI_MDL_HL1_VERSION 10
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_TRIANGLES)
|
||||
#define AI_MDL_HL1_MAX_TRIANGLES 20000
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_VERTICES)
|
||||
#define AI_MDL_HL1_MAX_VERTICES 2048
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_SEQUENCES)
|
||||
#define AI_MDL_HL1_MAX_SEQUENCES 2048
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_SEQUENCE_GROUPS)
|
||||
#define AI_MDL_HL1_MAX_SEQUENCE_GROUPS 32
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_TEXTURES)
|
||||
#define AI_MDL_HL1_MAX_TEXTURES 100
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_SKIN_FAMILIES)
|
||||
#define AI_MDL_HL1_MAX_SKIN_FAMILIES 100
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_BONES)
|
||||
#define AI_MDL_HL1_MAX_BONES 128
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_BODYPARTS)
|
||||
#define AI_MDL_HL1_MAX_BODYPARTS 32
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_MODELS)
|
||||
#define AI_MDL_HL1_MAX_MODELS 32
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_MESHES)
|
||||
#define AI_MDL_HL1_MAX_MESHES 256
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_EVENTS)
|
||||
#define AI_MDL_HL1_MAX_EVENTS 1024
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_BONE_CONTROLLERS)
|
||||
#define AI_MDL_HL1_MAX_BONE_CONTROLLERS 8
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_MAX_ATTACHMENTS)
|
||||
#define AI_MDL_HL1_MAX_ATTACHMENTS 512
|
||||
#endif
|
||||
|
||||
// lighting options
|
||||
#if (!defined AI_MDL_HL1_STUDIO_NF_FLATSHADE)
|
||||
#define AI_MDL_HL1_STUDIO_NF_FLATSHADE 0x0001
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_STUDIO_NF_CHROME)
|
||||
#define AI_MDL_HL1_STUDIO_NF_CHROME 0x0002
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_STUDIO_NF_ADDITIVE)
|
||||
#define AI_MDL_HL1_STUDIO_NF_ADDITIVE 0x0020
|
||||
#endif
|
||||
#if (!defined AI_MDL_HL1_STUDIO_NF_MASKED)
|
||||
#define AI_MDL_HL1_STUDIO_NF_MASKED 0x0040
|
||||
#endif
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // AI_HL1FILEDATA_INCLUDED
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 HL1ImportDefinitions.h
|
||||
* @brief HL1 MDL loader specific definitions.
|
||||
*/
|
||||
|
||||
#ifndef AI_MDL_HL1_IMPORT_DEFINITIONS_INCLUDED
|
||||
#define AI_MDL_HL1_IMPORT_DEFINITIONS_INCLUDED
|
||||
|
||||
#define AI_MDL_HL1_NODE_ROOT "<MDL_root>"
|
||||
#define AI_MDL_HL1_NODE_BODYPARTS "<MDL_bodyparts>"
|
||||
#define AI_MDL_HL1_NODE_BONES "<MDL_bones>"
|
||||
#define AI_MDL_HL1_NODE_BONE_CONTROLLERS "<MDL_bone_controllers>"
|
||||
#define AI_MDL_HL1_NODE_SEQUENCE_INFOS "<MDL_sequence_infos>"
|
||||
#define AI_MDL_HL1_NODE_SEQUENCE_GROUPS "<MDL_sequence_groups>"
|
||||
#define AI_MDL_HL1_NODE_SEQUENCE_TRANSITION_GRAPH "<MDL_sequence_transition_graph>"
|
||||
#define AI_MDL_HL1_NODE_ATTACHMENTS "<MDL_attachments>"
|
||||
#define AI_MDL_HL1_NODE_HITBOXES "<MDL_hitboxes>"
|
||||
#define AI_MDL_HL1_NODE_GLOBAL_INFO "<MDL_global_info>"
|
||||
#define AI_MDL_HL1_NODE_ANIMATION_EVENTS "AnimationEvents"
|
||||
#define AI_MDL_HL1_NODE_BLEND_CONTROLLERS "BlendControllers"
|
||||
|
||||
#define AI_MDL_HL1_MATKEY_CHROME(type, N) "$mat.HL1.chrome", type, N
|
||||
|
||||
#endif // AI_MDL_HL1_IMPORT_DEFINITIONS_INCLUDED
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 HL1ImportSettings.h
|
||||
* @brief Half-Life 1 MDL loader configuration settings.
|
||||
*/
|
||||
|
||||
#ifndef AI_HL1IMPORTSETTINGS_INCLUDED
|
||||
#define AI_HL1IMPORTSETTINGS_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
struct HL1ImportSettings {
|
||||
HL1ImportSettings() :
|
||||
read_animations(false),
|
||||
read_animation_events(false),
|
||||
read_blend_controllers(false),
|
||||
read_sequence_groups_info(false),
|
||||
read_sequence_transitions(false),
|
||||
read_attachments(false),
|
||||
read_bone_controllers(false),
|
||||
read_hitboxes(false),
|
||||
read_textures(false),
|
||||
read_misc_global_info(false) {
|
||||
}
|
||||
|
||||
bool read_animations;
|
||||
bool read_animation_events;
|
||||
bool read_blend_controllers;
|
||||
bool read_sequence_groups_info;
|
||||
bool read_sequence_transitions;
|
||||
bool read_attachments;
|
||||
bool read_bone_controllers;
|
||||
bool read_hitboxes;
|
||||
bool read_textures;
|
||||
bool read_misc_global_info;
|
||||
};
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // AI_HL1IMPORTSETTINGS_INCLUDED
|
||||
1353
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp
Normal file
1353
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp
Normal file
File diff suppressed because it is too large
Load diff
243
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1MDLLoader.h
Normal file
243
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1MDLLoader.h
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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, ai_real &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() == nullptr) {
|
||||
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
|
||||
127
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1MeshTrivert.h
Normal file
127
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/HL1MeshTrivert.h
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 HL1MeshTrivert.h
|
||||
* @brief This file contains the class declaration for the
|
||||
* HL1 mesh trivert class.
|
||||
*/
|
||||
|
||||
#ifndef AI_HL1MESHTRIVERT_INCLUDED
|
||||
#define AI_HL1MESHTRIVERT_INCLUDED
|
||||
|
||||
#include "HL1FileData.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
/* A class to help map model triverts to mesh triverts. */
|
||||
struct HL1MeshTrivert {
|
||||
HL1MeshTrivert() :
|
||||
vertindex(-1),
|
||||
normindex(-1),
|
||||
s(0),
|
||||
t(0),
|
||||
localindex(-1) {
|
||||
}
|
||||
|
||||
HL1MeshTrivert(short vertindex, short normindex, short s, short t, short localindex) :
|
||||
vertindex(vertindex),
|
||||
normindex(normindex),
|
||||
s(s),
|
||||
t(t),
|
||||
localindex(localindex) {
|
||||
}
|
||||
|
||||
HL1MeshTrivert(const Trivert &a) :
|
||||
vertindex(a.vertindex),
|
||||
normindex(a.normindex),
|
||||
s(a.s),
|
||||
t(a.t),
|
||||
localindex(-1) {
|
||||
}
|
||||
|
||||
inline bool operator==(const Trivert &a) const {
|
||||
return vertindex == a.vertindex &&
|
||||
normindex == a.normindex &&
|
||||
s == a.s &&
|
||||
t == a.t;
|
||||
}
|
||||
|
||||
inline bool operator!=(const Trivert &a) const {
|
||||
return !(*this == a);
|
||||
}
|
||||
|
||||
inline bool operator==(const HL1MeshTrivert &a) const {
|
||||
return localindex == a.localindex &&
|
||||
vertindex == a.vertindex &&
|
||||
normindex == a.normindex &&
|
||||
s == a.s &&
|
||||
t == a.t;
|
||||
}
|
||||
|
||||
inline bool operator!=(const HL1MeshTrivert &a) const {
|
||||
return !(*this == a);
|
||||
}
|
||||
|
||||
inline HL1MeshTrivert &operator=(const Trivert &other) {
|
||||
vertindex = other.vertindex;
|
||||
normindex = other.normindex;
|
||||
s = other.s;
|
||||
t = other.t;
|
||||
return *this;
|
||||
}
|
||||
|
||||
short vertindex;
|
||||
short normindex;
|
||||
short s, t;
|
||||
short localindex;
|
||||
};
|
||||
|
||||
struct HL1MeshFace {
|
||||
short v0, v1, v2;
|
||||
};
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // AI_HL1MESHTRIVERT_INCLUDED
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 HalfLifeMDLBaseHeader.h */
|
||||
|
||||
#ifndef AI_HALFLIFEMDLBASEHEADER_INCLUDED
|
||||
#define AI_HALFLIFEMDLBASEHEADER_INCLUDED
|
||||
|
||||
#include <assimp/types.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
/** Used to interface different Valve MDL formats. */
|
||||
struct HalfLifeMDLBaseHeader
|
||||
{
|
||||
//! Magic number: "IDST"/"IDSQ"
|
||||
char ident[4];
|
||||
|
||||
//! The file format version.
|
||||
int32_t version;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // AI_HALFLIFEMDLBASEHEADER_INCLUDED
|
||||
95
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/LogFunctions.h
Normal file
95
Engine/lib/assimp/code/AssetLib/MDL/HalfLife/LogFunctions.h
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 LogFunctions.h */
|
||||
|
||||
#ifndef AI_MDL_HALFLIFE_LOGFUNCTIONS_INCLUDED
|
||||
#define AI_MDL_HALFLIFE_LOGFUNCTIONS_INCLUDED
|
||||
|
||||
#include <assimp/Logger.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
/**
|
||||
* \brief A function to log precise messages regarding limits exceeded.
|
||||
*
|
||||
* \param[in] subject Subject.
|
||||
* \param[in] current_amount Current amount.
|
||||
* \param[in] direct_object Direct object.
|
||||
* LIMIT Limit constant.
|
||||
*
|
||||
* Example: Model has 100 textures, which exceeds the limit (50)
|
||||
*
|
||||
* where \p subject is 'Model'
|
||||
* \p current_amount is '100'
|
||||
* \p direct_object is 'textures'
|
||||
* LIMIT is '50'
|
||||
*/
|
||||
template <int LIMIT>
|
||||
static inline void log_warning_limit_exceeded(
|
||||
const std::string &subject, int current_amount,
|
||||
const std::string &direct_object) {
|
||||
|
||||
ASSIMP_LOG_WARN(MDL_HALFLIFE_LOG_HEADER
|
||||
+ subject
|
||||
+ " has "
|
||||
+ std::to_string(current_amount) + " "
|
||||
+ direct_object
|
||||
+ ", which exceeds the limit ("
|
||||
+ std::to_string(LIMIT)
|
||||
+ ")");
|
||||
}
|
||||
|
||||
/** \brief Same as above, but uses 'Model' as the subject. */
|
||||
template <int LIMIT>
|
||||
static inline void log_warning_limit_exceeded(int current_amount,
|
||||
const std::string &direct_object) {
|
||||
log_warning_limit_exceeded<LIMIT>("Model", current_amount, direct_object);
|
||||
}
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // AI_MDL_HALFLIFE_LOGFUNCTIONS_INCLUDED
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 UniqueNameGenerator.cpp
|
||||
* @brief Implementation for the unique name generator.
|
||||
*/
|
||||
|
||||
#include "UniqueNameGenerator.h"
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
UniqueNameGenerator::UniqueNameGenerator() :
|
||||
template_name_("unnamed"),
|
||||
separator_("_") {
|
||||
}
|
||||
|
||||
UniqueNameGenerator::UniqueNameGenerator(const char *template_name) :
|
||||
template_name_(template_name),
|
||||
separator_("_") {
|
||||
}
|
||||
|
||||
UniqueNameGenerator::UniqueNameGenerator(const char *template_name, const char *separator) :
|
||||
template_name_(template_name),
|
||||
separator_(separator) {
|
||||
}
|
||||
|
||||
UniqueNameGenerator::~UniqueNameGenerator() {
|
||||
}
|
||||
|
||||
void UniqueNameGenerator::make_unique(std::vector<std::string> &names) {
|
||||
struct DuplicateInfo {
|
||||
DuplicateInfo() :
|
||||
indices(),
|
||||
next_id(0) {
|
||||
}
|
||||
|
||||
std::list<size_t> indices;
|
||||
size_t next_id;
|
||||
};
|
||||
|
||||
std::vector<size_t> empty_names_indices;
|
||||
std::vector<size_t> template_name_duplicates;
|
||||
std::map<std::string, DuplicateInfo> names_to_duplicates;
|
||||
|
||||
const std::string template_name_with_separator(template_name_ + separator_);
|
||||
|
||||
auto format_name = [&](const std::string &base_name, size_t id) -> std::string {
|
||||
return base_name + separator_ + std::to_string(id);
|
||||
};
|
||||
|
||||
auto generate_unique_name = [&](const std::string &base_name) -> std::string {
|
||||
auto *duplicate_info = &names_to_duplicates[base_name];
|
||||
|
||||
std::string new_name;
|
||||
|
||||
bool found_identical_name;
|
||||
bool tried_with_base_name_only = false;
|
||||
do {
|
||||
// Assume that no identical name exists.
|
||||
found_identical_name = false;
|
||||
|
||||
if (!tried_with_base_name_only) {
|
||||
// First try with only the base name.
|
||||
new_name = base_name;
|
||||
} else {
|
||||
// Create the name expected to be unique.
|
||||
new_name = format_name(base_name, duplicate_info->next_id);
|
||||
}
|
||||
|
||||
// Check in the list of duplicates for an identical name.
|
||||
for (size_t i = 0;
|
||||
i < names.size() &&
|
||||
!found_identical_name;
|
||||
++i) {
|
||||
if (new_name == names[i])
|
||||
found_identical_name = true;
|
||||
}
|
||||
|
||||
if (tried_with_base_name_only)
|
||||
++duplicate_info->next_id;
|
||||
|
||||
tried_with_base_name_only = true;
|
||||
|
||||
} while (found_identical_name);
|
||||
|
||||
return new_name;
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
// Check for empty names.
|
||||
if (names[i].find_first_not_of(' ') == std::string::npos) {
|
||||
empty_names_indices.push_back(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check for potential duplicate.
|
||||
a) Either if this name is the same as the template name or
|
||||
b) <template name><separator> is found at the beginning. */
|
||||
if (names[i] == template_name_ ||
|
||||
names[i].substr(0, template_name_with_separator.length()) == template_name_with_separator)
|
||||
template_name_duplicates.push_back(i);
|
||||
|
||||
// Map each unique name to it's duplicate.
|
||||
if (names_to_duplicates.count(names[i]) == 0)
|
||||
names_to_duplicates.insert({ names[i], DuplicateInfo()});
|
||||
else
|
||||
names_to_duplicates[names[i]].indices.push_back(i);
|
||||
}
|
||||
|
||||
// Make every non-empty name unique.
|
||||
for (auto it = names_to_duplicates.begin();
|
||||
it != names_to_duplicates.end(); ++it) {
|
||||
for (auto it2 = it->second.indices.begin();
|
||||
it2 != it->second.indices.end();
|
||||
++it2)
|
||||
names[*it2] = generate_unique_name(it->first);
|
||||
}
|
||||
|
||||
// Generate a unique name for every empty string.
|
||||
if (template_name_duplicates.size()) {
|
||||
// At least one string ressembles to <template name>.
|
||||
for (auto it = empty_names_indices.begin();
|
||||
it != empty_names_indices.end(); ++it)
|
||||
names[*it] = generate_unique_name(template_name_);
|
||||
} else {
|
||||
// No string alike <template name> exists.
|
||||
size_t i = 0;
|
||||
for (auto it = empty_names_indices.begin();
|
||||
it != empty_names_indices.end(); ++it, ++i)
|
||||
names[*it] = format_name(template_name_, i);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 UniqueNameGenerator.h
|
||||
* @brief Declaration of the unique name generator.
|
||||
*/
|
||||
|
||||
#ifndef AI_UNIQUENAMEGENERATOR_INCLUDED
|
||||
#define AI_UNIQUENAMEGENERATOR_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
class UniqueNameGenerator {
|
||||
public:
|
||||
UniqueNameGenerator();
|
||||
UniqueNameGenerator(const char *template_name);
|
||||
UniqueNameGenerator(const char *template_name, const char *separator);
|
||||
~UniqueNameGenerator();
|
||||
|
||||
inline void set_template_name(const char *template_name) {
|
||||
template_name_ = template_name;
|
||||
}
|
||||
inline void set_separator(const char *separator) {
|
||||
separator_ = separator;
|
||||
}
|
||||
|
||||
void make_unique(std::vector<std::string> &names);
|
||||
|
||||
private:
|
||||
std::string template_name_;
|
||||
std::string separator_;
|
||||
};
|
||||
|
||||
} // namespace HalfLife
|
||||
} // namespace MDL
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // AI_UNIQUENAMEGENERATOR_INCLUDED
|
||||
120
Engine/lib/assimp/code/AssetLib/MDL/MDLDefaultColorMap.h
Normal file
120
Engine/lib/assimp/code/AssetLib/MDL/MDLDefaultColorMap.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 Defines the default color map used for Quake 1 model textures
|
||||
*
|
||||
* The lib tries to load colormap.lmp from the model's directory.
|
||||
* This table is only used when required.
|
||||
*/
|
||||
|
||||
#ifndef AI_MDL_DEFAULTLMP_H_INC
|
||||
#define AI_MDL_DEFAULTLMP_H_INC
|
||||
|
||||
const unsigned char g_aclrDefaultColorMap[256][3] = {
|
||||
{ 0, 0, 0}, { 15, 15, 15}, { 31, 31, 31}, { 47, 47, 47},
|
||||
{ 63, 63, 63}, { 75, 75, 75}, { 91, 91, 91}, {107, 107, 107},
|
||||
{123, 123, 123}, {139, 139, 139}, {155, 155, 155}, {171, 171, 171},
|
||||
{187, 187, 187}, {203, 203, 203}, {219, 219, 219}, {235, 235, 235},
|
||||
{ 15, 11, 7}, { 23, 15, 11}, { 31, 23, 11}, { 39, 27, 15},
|
||||
{ 47, 35, 19}, { 55, 43, 23}, { 63, 47, 23}, { 75, 55, 27},
|
||||
{ 83, 59, 27}, { 91, 67, 31}, { 99, 75, 31}, {107, 83, 31},
|
||||
{115, 87, 31}, {123, 95, 35}, {131, 103, 35}, {143, 111, 35},
|
||||
{ 11, 11, 15}, { 19, 19, 27}, { 27, 27, 39}, { 39, 39, 51},
|
||||
{ 47, 47, 63}, { 55, 55, 75}, { 63, 63, 87}, { 71, 71, 103},
|
||||
{ 79, 79, 115}, { 91, 91, 127}, { 99, 99, 139}, {107, 107, 151},
|
||||
{115, 115, 163}, {123, 123, 175}, {131, 131, 187}, {139, 139, 203},
|
||||
{ 0, 0, 0}, { 7, 7, 0}, { 11, 11, 0}, { 19, 19, 0},
|
||||
{ 27, 27, 0}, { 35, 35, 0}, { 43, 43, 7}, { 47, 47, 7},
|
||||
{ 55, 55, 7}, { 63, 63, 7}, { 71, 71, 7}, { 75, 75, 11},
|
||||
{ 83, 83, 11}, { 91, 91, 11}, { 99, 99, 11}, {107, 107, 15},
|
||||
{ 7, 0, 0}, { 15, 0, 0}, { 23, 0, 0}, { 31, 0, 0},
|
||||
{ 39, 0, 0}, { 47, 0, 0}, { 55, 0, 0}, { 63, 0, 0},
|
||||
{ 71, 0, 0}, { 79, 0, 0}, { 87, 0, 0}, { 95, 0, 0},
|
||||
{103, 0, 0}, {111, 0, 0}, {119, 0, 0}, {127, 0, 0},
|
||||
{ 19, 19, 0}, { 27, 27, 0}, { 35, 35, 0}, { 47, 43, 0},
|
||||
{ 55, 47, 0}, { 67, 55, 0}, { 75, 59, 7}, { 87, 67, 7},
|
||||
{ 95, 71, 7}, {107, 75, 11}, {119, 83, 15}, {131, 87, 19},
|
||||
{139, 91, 19}, {151, 95, 27}, {163, 99, 31}, {175, 103, 35},
|
||||
{ 35, 19, 7}, { 47, 23, 11}, { 59, 31, 15}, { 75, 35, 19},
|
||||
{ 87, 43, 23}, { 99, 47, 31}, {115, 55, 35}, {127, 59, 43},
|
||||
{143, 67, 51}, {159, 79, 51}, {175, 99, 47}, {191, 119, 47},
|
||||
{207, 143, 43}, {223, 171, 39}, {239, 203, 31}, {255, 243, 27},
|
||||
{ 11, 7, 0}, { 27, 19, 0}, { 43, 35, 15}, { 55, 43, 19},
|
||||
{ 71, 51, 27}, { 83, 55, 35}, { 99, 63, 43}, {111, 71, 51},
|
||||
{127, 83, 63}, {139, 95, 71}, {155, 107, 83}, {167, 123, 95},
|
||||
{183, 135, 107}, {195, 147, 123}, {211, 163, 139}, {227, 179, 151},
|
||||
{171, 139, 163}, {159, 127, 151}, {147, 115, 135}, {139, 103, 123},
|
||||
{127, 91, 111}, {119, 83, 99}, {107, 75, 87}, { 95, 63, 75},
|
||||
{ 87, 55, 67}, { 75, 47, 55}, { 67, 39, 47}, { 55, 31, 35},
|
||||
{ 43, 23, 27}, { 35, 19, 19}, { 23, 11, 11}, { 15, 7, 7},
|
||||
{187, 115, 159}, {175, 107, 143}, {163, 95, 131}, {151, 87, 119},
|
||||
{139, 79, 107}, {127, 75, 95}, {115, 67, 83}, {107, 59, 75},
|
||||
{ 95, 51, 63}, { 83, 43, 55}, { 71, 35, 43}, { 59, 31, 35},
|
||||
{ 47, 23, 27}, { 35, 19, 19}, { 23, 11, 11}, { 15, 7, 7},
|
||||
{219, 195, 187}, {203, 179, 167}, {191, 163, 155}, {175, 151, 139},
|
||||
{163, 135, 123}, {151, 123, 111}, {135, 111, 95}, {123, 99, 83},
|
||||
{107, 87, 71}, { 95, 75, 59}, { 83, 63, 51}, { 67, 51, 39},
|
||||
{ 55, 43, 31}, { 39, 31, 23}, { 27, 19, 15}, { 15, 11, 7},
|
||||
{111, 131, 123}, {103, 123, 111}, { 95, 115, 103}, { 87, 107, 95},
|
||||
{ 79, 99, 87}, { 71, 91, 79}, { 63, 83, 71}, { 55, 75, 63},
|
||||
{ 47, 67, 55}, { 43, 59, 47}, { 35, 51, 39}, { 31, 43, 31},
|
||||
{ 23, 35, 23}, { 15, 27, 19}, { 11, 19, 11}, { 7, 11, 7},
|
||||
{255, 243, 27}, {239, 223, 23}, {219, 203, 19}, {203, 183, 15},
|
||||
{187, 167, 15}, {171, 151, 11}, {155, 131, 7}, {139, 115, 7},
|
||||
{123, 99, 7}, {107, 83, 0}, { 91, 71, 0}, { 75, 55, 0},
|
||||
{ 59, 43, 0}, { 43, 31, 0}, { 27, 15, 0}, { 11, 7, 0},
|
||||
{ 0, 0, 255}, { 11, 11, 239}, { 19, 19, 223}, { 27, 27, 207},
|
||||
{ 35, 35, 191}, { 43, 43, 175}, { 47, 47, 159}, { 47, 47, 143},
|
||||
{ 47, 47, 127}, { 47, 47, 111}, { 47, 47, 95}, { 43, 43, 79},
|
||||
{ 35, 35, 63}, { 27, 27, 47}, { 19, 19, 31}, { 11, 11, 15},
|
||||
{ 43, 0, 0}, { 59, 0, 0}, { 75, 7, 0}, { 95, 7, 0},
|
||||
{111, 15, 0}, {127, 23, 7}, {147, 31, 7}, {163, 39, 11},
|
||||
{183, 51, 15}, {195, 75, 27}, {207, 99, 43}, {219, 127, 59},
|
||||
{227, 151, 79}, {231, 171, 95}, {239, 191, 119}, {247, 211, 139},
|
||||
{167, 123, 59}, {183, 155, 55}, {199, 195, 55}, {231, 227, 87},
|
||||
{127, 191, 255}, {171, 231, 255}, {215, 255, 255}, {103, 0, 0},
|
||||
{139, 0, 0}, {179, 0, 0}, {215, 0, 0}, {255, 0, 0},
|
||||
{255, 243, 147}, {255, 247, 199}, {255, 255, 255}, {159, 91, 83} };
|
||||
|
||||
|
||||
#endif // !! AI_MDL_DEFAULTLMP_H_INC
|
||||
945
Engine/lib/assimp/code/AssetLib/MDL/MDLFileData.h
Normal file
945
Engine/lib/assimp/code/AssetLib/MDL/MDLFileData.h
Normal file
|
|
@ -0,0 +1,945 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 MDLFileData.h
|
||||
* @brief Definition of in-memory structures for the MDL file format.
|
||||
*
|
||||
* The specification has been taken from various sources on the internet.
|
||||
* - http://tfc.duke.free.fr/coding/mdl-specs-en.html
|
||||
* - Conitec's MED SDK
|
||||
* - Many quite long HEX-editor sessions
|
||||
*/
|
||||
|
||||
#ifndef AI_MDLFILEHELPER_H_INC
|
||||
#define AI_MDLFILEHELPER_H_INC
|
||||
|
||||
#include <assimp/anim.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/Compiler/pushpack1.h>
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
struct aiMaterial;
|
||||
|
||||
namespace Assimp {
|
||||
namespace MDL {
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// to make it easier for us, we test the magic word against both "endianesses"
|
||||
|
||||
// magic bytes used in Quake 1 MDL meshes
|
||||
#define AI_MDL_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDPO")
|
||||
#define AI_MDL_MAGIC_NUMBER_LE AI_MAKE_MAGIC("OPDI")
|
||||
|
||||
// magic bytes used in GameStudio A<very low> MDL meshes
|
||||
#define AI_MDL_MAGIC_NUMBER_BE_GS3 AI_MAKE_MAGIC("MDL2")
|
||||
#define AI_MDL_MAGIC_NUMBER_LE_GS3 AI_MAKE_MAGIC("2LDM")
|
||||
|
||||
// magic bytes used in GameStudio A4 MDL meshes
|
||||
#define AI_MDL_MAGIC_NUMBER_BE_GS4 AI_MAKE_MAGIC("MDL3")
|
||||
#define AI_MDL_MAGIC_NUMBER_LE_GS4 AI_MAKE_MAGIC("3LDM")
|
||||
|
||||
// magic bytes used in GameStudio A5+ MDL meshes
|
||||
#define AI_MDL_MAGIC_NUMBER_BE_GS5a AI_MAKE_MAGIC("MDL4")
|
||||
#define AI_MDL_MAGIC_NUMBER_LE_GS5a AI_MAKE_MAGIC("4LDM")
|
||||
#define AI_MDL_MAGIC_NUMBER_BE_GS5b AI_MAKE_MAGIC("MDL5")
|
||||
#define AI_MDL_MAGIC_NUMBER_LE_GS5b AI_MAKE_MAGIC("5LDM")
|
||||
|
||||
// magic bytes used in GameStudio A7+ MDL meshes
|
||||
#define AI_MDL_MAGIC_NUMBER_BE_GS7 AI_MAKE_MAGIC("MDL7")
|
||||
#define AI_MDL_MAGIC_NUMBER_LE_GS7 AI_MAKE_MAGIC("7LDM")
|
||||
|
||||
// common limitations for Quake1 meshes. The loader does not check them,
|
||||
// (however it warns) but models should not exceed these limits.
|
||||
#if (!defined AI_MDL_VERSION)
|
||||
# define AI_MDL_VERSION 6
|
||||
#endif
|
||||
#if (!defined AI_MDL_MAX_FRAMES)
|
||||
# define AI_MDL_MAX_FRAMES 256
|
||||
#endif
|
||||
#if (!defined AI_MDL_MAX_UVS)
|
||||
# define AI_MDL_MAX_UVS 1024
|
||||
#endif
|
||||
#if (!defined AI_MDL_MAX_VERTS)
|
||||
# define AI_MDL_MAX_VERTS 1024
|
||||
#endif
|
||||
#if (!defined AI_MDL_MAX_TRIANGLES)
|
||||
# define AI_MDL_MAX_TRIANGLES 2048
|
||||
#endif
|
||||
|
||||
// material key that is set for dummy materials that are
|
||||
// just referencing another material
|
||||
#if (!defined AI_MDL7_REFERRER_MATERIAL)
|
||||
# define AI_MDL7_REFERRER_MATERIAL "&&&referrer&&&",0,0
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Header
|
||||
* \brief Data structure for the MDL main header
|
||||
*/
|
||||
struct Header {
|
||||
//! magic number: "IDPO"
|
||||
uint32_t ident;
|
||||
|
||||
//! version number: 6
|
||||
int32_t version;
|
||||
|
||||
//! scale factors for each axis
|
||||
ai_real scale[3];
|
||||
|
||||
//! translation factors for each axis
|
||||
ai_real translate[3];
|
||||
|
||||
//! bounding radius of the mesh
|
||||
float boundingradius;
|
||||
|
||||
//! Position of the viewer's exe. Ignored
|
||||
ai_real vEyePos[3];
|
||||
|
||||
//! Number of textures
|
||||
int32_t num_skins;
|
||||
|
||||
//! Texture width in pixels
|
||||
int32_t skinwidth;
|
||||
|
||||
//! Texture height in pixels
|
||||
int32_t skinheight;
|
||||
|
||||
//! Number of vertices contained in the file
|
||||
int32_t num_verts;
|
||||
|
||||
//! Number of triangles contained in the file
|
||||
int32_t num_tris;
|
||||
|
||||
//! Number of frames contained in the file
|
||||
int32_t num_frames;
|
||||
|
||||
//! 0 = synchron, 1 = random . Ignored
|
||||
//! (MDLn formats: number of texture coordinates)
|
||||
int32_t synctype;
|
||||
|
||||
//! State flag
|
||||
int32_t flags;
|
||||
|
||||
//! Could be the total size of the file (and not a float)
|
||||
float size;
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Header_MDL7
|
||||
* \brief Data structure for the MDL 7 main header
|
||||
*/
|
||||
struct Header_MDL7 {
|
||||
//! magic number: "MDL7"
|
||||
char ident[4];
|
||||
|
||||
//! Version number. Ignored
|
||||
int32_t version;
|
||||
|
||||
//! Number of bones in file
|
||||
uint32_t bones_num;
|
||||
|
||||
//! Number of groups in file
|
||||
uint32_t groups_num;
|
||||
|
||||
//! Size of data in the file
|
||||
uint32_t data_size;
|
||||
|
||||
//! Ignored. Used to store entity specific information
|
||||
int32_t entlump_size;
|
||||
|
||||
//! Ignored. Used to store MED related data
|
||||
int32_t medlump_size;
|
||||
|
||||
//! Size of the Bone_MDL7 data structure used in the file
|
||||
uint16_t bone_stc_size;
|
||||
|
||||
//! Size of the Skin_MDL 7 data structure used in the file
|
||||
uint16_t skin_stc_size;
|
||||
|
||||
//! Size of a single color (e.g. in a material)
|
||||
uint16_t colorvalue_stc_size;
|
||||
|
||||
//! Size of the Material_MDL7 data structure used in the file
|
||||
uint16_t material_stc_size;
|
||||
|
||||
//! Size of a texture coordinate set in the file
|
||||
uint16_t skinpoint_stc_size;
|
||||
|
||||
//! Size of a triangle in the file
|
||||
uint16_t triangle_stc_size;
|
||||
|
||||
//! Size of a normal vertex in the file
|
||||
uint16_t mainvertex_stc_size;
|
||||
|
||||
//! Size of a per-frame animated vertex in the file
|
||||
//! (this is not supported)
|
||||
uint16_t framevertex_stc_size;
|
||||
|
||||
//! Size of a bone animation matrix
|
||||
uint16_t bonetrans_stc_size;
|
||||
|
||||
//! Size of the Frame_MDL7 data structure used in the file
|
||||
uint16_t frame_stc_size;
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Bone_MDL7
|
||||
* \brief Data structure for a bone in a MDL7 file
|
||||
*/
|
||||
struct Bone_MDL7 {
|
||||
//! Index of the parent bone of *this* bone. 0xffff means:
|
||||
//! "hey, I have no parent, I'm an orphan"
|
||||
uint16_t parent_index;
|
||||
uint8_t _unused_[2];
|
||||
|
||||
//! Relative position of the bone (relative to the
|
||||
//! parent bone)
|
||||
float x,y,z;
|
||||
|
||||
//! Optional name of the bone
|
||||
char name[1 /* DUMMY SIZE */];
|
||||
} PACK_STRUCT;
|
||||
|
||||
#if (!defined AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS)
|
||||
# define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS (16 + 20)
|
||||
#endif
|
||||
|
||||
#if (!defined AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS)
|
||||
# define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS (16 + 32)
|
||||
#endif
|
||||
|
||||
#if (!defined AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE)
|
||||
# define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE (16)
|
||||
#endif
|
||||
|
||||
#if (!defined AI_MDL7_MAX_GROUPNAMESIZE)
|
||||
# define AI_MDL7_MAX_GROUPNAMESIZE 16
|
||||
#endif // ! AI_MDL7_MAX_GROUPNAMESIZE
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Group_MDL7
|
||||
* \brief Group in a MDL7 file
|
||||
*/
|
||||
struct Group_MDL7 {
|
||||
//! = '1' -> triangle based Mesh
|
||||
unsigned char typ;
|
||||
|
||||
int8_t deformers;
|
||||
int8_t max_weights;
|
||||
int8_t _unused_;
|
||||
|
||||
//! size of data for this group in bytes ( MD7_GROUP stc. included).
|
||||
int32_t groupdata_size;
|
||||
char name[AI_MDL7_MAX_GROUPNAMESIZE];
|
||||
|
||||
//! Number of skins
|
||||
int32_t numskins;
|
||||
|
||||
//! Number of texture coordinates
|
||||
int32_t num_stpts;
|
||||
|
||||
//! Number of triangles
|
||||
int32_t numtris;
|
||||
|
||||
//! Number of vertices
|
||||
int32_t numverts;
|
||||
|
||||
//! Number of frames
|
||||
int32_t numframes;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define AI_MDL7_SKINTYPE_MIPFLAG 0x08
|
||||
#define AI_MDL7_SKINTYPE_MATERIAL 0x10
|
||||
#define AI_MDL7_SKINTYPE_MATERIAL_ASCDEF 0x20
|
||||
#define AI_MDL7_SKINTYPE_RGBFLAG 0x80
|
||||
|
||||
#if (!defined AI_MDL7_MAX_BONENAMESIZE)
|
||||
# define AI_MDL7_MAX_BONENAMESIZE 20
|
||||
#endif // !! AI_MDL7_MAX_BONENAMESIZE
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Deformer_MDL7
|
||||
* \brief Deformer in a MDL7 file
|
||||
*/
|
||||
struct Deformer_MDL7 {
|
||||
int8_t deformer_version; // 0
|
||||
int8_t deformer_typ; // 0 - bones
|
||||
int8_t _unused_[2];
|
||||
int32_t group_index;
|
||||
int32_t elements;
|
||||
int32_t deformerdata_size;
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct DeformerElement_MDL7
|
||||
* \brief Deformer element in a MDL7 file
|
||||
*/
|
||||
struct DeformerElement_MDL7 {
|
||||
//! bei deformer_typ==0 (==bones) element_index == bone index
|
||||
int32_t element_index;
|
||||
char element_name[AI_MDL7_MAX_BONENAMESIZE];
|
||||
int32_t weights;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct DeformerWeight_MDL7
|
||||
* \brief Deformer weight in a MDL7 file
|
||||
*/
|
||||
struct DeformerWeight_MDL7 {
|
||||
//! for deformer_typ==0 (==bones) index == vertex index
|
||||
int32_t index;
|
||||
float weight;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// don't know why this was in the original headers ...
|
||||
typedef int32_t MD7_MATERIAL_ASCDEFSIZE;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct ColorValue_MDL7
|
||||
* \brief Data structure for a color value in a MDL7 file
|
||||
*/
|
||||
struct ColorValue_MDL7 {
|
||||
float r,g,b,a;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Material_MDL7
|
||||
* \brief Data structure for a Material in a MDL7 file
|
||||
*/
|
||||
struct Material_MDL7 {
|
||||
//! Diffuse base color of the material
|
||||
ColorValue_MDL7 Diffuse;
|
||||
|
||||
//! Ambient base color of the material
|
||||
ColorValue_MDL7 Ambient;
|
||||
|
||||
//! Specular base color of the material
|
||||
ColorValue_MDL7 Specular;
|
||||
|
||||
//! Emissive base color of the material
|
||||
ColorValue_MDL7 Emissive;
|
||||
|
||||
//! Phong power
|
||||
float Power;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Skin
|
||||
* \brief Skin data structure #1 - used by Quake1, MDL2, MDL3 and MDL4
|
||||
*/
|
||||
struct Skin {
|
||||
//! 0 = single (Skin), 1 = group (GroupSkin)
|
||||
//! For MDL3-5: Defines the type of the skin and there
|
||||
//! fore the size of the data to skip:
|
||||
//-------------------------------------------------------
|
||||
//! 2 for 565 RGB,
|
||||
//! 3 for 4444 ARGB,
|
||||
//! 10 for 565 mipmapped,
|
||||
//! 11 for 4444 mipmapped (bpp = 2),
|
||||
//! 12 for 888 RGB mipmapped (bpp = 3),
|
||||
//! 13 for 8888 ARGB mipmapped (bpp = 4)
|
||||
//-------------------------------------------------------
|
||||
int32_t group;
|
||||
|
||||
//! Texture data
|
||||
uint8_t *data;
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Skin
|
||||
* \brief Skin data structure #2 - used by MDL5, MDL6 and MDL7
|
||||
* \see Skin
|
||||
*/
|
||||
struct Skin_MDL5 {
|
||||
int32_t size, width, height;
|
||||
uint8_t *data;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// maximum length of texture file name
|
||||
#if (!defined AI_MDL7_MAX_TEXNAMESIZE)
|
||||
# define AI_MDL7_MAX_TEXNAMESIZE 0x10
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** \struct Skin_MDL7
|
||||
* \brief Skin data structure #3 - used by MDL7 and HMP7
|
||||
*/
|
||||
struct Skin_MDL7 {
|
||||
uint8_t typ;
|
||||
int8_t _unused_[3];
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
char texture_name[AI_MDL7_MAX_TEXNAMESIZE];
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct RGB565
|
||||
* \brief Data structure for a RGB565 pixel in a texture
|
||||
*/
|
||||
struct RGB565 {
|
||||
uint16_t r : 5;
|
||||
uint16_t g : 6;
|
||||
uint16_t b : 5;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct ARGB4
|
||||
* \brief Data structure for a ARGB4444 pixel in a texture
|
||||
*/
|
||||
struct ARGB4 {
|
||||
uint16_t a : 4;
|
||||
uint16_t r : 4;
|
||||
uint16_t g : 4;
|
||||
uint16_t b : 4;
|
||||
} /*PACK_STRUCT*/;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct GroupSkin
|
||||
* \brief Skin data structure #2 (group of pictures)
|
||||
*/
|
||||
struct GroupSkin {
|
||||
//! 0 = single (Skin), 1 = group (GroupSkin)
|
||||
int32_t group;
|
||||
|
||||
//! Number of images
|
||||
int32_t nb;
|
||||
|
||||
//! Time for each image
|
||||
float *time;
|
||||
|
||||
//! Data of each image
|
||||
uint8_t **data;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct TexCoord
|
||||
* \brief Texture coordinate data structure used by the Quake1 MDL format
|
||||
*/
|
||||
struct TexCoord {
|
||||
//! Is the vertex on the noundary between front and back piece?
|
||||
int32_t onseam;
|
||||
|
||||
//! Texture coordinate in the tx direction
|
||||
int32_t s;
|
||||
|
||||
//! Texture coordinate in the ty direction
|
||||
int32_t t;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct TexCoord_MDL3
|
||||
* \brief Data structure for an UV coordinate in the 3DGS MDL3 format
|
||||
*/
|
||||
struct TexCoord_MDL3 {
|
||||
//! position, horizontally in range 0..skinwidth-1
|
||||
int16_t u;
|
||||
|
||||
//! position, vertically in range 0..skinheight-1
|
||||
int16_t v;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct TexCoord_MDL7
|
||||
* \brief Data structure for an UV coordinate in the 3DGS MDL7 format
|
||||
*/
|
||||
struct TexCoord_MDL7 {
|
||||
//! position, horizontally in range 0..1
|
||||
float u;
|
||||
|
||||
//! position, vertically in range 0..1
|
||||
float v;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct SkinSet_MDL7
|
||||
* \brief Skin set data structure for the 3DGS MDL7 format
|
||||
* MDL7 references UV coordinates per face via an index list.
|
||||
* This allows the use of multiple skins per face with just one
|
||||
* UV coordinate set.
|
||||
*/
|
||||
struct SkinSet_MDL7
|
||||
{
|
||||
//! Index into the UV coordinate list
|
||||
uint16_t st_index[3]; // size 6
|
||||
|
||||
//! Material index
|
||||
int32_t material; // size 4
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Triangle
|
||||
* \brief Triangle data structure for the Quake1 MDL format
|
||||
*/
|
||||
struct Triangle
|
||||
{
|
||||
//! 0 = backface, 1 = frontface
|
||||
int32_t facesfront;
|
||||
|
||||
//! Vertex indices
|
||||
int32_t vertex[3];
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Triangle_MDL3
|
||||
* \brief Triangle data structure for the 3DGS MDL3 format
|
||||
*/
|
||||
struct Triangle_MDL3
|
||||
{
|
||||
//! Index of 3 3D vertices in range 0..numverts
|
||||
uint16_t index_xyz[3];
|
||||
|
||||
//! Index of 3 skin vertices in range 0..numskinverts
|
||||
uint16_t index_uv[3];
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Triangle_MDL7
|
||||
* \brief Triangle data structure for the 3DGS MDL7 format
|
||||
*/
|
||||
struct Triangle_MDL7
|
||||
{
|
||||
//! Vertex indices
|
||||
uint16_t v_index[3]; // size 6
|
||||
|
||||
//! Two skinsets. The second will be used for multi-texturing
|
||||
SkinSet_MDL7 skinsets[2];
|
||||
} PACK_STRUCT;
|
||||
|
||||
#if (!defined AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV)
|
||||
# define AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV (6+sizeof(SkinSet_MDL7)-sizeof(uint32_t))
|
||||
#endif
|
||||
#if (!defined AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX)
|
||||
# define AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX (6+sizeof(SkinSet_MDL7))
|
||||
#endif
|
||||
#if (!defined AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV)
|
||||
# define AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV (6+2*sizeof(SkinSet_MDL7))
|
||||
#endif
|
||||
|
||||
// Helper constants for Triangle::facesfront
|
||||
#if (!defined AI_MDL_BACKFACE)
|
||||
# define AI_MDL_BACKFACE 0x0
|
||||
#endif
|
||||
#if (!defined AI_MDL_FRONTFACE)
|
||||
# define AI_MDL_FRONTFACE 0x1
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Vertex
|
||||
* \brief Vertex data structure
|
||||
*/
|
||||
struct Vertex
|
||||
{
|
||||
uint8_t v[3];
|
||||
uint8_t normalIndex;
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
struct Vertex_MDL4
|
||||
{
|
||||
uint16_t v[3];
|
||||
uint8_t normalIndex;
|
||||
uint8_t unused;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define AI_MDL7_FRAMEVERTEX120503_STCSIZE 16
|
||||
#define AI_MDL7_FRAMEVERTEX030305_STCSIZE 26
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Vertex_MDL7
|
||||
* \brief Vertex data structure used in MDL7 files
|
||||
*/
|
||||
struct Vertex_MDL7
|
||||
{
|
||||
float x,y,z;
|
||||
uint16_t vertindex; // = bone index
|
||||
union {
|
||||
uint8_t norm162index;
|
||||
float norm[3];
|
||||
};
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct BoneTransform_MDL7
|
||||
* \brief bone transformation matrix structure used in MDL7 files
|
||||
*/
|
||||
struct BoneTransform_MDL7
|
||||
{
|
||||
//! 4*3
|
||||
float m [4*4];
|
||||
|
||||
//! the index of this vertex, 0.. header::bones_num - 1
|
||||
uint16_t bone_index;
|
||||
|
||||
//! I HATE 3DGS AND THE SILLY DEVELOPER WHO DESIGNED
|
||||
//! THIS STUPID FILE FORMAT!
|
||||
int8_t _unused_[2];
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
#define AI_MDL7_MAX_FRAMENAMESIZE 16
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Frame_MDL7
|
||||
* \brief Frame data structure used by MDL7 files
|
||||
*/
|
||||
struct Frame_MDL7
|
||||
{
|
||||
char frame_name[AI_MDL7_MAX_FRAMENAMESIZE];
|
||||
uint32_t vertices_count;
|
||||
uint32_t transmatrix_count;
|
||||
};
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct SimpleFrame
|
||||
* \brief Data structure for a simple frame
|
||||
*/
|
||||
struct SimpleFrame
|
||||
{
|
||||
//! Minimum vertex of the bounding box
|
||||
Vertex bboxmin;
|
||||
|
||||
//! Maximum vertex of the bounding box
|
||||
Vertex bboxmax;
|
||||
|
||||
//! Name of the frame
|
||||
char name[16];
|
||||
|
||||
//! Vertex list of the frame
|
||||
Vertex *verts;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct Frame
|
||||
* \brief Model frame data structure
|
||||
*/
|
||||
struct Frame
|
||||
{
|
||||
//! 0 = simple frame, !0 = group frame
|
||||
int32_t type;
|
||||
|
||||
//! Frame data
|
||||
SimpleFrame frame;
|
||||
} PACK_STRUCT;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
struct SimpleFrame_MDLn_SP
|
||||
{
|
||||
//! Minimum vertex of the bounding box
|
||||
Vertex_MDL4 bboxmin;
|
||||
|
||||
//! Maximum vertex of the bounding box
|
||||
Vertex_MDL4 bboxmax;
|
||||
|
||||
//! Name of the frame
|
||||
char name[16];
|
||||
|
||||
//! Vertex list of the frame
|
||||
Vertex_MDL4 *verts;
|
||||
} PACK_STRUCT;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct GroupFrame
|
||||
* \brief Data structure for a group of frames
|
||||
*/
|
||||
struct GroupFrame
|
||||
{
|
||||
//! 0 = simple frame, !0 = group frame
|
||||
int32_t type;
|
||||
|
||||
int32_t numframes;
|
||||
|
||||
//! Minimum vertex for all single frames
|
||||
Vertex min;
|
||||
|
||||
//! Maximum vertex for all single frames
|
||||
Vertex max;
|
||||
|
||||
//! List of times for all single frames
|
||||
float *times;
|
||||
|
||||
//! List of single frames
|
||||
SimpleFrame *frames;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#include <assimp/Compiler/poppack1.h>
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct IntFace_MDL7
|
||||
* \brief Internal data structure to temporarily represent a face
|
||||
*/
|
||||
struct IntFace_MDL7 {
|
||||
// provide a constructor for our own convenience
|
||||
IntFace_MDL7() AI_NO_EXCEPT {
|
||||
::memset( mIndices, 0, sizeof(uint32_t) *3);
|
||||
::memset( iMatIndex, 0, sizeof( unsigned int) *2);
|
||||
}
|
||||
|
||||
//! Vertex indices
|
||||
uint32_t mIndices[3];
|
||||
|
||||
//! Material index (maximally two channels, which are joined later)
|
||||
unsigned int iMatIndex[2];
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct IntMaterial_MDL7
|
||||
* \brief Internal data structure to temporarily represent a material
|
||||
* which has been created from two single materials along with the
|
||||
* original material indices.
|
||||
*/
|
||||
struct IntMaterial_MDL7 {
|
||||
// provide a constructor for our own convenience
|
||||
IntMaterial_MDL7() AI_NO_EXCEPT
|
||||
: pcMat( nullptr ) {
|
||||
::memset( iOldMatIndices, 0, sizeof(unsigned int) *2);
|
||||
}
|
||||
|
||||
//! Material instance
|
||||
aiMaterial* pcMat;
|
||||
|
||||
//! Old material indices
|
||||
unsigned int iOldMatIndices[2];
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
/** \struct IntBone_MDL7
|
||||
* \brief Internal data structure to represent a bone in a MDL7 file with
|
||||
* all of its animation channels assigned to it.
|
||||
*/
|
||||
struct IntBone_MDL7 : aiBone
|
||||
{
|
||||
//! Default constructor
|
||||
IntBone_MDL7() AI_NO_EXCEPT : iParent (0xffff)
|
||||
{
|
||||
pkeyPositions.reserve(30);
|
||||
pkeyScalings.reserve(30);
|
||||
pkeyRotations.reserve(30);
|
||||
}
|
||||
|
||||
//! Parent bone of the bone
|
||||
uint64_t iParent;
|
||||
|
||||
//! Relative position of the bone
|
||||
aiVector3D vPosition;
|
||||
|
||||
//! Array of position keys
|
||||
std::vector<aiVectorKey> pkeyPositions;
|
||||
|
||||
//! Array of scaling keys
|
||||
std::vector<aiVectorKey> pkeyScalings;
|
||||
|
||||
//! Array of rotation keys
|
||||
std::vector<aiQuatKey> pkeyRotations;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//! Describes a MDL7 frame
|
||||
struct IntFrameInfo_MDL7
|
||||
{
|
||||
//! Construction from an existing frame header
|
||||
IntFrameInfo_MDL7(BE_NCONST MDL::Frame_MDL7* _pcFrame,unsigned int _iIndex)
|
||||
: iIndex(_iIndex)
|
||||
, pcFrame(_pcFrame)
|
||||
{}
|
||||
|
||||
//! Index of the frame
|
||||
unsigned int iIndex;
|
||||
|
||||
//! Points to the header of the frame
|
||||
BE_NCONST MDL::Frame_MDL7* pcFrame;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//! Describes a MDL7 mesh group
|
||||
struct IntGroupInfo_MDL7
|
||||
{
|
||||
//! Default constructor
|
||||
IntGroupInfo_MDL7() AI_NO_EXCEPT
|
||||
: iIndex(0)
|
||||
, pcGroup(nullptr)
|
||||
, pcGroupUVs(nullptr)
|
||||
, pcGroupTris(nullptr)
|
||||
, pcGroupVerts(nullptr)
|
||||
{}
|
||||
|
||||
//! Construction from an existing group header
|
||||
IntGroupInfo_MDL7(BE_NCONST MDL::Group_MDL7* _pcGroup, unsigned int _iIndex)
|
||||
: iIndex(_iIndex)
|
||||
, pcGroup(_pcGroup)
|
||||
, pcGroupUVs()
|
||||
, pcGroupTris()
|
||||
, pcGroupVerts()
|
||||
{}
|
||||
|
||||
//! Index of the group
|
||||
unsigned int iIndex;
|
||||
|
||||
//! Points to the header of the group
|
||||
BE_NCONST MDL::Group_MDL7* pcGroup;
|
||||
|
||||
//! Points to the beginning of the uv coordinate section
|
||||
BE_NCONST MDL::TexCoord_MDL7* pcGroupUVs;
|
||||
|
||||
//! Points to the beginning of the triangle section
|
||||
MDL::Triangle_MDL7* pcGroupTris;
|
||||
|
||||
//! Points to the beginning of the vertex section
|
||||
BE_NCONST MDL::Vertex_MDL7* pcGroupVerts;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//! Holds the data that belongs to a MDL7 mesh group
|
||||
struct IntGroupData_MDL7
|
||||
{
|
||||
IntGroupData_MDL7() AI_NO_EXCEPT
|
||||
: bNeed2UV(false)
|
||||
{}
|
||||
|
||||
//! Array of faces that belong to the group
|
||||
std::vector<MDL::IntFace_MDL7> pcFaces;
|
||||
|
||||
//! Array of vertex positions
|
||||
std::vector<aiVector3D> vPositions;
|
||||
|
||||
//! Array of vertex normals
|
||||
std::vector<aiVector3D> vNormals;
|
||||
|
||||
//! Array of bones indices
|
||||
std::vector<unsigned int> aiBones;
|
||||
|
||||
//! First UV coordinate set
|
||||
std::vector<aiVector3D> vTextureCoords1;
|
||||
|
||||
//! Optional second UV coordinate set
|
||||
std::vector<aiVector3D> vTextureCoords2;
|
||||
|
||||
//! Specifies whether there are two texture
|
||||
//! coordinate sets required
|
||||
bool bNeed2UV;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//! Holds data from an MDL7 file that is shared by all mesh groups
|
||||
struct IntSharedData_MDL7 {
|
||||
//! Default constructor
|
||||
IntSharedData_MDL7() AI_NO_EXCEPT
|
||||
: apcOutBones(),
|
||||
iNum()
|
||||
{
|
||||
abNeedMaterials.reserve(10);
|
||||
}
|
||||
|
||||
//! Destruction: properly delete all allocated resources
|
||||
~IntSharedData_MDL7()
|
||||
{
|
||||
// kill all bones
|
||||
if (this->apcOutBones)
|
||||
{
|
||||
for (unsigned int m = 0; m < iNum;++m)
|
||||
delete this->apcOutBones[m];
|
||||
delete[] this->apcOutBones;
|
||||
}
|
||||
}
|
||||
|
||||
//! Specifies which materials are used
|
||||
std::vector<bool> abNeedMaterials;
|
||||
|
||||
//! List of all materials
|
||||
std::vector<aiMaterial*> pcMats;
|
||||
|
||||
//! List of all bones
|
||||
IntBone_MDL7** apcOutBones;
|
||||
|
||||
//! number of bones
|
||||
unsigned int iNum;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//! Contains input data for GenerateOutputMeshes_3DGS_MDL7
|
||||
struct IntSplitGroupData_MDL7
|
||||
{
|
||||
//! Construction from a given shared data set
|
||||
IntSplitGroupData_MDL7(IntSharedData_MDL7& _shared,
|
||||
std::vector<aiMesh*>& _avOutList)
|
||||
|
||||
: aiSplit(), shared(_shared), avOutList(_avOutList)
|
||||
{
|
||||
}
|
||||
|
||||
//! Destruction: properly delete all allocated resources
|
||||
~IntSplitGroupData_MDL7()
|
||||
{
|
||||
// kill all face lists
|
||||
if(this->aiSplit)
|
||||
{
|
||||
for (unsigned int m = 0; m < shared.pcMats.size();++m)
|
||||
delete this->aiSplit[m];
|
||||
delete[] this->aiSplit;
|
||||
}
|
||||
}
|
||||
|
||||
//! Contains a list of all faces per material
|
||||
std::vector<unsigned int>** aiSplit;
|
||||
|
||||
//! Shared data for all groups of the model
|
||||
IntSharedData_MDL7& shared;
|
||||
|
||||
//! List of meshes
|
||||
std::vector<aiMesh*>& avOutList;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // end namespaces
|
||||
|
||||
#endif // !! AI_MDLFILEHELPER_H_INC
|
||||
1979
Engine/lib/assimp/code/AssetLib/MDL/MDLLoader.cpp
Normal file
1979
Engine/lib/assimp/code/AssetLib/MDL/MDLLoader.cpp
Normal file
File diff suppressed because it is too large
Load diff
451
Engine/lib/assimp/code/AssetLib/MDL/MDLLoader.h
Normal file
451
Engine/lib/assimp/code/AssetLib/MDL/MDLLoader.h
Normal file
|
|
@ -0,0 +1,451 @@
|
|||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 MDLLoader.h
|
||||
* @brief Declaration of the loader for MDL files
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef AI_MDLLOADER_H_INCLUDED
|
||||
#define AI_MDLLOADER_H_INCLUDED
|
||||
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include "MDLFileData.h"
|
||||
#include "AssetLib/HMP/HalfLifeFileData.h"
|
||||
#include "AssetLib/MDL/HalfLife/HL1ImportSettings.h"
|
||||
|
||||
struct aiNode;
|
||||
struct aiTexture;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
using namespace MDL;
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// Include file/line information in debug builds
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
# define VALIDATE_FILE_SIZE(msg) SizeCheck(msg,__FILE__,__LINE__)
|
||||
#else
|
||||
# define VALIDATE_FILE_SIZE(msg) SizeCheck(msg)
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
/** @brief Class to load MDL files.
|
||||
*
|
||||
* Several subformats exist:
|
||||
* <ul>
|
||||
* <li>Quake I</li>
|
||||
* <li>3D Game Studio MDL3, MDL4</li>
|
||||
* <li>3D Game Studio MDL5</li>
|
||||
* <li>3D Game Studio MDL7</li>
|
||||
* <li>Halflife 1</li>
|
||||
* <li>Halflife 2</li>
|
||||
* </ul>
|
||||
* These formats are partially identical and it would be possible to load
|
||||
* them all with a single 1000-line function-beast. However, it has been
|
||||
* split into several code paths to make the code easier to read and maintain.
|
||||
*/
|
||||
class MDLImporter : public BaseImporter
|
||||
{
|
||||
public:
|
||||
MDLImporter();
|
||||
~MDLImporter() override;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Returns whether the class can handle the format of the given file.
|
||||
* See BaseImporter::CanRead() for details. */
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||
bool checkSig) const override;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Called prior to ReadFile().
|
||||
* The function is a request to the importer to update its configuration
|
||||
* basing on the Importer's configuration property list.
|
||||
*/
|
||||
void SetupProperties(const Importer* pImp) override;
|
||||
|
||||
protected:
|
||||
// -------------------------------------------------------------------
|
||||
/** Return importer meta information.
|
||||
* See #BaseImporter::GetInfo for the details
|
||||
*/
|
||||
const aiImporterDesc* GetInfo () const override;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Imports the given file into the given scene structure.
|
||||
* See BaseImporter::InternReadFile() for details
|
||||
*/
|
||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||
IOSystem* pIOHandler) override;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Import a quake 1 MDL file (IDPO)
|
||||
*/
|
||||
void InternReadFile_Quake1( );
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Import a GameStudio A4/A5 file (MDL 3,4,5)
|
||||
*/
|
||||
void InternReadFile_3DGS_MDL345( );
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Import a GameStudio A7 file (MDL 7)
|
||||
*/
|
||||
void InternReadFile_3DGS_MDL7( );
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Import a Half-Life 1 MDL file
|
||||
*/
|
||||
void InternReadFile_HL1(const std::string& pFile, const uint32_t iMagicWord);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Import a CS:S/HL2 MDL file (not fully implemented)
|
||||
*/
|
||||
void InternReadFile_HL2( );
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Check whether a given position is inside the valid range
|
||||
* Throw a DeadlyImportError if it is not
|
||||
* \param szPos Cursor position
|
||||
* \param szFile Name of the source file from which the function was called
|
||||
* \param iLine Source code line from which the function was called
|
||||
*/
|
||||
void SizeCheck(const void* szPos);
|
||||
void SizeCheck(const void* szPos, const char* szFile, unsigned int iLine);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Validate the header data structure of a game studio MDL7 file
|
||||
* \param pcHeader Input header to be validated
|
||||
*/
|
||||
void ValidateHeader_3DGS_MDL7(const MDL::Header_MDL7* pcHeader);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Validate the header data structure of a Quake 1 model
|
||||
* \param pcHeader Input header to be validated
|
||||
*/
|
||||
void ValidateHeader_Quake1(const MDL::Header* pcHeader);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Try to load a palette from the current directory (colormap.lmp)
|
||||
* If it is not found the default palette of Quake1 is returned
|
||||
*/
|
||||
void SearchPalette(const unsigned char** pszColorMap);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Free a palette created with a previous call to SearchPalette()
|
||||
*/
|
||||
void FreePalette(const unsigned char* pszColorMap);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Load a palletized texture from the file and convert it to 32bpp
|
||||
*/
|
||||
void CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Used to load textures from MDL3/4
|
||||
* \param szData Input data
|
||||
* \param iType Color data type
|
||||
* \param piSkip Receive: Size to skip, in bytes
|
||||
*/
|
||||
void CreateTexture_3DGS_MDL4(const unsigned char* szData,
|
||||
unsigned int iType,
|
||||
unsigned int* piSkip);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Used to load textures from MDL5
|
||||
* \param szData Input data
|
||||
* \param iType Color data type
|
||||
* \param piSkip Receive: Size to skip, in bytes
|
||||
*/
|
||||
void CreateTexture_3DGS_MDL5(const unsigned char* szData,
|
||||
unsigned int iType,
|
||||
unsigned int* piSkip);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Checks whether a texture can be replaced with a single color
|
||||
* This is useful for all file formats before MDL7 (all those
|
||||
* that are not containing material colors separate from textures).
|
||||
* MED seems to write dummy 8x8 monochrome images instead.
|
||||
* \param pcTexture Input texture
|
||||
* \return aiColor.r is set to qnan if the function fails and no
|
||||
* color can be found.
|
||||
*/
|
||||
aiColor4D ReplaceTextureWithColor(const aiTexture* pcTexture);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Converts the absolute texture coordinates in MDL5 files to
|
||||
* relative in a range between 0 and 1
|
||||
*/
|
||||
void CalculateUVCoordinates_MDL5();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Read an UV coordinate from the file. If the file format is not
|
||||
* MDL5, the function calculates relative texture coordinates
|
||||
* \param vOut Receives the output UV coord
|
||||
* \param pcSrc UV coordinate buffer
|
||||
* \param UV coordinate index
|
||||
*/
|
||||
void ImportUVCoordinate_3DGS_MDL345( aiVector3D& vOut,
|
||||
const MDL::TexCoord_MDL3* pcSrc,
|
||||
unsigned int iIndex);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Setup the material properties for Quake and MDL<7 models.
|
||||
* These formats don't support more than one material per mesh,
|
||||
* therefore the method processes only ONE skin and removes
|
||||
* all others.
|
||||
*/
|
||||
void SetupMaterialProperties_3DGS_MDL5_Quake1( );
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parse a skin lump in a MDL7/HMP7 file with all of its features
|
||||
* variant 1: Current cursor position is the beginning of the skin header
|
||||
* \param szCurrent Current data pointer
|
||||
* \param szCurrentOut Output data pointer
|
||||
* \param pcMats Material list for this group. To be filled ...
|
||||
*/
|
||||
void ParseSkinLump_3DGS_MDL7(
|
||||
const unsigned char* szCurrent,
|
||||
const unsigned char** szCurrentOut,
|
||||
std::vector<aiMaterial*>& pcMats);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parse a skin lump in a MDL7/HMP7 file with all of its features
|
||||
* variant 2: Current cursor position is the beginning of the skin data
|
||||
* \param szCurrent Current data pointer
|
||||
* \param szCurrentOut Output data pointer
|
||||
* \param pcMatOut Output material
|
||||
* \param iType header.typ
|
||||
* \param iWidth header.width
|
||||
* \param iHeight header.height
|
||||
*/
|
||||
void ParseSkinLump_3DGS_MDL7(
|
||||
const unsigned char* szCurrent,
|
||||
const unsigned char** szCurrentOut,
|
||||
aiMaterial* pcMatOut,
|
||||
unsigned int iType,
|
||||
unsigned int iWidth,
|
||||
unsigned int iHeight);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Skip a skin lump in a MDL7/HMP7 file
|
||||
* \param szCurrent Current data pointer
|
||||
* \param szCurrentOut Output data pointer. Points to the byte just
|
||||
* behind the last byte of the skin.
|
||||
* \param iType header.typ
|
||||
* \param iWidth header.width
|
||||
* \param iHeight header.height
|
||||
*/
|
||||
void SkipSkinLump_3DGS_MDL7(const unsigned char* szCurrent,
|
||||
const unsigned char** szCurrentOut,
|
||||
unsigned int iType,
|
||||
unsigned int iWidth,
|
||||
unsigned int iHeight);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parse texture color data for MDL5, MDL6 and MDL7 formats
|
||||
* \param szData Current data pointer
|
||||
* \param iType type of the texture data. No DDS or external
|
||||
* \param piSkip Receive the number of bytes to skip
|
||||
* \param pcNew Must point to fully initialized data. Width and
|
||||
* height must be set. If pcNew->pcData is set to UINT_MAX,
|
||||
* piSkip will receive the size of the texture, in bytes, but no
|
||||
* color data will be read.
|
||||
*/
|
||||
void ParseTextureColorData(const unsigned char* szData,
|
||||
unsigned int iType,
|
||||
unsigned int* piSkip,
|
||||
aiTexture* pcNew);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Join two materials / skins. Setup UV source ... etc
|
||||
* \param pcMat1 First input material
|
||||
* \param pcMat2 Second input material
|
||||
* \param pcMatOut Output material instance to be filled. Must be empty
|
||||
*/
|
||||
void JoinSkins_3DGS_MDL7(aiMaterial* pcMat1,
|
||||
aiMaterial* pcMat2,
|
||||
aiMaterial* pcMatOut);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Add a bone transformation key to an animation
|
||||
* \param iTrafo Index of the transformation (always==frame index?)
|
||||
* No need to validate this index, it is always valid.
|
||||
* \param pcBoneTransforms Bone transformation for this index
|
||||
* \param apcOutBones Output bones array
|
||||
*/
|
||||
void AddAnimationBoneTrafoKey_3DGS_MDL7(unsigned int iTrafo,
|
||||
const MDL::BoneTransform_MDL7* pcBoneTransforms,
|
||||
MDL::IntBone_MDL7** apcBonesOut);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Load the bone list of a MDL7 file
|
||||
* \return If the bones could be loaded successfully, a valid
|
||||
* array containing pointers to a temporary bone
|
||||
* representation. nullptr if the bones could not be loaded.
|
||||
*/
|
||||
MDL::IntBone_MDL7** LoadBones_3DGS_MDL7();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Load bone transformation keyframes from a file chunk
|
||||
* \param groupInfo -> doc of data structure
|
||||
* \param frame -> doc of data structure
|
||||
* \param shared -> doc of data structure
|
||||
*/
|
||||
void ParseBoneTrafoKeys_3DGS_MDL7(
|
||||
const MDL::IntGroupInfo_MDL7& groupInfo,
|
||||
IntFrameInfo_MDL7& frame,
|
||||
MDL::IntSharedData_MDL7& shared);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Calculate absolute bone animation matrices for each bone
|
||||
* \param apcOutBones Output bones array
|
||||
*/
|
||||
void CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Add all bones to the nodegraph (as children of the root node)
|
||||
* \param apcBonesOut List of bones
|
||||
* \param pcParent Parent node. New nodes will be added to this node
|
||||
* \param iParentIndex Index of the parent bone
|
||||
*/
|
||||
void AddBonesToNodeGraph_3DGS_MDL7(const MDL::IntBone_MDL7** apcBonesOut,
|
||||
aiNode* pcParent,uint16_t iParentIndex);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Build output animations
|
||||
* \param apcBonesOut List of bones
|
||||
*/
|
||||
void BuildOutputAnims_3DGS_MDL7(const MDL::IntBone_MDL7** apcBonesOut);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Handles materials that are just referencing another material
|
||||
* There is no test file for this feature, but Conitec's doc
|
||||
* say it is used.
|
||||
*/
|
||||
void HandleMaterialReferences_3DGS_MDL7();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Copies only the material that are referenced by at least one
|
||||
* mesh to the final output material list. All other materials
|
||||
* will be discarded.
|
||||
* \param shared -> doc of data structure
|
||||
*/
|
||||
void CopyMaterials_3DGS_MDL7(MDL::IntSharedData_MDL7 &shared);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Process the frame section at the end of a group
|
||||
* \param groupInfo -> doc of data structure
|
||||
* \param shared -> doc of data structure
|
||||
* \param szCurrent Pointer to the start of the frame section
|
||||
* \param szCurrentOut Receives a pointer to the first byte of the
|
||||
* next data section.
|
||||
* \return false to read no further groups (a small workaround for
|
||||
* some tiny and unsolved problems ... )
|
||||
*/
|
||||
bool ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo,
|
||||
MDL::IntGroupData_MDL7& groupData,
|
||||
MDL::IntSharedData_MDL7& shared,
|
||||
const unsigned char* szCurrent,
|
||||
const unsigned char** szCurrentOut);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Sort all faces by their materials. If the mesh is using
|
||||
* multiple materials per face (that are blended together) the function
|
||||
* might create new materials.
|
||||
* \param groupInfo -> doc of data structure
|
||||
* \param groupData -> doc of data structure
|
||||
* \param splitGroupData -> doc of data structure
|
||||
*/
|
||||
void SortByMaterials_3DGS_MDL7(
|
||||
const MDL::IntGroupInfo_MDL7& groupInfo,
|
||||
MDL::IntGroupData_MDL7& groupData,
|
||||
MDL::IntSplitGroupData_MDL7& splitGroupData);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Read all faces and vertices from a MDL7 group. The function fills
|
||||
* preallocated memory buffers.
|
||||
* \param groupInfo -> doc of data structure
|
||||
* \param groupData -> doc of data structure
|
||||
*/
|
||||
void ReadFaces_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo,
|
||||
MDL::IntGroupData_MDL7& groupData);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Generate the final output meshes for a7 models
|
||||
* \param groupData -> doc of data structure
|
||||
* \param splitGroupData -> doc of data structure
|
||||
*/
|
||||
void GenerateOutputMeshes_3DGS_MDL7(
|
||||
MDL::IntGroupData_MDL7& groupData,
|
||||
MDL::IntSplitGroupData_MDL7& splitGroupData);
|
||||
|
||||
protected:
|
||||
|
||||
/** Configuration option: frame to be loaded */
|
||||
unsigned int configFrameID;
|
||||
|
||||
/** Configuration option: palette to be used to decode palletized images*/
|
||||
std::string configPalette;
|
||||
|
||||
/** Buffer to hold the loaded file */
|
||||
unsigned char* mBuffer;
|
||||
|
||||
/** For GameStudio MDL files: The number in the magic word, either 3,4 or 5
|
||||
* (MDL7 doesn't need this, the format has a separate loader) */
|
||||
unsigned int iGSFileVersion;
|
||||
|
||||
/** Output I/O handler. used to load external lmp files */
|
||||
IOSystem* mIOHandler;
|
||||
|
||||
/** Output scene to be filled */
|
||||
aiScene* pScene;
|
||||
|
||||
/** Size of the input file in bytes */
|
||||
unsigned int iFileSize;
|
||||
|
||||
/* Configuration for HL1 MDL */
|
||||
HalfLife::HL1ImportSettings mHL1ImportSettings;
|
||||
};
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
#endif // AI_3DSIMPORTER_H_INC
|
||||
765
Engine/lib/assimp/code/AssetLib/MDL/MDLMaterialLoader.cpp
Normal file
765
Engine/lib/assimp/code/AssetLib/MDL/MDLMaterialLoader.cpp
Normal file
|
|
@ -0,0 +1,765 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, 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 Implementation of the material part of the MDL importer class */
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_MDL_IMPORTER
|
||||
|
||||
#include "MDLDefaultColorMap.h"
|
||||
#include "MDLLoader.h"
|
||||
|
||||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/qnan.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/texture.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
static aiTexel *const bad_texel = reinterpret_cast<aiTexel *>(SIZE_MAX);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Find a suitable palette file or take the default one
|
||||
void MDLImporter::SearchPalette(const unsigned char **pszColorMap) {
|
||||
// now try to find the color map in the current directory
|
||||
IOStream *pcStream = mIOHandler->Open(configPalette, "rb");
|
||||
|
||||
const unsigned char *szColorMap = (const unsigned char *)::g_aclrDefaultColorMap;
|
||||
if (pcStream) {
|
||||
if (pcStream->FileSize() >= 768) {
|
||||
size_t len = 256 * 3;
|
||||
unsigned char *colorMap = new unsigned char[len];
|
||||
szColorMap = colorMap;
|
||||
pcStream->Read(colorMap, len, 1);
|
||||
ASSIMP_LOG_INFO("Found valid colormap.lmp in directory. "
|
||||
"It will be used to decode embedded textures in palletized formats.");
|
||||
}
|
||||
delete pcStream;
|
||||
pcStream = nullptr;
|
||||
}
|
||||
*pszColorMap = szColorMap;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Free the palette again
|
||||
void MDLImporter::FreePalette(const unsigned char *szColorMap) {
|
||||
if (szColorMap != (const unsigned char *)::g_aclrDefaultColorMap) {
|
||||
delete[] szColorMap;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Check whether we can replace a texture with a single color
|
||||
aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture *pcTexture) {
|
||||
ai_assert(nullptr != pcTexture);
|
||||
|
||||
aiColor4D clrOut;
|
||||
clrOut.r = get_qnan();
|
||||
if (!pcTexture->mHeight || !pcTexture->mWidth)
|
||||
return clrOut;
|
||||
|
||||
const unsigned int iNumPixels = pcTexture->mHeight * pcTexture->mWidth;
|
||||
const aiTexel *pcTexel = pcTexture->pcData + 1;
|
||||
const aiTexel *const pcTexelEnd = &pcTexture->pcData[iNumPixels];
|
||||
|
||||
while (pcTexel != pcTexelEnd) {
|
||||
if (*pcTexel != *(pcTexel - 1)) {
|
||||
pcTexel = nullptr;
|
||||
break;
|
||||
}
|
||||
++pcTexel;
|
||||
}
|
||||
if (pcTexel) {
|
||||
clrOut.r = pcTexture->pcData->r / 255.0f;
|
||||
clrOut.g = pcTexture->pcData->g / 255.0f;
|
||||
clrOut.b = pcTexture->pcData->b / 255.0f;
|
||||
clrOut.a = pcTexture->pcData->a / 255.0f;
|
||||
}
|
||||
return clrOut;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Read a texture from a MDL3 file
|
||||
void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char *szData) {
|
||||
const MDL::Header *pcHeader = (const MDL::Header *)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function
|
||||
|
||||
VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth *
|
||||
pcHeader->skinheight);
|
||||
|
||||
// allocate a new texture object
|
||||
aiTexture *pcNew = new aiTexture();
|
||||
pcNew->mWidth = pcHeader->skinwidth;
|
||||
pcNew->mHeight = pcHeader->skinheight;
|
||||
|
||||
if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
|
||||
throw DeadlyImportError("Invalid MDL file. A texture is too big.");
|
||||
}
|
||||
pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight];
|
||||
|
||||
const unsigned char *szColorMap;
|
||||
this->SearchPalette(&szColorMap);
|
||||
|
||||
// copy texture data
|
||||
for (unsigned int i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
|
||||
const unsigned char val = szData[i];
|
||||
const unsigned char *sz = &szColorMap[val * 3];
|
||||
|
||||
pcNew->pcData[i].a = 0xFF;
|
||||
pcNew->pcData[i].r = *sz++;
|
||||
pcNew->pcData[i].g = *sz++;
|
||||
pcNew->pcData[i].b = *sz;
|
||||
}
|
||||
|
||||
FreePalette(szColorMap);
|
||||
|
||||
// store the texture
|
||||
aiTexture **pc = this->pScene->mTextures;
|
||||
this->pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
|
||||
for (unsigned int i = 0; i < pScene->mNumTextures; ++i)
|
||||
pScene->mTextures[i] = pc[i];
|
||||
|
||||
pScene->mTextures[this->pScene->mNumTextures] = pcNew;
|
||||
pScene->mNumTextures++;
|
||||
delete[] pc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Read a texture from a MDL4 file
|
||||
void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char *szData,
|
||||
unsigned int iType,
|
||||
unsigned int *piSkip) {
|
||||
ai_assert(nullptr != piSkip);
|
||||
|
||||
const MDL::Header *pcHeader = (const MDL::Header *)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function
|
||||
|
||||
if (iType == 1 || iType > 3) {
|
||||
ASSIMP_LOG_ERROR("Unsupported texture file format");
|
||||
return;
|
||||
}
|
||||
|
||||
const bool bNoRead = *piSkip == UINT_MAX;
|
||||
|
||||
// allocate a new texture object
|
||||
aiTexture *pcNew = new aiTexture();
|
||||
pcNew->mWidth = pcHeader->skinwidth;
|
||||
pcNew->mHeight = pcHeader->skinheight;
|
||||
|
||||
if (bNoRead) pcNew->pcData = bad_texel;
|
||||
ParseTextureColorData(szData, iType, piSkip, pcNew);
|
||||
|
||||
// store the texture
|
||||
if (!bNoRead) {
|
||||
if (!this->pScene->mNumTextures) {
|
||||
pScene->mNumTextures = 1;
|
||||
pScene->mTextures = new aiTexture *[1];
|
||||
pScene->mTextures[0] = pcNew;
|
||||
} else {
|
||||
aiTexture **pc = pScene->mTextures;
|
||||
pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
|
||||
for (unsigned int i = 0; i < this->pScene->mNumTextures; ++i)
|
||||
pScene->mTextures[i] = pc[i];
|
||||
pScene->mTextures[pScene->mNumTextures] = pcNew;
|
||||
pScene->mNumTextures++;
|
||||
delete[] pc;
|
||||
}
|
||||
} else {
|
||||
pcNew->pcData = nullptr;
|
||||
delete pcNew;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Load color data of a texture and convert it to our output format
|
||||
void MDLImporter::ParseTextureColorData(const unsigned char *szData,
|
||||
unsigned int iType,
|
||||
unsigned int *piSkip,
|
||||
aiTexture *pcNew) {
|
||||
const bool do_read = bad_texel != pcNew->pcData;
|
||||
|
||||
// allocate storage for the texture image
|
||||
if (do_read) {
|
||||
if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
|
||||
throw DeadlyImportError("Invalid MDL file. A texture is too big.");
|
||||
}
|
||||
pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight];
|
||||
}
|
||||
|
||||
// R5G6B5 format (with or without MIPs)
|
||||
// ****************************************************************
|
||||
if (2 == iType || 10 == iType) {
|
||||
VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 2);
|
||||
|
||||
// copy texture data
|
||||
unsigned int i;
|
||||
if (do_read) {
|
||||
for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
|
||||
MDL::RGB565 val = ((MDL::RGB565 *)szData)[i];
|
||||
AI_SWAP2(val);
|
||||
|
||||
pcNew->pcData[i].a = 0xFF;
|
||||
pcNew->pcData[i].r = (unsigned char)val.b << 3;
|
||||
pcNew->pcData[i].g = (unsigned char)val.g << 2;
|
||||
pcNew->pcData[i].b = (unsigned char)val.r << 3;
|
||||
}
|
||||
} else {
|
||||
i = pcNew->mWidth * pcNew->mHeight;
|
||||
}
|
||||
*piSkip = i * 2;
|
||||
|
||||
// apply MIP maps
|
||||
if (10 == iType) {
|
||||
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 1;
|
||||
VALIDATE_FILE_SIZE(szData + *piSkip);
|
||||
}
|
||||
}
|
||||
// ARGB4 format (with or without MIPs)
|
||||
// ****************************************************************
|
||||
else if (3 == iType || 11 == iType) {
|
||||
VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 4);
|
||||
|
||||
// copy texture data
|
||||
unsigned int i;
|
||||
if (do_read) {
|
||||
for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
|
||||
MDL::ARGB4 val = ((MDL::ARGB4 *)szData)[i];
|
||||
AI_SWAP2(val);
|
||||
|
||||
pcNew->pcData[i].a = (unsigned char)val.a << 4;
|
||||
pcNew->pcData[i].r = (unsigned char)val.r << 4;
|
||||
pcNew->pcData[i].g = (unsigned char)val.g << 4;
|
||||
pcNew->pcData[i].b = (unsigned char)val.b << 4;
|
||||
}
|
||||
} else
|
||||
i = pcNew->mWidth * pcNew->mHeight;
|
||||
*piSkip = i * 2;
|
||||
|
||||
// apply MIP maps
|
||||
if (11 == iType) {
|
||||
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 1;
|
||||
VALIDATE_FILE_SIZE(szData + *piSkip);
|
||||
}
|
||||
}
|
||||
// RGB8 format (with or without MIPs)
|
||||
// ****************************************************************
|
||||
else if (4 == iType || 12 == iType) {
|
||||
VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 3);
|
||||
|
||||
// copy texture data
|
||||
unsigned int i;
|
||||
if (do_read) {
|
||||
for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
|
||||
const unsigned char *_szData = &szData[i * 3];
|
||||
|
||||
pcNew->pcData[i].a = 0xFF;
|
||||
pcNew->pcData[i].b = *_szData++;
|
||||
pcNew->pcData[i].g = *_szData++;
|
||||
pcNew->pcData[i].r = *_szData;
|
||||
}
|
||||
} else
|
||||
i = pcNew->mWidth * pcNew->mHeight;
|
||||
|
||||
// apply MIP maps
|
||||
*piSkip = i * 3;
|
||||
if (12 == iType) {
|
||||
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) * 3;
|
||||
VALIDATE_FILE_SIZE(szData + *piSkip);
|
||||
}
|
||||
}
|
||||
// ARGB8 format (with ir without MIPs)
|
||||
// ****************************************************************
|
||||
else if (5 == iType || 13 == iType) {
|
||||
VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 4);
|
||||
|
||||
// copy texture data
|
||||
unsigned int i;
|
||||
if (do_read) {
|
||||
for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
|
||||
const unsigned char *_szData = &szData[i * 4];
|
||||
|
||||
pcNew->pcData[i].b = *_szData++;
|
||||
pcNew->pcData[i].g = *_szData++;
|
||||
pcNew->pcData[i].r = *_szData++;
|
||||
pcNew->pcData[i].a = *_szData;
|
||||
}
|
||||
} else {
|
||||
i = pcNew->mWidth * pcNew->mHeight;
|
||||
}
|
||||
|
||||
// apply MIP maps
|
||||
*piSkip = i << 2;
|
||||
if (13 == iType) {
|
||||
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 2;
|
||||
}
|
||||
}
|
||||
// palletized 8 bit texture. As for Quake 1
|
||||
// ****************************************************************
|
||||
else if (0 == iType) {
|
||||
VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight);
|
||||
|
||||
// copy texture data
|
||||
unsigned int i;
|
||||
if (do_read) {
|
||||
|
||||
const unsigned char *szColorMap;
|
||||
SearchPalette(&szColorMap);
|
||||
|
||||
for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
|
||||
const unsigned char val = szData[i];
|
||||
const unsigned char *sz = &szColorMap[val * 3];
|
||||
|
||||
pcNew->pcData[i].a = 0xFF;
|
||||
pcNew->pcData[i].r = *sz++;
|
||||
pcNew->pcData[i].g = *sz++;
|
||||
pcNew->pcData[i].b = *sz;
|
||||
}
|
||||
this->FreePalette(szColorMap);
|
||||
|
||||
} else
|
||||
i = pcNew->mWidth * pcNew->mHeight;
|
||||
*piSkip = i;
|
||||
|
||||
// FIXME: Also support for MIP maps?
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a texture from a MDL5 file
|
||||
void MDLImporter::CreateTexture_3DGS_MDL5(const unsigned char *szData,
|
||||
unsigned int iType,
|
||||
unsigned int *piSkip) {
|
||||
ai_assert(nullptr != piSkip);
|
||||
bool bNoRead = *piSkip == UINT_MAX;
|
||||
|
||||
// allocate a new texture object
|
||||
aiTexture *pcNew = new aiTexture();
|
||||
|
||||
VALIDATE_FILE_SIZE(szData + 8);
|
||||
|
||||
// first read the size of the texture
|
||||
pcNew->mWidth = *((uint32_t *)szData);
|
||||
AI_SWAP4(pcNew->mWidth);
|
||||
szData += sizeof(uint32_t);
|
||||
|
||||
pcNew->mHeight = *((uint32_t *)szData);
|
||||
AI_SWAP4(pcNew->mHeight);
|
||||
szData += sizeof(uint32_t);
|
||||
|
||||
if (bNoRead) {
|
||||
pcNew->pcData = bad_texel;
|
||||
}
|
||||
|
||||
// this should not occur - at least the docs say it shouldn't.
|
||||
// however, one can easily try out what MED does if you have
|
||||
// a model with a DDS texture and export it to MDL5 ...
|
||||
// yeah, it embeds the DDS file.
|
||||
if (6 == iType) {
|
||||
// this is a compressed texture in DDS format
|
||||
*piSkip = pcNew->mWidth;
|
||||
VALIDATE_FILE_SIZE(szData + *piSkip);
|
||||
|
||||
if (!bNoRead) {
|
||||
// place a hint and let the application know that this is a DDS file
|
||||
pcNew->mHeight = 0;
|
||||
pcNew->achFormatHint[0] = 'd';
|
||||
pcNew->achFormatHint[1] = 'd';
|
||||
pcNew->achFormatHint[2] = 's';
|
||||
pcNew->achFormatHint[3] = '\0';
|
||||
|
||||
pcNew->pcData = (aiTexel *)new unsigned char[pcNew->mWidth];
|
||||
::memcpy(pcNew->pcData, szData, pcNew->mWidth);
|
||||
}
|
||||
} else {
|
||||
// parse the color data of the texture
|
||||
ParseTextureColorData(szData, iType, piSkip, pcNew);
|
||||
}
|
||||
*piSkip += sizeof(uint32_t) * 2;
|
||||
|
||||
if (!bNoRead) {
|
||||
// store the texture
|
||||
if (!this->pScene->mNumTextures) {
|
||||
pScene->mNumTextures = 1;
|
||||
pScene->mTextures = new aiTexture *[1];
|
||||
pScene->mTextures[0] = pcNew;
|
||||
} else {
|
||||
aiTexture **pc = pScene->mTextures;
|
||||
pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
|
||||
for (unsigned int i = 0; i < pScene->mNumTextures; ++i)
|
||||
this->pScene->mTextures[i] = pc[i];
|
||||
|
||||
pScene->mTextures[pScene->mNumTextures] = pcNew;
|
||||
pScene->mNumTextures++;
|
||||
delete[] pc;
|
||||
}
|
||||
} else {
|
||||
pcNew->pcData = nullptr;
|
||||
delete pcNew;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a skin from a MDL7 file - more complex than all other subformats
|
||||
void MDLImporter::ParseSkinLump_3DGS_MDL7(
|
||||
const unsigned char *szCurrent,
|
||||
const unsigned char **szCurrentOut,
|
||||
aiMaterial *pcMatOut,
|
||||
unsigned int iType,
|
||||
unsigned int iWidth,
|
||||
unsigned int iHeight) {
|
||||
std::unique_ptr<aiTexture> pcNew;
|
||||
|
||||
// get the type of the skin
|
||||
unsigned int iMasked = (unsigned int)(iType & 0xF);
|
||||
|
||||
if (0x1 == iMasked) {
|
||||
// ***** REFERENCE TO ANOTHER SKIN INDEX *****
|
||||
int referrer = (int)iWidth;
|
||||
pcMatOut->AddProperty<int>(&referrer, 1, AI_MDL7_REFERRER_MATERIAL);
|
||||
} else if (0x6 == iMasked) {
|
||||
// ***** EMBEDDED DDS FILE *****
|
||||
if (1 != iHeight) {
|
||||
ASSIMP_LOG_WARN("Found a reference to an embedded DDS texture, "
|
||||
"but texture height is not equal to 1, which is not supported by MED");
|
||||
}
|
||||
if (iWidth == 0) {
|
||||
ASSIMP_LOG_ERROR("Found a reference to an embedded DDS texture, but texture width is zero, aborting import.");
|
||||
return;
|
||||
}
|
||||
|
||||
pcNew.reset(new aiTexture);
|
||||
pcNew->mHeight = 0;
|
||||
pcNew->mWidth = iWidth;
|
||||
|
||||
// place a proper format hint
|
||||
pcNew->achFormatHint[0] = 'd';
|
||||
pcNew->achFormatHint[1] = 'd';
|
||||
pcNew->achFormatHint[2] = 's';
|
||||
pcNew->achFormatHint[3] = '\0';
|
||||
|
||||
pcNew->pcData = (aiTexel *)new unsigned char[pcNew->mWidth];
|
||||
memcpy(pcNew->pcData, szCurrent, pcNew->mWidth);
|
||||
szCurrent += iWidth;
|
||||
} else if (0x7 == iMasked) {
|
||||
// ***** REFERENCE TO EXTERNAL FILE *****
|
||||
if (1 != iHeight) {
|
||||
ASSIMP_LOG_WARN("Found a reference to an external texture, "
|
||||
"but texture height is not equal to 1, which is not supported by MED");
|
||||
}
|
||||
|
||||
aiString szFile;
|
||||
const size_t iLen = strlen((const char *)szCurrent);
|
||||
size_t iLen2 = iLen + 1;
|
||||
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
|
||||
memcpy(szFile.data, (const char *)szCurrent, iLen2);
|
||||
szFile.length = static_cast<ai_uint32>(iLen2);
|
||||
|
||||
szCurrent += iLen2;
|
||||
|
||||
// place this as diffuse texture
|
||||
pcMatOut->AddProperty(&szFile, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
} else if (iMasked || !iType || (iType && iWidth && iHeight)) {
|
||||
pcNew.reset(new aiTexture());
|
||||
if (!iHeight || !iWidth) {
|
||||
ASSIMP_LOG_WARN("Found embedded texture, but its width "
|
||||
"an height are both 0. Is this a joke?");
|
||||
|
||||
// generate an empty chess pattern
|
||||
pcNew->mWidth = pcNew->mHeight = 8;
|
||||
pcNew->pcData = new aiTexel[64];
|
||||
for (unsigned int x = 0; x < 8; ++x) {
|
||||
for (unsigned int y = 0; y < 8; ++y) {
|
||||
const bool bSet = ((0 == x % 2 && 0 != y % 2) ||
|
||||
(0 != x % 2 && 0 == y % 2));
|
||||
|
||||
aiTexel *pc = &pcNew->pcData[y * 8 + x];
|
||||
pc->r = pc->b = pc->g = (bSet ? 0xFF : 0);
|
||||
pc->a = 0xFF;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// it is a standard color texture. Fill in width and height
|
||||
// and call the same function we used for loading MDL5 files
|
||||
|
||||
pcNew->mWidth = iWidth;
|
||||
pcNew->mHeight = iHeight;
|
||||
|
||||
unsigned int iSkip = 0;
|
||||
ParseTextureColorData(szCurrent, iMasked, &iSkip, pcNew.get());
|
||||
|
||||
// skip length of texture data
|
||||
szCurrent += iSkip;
|
||||
}
|
||||
}
|
||||
|
||||
// sometimes there are MDL7 files which have a monochrome
|
||||
// texture instead of material colors ... possible they have
|
||||
// been converted to MDL7 from other formats, such as MDL5
|
||||
aiColor4D clrTexture;
|
||||
if (pcNew)
|
||||
clrTexture = ReplaceTextureWithColor(pcNew.get());
|
||||
else
|
||||
clrTexture.r = get_qnan();
|
||||
|
||||
// check whether a material definition is contained in the skin
|
||||
if (iType & AI_MDL7_SKINTYPE_MATERIAL) {
|
||||
BE_NCONST MDL::Material_MDL7 *pcMatIn = (BE_NCONST MDL::Material_MDL7 *)szCurrent;
|
||||
szCurrent = (unsigned char *)(pcMatIn + 1);
|
||||
VALIDATE_FILE_SIZE(szCurrent);
|
||||
|
||||
aiColor3D clrTemp;
|
||||
|
||||
#define COLOR_MULTIPLY_RGB() \
|
||||
if (is_not_qnan(clrTexture.r)) { \
|
||||
clrTemp.r *= clrTexture.r; \
|
||||
clrTemp.g *= clrTexture.g; \
|
||||
clrTemp.b *= clrTexture.b; \
|
||||
}
|
||||
|
||||
// read diffuse color
|
||||
clrTemp.r = pcMatIn->Diffuse.r;
|
||||
AI_SWAP4(clrTemp.r);
|
||||
clrTemp.g = pcMatIn->Diffuse.g;
|
||||
AI_SWAP4(clrTemp.g);
|
||||
clrTemp.b = pcMatIn->Diffuse.b;
|
||||
AI_SWAP4(clrTemp.b);
|
||||
COLOR_MULTIPLY_RGB();
|
||||
pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||
|
||||
// read specular color
|
||||
clrTemp.r = pcMatIn->Specular.r;
|
||||
AI_SWAP4(clrTemp.r);
|
||||
clrTemp.g = pcMatIn->Specular.g;
|
||||
AI_SWAP4(clrTemp.g);
|
||||
clrTemp.b = pcMatIn->Specular.b;
|
||||
AI_SWAP4(clrTemp.b);
|
||||
COLOR_MULTIPLY_RGB();
|
||||
pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||
|
||||
// read ambient color
|
||||
clrTemp.r = pcMatIn->Ambient.r;
|
||||
AI_SWAP4(clrTemp.r);
|
||||
clrTemp.g = pcMatIn->Ambient.g;
|
||||
AI_SWAP4(clrTemp.g);
|
||||
clrTemp.b = pcMatIn->Ambient.b;
|
||||
AI_SWAP4(clrTemp.b);
|
||||
COLOR_MULTIPLY_RGB();
|
||||
pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_AMBIENT);
|
||||
|
||||
// read emissive color
|
||||
clrTemp.r = pcMatIn->Emissive.r;
|
||||
AI_SWAP4(clrTemp.r);
|
||||
clrTemp.g = pcMatIn->Emissive.g;
|
||||
AI_SWAP4(clrTemp.g);
|
||||
clrTemp.b = pcMatIn->Emissive.b;
|
||||
AI_SWAP4(clrTemp.b);
|
||||
pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||
|
||||
#undef COLOR_MULITPLY_RGB
|
||||
|
||||
// FIX: Take the opacity from the ambient color.
|
||||
// The doc say something else, but it is fact that MED exports the
|
||||
// opacity like this .... oh well.
|
||||
clrTemp.r = pcMatIn->Ambient.a;
|
||||
AI_SWAP4(clrTemp.r);
|
||||
if (is_not_qnan(clrTexture.r)) {
|
||||
clrTemp.r *= clrTexture.a;
|
||||
}
|
||||
pcMatOut->AddProperty<ai_real>(&clrTemp.r, 1, AI_MATKEY_OPACITY);
|
||||
|
||||
// read phong power
|
||||
int iShadingMode = (int)aiShadingMode_Gouraud;
|
||||
AI_SWAP4(pcMatIn->Power);
|
||||
if (0.0f != pcMatIn->Power) {
|
||||
iShadingMode = (int)aiShadingMode_Phong;
|
||||
// pcMatIn is packed, we can't form pointers to its members
|
||||
float power = pcMatIn->Power;
|
||||
pcMatOut->AddProperty<float>(&power, 1, AI_MATKEY_SHININESS);
|
||||
}
|
||||
pcMatOut->AddProperty<int>(&iShadingMode, 1, AI_MATKEY_SHADING_MODEL);
|
||||
} else if (is_not_qnan(clrTexture.r)) {
|
||||
pcMatOut->AddProperty<aiColor4D>(&clrTexture, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||
pcMatOut->AddProperty<aiColor4D>(&clrTexture, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||
}
|
||||
// if the texture could be replaced by a single material color
|
||||
// we don't need the texture anymore
|
||||
if (is_not_qnan(clrTexture.r)) {
|
||||
pcNew.reset();
|
||||
}
|
||||
|
||||
// If an ASCII effect description (HLSL?) is contained in the file,
|
||||
// we can simply ignore it ...
|
||||
if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) {
|
||||
VALIDATE_FILE_SIZE(szCurrent);
|
||||
int32_t iMe = *((int32_t *)szCurrent);
|
||||
AI_SWAP4(iMe);
|
||||
szCurrent += sizeof(char) * iMe + sizeof(int32_t);
|
||||
VALIDATE_FILE_SIZE(szCurrent);
|
||||
}
|
||||
|
||||
// If an embedded texture has been loaded setup the corresponding
|
||||
// data structures in the aiScene instance
|
||||
if (pcNew && pScene->mNumTextures <= 999) {
|
||||
// place this as diffuse texture
|
||||
char current[5];
|
||||
ai_snprintf(current, 5, "*%i", this->pScene->mNumTextures);
|
||||
|
||||
aiString szFile;
|
||||
const size_t iLen = strlen((const char *)current);
|
||||
::memcpy(szFile.data, (const char *)current, iLen + 1);
|
||||
szFile.length = (ai_uint32)iLen;
|
||||
|
||||
pcMatOut->AddProperty(&szFile, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
|
||||
// store the texture
|
||||
if (!pScene->mNumTextures) {
|
||||
pScene->mNumTextures = 1;
|
||||
pScene->mTextures = new aiTexture *[1];
|
||||
pScene->mTextures[0] = pcNew.release();
|
||||
} else {
|
||||
aiTexture **pc = pScene->mTextures;
|
||||
pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
|
||||
for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {
|
||||
pScene->mTextures[i] = pc[i];
|
||||
}
|
||||
|
||||
pScene->mTextures[pScene->mNumTextures] = pcNew.release();
|
||||
pScene->mNumTextures++;
|
||||
delete[] pc;
|
||||
}
|
||||
}
|
||||
VALIDATE_FILE_SIZE(szCurrent);
|
||||
*szCurrentOut = szCurrent;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Skip a skin lump
|
||||
void MDLImporter::SkipSkinLump_3DGS_MDL7(
|
||||
const unsigned char *szCurrent,
|
||||
const unsigned char **szCurrentOut,
|
||||
unsigned int iType,
|
||||
unsigned int iWidth,
|
||||
unsigned int iHeight) {
|
||||
// get the type of the skin
|
||||
const unsigned int iMasked = (unsigned int)(iType & 0xF);
|
||||
|
||||
if (0x6 == iMasked) {
|
||||
szCurrent += iWidth;
|
||||
}
|
||||
if (0x7 == iMasked) {
|
||||
const size_t iLen = std::strlen((const char *)szCurrent);
|
||||
szCurrent += iLen + 1;
|
||||
} else if (iMasked || !iType) {
|
||||
if (iMasked || !iType || (iType && iWidth && iHeight)) {
|
||||
// ParseTextureColorData(..., aiTexture::pcData == bad_texel) will simply
|
||||
// return the size of the color data in bytes in iSkip
|
||||
unsigned int iSkip = 0;
|
||||
|
||||
aiTexture tex;
|
||||
tex.pcData = bad_texel;
|
||||
tex.mHeight = iHeight;
|
||||
tex.mWidth = iWidth;
|
||||
ParseTextureColorData(szCurrent, iMasked, &iSkip, &tex);
|
||||
|
||||
// FIX: Important, otherwise the destructor will crash
|
||||
tex.pcData = nullptr;
|
||||
|
||||
// skip length of texture data
|
||||
szCurrent += iSkip;
|
||||
}
|
||||
}
|
||||
|
||||
// check whether a material definition is contained in the skin
|
||||
if (iType & AI_MDL7_SKINTYPE_MATERIAL) {
|
||||
BE_NCONST MDL::Material_MDL7 *pcMatIn = (BE_NCONST MDL::Material_MDL7 *)szCurrent;
|
||||
szCurrent = (unsigned char *)(pcMatIn + 1);
|
||||
}
|
||||
|
||||
// if an ASCII effect description (HLSL?) is contained in the file,
|
||||
// we can simply ignore it ...
|
||||
if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) {
|
||||
int32_t iMe = *((int32_t *)szCurrent);
|
||||
AI_SWAP4(iMe);
|
||||
szCurrent += sizeof(char) * iMe + sizeof(int32_t);
|
||||
}
|
||||
*szCurrentOut = szCurrent;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void MDLImporter::ParseSkinLump_3DGS_MDL7(
|
||||
const unsigned char *szCurrent,
|
||||
const unsigned char **szCurrentOut,
|
||||
std::vector<aiMaterial *> &pcMats) {
|
||||
ai_assert(nullptr != szCurrent);
|
||||
ai_assert(nullptr != szCurrentOut);
|
||||
|
||||
*szCurrentOut = szCurrent;
|
||||
BE_NCONST MDL::Skin_MDL7 *pcSkin = (BE_NCONST MDL::Skin_MDL7 *)szCurrent;
|
||||
AI_SWAP4(pcSkin->width);
|
||||
AI_SWAP4(pcSkin->height);
|
||||
szCurrent += 12;
|
||||
|
||||
// allocate an output material
|
||||
aiMaterial *pcMatOut = new aiMaterial();
|
||||
pcMats.push_back(pcMatOut);
|
||||
|
||||
// skip length of file name
|
||||
szCurrent += AI_MDL7_MAX_TEXNAMESIZE;
|
||||
|
||||
ParseSkinLump_3DGS_MDL7(szCurrent, szCurrentOut, pcMatOut,
|
||||
pcSkin->typ, pcSkin->width, pcSkin->height);
|
||||
|
||||
// place the name of the skin in the material
|
||||
if (pcSkin->texture_name[0]) {
|
||||
// the 0 termination could be there or not - we can't know
|
||||
aiString szFile;
|
||||
::memcpy(szFile.data, pcSkin->texture_name, sizeof(pcSkin->texture_name));
|
||||
szFile.data[sizeof(pcSkin->texture_name)] = '\0';
|
||||
szFile.length = (ai_uint32)::strlen(szFile.data);
|
||||
|
||||
pcMatOut->AddProperty(&szFile, AI_MATKEY_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_MDL_IMPORTER
|
||||
Loading…
Add table
Add a link
Reference in a new issue