Commit c2ec44c7 authored by hybrid's avatar hybrid

Minor cleanup.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@761 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 64ea350e
// Copyright (C) 2002-2007 Nikolaus Gebhardt // Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
// //
// This file was originally written by ZDimitor. // This file was originally written by ZDimitor.
//---------------------------------------------------------------------- //----------------------------------------------------------------------
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
#define __C_MY3D_HELPER_H_INCLUDED__ #define __C_MY3D_HELPER_H_INCLUDED__
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
namespace irr namespace irr
{ {
namespace core namespace core
{ {
//-----------------RLE stuff----------------------------------------- //-----------------RLE stuff-----------------------------------------
...@@ -41,7 +41,7 @@ void flush_outbuf( ...@@ -41,7 +41,7 @@ void flush_outbuf(
unsigned char *out_buf, int out_buf_size unsigned char *out_buf, int out_buf_size
); );
unsigned long get_byte ( unsigned long get_byte (
unsigned char *ch, unsigned char *ch,
unsigned char *in_buf, int in_buf_size, unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size unsigned char *out_buf, int out_buf_size
); );
...@@ -60,10 +60,10 @@ int nDecodedBytes=0; ...@@ -60,10 +60,10 @@ int nDecodedBytes=0;
int nCodedBytes=0; int nCodedBytes=0;
// number of read bytes // number of read bytes
int nReadedBytes=0; int nReadedBytes=0;
// table used to look for sequences of repeating bytes // table used to look for sequences of repeating bytes
unsigned char tmpbuf[4]; // we use subscripts 1 - 3 unsigned char tmpbuf[4]; // we use subscripts 1 - 3
int tmpbuf_cnt; int tmpbuf_cnt;
// output buffer for non-compressed output data // output buffer for non-compressed output data
unsigned char outbuf[128]; unsigned char outbuf[128];
int outbuf_cnt; int outbuf_cnt;
...@@ -73,7 +73,7 @@ int rle_encode ( ...@@ -73,7 +73,7 @@ int rle_encode (
unsigned char *in_buf, int in_buf_size, unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size unsigned char *out_buf, int out_buf_size
) )
{ {
unsigned long ret_code; unsigned long ret_code;
unsigned char ch; unsigned char ch;
...@@ -81,31 +81,31 @@ int rle_encode ( ...@@ -81,31 +81,31 @@ int rle_encode (
nCodedBytes=0; nCodedBytes=0;
nReadedBytes=0; nReadedBytes=0;
tmpbuf_cnt = 0; // no. of char's in tmpbuf tmpbuf_cnt = 0; // no. of char's in tmpbuf
outbuf_cnt = 0; // no. of char's in outbuf outbuf_cnt = 0; // no. of char's in outbuf
while (1) while (1)
{ {
if (get_byte(&ch, in_buf, in_buf_size, if (get_byte(&ch, in_buf, in_buf_size,
out_buf, out_buf_size) == (int)EOD) // read next byte into ch out_buf, out_buf_size) == (int)EOD) // read next byte into ch
break; break;
tmpbuf[++tmpbuf_cnt] = (unsigned char) ch; tmpbuf[++tmpbuf_cnt] = (unsigned char) ch;
if (tmpbuf_cnt == 3) if (tmpbuf_cnt == 3)
{ {
// see if all 3 match each other // see if all 3 match each other
if ((tmpbuf[1] == tmpbuf[2]) && (tmpbuf[2] == tmpbuf[3])) if ((tmpbuf[1] == tmpbuf[2]) && (tmpbuf[2] == tmpbuf[3]))
{ {
// they do - add compression // they do - add compression
// this will process all bytes in input file until // this will process all bytes in input file until
// a non-match occurs, or 128 bytes are processed, // a non-match occurs, or 128 bytes are processed,
// or we find eod */ // or we find eod */
ret_code = process_comp(in_buf, in_buf_size, out_buf, out_buf_size); ret_code = process_comp(in_buf, in_buf_size, out_buf, out_buf_size);
if (ret_code == (int)EOD_FOUND) if (ret_code == (int)EOD_FOUND)
break; // stop compressing break; // stop compressing
if (ret_code == (int)NON_MATCH) if (ret_code == (int)NON_MATCH)
tmpbuf_cnt=1; /* save the char that didn't match */ tmpbuf_cnt=1; /* save the char that didn't match */
else else
// we just compressed the max. of 128 bytes // we just compressed the max. of 128 bytes
tmpbuf_cnt=0; /* start over for next chunk */ tmpbuf_cnt=0; /* start over for next chunk */
} }
else else
...@@ -114,7 +114,7 @@ int rle_encode ( ...@@ -114,7 +114,7 @@ int rle_encode (
// others, so just send it out as uncompressed. */ // others, so just send it out as uncompressed. */
process_uncomp(tmpbuf[1], out_buf, out_buf_size); process_uncomp(tmpbuf[1], out_buf, out_buf_size);
// see if the last 2 bytes in the buffer match // see if the last 2 bytes in the buffer match
if (tmpbuf[2] == tmpbuf[3]) if (tmpbuf[2] == tmpbuf[3])
{ {
// move byte 3 to position 1 and pretend we just // move byte 3 to position 1 and pretend we just
...@@ -128,14 +128,14 @@ int rle_encode ( ...@@ -128,14 +128,14 @@ int rle_encode (
// send byte 2 and keep byte 3 - it may match the // send byte 2 and keep byte 3 - it may match the
// next byte. Move byte 3 to position 1 and set // next byte. Move byte 3 to position 1 and set
// count to 1. Note that the first byte was // count to 1. Note that the first byte was
// already sent to output // already sent to output
process_uncomp(tmpbuf[2], out_buf, out_buf_size); process_uncomp(tmpbuf[2], out_buf, out_buf_size);
tmpbuf[1]=tmpbuf[3]; tmpbuf[1]=tmpbuf[3];
tmpbuf_cnt=1; tmpbuf_cnt=1;
} }
} }
} }
} // end while } // end while
flush_outbuf(out_buf, out_buf_size); flush_outbuf(out_buf, out_buf_size);
return nCodedBytes; return nCodedBytes;
...@@ -156,22 +156,21 @@ unsigned long process_comp( ...@@ -156,22 +156,21 @@ unsigned long process_comp(
unsigned char *buf, int buf_size, unsigned char *buf, int buf_size,
unsigned char *out_buf, int out_buf_size) unsigned char *out_buf, int out_buf_size)
{ {
// we start out with 3 repeating bytes // we start out with 3 repeating bytes
register int len = 3; register int len = 3;
unsigned char ch; unsigned char ch;
// we're starting a repeating chunk - end the non-repeaters // we're starting a repeating chunk - end the non-repeaters
flush_outbuf(out_buf, out_buf_size); flush_outbuf(out_buf, out_buf_size);
while (get_byte(&ch, buf, buf_size, out_buf, out_buf_size) != (int)EOD) while (get_byte(&ch, buf, buf_size, out_buf, out_buf_size) != (int)EOD)
{ {
if (ch != tmpbuf[1]) if (ch != tmpbuf[1])
{ {
// send no. of repeated bytes to be encoded // send no. of repeated bytes to be encoded
put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size);
// send the byte's value being repeated // send the byte's value being repeated
put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size);
/* save the non-matching character just read */ /* save the non-matching character just read */
tmpbuf[1]=(unsigned char) ch; tmpbuf[1]=(unsigned char) ch;
...@@ -181,18 +180,18 @@ unsigned long process_comp( ...@@ -181,18 +180,18 @@ unsigned long process_comp(
len++; len++;
if (len == 128) if (len == 128)
{ {
// send no. of repeated bytes to be encoded // send no. of repeated bytes to be encoded
put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size);
// send the byte's value being repeated // send the byte's value being repeated
put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size);
return LIMIT; return LIMIT;
} }
} // end while } // end while
// if flow comes here, we just read an EOD // if flow comes here, we just read an EOD
// send no. of repeated bytes to be encoded // send no. of repeated bytes to be encoded
put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size);
// send the byte's value being repeated // send the byte's value being repeated
put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size);
return EOD_FOUND; return EOD_FOUND;
} }
...@@ -213,7 +212,7 @@ void process_uncomp( ...@@ -213,7 +212,7 @@ void process_uncomp(
} }
//----------------------------------------------------------- //-----------------------------------------------------------
// This flushes any non-compressed data not yet sent. // This flushes any non-compressed data not yet sent.
// On exit, outbuf_cnt will equal zero. // On exit, outbuf_cnt will equal zero.
//----------------------------------------------------------- //-----------------------------------------------------------
void flush_outbuf(unsigned char *out_buf, int out_buf_size) void flush_outbuf(unsigned char *out_buf, int out_buf_size)
{ {
...@@ -222,7 +221,7 @@ void flush_outbuf(unsigned char *out_buf, int out_buf_size) ...@@ -222,7 +221,7 @@ void flush_outbuf(unsigned char *out_buf, int out_buf_size)
if(!outbuf_cnt) if(!outbuf_cnt)
return; // nothing to do */ return; // nothing to do */
// send no. of unencoded bytes to be sent // send no. of unencoded bytes to be sent
put_byte((unsigned char)(outbuf_cnt - 1), out_buf, out_buf_size); put_byte((unsigned char)(outbuf_cnt - 1), out_buf, out_buf_size);
for ( ; outbuf_cnt; outbuf_cnt--) for ( ; outbuf_cnt; outbuf_cnt--)
...@@ -230,7 +229,7 @@ void flush_outbuf(unsigned char *out_buf, int out_buf_size) ...@@ -230,7 +229,7 @@ void flush_outbuf(unsigned char *out_buf, int out_buf_size)
} }
//--------------------------------------------------- //---------------------------------------------------
void put_byte(unsigned char ch, unsigned char *out_buf, int out_buf_size) void put_byte(unsigned char ch, unsigned char *out_buf, int out_buf_size)
{ {
if (nCodedBytes<=(out_buf_size-1)) if (nCodedBytes<=(out_buf_size-1))
{ out_buf[nCodedBytes++]=ch; { out_buf[nCodedBytes++]=ch;
out_buf[nCodedBytes]=0; out_buf[nCodedBytes]=0;
...@@ -238,17 +237,17 @@ void put_byte(unsigned char ch, unsigned char *out_buf, int out_buf_size) ...@@ -238,17 +237,17 @@ void put_byte(unsigned char ch, unsigned char *out_buf, int out_buf_size)
} }
//--------------------------------------------------- //---------------------------------------------------
// This reads the next byte into ch. It returns EOD // This reads the next byte into ch. It returns EOD
// at end-of-data // at end-of-data
//--------------------------------------------------- //---------------------------------------------------
unsigned long get_byte( unsigned long get_byte(
unsigned char *ch, unsigned char *ch,
unsigned char *in_buf, int in_buf_size, unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size unsigned char *out_buf, int out_buf_size
) )
{ {
if (nReadedBytes>=in_buf_size) if (nReadedBytes>=in_buf_size)
{ {
// there are either 0, 1, or 2 char's to write before we quit // there are either 0, 1, or 2 char's to write before we quit
if (tmpbuf_cnt == 1) if (tmpbuf_cnt == 1)
process_uncomp(tmpbuf[1], out_buf, out_buf_size); process_uncomp(tmpbuf[1], out_buf, out_buf_size);
else else
...@@ -263,7 +262,7 @@ unsigned long get_byte( ...@@ -263,7 +262,7 @@ unsigned long get_byte(
return EOD; return EOD;
} }
(*ch) = (unsigned char)in_buf[nReadedBytes++]; (*ch) = (unsigned char)in_buf[nReadedBytes++];
return 0; return 0;
...@@ -289,27 +288,27 @@ int rle_decode ( ...@@ -289,27 +288,27 @@ int rle_decode (
if (ch > 127) if (ch > 127)
{ {
i = ch - 127; // i is the number of repetitions i = ch - 127; // i is the number of repetitions
// get the byte to be repeated // get the byte to be repeated
if (nReadedBytes>=in_buf_size) if (nReadedBytes>=in_buf_size)
break; break;
else else
ch=in_buf[nReadedBytes]; ch=in_buf[nReadedBytes];
nReadedBytes++; nReadedBytes++;
// uncompress a chunk // uncompress a chunk
for ( ; i ; i--) for ( ; i ; i--)
{ {
if (nDecodedBytes<out_buf_size) if (nDecodedBytes<out_buf_size)
out_buf[nDecodedBytes] = ch; out_buf[nDecodedBytes] = ch;
nDecodedBytes++; nDecodedBytes++;
} }
} }
else else
{ {
// copy out some uncompressed bytes // copy out some uncompressed bytes
i = ch + 1; // i is the no. of bytes i = ch + 1; // i is the no. of bytes
// uncompress a chunk // uncompress a chunk
for ( ; i ; i--) for ( ; i ; i--)
{ {
if (nReadedBytes>=in_buf_size) if (nReadedBytes>=in_buf_size)
...@@ -318,12 +317,12 @@ int rle_decode ( ...@@ -318,12 +317,12 @@ int rle_decode (
ch=in_buf[nReadedBytes]; ch=in_buf[nReadedBytes];
nReadedBytes++; nReadedBytes++;
if (nDecodedBytes<out_buf_size) if (nDecodedBytes<out_buf_size)
out_buf[nDecodedBytes] = ch; out_buf[nDecodedBytes] = ch;
nDecodedBytes++; nDecodedBytes++;
} }
} }
} // end while } // end while
return nDecodedBytes; return nDecodedBytes;
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "SMeshBuffer.h" #include "SMeshBuffer.h"
#include "IReadFile.h" #include "IReadFile.h"
#include "IAttributes.h" #include "IAttributes.h"
#include "CImage.h"
#include "CColorConverter.h"
#include "CMY3DHelper.h" #include "CMY3DHelper.h"
#include "os.h" #include "os.h"
...@@ -55,7 +57,7 @@ CMY3DMeshFileLoader::~CMY3DMeshFileLoader() ...@@ -55,7 +57,7 @@ CMY3DMeshFileLoader::~CMY3DMeshFileLoader()
bool CMY3DMeshFileLoader::isALoadableFileExtension(const c8* filename) bool CMY3DMeshFileLoader::isALoadableFileExtension(const c8* filename)
{ {
return strstr(filename, ".my3d") != 0; return strstr(filename, ".my3d") != 0;
} }
...@@ -117,13 +119,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -117,13 +119,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
file->read(&id, sizeof(id)); file->read(&id, sizeof(id));
s32 texCount=0, ligCount=0, matCount=0; s32 texCount=0, matCount=0;
c8 name[256]; c8 name[256];
for (s32 m=0; m<sceneHeader.MaterialCount; ++m) for (s32 m=0; m<sceneHeader.MaterialCount; ++m)
{ {
if (id!=MY_MAT_HEADER_ID) if (id!=MY_MAT_HEADER_ID)
{ {
os::Printer::log("Cannot find MY_MAT_HEADER_ID, loading failed!", ELL_ERROR); os::Printer::log("Cannot find MY_MAT_HEADER_ID, loading failed!", ELL_ERROR);
return 0; return 0;
} }
...@@ -168,8 +170,8 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -168,8 +170,8 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24) if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
pixFormatStr = "24bit,"; pixFormatStr = "24bit,";
else else
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_16) if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_16)
pixFormatStr = "16bit,"; pixFormatStr = "16bit,";
else else
{ {
msg="Unknown format of image data ("; msg="Unknown format of image data (";
...@@ -179,120 +181,117 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -179,120 +181,117 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
return 0; return 0;
} }
if (texDataHeader.ComprMode != MY_TEXDATA_COMPR_NONE_ID && if (texDataHeader.ComprMode != MY_TEXDATA_COMPR_NONE_ID &&
texDataHeader.ComprMode != MY_TEXDATA_COMPR_RLE_ID && texDataHeader.ComprMode != MY_TEXDATA_COMPR_RLE_ID &&
texDataHeader.ComprMode != MY_TEXDATA_COMPR_SIMPLE_ID ) texDataHeader.ComprMode != MY_TEXDATA_COMPR_SIMPLE_ID )
{ {
os::Printer::log("Unknown method of compression image data, loading failed!", ELL_ERROR); os::Printer::log("Unknown method of compression image data, loading failed!", ELL_ERROR);
return 0; return 0;
} }
u32 num_pixels = texDataHeader.Width*texDataHeader.Height; u32 num_pixels = texDataHeader.Width*texDataHeader.Height;
void* data = 0; void* data = 0;
if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_NONE_ID) if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_NONE_ID)
{
// none compressed image data
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
{ {
// none compressed image data data = (void*) new SMyPixelColor24[num_pixels];
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24) file->read(data, sizeof(SMyPixelColor24)*num_pixels);
{
data = (void*) new SMyPixelColor24[num_pixels];
file->read(data, sizeof(SMyPixelColor24)*num_pixels);
}
else
{
data = (void*) new SMyPixelColor16[num_pixels];
file->read(data, sizeof(SMyPixelColor16)*num_pixels);
}
} }
else else
if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_RLE_ID) {
{ data = (void*) new SMyPixelColor16[num_pixels];
// read RLE header identificator file->read(data, sizeof(SMyPixelColor16)*num_pixels);
file->read(&id, sizeof(id)); }
if (id!=MY_TEXDATA_RLE_HEADER_ID) }
{ else
os::Printer::log("Can not find MY_TEXDATA_RLE_HEADER_ID, loading failed!", ELL_ERROR); if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_RLE_ID)
return 0; {
} // read RLE header identificator
file->read(&id, sizeof(id));
// read RLE header if (id!=MY_TEXDATA_RLE_HEADER_ID)
SMyRLEHeader rleHeader; {
file->read(&rleHeader, sizeof(SMyRLEHeader)); os::Printer::log("Can not find MY_TEXDATA_RLE_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
//allocate memory for input and output buffers // read RLE header
void *input_buffer = (void*) new unsigned char[rleHeader.nEncodedBytes]; SMyRLEHeader rleHeader;
void *output_buffer = (void*) new unsigned char[rleHeader.nDecodedBytes]; file->read(&rleHeader, sizeof(SMyRLEHeader));
// read encoded data //allocate memory for input and output buffers
file->read(input_buffer, rleHeader.nEncodedBytes); void *input_buffer = (void*) new unsigned char[rleHeader.nEncodedBytes];
void *output_buffer = (void*) new unsigned char[rleHeader.nDecodedBytes];
// decode data // read encoded data
data = 0;//(void*) new unsigned char[rleHeader.nDecodedBytes]; file->read(input_buffer, rleHeader.nEncodedBytes);
s32 decodedBytes = core::rle_decode(
(unsigned char*)input_buffer, rleHeader.nEncodedBytes,
(unsigned char*)output_buffer, rleHeader.nDecodedBytes);
if (decodedBytes!=(s32)rleHeader.nDecodedBytes) // decode data
{ data = 0;//(void*) new unsigned char[rleHeader.nDecodedBytes];
os::Printer::log("Error extracting data from RLE compression, loading failed!", ELL_ERROR); s32 decodedBytes = core::rle_decode(
return 0; (unsigned char*)input_buffer, rleHeader.nEncodedBytes,
} (unsigned char*)output_buffer, rleHeader.nDecodedBytes);
// free input buffer if (decodedBytes!=(s32)rleHeader.nDecodedBytes)
delete [] (unsigned char*)input_buffer; {
os::Printer::log("Error extracting data from RLE compression, loading failed!", ELL_ERROR);
return 0;
}
// here decoded data // free input buffer
data = output_buffer; delete [] (unsigned char*)input_buffer;
} // here decoded data
data = output_buffer;
}
else if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_SIMPLE_ID) else if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_SIMPLE_ID)
{ {
// simple compressed image data // simple compressed image data
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24) if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
data = (void*) new SMyPixelColor24[num_pixels]; data = (void*) new SMyPixelColor24[num_pixels];
else else
data = (void*) new SMyPixelColor16[num_pixels]; data = (void*) new SMyPixelColor16[num_pixels];
u32 nReadedPixels =0, nToRead =0; u32 nReadedPixels=0, nToRead=0;
while (true) while (true)
{ {
file->read(&nToRead, sizeof(nToRead)); file->read(&nToRead, sizeof(nToRead));
if ((nReadedPixels+nToRead) > num_pixels) if ((nReadedPixels+nToRead) > num_pixels)
break; break;
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24) if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
{ {
SMyPixelColor24 col24; SMyPixelColor24 col24;
file->read(&col24, sizeof(SMyPixelColor24)); file->read(&col24, sizeof(SMyPixelColor24));
for (u32 p=0; p<nToRead; p++) for (u32 p=0; p<nToRead; p++)
{
((SMyPixelColor24*)data)[nReadedPixels+p] =
SMyPixelColor24(col24.r, col24.g, col24.b);
}
}
else
{ {
((SMyPixelColor24*)data)[nReadedPixels+p] = SMyPixelColor16 col16;
SMyPixelColor24(col24.r, col24.g, col24.b); file->read(&col16, sizeof(SMyPixelColor16));
for (u32 p=0; p<nToRead; p++)
((SMyPixelColor16*)data)[nReadedPixels+p].argb = col16.argb;
} }
}
else
{
SMyPixelColor16 col16;
file->read(&col16, sizeof(SMyPixelColor16));
for (u32 p=0; p<nToRead; p++)
{
((SMyPixelColor16*)data)[nReadedPixels+p].argb = col16.argb;
}
}
nReadedPixels+=nToRead; nReadedPixels+=nToRead;
if (nReadedPixels >= num_pixels) if (nReadedPixels >= num_pixels)
break; break;
} }
if (nReadedPixels != num_pixels) if (nReadedPixels != num_pixels)
{ {
os::Printer::log("Image data seems to be corrupted, loading failed!", ELL_ERROR); os::Printer::log("Image data seems to be corrupted, loading failed!", ELL_ERROR);
return 0; return 0;
} }
} }
//! Creates a software image from a byte array. //! Creates a software image from a byte array.
...@@ -300,7 +299,7 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -300,7 +299,7 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24) if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
{ {
// 24 bit lightmap format // 24 bit lightmap format
light_img = Driver->createImageFromData( light_img = Driver->createImageFromData(
video::ECF_R8G8B8, video::ECF_R8G8B8,
core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height), core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height),
...@@ -308,83 +307,72 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -308,83 +307,72 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
} }
else else
{ {
// 16 bit lightmap format // 16 bit lightmap format
light_img = Driver->createImageFromData( light_img = Driver->createImageFromData(
video::ECF_A1R5G5B5, video::ECF_A1R5G5B5,
core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height), core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height),
data, true); data, true);
} }
bool oldMipMapState = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); const bool oldMipMapState = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
me.Texture2 = Driver->addTexture(LightMapName, light_img); me.Texture2 = Driver->addTexture(LightMapName, light_img);
ligCount++; Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
light_img->drop(); light_img->drop();
GetLightMap = true; GetLightMap = true;
} }
core::stringc Name = name; const core::stringc Name = name;
int pos2 = Name.findLast('.'); const s32 pos2 = Name.findLast('.');
core::stringc LightingMapStr = "LightingMap"; const core::stringc LightingMapStr = "LightingMap";
int ls = LightingMapStr.size(); const u32 ls = LightingMapStr.size();
core::stringc sub = Name.subString(core::max_(0, (pos2 - ls)), ls); const bool isSubString = (LightingMapStr == Name.subString(core::max_(0u, (pos2 - ls)), ls));
if ((sub == LightingMapStr || (Name[pos2-1]=='m' && if ((isSubString || (Name[pos2-1]=='m' &&
Name[pos2-2]=='l' && Name[pos2-3]=='_')) && Name[pos2-2]=='l' && Name[pos2-3]=='_')) &&
!GetLightMap) !GetLightMap)
{ {
bool oldMipMapState = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); const bool oldMipMapState = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
me.Texture2FileName = texturePath.size() ? texturePath : filepath; me.Texture2FileName = texturePath.size() ? texturePath : filepath;
me.Texture2FileName.append("Lightmaps/"); me.Texture2FileName.append("Lightmaps/");
me.Texture2FileName.append(Name); me.Texture2FileName.append(Name);
if (Name.size()>0) if (Name.size()>0)
{
me.Texture2 = Driver->getTexture(me.Texture2FileName.c_str()); me.Texture2 = Driver->getTexture(me.Texture2FileName.c_str());
ligCount++;
}
GetLightMap = true;
me.MaterialType = video::EMT_LIGHTMAP_M2; me.MaterialType = video::EMT_LIGHTMAP_M2;
GetLightMap = true;
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState); Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
} }
else else
if (!GetLightMap&&GetMainMap) if (!GetLightMap&&GetMainMap)
{ {
me.Texture2FileName = texturePath.size() ? texturePath : filepath; me.Texture2FileName = texturePath.size() ? texturePath : filepath;
me.Texture2FileName.append(Name); me.Texture2FileName.append(Name);
if (Name.size()) if (Name.size())
{
me.Texture2 = Driver->getTexture(me.Texture2FileName.c_str()); me.Texture2 = Driver->getTexture(me.Texture2FileName.c_str());
ligCount++;
}
me.MaterialType = video::EMT_REFLECTION_2_LAYER; me.MaterialType = video::EMT_REFLECTION_2_LAYER;
} }
else else
if (!GetMainMap && !GetLightMap ) if (!GetMainMap && !GetLightMap )
{ {
me.Texture1FileName = filepath; me.Texture1FileName = filepath;
me.Texture1FileName.append(Name); me.Texture1FileName.append(Name);
if (Name.size()) if (Name.size())
{ {
me.Texture1 = Driver->getTexture(me.Texture1FileName.c_str()); me.Texture1 = Driver->getTexture(me.Texture1FileName.c_str());
texCount++; texCount++;
} }
GetMainMap = true; GetMainMap = true;
me.MaterialType = video::EMT_SOLID; me.MaterialType = video::EMT_SOLID;
} }
else else
if (GetLightMap) if (GetLightMap)
{ {
me.MaterialType = video::EMT_LIGHTMAP_M2; me.MaterialType = video::EMT_LIGHTMAP_M2;
...@@ -393,7 +381,7 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -393,7 +381,7 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
file->read(&id, sizeof(id)); file->read(&id, sizeof(id));
} }
// override materials types from they names // override material types based on their names
if (!strncmp(me.Header.Name, "AlphaChannel-", 13)) if (!strncmp(me.Header.Name, "AlphaChannel-", 13))
me.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; me.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
else else
...@@ -405,10 +393,10 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -405,10 +393,10 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
// loading meshes // loading meshes
if (Mesh) if (Mesh)
Mesh->drop(); Mesh->drop();
Mesh = new SMesh(); Mesh = new SMesh();
if (id!=MY_MESH_LIST_ID) if (id!=MY_MESH_LIST_ID)
{ {
...@@ -417,13 +405,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -417,13 +405,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
} }
file->read(&id, sizeof(id)); file->read(&id, sizeof(id));
for (s32 mesh_id=0; mesh_id<sceneHeader.MeshCount; mesh_id++) for (s32 mesh_id=0; mesh_id<sceneHeader.MeshCount; mesh_id++)
{ {
// Warning!!! In some cases MY3D exporter uncorrectly calculates // Warning!!! In some cases MY3D exporter uncorrectly calculates
// MeshCount (it's a problem, has to be solved) thats why // MeshCount (it's a problem, has to be solved) thats why
// i added this code line // i added this code line
if (id!=MY_MESH_HEADER_ID) if (id!=MY_MESH_HEADER_ID)
break; break;
if (id!=MY_MESH_HEADER_ID) if (id!=MY_MESH_HEADER_ID)
...@@ -478,72 +466,74 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -478,72 +466,74 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
// reading texture coords // reading texture coords
file->read(&id, sizeof(id)); file->read(&id, sizeof(id));
if (id!=MY_TVERTS_ID) if (id!=MY_TVERTS_ID)
{ msg="Can not find MY_TVERTS_ID ("; {
msg.append(tex); msg="Can not find MY_TVERTS_ID (";
msg.append("texture channel), loading failed!"); msg.append(tex);
os::Printer::log(msg.c_str(), ELL_ERROR); msg.append("texture channel), loading failed!");
return 0; os::Printer::log(msg.c_str(), ELL_ERROR);
} return 0;
}
file->read(&tVertsNum, sizeof(tVertsNum)); file->read(&tVertsNum, sizeof(tVertsNum));
if (tex==0) if (tex==0)
{ {
// 1st texture channel // 1st texture channel
TVertex1.reallocate(tVertsNum); TVertex1.reallocate(tVertsNum);
file->read(TVertex1.pointer(), sizeof(SMyTVertex)*tVertsNum); file->read(TVertex1.pointer(), sizeof(SMyTVertex)*tVertsNum);
TVertex1.set_used(tVertsNum); TVertex1.set_used(tVertsNum);
} }
else else
if (tex==1) if (tex==1)
{ {
// 2nd texture channel // 2nd texture channel
TVertex2.reallocate(tVertsNum); TVertex2.reallocate(tVertsNum);
file->read(TVertex2.pointer(), sizeof(SMyTVertex)*tVertsNum); file->read(TVertex2.pointer(), sizeof(SMyTVertex)*tVertsNum);
TVertex2.set_used(tVertsNum); TVertex2.set_used(tVertsNum);
} }
else else
{ {
// skip other texture channels // skip other texture channels
u32 pos = file->getPos(); u32 pos = file->getPos();
file->seek(pos+sizeof(SMyTVertex)*tVertsNum); file->seek(pos+sizeof(SMyTVertex)*tVertsNum);
} }
// reading texture faces // reading texture faces
file->read(&id, sizeof(id)); file->read(&id, sizeof(id));
if (id!=MY_TFACES_ID) if (id!=MY_TFACES_ID)
{ msg="Can not find MY_TFACES_ID ("; {
msg.append(tex); msg="Can not find MY_TFACES_ID (";
msg.append("texture channel), loading failed!"); msg.append(tex);
os::Printer::log(msg.c_str(), ELL_ERROR); msg.append("texture channel), loading failed!");
return 0; os::Printer::log(msg.c_str(), ELL_ERROR);
} return 0;
}
file->read(&tFacesNum, sizeof(tFacesNum)); file->read(&tFacesNum, sizeof(tFacesNum));
if (tex==0) if (tex==0)
{ {
// 1st texture channel // 1st texture channel
TFace1.reallocate(tFacesNum); TFace1.reallocate(tFacesNum);
file->read(TFace1.pointer(), sizeof(SMyFace)*tFacesNum); file->read(TFace1.pointer(), sizeof(SMyFace)*tFacesNum);
TFace1.set_used(tFacesNum); TFace1.set_used(tFacesNum);
} }
else if (tex==1) else if (tex==1)
{ {
// 2nd texture channel // 2nd texture channel
TFace2.reallocate(tFacesNum); TFace2.reallocate(tFacesNum);
file->read(TFace2.pointer(), sizeof(SMyFace)*tFacesNum); file->read(TFace2.pointer(), sizeof(SMyFace)*tFacesNum);
TFace2.set_used(tFacesNum); TFace2.set_used(tFacesNum);
} }
else else
{ {
// skip other texture channels // skip other texture channels
u32 pos = file->getPos(); u32 pos = file->getPos();
file->seek(pos+sizeof(SMyFace)*tFacesNum); file->seek(pos+sizeof(SMyFace)*tFacesNum);
} }
} }
// trying to find material // trying to find material
...@@ -609,15 +599,15 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -609,15 +599,15 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
); );
} }
else else
{ {
buffer->Material.Textures[0] = 0; buffer->Material.Textures[0] = 0;
buffer->Material.Textures[1] = 0; buffer->Material.Textures[1] = 0;
buffer->Material.AmbientColor = video::SColor(255, 255, 255, 255); buffer->Material.AmbientColor = video::SColor(255, 255, 255, 255);
buffer->Material.DiffuseColor = video::SColor(255, 255, 255, 255); buffer->Material.DiffuseColor = video::SColor(255, 255, 255, 255);
buffer->Material.EmissiveColor = video::SColor(0, 0, 0, 0); buffer->Material.EmissiveColor = video::SColor(0, 0, 0, 0);
buffer->Material.SpecularColor = video::SColor(0, 0, 0, 0); buffer->Material.SpecularColor = video::SColor(0, 0, 0, 0);
} }
if (matEnt && matEnt->Header.Transparency!=0) if (matEnt && matEnt->Header.Transparency!=0)
{ {
...@@ -633,14 +623,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -633,14 +623,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
buffer->Material.Lighting = false; buffer->Material.Lighting = false;
buffer->Material.BackfaceCulling = false; buffer->Material.BackfaceCulling = false;
} }
} }
else if ( else if (
!buffer->Material.Textures[1] && !buffer->Material.Textures[1] &&
buffer->Material.MaterialType != video::EMT_TRANSPARENT_ALPHA_CHANNEL && buffer->Material.MaterialType != video::EMT_TRANSPARENT_ALPHA_CHANNEL &&
buffer->Material.MaterialType != video::EMT_SPHERE_MAP buffer->Material.MaterialType != video::EMT_SPHERE_MAP)
) {
{ buffer->Material.MaterialType = video::EMT_SOLID;
buffer->Material.MaterialType = video::EMT_SOLID;
buffer->Material.Lighting = true; buffer->Material.Lighting = true;
} }
......
...@@ -77,7 +77,7 @@ private: ...@@ -77,7 +77,7 @@ private:
{ {
SMyMaterialEntry () SMyMaterialEntry ()
: Texture1FileName("null"), Texture2FileName("null"), : Texture1FileName("null"), Texture2FileName("null"),
Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {;} Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {}
SMyMaterialHeader Header; SMyMaterialHeader Header;
core::stringc Texture1FileName; core::stringc Texture1FileName;
...@@ -91,18 +91,18 @@ private: ...@@ -91,18 +91,18 @@ private:
{ {
SMyMeshBufferEntry() : MaterialIndex(-1), MeshBuffer(0) {} SMyMeshBufferEntry() : MaterialIndex(-1), MeshBuffer(0) {}
SMyMeshBufferEntry(s32 mi, SMeshBufferLightMap* mb) SMyMeshBufferEntry(s32 mi, SMeshBufferLightMap* mb)
: MaterialIndex(mi), MeshBuffer(mb) {;} : MaterialIndex(mi), MeshBuffer(mb) {}
s32 MaterialIndex; s32 MaterialIndex;
SMeshBufferLightMap* MeshBuffer; SMeshBufferLightMap* MeshBuffer;
}; };
core::array<SMyMaterialEntry> MaterialEntry;
core::array<SMyMeshBufferEntry> MeshBufferEntry;
SMyMaterialEntry* getMaterialEntryByIndex (u32 matInd); SMyMaterialEntry* getMaterialEntryByIndex (u32 matInd);
SMeshBufferLightMap* getMeshBufferByMaterialIndex(u32 matInd); SMeshBufferLightMap* getMeshBufferByMaterialIndex(u32 matInd);
core::array<SMyMaterialEntry> MaterialEntry;
core::array<SMyMeshBufferEntry> MeshBufferEntry;
core::array<ISceneNode*> ChildNodes; core::array<ISceneNode*> ChildNodes;
}; };
......
// Copyright (C) 2002-2007 Nikolaus Gebhardt // Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
// //
// This file was originally written by ZDimitor. // This file was originally written by ZDimitor.
//---------------------------------------------------------------------- //----------------------------------------------------------------------
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
#include <irrTypes.h> #include <irrTypes.h>
namespace irr namespace irr
{ {
namespace scene namespace scene
{ {
//********************************************************************** //**********************************************************************
...@@ -54,7 +54,7 @@ const unsigned long MY_PIXEL_FORMAT_24 = 0x5f32345f; // was: #define MY_PIXEL_FO ...@@ -54,7 +54,7 @@ const unsigned long MY_PIXEL_FORMAT_24 = 0x5f32345f; // was: #define MY_PIXEL_FO
const unsigned long MY_PIXEL_FORMAT_16 = 0x5f31365f; // was: #define MY_PIXEL_FORMAT_16 '_16_' const unsigned long MY_PIXEL_FORMAT_16 = 0x5f31365f; // was: #define MY_PIXEL_FORMAT_16 '_16_'
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// byte-align structures // byte-align structures
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( push, packing ) # pragma pack( push, packing )
# pragma pack( 1 ) # pragma pack( 1 )
# define PACK_STRUCT # define PACK_STRUCT
...@@ -64,7 +64,7 @@ const unsigned long MY_PIXEL_FORMAT_16 = 0x5f31365f; // was: #define MY_PIXEL_FO ...@@ -64,7 +64,7 @@ const unsigned long MY_PIXEL_FORMAT_16 = 0x5f31365f; // was: #define MY_PIXEL_FO
# error compiler not supported # error compiler not supported
#endif #endif
//---------------------------------------------------------------------- //----------------------------------------------------------------------
struct SMyColor struct SMyColor
{ SMyColor () {;} { SMyColor () {;}
SMyColor (s32 __R, s32 __G, s32 __B, s32 __A) SMyColor (s32 __R, s32 __G, s32 __B, s32 __A)
: R(__R), G(__G), B(__B), A(__A) {} : R(__R), G(__G), B(__B), A(__A) {}
...@@ -83,15 +83,15 @@ struct SMyVector2 ...@@ -83,15 +83,15 @@ struct SMyVector2
SMyVector2(f32 __X, f32 __Y) SMyVector2(f32 __X, f32 __Y)
: X(__X), Y(__Y) {} : X(__X), Y(__Y) {}
f32 X, Y; f32 X, Y;
} PACK_STRUCT; } PACK_STRUCT;
struct SMyVertex struct SMyVertex
{ SMyVertex () {;} { SMyVertex () {;}
SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal) SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal)
:Coord(_Coord), Color(_Color), Normal(_Normal) {;} :Coord(_Coord), Color(_Color), Normal(_Normal) {;}
SMyVector3 Coord; SMyVector3 Coord;
SMyColor Color; SMyColor Color;
SMyVector3 Normal; SMyVector3 Normal;
} PACK_STRUCT; } PACK_STRUCT;
struct SMyTVertex struct SMyTVertex
...@@ -117,7 +117,7 @@ struct SMyFileHeader ...@@ -117,7 +117,7 @@ struct SMyFileHeader
// scene header // scene header
struct SMySceneHeader struct SMySceneHeader
{ SMyColor BackgrColor; // background color { SMyColor BackgrColor; // background color
SMyColor AmbientColor; // ambient color SMyColor AmbientColor; // ambient color
s32 MaterialCount; // material count s32 MaterialCount; // material count
s32 MeshCount; // mesh count s32 MeshCount; // mesh count
} PACK_STRUCT; } PACK_STRUCT;
...@@ -130,7 +130,7 @@ struct SMyMaterialHeader ...@@ -130,7 +130,7 @@ struct SMyMaterialHeader
SMyColor DiffuseColor; SMyColor DiffuseColor;
SMyColor EmissiveColor; SMyColor EmissiveColor;
SMyColor SpecularColor; SMyColor SpecularColor;
f32 Shininess; f32 Shininess;
f32 Transparency; f32 Transparency;
s32 TextureCount; // texture count s32 TextureCount; // texture count
} PACK_STRUCT; } PACK_STRUCT;
...@@ -144,7 +144,7 @@ struct SMyMeshHeader ...@@ -144,7 +144,7 @@ struct SMyMeshHeader
// texture data header // texture data header
struct SMyTexDataHeader struct SMyTexDataHeader
{ c8 Name[256]; // texture name { c8 Name[256]; // texture name
u32 ComprMode; //compression mode u32 ComprMode; //compression mode
u32 PixelFormat; u32 PixelFormat;
u32 Width; // image width u32 Width; // image width
...@@ -177,12 +177,12 @@ struct SMyRLEHeader ...@@ -177,12 +177,12 @@ struct SMyRLEHeader
} PACK_STRUCT; } PACK_STRUCT;
// Default alignment // Default alignment
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop, packing ) # pragma pack( pop, packing )
#endif #endif
} // end namespace } // end namespace
} // end namespace } // end namespace
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment