Model loading and texturing
This commit is contained in:
120
thirdparty/assimp/code/MDL/MDLDefaultColorMap.h
vendored
Normal file
120
thirdparty/assimp/code/MDL/MDLDefaultColorMap.h
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, 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
|
||||
943
thirdparty/assimp/code/MDL/MDLFileData.h
vendored
Normal file
943
thirdparty/assimp/code/MDL/MDLFileData.h
vendored
Normal file
@@ -0,0 +1,943 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, 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;
|
||||
|
||||
//! Minimum vertex for all single frames
|
||||
Vertex min;
|
||||
|
||||
//! Maximum vertex for all single frames
|
||||
Vertex max;
|
||||
|
||||
//! Time for all single frames
|
||||
float *time;
|
||||
|
||||
//! 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
|
||||
1967
thirdparty/assimp/code/MDL/MDLLoader.cpp
vendored
Normal file
1967
thirdparty/assimp/code/MDL/MDLLoader.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
443
thirdparty/assimp/code/MDL/MDLLoader.h
vendored
Normal file
443
thirdparty/assimp/code/MDL/MDLLoader.h
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, 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
|
||||
*/
|
||||
|
||||
#ifndef AI_MDLLOADER_H_INCLUDED
|
||||
#define AI_MDLLOADER_H_INCLUDED
|
||||
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include "MDLFileData.h"
|
||||
#include "HMP/HalfLifeFileData.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 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();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** 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;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** 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);
|
||||
|
||||
protected:
|
||||
// -------------------------------------------------------------------
|
||||
/** Return importer meta information.
|
||||
* See #BaseImporter::GetInfo for the details
|
||||
*/
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Imports the given file into the given scene structure.
|
||||
* See BaseImporter::InternReadFile() for details
|
||||
*/
|
||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||
IOSystem* pIOHandler);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** 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 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. NULL 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* pIOHandler;
|
||||
|
||||
/** Output scene to be filled */
|
||||
aiScene* pScene;
|
||||
|
||||
/** Size of the input file in bytes */
|
||||
unsigned int iFileSize;
|
||||
};
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
#endif // AI_3DSIMPORTER_H_INC
|
||||
840
thirdparty/assimp/code/MDL/MDLMaterialLoader.cpp
vendored
Normal file
840
thirdparty/assimp/code/MDL/MDLMaterialLoader.cpp
vendored
Normal file
@@ -0,0 +1,840 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, 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
|
||||
|
||||
// internal headers
|
||||
#include "MDLLoader.h"
|
||||
#include "MDLDefaultColorMap.h"
|
||||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/texture.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/Defines.h>
|
||||
#include <assimp/qnan.h>
|
||||
|
||||
#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 = pIOHandler->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 = NULL;
|
||||
}
|
||||
*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(NULL != 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 = NULL;
|
||||
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;
|
||||
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Read a texture from a MDL4 file
|
||||
void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
|
||||
unsigned int iType,
|
||||
unsigned int* piSkip)
|
||||
{
|
||||
ai_assert(NULL != 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 = NULL;
|
||||
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) {
|
||||
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(NULL != 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 embedds 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 = NULL;
|
||||
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");
|
||||
}
|
||||
|
||||
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 = iLen;
|
||||
|
||||
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 ... posssible 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 szCurrent[5];
|
||||
ai_snprintf(szCurrent,5,"*%i",this->pScene->mNumTextures);
|
||||
|
||||
aiString szFile;
|
||||
const size_t iLen = strlen((const char*)szCurrent);
|
||||
::memcpy(szFile.data,(const char*)szCurrent,iLen+1);
|
||||
szFile.length = 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 = ::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 = NULL;
|
||||
|
||||
// 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(NULL != szCurrent);
|
||||
ai_assert(NULL != 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 = ::strlen(szFile.data);
|
||||
|
||||
pcMatOut->AddProperty(&szFile,AI_MATKEY_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_MDL_IMPORTER
|
||||
Reference in New Issue
Block a user