MDL

#15
I'm just working on importing/saving the files so that you will be able to take any model files you find/make with your favorite editor and convert those to Som files or vice versa. Below is the code I've written so far if that helps you understand what I'm up to.

[code=SomFileHelper.h]
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------

Copyright © 2006-2008, ASSIMP Development 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 Development 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 Definition of in-memory structures for the HL2 MDL file format
// ‎  and for the HalfLife text format (SMD)
//
// The specification has been taken from various sources on the internet.


#ifndef AI_SWORDOFMOONLIGHT_H_INC
#define AI_SWORDOFMOONLIGHT_H_INC

#include "./../include/Compiler/pushpack1.h"

namespace Assimp_x //! experimental
{
struct aiScene2;
}

namespace Assimp{

namespace MDL{

struct Header_SOM
{
//! 16 bytes
uint8_t unknown00; //! perhaps bitwise flags
uint8_t num_anims; //! reference frame animation
uint8_t num_stops; //! stop-motion like animation
uint8_t num_skins; //! texture images
uint8_t num_parts; //! one or more required
uint8_t unknown03; //! perhaps always one
int32_t off_anims; //! dword anim/stop/skin block offset
int16_t unknown04; //! perhaps always zero
int16_t add_anims; //! dword sizeof anims block
int16_t add_stops; //! dword sizeof stops block

//! this is the actual order of the data blocks in the file
int32_t offset(int fourcc, int pt=0)const
{
switch(fourcc)
{ ‎ 
case 'base': return 4+7*num_parts;

case 'face': return 4+AI_BE(parts[pt].off_faces);
case 'vert': return 4+AI_BE(parts[pt].off_verts);
case 'norm': return 4+AI_BE(parts[pt].off_norms);

case 'anim': return 4+AI_BE(off_anims);
case 'stop': return 4+AI_BE(off_anims)
‎  ‎  +AI_BE(add_anims);
case 'skin': return 4+AI_BE(off_anims)
‎  ‎  +AI_BE(add_anims)
+AI_BE(add_stops);

default: return 0x7FFFFFFF;
}
}

struct //! 28 bytes (these may actually be 16bit)
{
int32_t off_verts; //! dword offset to vertex block
int32_t num_verts; //!
int32_t off_norms; //! dword offset to normal block
int32_t num_norms; //!
int32_t off_faces; //! dword offset to face block
int32_t num_faces; //!
int32_t reserve00; //! probably always zero
}parts[1] PACK_STRUCT;

} PACK_STRUCT;

union Packet_SOM //! 4 bytes
{
struct{ uint16_t lo, hi; };

struct{ uint8_t s, t, u, v; };

} PACK_STRUCT;

struct Bitmap_SOM //Playstation TIM format
{
//! 8 bytes
uint8_t ‎  ‎  ‎  id; ‎  //! historically always 0x10
uint8_t version; ‎  //! historically always zero
int16_t ‎  ‎  ‎  :16; //! reserved
uint8_t ‎  pmode:3; ‎  //! data block bits per pixel
uint8_t ‎  ‎  cf:1; ‎  //! CLUT (color lookup table) present
uint8_t ‎  ‎  ‎  :4; ‎  //! reserved
‎  ‎  uint8_t ‎  ‎  ‎  :8; ‎  //! reserved

typedef struct
{
//! 12 bytes
uint32_t bnum; //! sizeof block in bytes
uint16_t dx; ‎  //! should not be non-zero
uint16_t dy; ‎  //! should not be non-zero
uint16_t w; ‎  ‎  //! width in 16bit units
uint16_t h; ‎  ‎  //! height

/* Data/CLUT entries
* depends on the following settings for pmode
* 0x00: 4bits per texel lookup into CLUT (up to 16x16)
* 0x01: 8bits per texel lookup into CLUT (up to 256x256)
* 0x02: 5bits per rgb plus highest order transparency mode bit
* 0x03: 2/3rds of a 24-bit rgb triplet (3 entries per two texels)
* 0x04: mixed mode (interpretation requires external info)
*/
union
{
uint16_t data[1];
uint16_t clut[1];
};

}BLOCK PACK_STRUCT;

const BLOCK *data_block()const
{
const BLOCK *out = clut_block();

if(!out) return (const BLOCK*)(this+1);

return (const BLOCK*)((const char*)out+AI_BE(out->bnum));
}
const BLOCK *clut_block()const
{
return (const BLOCK*)(cf?this+1:NULL);
}

} PACK_STRUCT;

} // end namespace MDL

class SomFileHelper
{
public:

bool detect(const MDL::Header_SOM*)const;

const int32_t *offset(const MDL::Header_SOM *in, int fourcc, int pt=0)const;

bool unpack(const MDL::Header_SOM*,
const MDL::Packet_SOM**, int fourcc, int pt=0)const;
bool bitmap(const MDL::Header_SOM*,
const MDL::Bitmap_SOM**)const;

template<typename t>
const t *offset(const MDL::Header_SOM *in, const t**out, int cc, int pt=0)const
{
const t *off = (const t*)offset(in,cc,pt); if(out) *out = off; return off;
}
template<typename t>
bool unpack(const MDL::Header_SOM *in, const t **p, int fourcc, int pt=0)const
{
return unpack(in,(const MDL::Packet_SOM**)p,fourcc);
} ‎ 
template<typename t>
bool bitmap(const MDL::Header_SOM *in, const t **p)const
{
return bitmap(in,(const MDL::Bitmap_SOM**)p);
} ‎ 

void sizecheck(const void *szPos)const
{
if(!szPos||(const unsigned char*)szPos>pcEof)
{
throw new ImportErrorException("Invalid Sword of Moonlight MDL file. The file is too small or contains invalid data");
}
}

SomFileHelper(const void *eof, aiScene *out=0);

~SomFileHelper(); //flushes pAssimp


private:

mutable aiScene *pAssimp;

mutable Assimp_x::aiScene2 *pAssimp2;

const void *pcEof;
};

} // end namespace Assimp

#include "./../include/Compiler/poppack1.h"

#endif // ! AI_SWORDOFMOONLIGHT_H_INC
[/code]
Reply



Messages In This Thread
MDL - by HolyDiver - 2010-04-02, 04:35 PM
Re: MDL - by HolyDiver - 2010-04-02, 07:17 PM
Re: MDL - by HolyDiver - 2010-04-05, 04:05 AM
Re: MDL - by Madison Lastrega - 2010-04-06, 06:28 AM
Re: MDL - by Madison Lastrega - 2010-04-06, 07:19 AM
Re: MDL - by HolyDiver - 2010-04-06, 06:56 PM
Re: MDL - by HolyDiver - 2010-04-06, 11:27 PM
Re: MDL - by Madison Lastrega - 2010-04-07, 05:17 PM
Re: MDL - by HolyDiver - 2010-04-07, 06:23 PM
Re: MDL - by HolyDiver - 2010-04-08, 03:18 AM
Re: MDL - by HolyDiver - 2010-04-08, 10:19 PM
Re: MDL - by Madison Lastrega - 2010-04-10, 05:15 AM
Re: MDL - by HolyDiver - 2010-04-10, 05:55 AM
Re: MDL - by Madison Lastrega - 2010-04-10, 07:22 PM
Re: MDL - by HolyDiver - 2010-04-10, 09:22 PM
Re: MDL - by HolyDiver - 2010-04-10, 09:24 PM
Re: MDL - by HolyDiver - 2010-04-20, 10:48 AM
Re: MDL - by HolyDiver - 2010-04-21, 01:45 PM
Re: MDL - by HolyDiver - 2010-05-03, 01:06 AM
Re: MDL - by HolyDiver - 2010-05-03, 07:59 PM
Re: MDL - by HolyDiver - 2010-05-04, 12:16 AM
Re: MDL - by HolyDiver - 2010-05-07, 07:27 AM
Re: MDL - by HolyDiver - 2010-05-10, 11:29 AM



Users browsing this thread:
8 Guest(s)