Minor cleanup.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@761 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2007-07-05 22:33:56 +00:00
parent 64ea350e23
commit c2ec44c7dc
4 changed files with 253 additions and 265 deletions

View File

@ -1,7 +1,7 @@
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
//
// This file was originally written by ZDimitor.
//----------------------------------------------------------------------
@ -19,9 +19,9 @@
#define __C_MY3D_HELPER_H_INCLUDED__
//--------------------------------------------------------------------------------
namespace irr
namespace irr
{
namespace core
namespace core
{
//-----------------RLE stuff-----------------------------------------
@ -41,7 +41,7 @@ void flush_outbuf(
unsigned char *out_buf, int out_buf_size
);
unsigned long get_byte (
unsigned char *ch,
unsigned char *ch,
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
);
@ -60,10 +60,10 @@ int nDecodedBytes=0;
int nCodedBytes=0;
// number of read bytes
int nReadedBytes=0;
// table used to look for sequences of repeating bytes
unsigned char tmpbuf[4]; // we use subscripts 1 - 3
// table used to look for sequences of repeating bytes
unsigned char tmpbuf[4]; // we use subscripts 1 - 3
int tmpbuf_cnt;
// output buffer for non-compressed output data
// output buffer for non-compressed output data
unsigned char outbuf[128];
int outbuf_cnt;
@ -73,7 +73,7 @@ int rle_encode (
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_buf_size
)
{
{
unsigned long ret_code;
unsigned char ch;
@ -81,31 +81,31 @@ int rle_encode (
nCodedBytes=0;
nReadedBytes=0;
tmpbuf_cnt = 0; // no. of char's in tmpbuf
outbuf_cnt = 0; // no. of char's in outbuf
tmpbuf_cnt = 0; // no. of char's in tmpbuf
outbuf_cnt = 0; // no. of char's in outbuf
while (1)
{
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;
tmpbuf[++tmpbuf_cnt] = (unsigned char) ch;
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]))
{
// they do - add compression
// they do - add compression
// this will process all bytes in input file until
// a non-match occurs, or 128 bytes are processed,
// or we find eod */
ret_code = process_comp(in_buf, in_buf_size, out_buf, out_buf_size);
if (ret_code == (int)EOD_FOUND)
break; // stop compressing
break; // stop compressing
if (ret_code == (int)NON_MATCH)
tmpbuf_cnt=1; /* save the char that didn't match */
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 */
}
else
@ -114,7 +114,7 @@ int rle_encode (
// others, so just send it out as uncompressed. */
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])
{
// move byte 3 to position 1 and pretend we just
@ -128,14 +128,14 @@ int rle_encode (
// send byte 2 and keep byte 3 - it may match the
// next byte. Move byte 3 to position 1 and set
// 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);
tmpbuf[1]=tmpbuf[3];
tmpbuf_cnt=1;
}
}
}
} // end while
} // end while
flush_outbuf(out_buf, out_buf_size);
return nCodedBytes;
@ -156,22 +156,21 @@ unsigned long process_comp(
unsigned char *buf, int 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;
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);
while (get_byte(&ch, buf, buf_size, out_buf, out_buf_size) != (int)EOD)
{
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);
// 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);
/* save the non-matching character just read */
tmpbuf[1]=(unsigned char) ch;
@ -181,18 +180,18 @@ unsigned long process_comp(
len++;
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);
// 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);
return LIMIT;
}
} // end while
} // end while
// if flow comes here, we just read an EOD
// send no. of repeated bytes to be encoded
// if flow comes here, we just read an EOD
// send no. of repeated bytes to be encoded
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);
return EOD_FOUND;
}
@ -213,7 +212,7 @@ void process_uncomp(
}
//-----------------------------------------------------------
// 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)
{
@ -222,7 +221,7 @@ void flush_outbuf(unsigned char *out_buf, int out_buf_size)
if(!outbuf_cnt)
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);
for ( ; outbuf_cnt; outbuf_cnt--)
@ -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)
{
{
if (nCodedBytes<=(out_buf_size-1))
{ out_buf[nCodedBytes++]=ch;
out_buf[nCodedBytes]=0;
@ -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
// at end-of-data
// at end-of-data
//---------------------------------------------------
unsigned long get_byte(
unsigned char *ch,
unsigned char *ch,
unsigned char *in_buf, int in_buf_size,
unsigned char *out_buf, int out_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)
process_uncomp(tmpbuf[1], out_buf, out_buf_size);
else
@ -263,7 +262,7 @@ unsigned long get_byte(
return EOD;
}
(*ch) = (unsigned char)in_buf[nReadedBytes++];
return 0;
@ -289,27 +288,27 @@ int rle_decode (
if (ch > 127)
{
i = ch - 127; // i is the number of repetitions
// get the byte to be repeated
i = ch - 127; // i is the number of repetitions
// get the byte to be repeated
if (nReadedBytes>=in_buf_size)
break;
else
ch=in_buf[nReadedBytes];
nReadedBytes++;
// uncompress a chunk
// uncompress a chunk
for ( ; i ; i--)
{
if (nDecodedBytes<out_buf_size)
if (nDecodedBytes<out_buf_size)
out_buf[nDecodedBytes] = ch;
nDecodedBytes++;
}
}
else
{
// copy out some uncompressed bytes
i = ch + 1; // i is the no. of bytes
// uncompress a chunk
// copy out some uncompressed bytes
i = ch + 1; // i is the no. of bytes
// uncompress a chunk
for ( ; i ; i--)
{
if (nReadedBytes>=in_buf_size)
@ -318,12 +317,12 @@ int rle_decode (
ch=in_buf[nReadedBytes];
nReadedBytes++;
if (nDecodedBytes<out_buf_size)
if (nDecodedBytes<out_buf_size)
out_buf[nDecodedBytes] = ch;
nDecodedBytes++;
}
}
} // end while
} // end while
return nDecodedBytes;
}

View File

@ -14,6 +14,8 @@
#include "SMeshBuffer.h"
#include "IReadFile.h"
#include "IAttributes.h"
#include "CImage.h"
#include "CColorConverter.h"
#include "CMY3DHelper.h"
#include "os.h"
@ -55,7 +57,7 @@ CMY3DMeshFileLoader::~CMY3DMeshFileLoader()
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)
file->read(&id, sizeof(id));
s32 texCount=0, ligCount=0, matCount=0;
s32 texCount=0, matCount=0;
c8 name[256];
for (s32 m=0; m<sceneHeader.MaterialCount; ++m)
{
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;
}
@ -168,8 +170,8 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
pixFormatStr = "24bit,";
else
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_16)
pixFormatStr = "16bit,";
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_16)
pixFormatStr = "16bit,";
else
{
msg="Unknown format of image data (";
@ -179,120 +181,117 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
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_SIMPLE_ID )
{
os::Printer::log("Unknown method of compression image data, loading failed!", ELL_ERROR);
return 0;
}
u32 num_pixels = texDataHeader.Width*texDataHeader.Height;
void* data = 0;
if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_NONE_ID)
{
// none compressed image data
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
{
os::Printer::log("Unknown method of compression image data, loading failed!", ELL_ERROR);
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
if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_RLE_ID)
{
// read RLE header identificator
file->read(&id, sizeof(id));
if (id!=MY_TEXDATA_RLE_HEADER_ID)
{
os::Printer::log("Can not find MY_TEXDATA_RLE_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
u32 num_pixels = texDataHeader.Width*texDataHeader.Height;
// read RLE header
SMyRLEHeader rleHeader;
file->read(&rleHeader, sizeof(SMyRLEHeader));
void* data = 0;
//allocate memory for input and output buffers
void *input_buffer = (void*) new unsigned char[rleHeader.nEncodedBytes];
void *output_buffer = (void*) new unsigned char[rleHeader.nDecodedBytes];
if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_NONE_ID)
// read encoded data
file->read(input_buffer, rleHeader.nEncodedBytes);
// decode data
data = 0;//(void*) new unsigned char[rleHeader.nDecodedBytes];
s32 decodedBytes = core::rle_decode(
(unsigned char*)input_buffer, rleHeader.nEncodedBytes,
(unsigned char*)output_buffer, rleHeader.nDecodedBytes);
if (decodedBytes!=(s32)rleHeader.nDecodedBytes)
{
// none compressed image data
os::Printer::log("Error extracting data from RLE compression, loading failed!", ELL_ERROR);
return 0;
}
// free input buffer
delete [] (unsigned char*)input_buffer;
// here decoded data
data = output_buffer;
}
else if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_SIMPLE_ID)
{
// simple compressed image data
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
data = (void*) new SMyPixelColor24[num_pixels];
else
data = (void*) new SMyPixelColor16[num_pixels];
u32 nReadedPixels=0, nToRead=0;
while (true)
{
file->read(&nToRead, sizeof(nToRead));
if ((nReadedPixels+nToRead) > num_pixels)
break;
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
{
data = (void*) new SMyPixelColor24[num_pixels];
file->read(data, sizeof(SMyPixelColor24)*num_pixels);
SMyPixelColor24 col24;
file->read(&col24, sizeof(SMyPixelColor24));
for (u32 p=0; p<nToRead; p++)
{
((SMyPixelColor24*)data)[nReadedPixels+p] =
SMyPixelColor24(col24.r, col24.g, col24.b);
}
}
else
{
data = (void*) new SMyPixelColor16[num_pixels];
file->read(data, sizeof(SMyPixelColor16)*num_pixels);
SMyPixelColor16 col16;
file->read(&col16, sizeof(SMyPixelColor16));
for (u32 p=0; p<nToRead; p++)
((SMyPixelColor16*)data)[nReadedPixels+p].argb = col16.argb;
}
nReadedPixels+=nToRead;
if (nReadedPixels >= num_pixels)
break;
}
else
if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_RLE_ID)
{
// read RLE header identificator
file->read(&id, sizeof(id));
if (id!=MY_TEXDATA_RLE_HEADER_ID)
{
os::Printer::log("Can not find MY_TEXDATA_RLE_HEADER_ID, loading failed!", ELL_ERROR);
return 0;
}
// read RLE header
SMyRLEHeader rleHeader;
file->read(&rleHeader, sizeof(SMyRLEHeader));
//allocate memory for input and output buffers
void *input_buffer = (void*) new unsigned char[rleHeader.nEncodedBytes];
void *output_buffer = (void*) new unsigned char[rleHeader.nDecodedBytes];
// read encoded data
file->read(input_buffer, rleHeader.nEncodedBytes);
// decode data
data = 0;//(void*) new unsigned char[rleHeader.nDecodedBytes];
s32 decodedBytes = core::rle_decode(
(unsigned char*)input_buffer, rleHeader.nEncodedBytes,
(unsigned char*)output_buffer, rleHeader.nDecodedBytes);
if (decodedBytes!=(s32)rleHeader.nDecodedBytes)
{
os::Printer::log("Error extracting data from RLE compression, loading failed!", ELL_ERROR);
return 0;
}
// free input buffer
delete [] (unsigned char*)input_buffer;
// here decoded data
data = output_buffer;
}
else if (texDataHeader.ComprMode==MY_TEXDATA_COMPR_SIMPLE_ID)
{
// simple compressed image data
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
data = (void*) new SMyPixelColor24[num_pixels];
else
data = (void*) new SMyPixelColor16[num_pixels];
u32 nReadedPixels =0, nToRead =0;
while (true)
{
file->read(&nToRead, sizeof(nToRead));
if ((nReadedPixels+nToRead) > num_pixels)
break;
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
if (nReadedPixels != num_pixels)
{
SMyPixelColor24 col24;
file->read(&col24, sizeof(SMyPixelColor24));
for (u32 p=0; p<nToRead; p++)
{
((SMyPixelColor24*)data)[nReadedPixels+p] =
SMyPixelColor24(col24.r, col24.g, col24.b);
}
}
else
{
SMyPixelColor16 col16;
file->read(&col16, sizeof(SMyPixelColor16));
for (u32 p=0; p<nToRead; p++)
{
((SMyPixelColor16*)data)[nReadedPixels+p].argb = col16.argb;
}
}
nReadedPixels+=nToRead;
if (nReadedPixels >= num_pixels)
break;
}
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;
}
}
}
//! Creates a software image from a byte array.
@ -300,7 +299,7 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
if (texDataHeader.PixelFormat == MY_PIXEL_FORMAT_24)
{
// 24 bit lightmap format
// 24 bit lightmap format
light_img = Driver->createImageFromData(
video::ECF_R8G8B8,
core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height),
@ -308,83 +307,72 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
}
else
{
// 16 bit lightmap format
// 16 bit lightmap format
light_img = Driver->createImageFromData(
video::ECF_A1R5G5B5,
core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height),
video::ECF_A1R5G5B5,
core::dimension2d<s32>(texDataHeader.Width, texDataHeader.Height),
data, true);
}
bool oldMipMapState = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
const bool oldMipMapState = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
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();
GetLightMap = true;
}
core::stringc Name = name;
int pos2 = Name.findLast('.');
core::stringc LightingMapStr = "LightingMap";
int ls = LightingMapStr.size();
core::stringc sub = Name.subString(core::max_(0, (pos2 - ls)), ls);
if ((sub == LightingMapStr || (Name[pos2-1]=='m' &&
Name[pos2-2]=='l' && Name[pos2-3]=='_')) &&
const core::stringc Name = name;
const s32 pos2 = Name.findLast('.');
const core::stringc LightingMapStr = "LightingMap";
const u32 ls = LightingMapStr.size();
const bool isSubString = (LightingMapStr == Name.subString(core::max_(0u, (pos2 - ls)), ls));
if ((isSubString || (Name[pos2-1]=='m' &&
Name[pos2-2]=='l' && Name[pos2-3]=='_')) &&
!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);
me.Texture2FileName = texturePath.size() ? texturePath : filepath;
me.Texture2FileName.append("Lightmaps/");
me.Texture2FileName.append("Lightmaps/");
me.Texture2FileName.append(Name);
if (Name.size()>0)
{
me.Texture2 = Driver->getTexture(me.Texture2FileName.c_str());
ligCount++;
}
GetLightMap = true;
me.MaterialType = video::EMT_LIGHTMAP_M2;
GetLightMap = true;
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState);
}
else
else
if (!GetLightMap&&GetMainMap)
{
me.Texture2FileName = texturePath.size() ? texturePath : filepath;
me.Texture2FileName.append(Name);
if (Name.size())
{
me.Texture2 = Driver->getTexture(me.Texture2FileName.c_str());
ligCount++;
}
me.MaterialType = video::EMT_REFLECTION_2_LAYER;
}
else
else
if (!GetMainMap && !GetLightMap )
{
me.Texture1FileName = filepath;
me.Texture1FileName.append(Name);
if (Name.size())
{
me.Texture1 = Driver->getTexture(me.Texture1FileName.c_str());
me.Texture1 = Driver->getTexture(me.Texture1FileName.c_str());
texCount++;
}
GetMainMap = true;
me.MaterialType = video::EMT_SOLID;
}
else
else
if (GetLightMap)
{
me.MaterialType = video::EMT_LIGHTMAP_M2;
@ -393,7 +381,7 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
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))
me.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
else
@ -405,10 +393,10 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
// loading meshes
if (Mesh)
if (Mesh)
Mesh->drop();
Mesh = new SMesh();
Mesh = new SMesh();
if (id!=MY_MESH_LIST_ID)
{
@ -417,13 +405,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
}
file->read(&id, sizeof(id));
for (s32 mesh_id=0; mesh_id<sceneHeader.MeshCount; mesh_id++)
{
// 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
if (id!=MY_MESH_HEADER_ID)
if (id!=MY_MESH_HEADER_ID)
break;
if (id!=MY_MESH_HEADER_ID)
@ -478,72 +466,74 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
// reading texture coords
file->read(&id, sizeof(id));
if (id!=MY_TVERTS_ID)
{ msg="Can not find MY_TVERTS_ID (";
msg.append(tex);
msg.append("texture channel), loading failed!");
os::Printer::log(msg.c_str(), ELL_ERROR);
return 0;
}
if (id!=MY_TVERTS_ID)
{
msg="Can not find MY_TVERTS_ID (";
msg.append(tex);
msg.append("texture channel), loading failed!");
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
TVertex1.reallocate(tVertsNum);
file->read(TVertex1.pointer(), sizeof(SMyTVertex)*tVertsNum);
TVertex1.set_used(tVertsNum);
}
else
file->read(TVertex1.pointer(), sizeof(SMyTVertex)*tVertsNum);
TVertex1.set_used(tVertsNum);
}
else
if (tex==1)
{
{
// 2nd texture channel
TVertex2.reallocate(tVertsNum);
file->read(TVertex2.pointer(), sizeof(SMyTVertex)*tVertsNum);
TVertex2.set_used(tVertsNum);
}
else
{
file->read(TVertex2.pointer(), sizeof(SMyTVertex)*tVertsNum);
TVertex2.set_used(tVertsNum);
}
else
{
// skip other texture channels
u32 pos = file->getPos();
file->seek(pos+sizeof(SMyTVertex)*tVertsNum);
}
file->seek(pos+sizeof(SMyTVertex)*tVertsNum);
}
// reading texture faces
file->read(&id, sizeof(id));
// reading texture faces
file->read(&id, sizeof(id));
if (id!=MY_TFACES_ID)
{ msg="Can not find MY_TFACES_ID (";
msg.append(tex);
msg.append("texture channel), loading failed!");
os::Printer::log(msg.c_str(), ELL_ERROR);
return 0;
}
if (id!=MY_TFACES_ID)
{
msg="Can not find MY_TFACES_ID (";
msg.append(tex);
msg.append("texture channel), loading failed!");
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
TFace1.reallocate(tFacesNum);
file->read(TFace1.pointer(), sizeof(SMyFace)*tFacesNum);
TFace1.set_used(tFacesNum);
}
else if (tex==1)
{
file->read(TFace1.pointer(), sizeof(SMyFace)*tFacesNum);
TFace1.set_used(tFacesNum);
}
else if (tex==1)
{
// 2nd texture channel
TFace2.reallocate(tFacesNum);
file->read(TFace2.pointer(), sizeof(SMyFace)*tFacesNum);
TFace2.set_used(tFacesNum);
}
else
{
file->read(TFace2.pointer(), sizeof(SMyFace)*tFacesNum);
TFace2.set_used(tFacesNum);
}
else
{
// skip other texture channels
u32 pos = file->getPos();
file->seek(pos+sizeof(SMyFace)*tFacesNum);
}
}
file->seek(pos+sizeof(SMyFace)*tFacesNum);
}
}
// trying to find material
@ -609,15 +599,15 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
);
}
else
{
buffer->Material.Textures[0] = 0;
buffer->Material.Textures[1] = 0;
{
buffer->Material.Textures[0] = 0;
buffer->Material.Textures[1] = 0;
buffer->Material.AmbientColor = 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.SpecularColor = video::SColor(0, 0, 0, 0);
}
buffer->Material.AmbientColor = 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.SpecularColor = video::SColor(0, 0, 0, 0);
}
if (matEnt && matEnt->Header.Transparency!=0)
{
@ -633,14 +623,13 @@ IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file)
buffer->Material.Lighting = false;
buffer->Material.BackfaceCulling = false;
}
}
}
else if (
!buffer->Material.Textures[1] &&
buffer->Material.MaterialType != video::EMT_TRANSPARENT_ALPHA_CHANNEL &&
buffer->Material.MaterialType != video::EMT_SPHERE_MAP
)
{
buffer->Material.MaterialType = video::EMT_SOLID;
buffer->Material.MaterialType != video::EMT_SPHERE_MAP)
{
buffer->Material.MaterialType = video::EMT_SOLID;
buffer->Material.Lighting = true;
}

View File

@ -77,7 +77,7 @@ private:
{
SMyMaterialEntry ()
: Texture1FileName("null"), Texture2FileName("null"),
Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {;}
Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {}
SMyMaterialHeader Header;
core::stringc Texture1FileName;
@ -91,18 +91,18 @@ private:
{
SMyMeshBufferEntry() : MaterialIndex(-1), MeshBuffer(0) {}
SMyMeshBufferEntry(s32 mi, SMeshBufferLightMap* mb)
: MaterialIndex(mi), MeshBuffer(mb) {;}
: MaterialIndex(mi), MeshBuffer(mb) {}
s32 MaterialIndex;
SMeshBufferLightMap* MeshBuffer;
};
core::array<SMyMaterialEntry> MaterialEntry;
core::array<SMyMeshBufferEntry> MeshBufferEntry;
SMyMaterialEntry* getMaterialEntryByIndex (u32 matInd);
SMeshBufferLightMap* getMeshBufferByMaterialIndex(u32 matInd);
core::array<SMyMaterialEntry> MaterialEntry;
core::array<SMyMeshBufferEntry> MeshBufferEntry;
core::array<ISceneNode*> ChildNodes;
};

View File

@ -1,7 +1,7 @@
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
//
// This file was originally written by ZDimitor.
//----------------------------------------------------------------------
@ -16,9 +16,9 @@
#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
const unsigned long MY_PIXEL_FORMAT_16 = 0x5f31365f; // was: #define MY_PIXEL_FORMAT_16 '_16_'
//--------------------------------------------------------------------
// 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( 1 )
# define PACK_STRUCT
@ -64,7 +64,7 @@ const unsigned long MY_PIXEL_FORMAT_16 = 0x5f31365f; // was: #define MY_PIXEL_FO
# error compiler not supported
#endif
//----------------------------------------------------------------------
struct SMyColor
struct SMyColor
{ SMyColor () {;}
SMyColor (s32 __R, s32 __G, s32 __B, s32 __A)
: R(__R), G(__G), B(__B), A(__A) {}
@ -83,15 +83,15 @@ struct SMyVector2
SMyVector2(f32 __X, f32 __Y)
: X(__X), Y(__Y) {}
f32 X, Y;
} PACK_STRUCT;
} PACK_STRUCT;
struct SMyVertex
{ SMyVertex () {;}
SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal)
:Coord(_Coord), Color(_Color), Normal(_Normal) {;}
:Coord(_Coord), Color(_Color), Normal(_Normal) {;}
SMyVector3 Coord;
SMyColor Color;
SMyVector3 Normal;
SMyColor Color;
SMyVector3 Normal;
} PACK_STRUCT;
struct SMyTVertex
@ -117,7 +117,7 @@ struct SMyFileHeader
// scene header
struct SMySceneHeader
{ SMyColor BackgrColor; // background color
SMyColor AmbientColor; // ambient color
SMyColor AmbientColor; // ambient color
s32 MaterialCount; // material count
s32 MeshCount; // mesh count
} PACK_STRUCT;
@ -130,7 +130,7 @@ struct SMyMaterialHeader
SMyColor DiffuseColor;
SMyColor EmissiveColor;
SMyColor SpecularColor;
f32 Shininess;
f32 Shininess;
f32 Transparency;
s32 TextureCount; // texture count
} PACK_STRUCT;
@ -144,7 +144,7 @@ struct SMyMeshHeader
// texture data header
struct SMyTexDataHeader
{ c8 Name[256]; // texture name
{ c8 Name[256]; // texture name
u32 ComprMode; //compression mode
u32 PixelFormat;
u32 Width; // image width
@ -177,12 +177,12 @@ struct SMyRLEHeader
} PACK_STRUCT;
// Default alignment
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop, packing )
#endif
} // end namespace
} // end namespace
} // end namespace
} // end namespace
#endif