From c4903cb8ecd3c94c822fd3e4e2ce5fcdffb297f5 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 10 Jan 2015 19:29:14 +0100 Subject: [PATCH] Remove My3D --- lib/irrlicht/CMakeLists.txt | 3 - lib/irrlicht/include/IrrCompileConfig.h | 5 - lib/irrlicht/source/Irrlicht/CMY3DHelper.h | 447 --------- .../source/Irrlicht/CMY3DMeshFileLoader.cpp | 882 ------------------ .../source/Irrlicht/CMY3DMeshFileLoader.h | 131 --- .../source/Irrlicht/CSceneManager.cpp | 7 - 6 files changed, 1475 deletions(-) delete mode 100644 lib/irrlicht/source/Irrlicht/CMY3DHelper.h delete mode 100644 lib/irrlicht/source/Irrlicht/CMY3DMeshFileLoader.cpp delete mode 100644 lib/irrlicht/source/Irrlicht/CMY3DMeshFileLoader.h diff --git a/lib/irrlicht/CMakeLists.txt b/lib/irrlicht/CMakeLists.txt index 421e7ffae..479f66075 100644 --- a/lib/irrlicht/CMakeLists.txt +++ b/lib/irrlicht/CMakeLists.txt @@ -155,7 +155,6 @@ source/Irrlicht/CXMLWriter.cpp source/Irrlicht/COBJMeshFileLoader.cpp source/Irrlicht/CSceneNodeAnimatorCameraFPS.cpp source/Irrlicht/CImageLoaderPPM.cpp -source/Irrlicht/CMY3DMeshFileLoader.cpp source/Irrlicht/CGUIColorSelectDialog.cpp source/Irrlicht/CSceneManager.cpp source/Irrlicht/Irrlicht.cpp @@ -249,7 +248,6 @@ source/Irrlicht/CSceneNodeAnimatorCameraFPS.h source/Irrlicht/CParticleFadeOutAffector.h source/Irrlicht/COpenGLSLMaterialRenderer.h source/Irrlicht/CParticleAttractionAffector.h -source/Irrlicht/CMY3DMeshFileLoader.h source/Irrlicht/MacOSX/AppDelegate.h source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h source/Irrlicht/MacOSX/OSXClipboard.h @@ -277,7 +275,6 @@ source/Irrlicht/CParticleBoxEmitter.h source/Irrlicht/CShadowVolumeSceneNode.h source/Irrlicht/COctreeSceneNode.h source/Irrlicht/CReadFile.h -source/Irrlicht/CMY3DHelper.h source/Irrlicht/CImageLoaderDDS.h source/Irrlicht/COSOperator.h source/Irrlicht/CLightSceneNode.h diff --git a/lib/irrlicht/include/IrrCompileConfig.h b/lib/irrlicht/include/IrrCompileConfig.h index a5c0b0320..c9a28f358 100644 --- a/lib/irrlicht/include/IrrCompileConfig.h +++ b/lib/irrlicht/include/IrrCompileConfig.h @@ -327,11 +327,6 @@ B3D, MS3D or X meshes */ #ifdef NO_IRR_COMPILE_WITH_LMTS_LOADER_ #undef _IRR_COMPILE_WITH_LMTS_LOADER_ #endif -//! Define _IRR_COMPILE_WITH_MY3D_LOADER_ if you want to load MY3D files -#define _IRR_COMPILE_WITH_MY3D_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_MY3D_LOADER_ -#undef _IRR_COMPILE_WITH_MY3D_LOADER_ -#endif //! Define _IRR_COMPILE_WITH_OBJ_LOADER_ if you want to load Wavefront OBJ files #define _IRR_COMPILE_WITH_OBJ_LOADER_ #ifdef NO_IRR_COMPILE_WITH_OBJ_LOADER_ diff --git a/lib/irrlicht/source/Irrlicht/CMY3DHelper.h b/lib/irrlicht/source/Irrlicht/CMY3DHelper.h deleted file mode 100644 index e04544447..000000000 --- a/lib/irrlicht/source/Irrlicht/CMY3DHelper.h +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright (C) 2002-2012 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. - -//---------------------------------------------------------------------- -// somefuncs.h - part of the My3D Tools -// -// This tool was created by Zhuck Dmitry (ZDimitor). -// Everyone can use it as wants ( i'll be happy if it helps to someone :) ). -//---------------------------------------------------------------------- - -//********************************************************************** -// some useful functions -//********************************************************************** - -#ifndef __C_MY3D_HELPER_H_INCLUDED__ -#define __C_MY3D_HELPER_H_INCLUDED__ - -#include - -namespace irr -{ -namespace scene -{ - -//********************************************************************** -// MY3D stuff -//********************************************************************** - -// byte-align structures -#include "irrpack.h" - -struct SMyVector3 -{ SMyVector3 () {;} - SMyVector3 (f32 __X, f32 __Y, f32 __Z) - : X(__X), Y(__Y), Z(__Z) {} - f32 X, Y, Z; -} PACK_STRUCT; - -struct SMyVector2 -{ SMyVector2 () {;} - SMyVector2(f32 __X, f32 __Y) - : X(__X), Y(__Y) {} - f32 X, Y; -} PACK_STRUCT; - -struct SMyVertex -{ SMyVertex () {;} - SMyVertex (SMyVector3 _Coord, SMyColor _Color, SMyVector3 _Normal) - :Coord(_Coord), Color(_Color), Normal(_Normal) {;} - SMyVector3 Coord; - SMyColor Color; - SMyVector3 Normal; -} PACK_STRUCT; - -struct SMyTVertex -{ SMyTVertex () {;} - SMyTVertex (SMyVector2 _TCoord) - : TCoord(_TCoord) {;} - SMyVector2 TCoord; -} PACK_STRUCT; - -struct SMyFace -{ SMyFace() {;} - SMyFace(u32 __A, u32 __B, u32 __C) - : A(__A), B(__B), C(__C) {} - u32 A, B, C; -} PACK_STRUCT; - -// file header (6 bytes) -struct SMyFileHeader -{ u32 MyId; // MY3D - u16 Ver; // Version -} PACK_STRUCT; - -// scene header -struct SMySceneHeader -{ SMyColor BackgrColor; // background color - SMyColor AmbientColor; // ambient color - s32 MaterialCount; // material count - s32 MeshCount; // mesh count -} PACK_STRUCT; - -// mesh header -struct SMyMeshHeader -{ c8 Name[256]; // material name - u32 MatIndex; // index of the mesh material - u32 TChannelCnt; // mesh mapping channels count -} PACK_STRUCT; - -// texture data header -struct SMyTexDataHeader -{ c8 Name[256]; // texture name - u32 ComprMode; //compression mode - u32 PixelFormat; - u32 Width; // image width - u32 Height; // image height -} PACK_STRUCT; - -// pixel color 24bit (R8G8B8) -struct SMyPixelColor24 -{ SMyPixelColor24() {;} - SMyPixelColor24(u8 __r, u8 __g, u8 __b) - : r(__r), g(__g), b(__b) {} - u8 r, g, b; -} PACK_STRUCT; - -// pixel color 16bit (A1R5G5B5) -struct SMyPixelColor16 -{ SMyPixelColor16() {;} - SMyPixelColor16(s16 _argb): argb(_argb) {;} - SMyPixelColor16(u8 r, u8 g, u8 b) - { argb = ((r&0x1F)<<10) | ((g&0x1F)<<5) | (b&0x1F); - } - s16 argb; -} PACK_STRUCT; - -// RLE Header -struct SMyRLEHeader -{ SMyRLEHeader() {} - u32 nEncodedBytes; - u32 nDecodedBytes; -} PACK_STRUCT; - -// Default alignment -#include "irrunpack.h" - -} // end namespace -} // end namespace - -//----------------------------------------------------------------------------- -namespace irr -{ -namespace core -{ - -//-----------------RLE stuff----------------------------------------- - -int rle_encode ( - unsigned char *in_buf, int in_buf_size, - unsigned char *out_buf, int out_buf_size - ); -unsigned long process_comp( - unsigned char *buf, int buf_size, - unsigned char *out_buf, int out_buf_size - ); -void process_uncomp( - unsigned char, unsigned char *out_buf, int out_buf_size - ); -void flush_outbuf( - unsigned char *out_buf, int out_buf_size - ); -unsigned long get_byte ( - unsigned char *ch, - unsigned char *in_buf, int in_buf_size, - unsigned char *out_buf, int out_buf_size - ); -void put_byte( - unsigned char ch, unsigned char *out_buf, int out_buf_size - ); -//----------------------------------------------------------- -const unsigned long LIMIT = 1; // was #define LIMIT 1 -const unsigned long NON_MATCH = 2; // was: #define NON_MATCH 2 -const unsigned long EOD_FOUND = 3; // was: #define EOD_FOUND 3 -const unsigned long EOD = 0x00454f44; // was: #define EOD 'EOD' -//----------------------------------------------------------- -// number of decoded bytes -static int nDecodedBytes=0; -// number of coded bytes -static int nCodedBytes=0; -// number of read bytes -static int nReadedBytes=0; -// table used to look for sequences of repeating bytes -static unsigned char tmpbuf[4]; // we use subscripts 1 - 3 -static int tmpbuf_cnt; -// output buffer for non-compressed output data -static unsigned char outbuf[128]; -static int outbuf_cnt; - - -//----------------------------------------------------------- -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; - - nCodedBytes=0; - nReadedBytes=0; - - 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 - break; - - tmpbuf[++tmpbuf_cnt] = (unsigned char) ch; - if (tmpbuf_cnt == 3) - { - // see if all 3 match each other - if ((tmpbuf[1] == tmpbuf[2]) && (tmpbuf[2] == tmpbuf[3])) - { - // 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 - 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 - tmpbuf_cnt=0; /* start over for next chunk */ - } - else - { - // we know the first byte doesn't match 2 or more - // 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 - if (tmpbuf[2] == tmpbuf[3]) - { - // move byte 3 to position 1 and pretend we just - // have 2 bytes -- note that the first byte was - // already sent to output */ - tmpbuf[1]=tmpbuf[3]; - tmpbuf_cnt=2; - } - else - { - // 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 - process_uncomp(tmpbuf[2], out_buf, out_buf_size); - tmpbuf[1]=tmpbuf[3]; - tmpbuf_cnt=1; - } - } - } - } // end while - flush_outbuf(out_buf, out_buf_size); - - return nCodedBytes; -} - - -//------------------------------------------------------------------ -// This flushes any non-compressed data not yet sent, then it processes -// repeating bytes until > 128, or EOD, or non-match. -// return values: LIMIT, EOD_FOUND, NON_MATCH -// Prior to ANY return, it writes out the 2 byte compressed code. -// If a NON_MATCH was found, this returns with the non-matching char -// residing in tmpbuf[0]. -// Inputs: tmpbuf[0], input file -// Outputs: tmpbuf[0] (sometimes), output file, and return code -//------------------------------------------------------------------ -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 - register int len = 3; - - unsigned char ch; - - // 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 - put_byte((unsigned char)((--len) | 0x80), out_buf, out_buf_size); - // 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; - return NON_MATCH; - } - /* we know the new byte is part of the repeating seq */ - len++; - if (len == 128) - { - // 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 - put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); - return LIMIT; - } - } // end while - - // 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 - put_byte((unsigned char)tmpbuf[1], out_buf, out_buf_size); - return EOD_FOUND; -} - - -//---------------------------------------------------------------- -// This adds 1 non-repeating byte to outbuf. If outbuf becomes full -// with 128 bytes, it flushes outbuf. -// There are no return codes and no bytes are read from the input. -//---------------------------------------------------------------- -void process_uncomp( - unsigned char char1, unsigned char *out_buf, int out_buf_size - ) -{ - outbuf[outbuf_cnt++] = char1; - if (outbuf_cnt == 128) - flush_outbuf(out_buf, out_buf_size); -} -//----------------------------------------------------------- -// This flushes any non-compressed data not yet sent. -// On exit, outbuf_cnt will equal zero. -//----------------------------------------------------------- -void flush_outbuf(unsigned char *out_buf, int out_buf_size) -{ - register int pos=0; - - if(!outbuf_cnt) - return; // nothing to do */ - - // 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--) - put_byte((unsigned char)outbuf[pos++], out_buf, 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; - } -} -//--------------------------------------------------- -// This reads the next byte into ch. It returns EOD -// at end-of-data -//--------------------------------------------------- -unsigned long get_byte( - 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 - if (tmpbuf_cnt == 1) - process_uncomp(tmpbuf[1], out_buf, out_buf_size); - else - { - if (tmpbuf_cnt == 2) - { - process_uncomp(tmpbuf[1], out_buf, out_buf_size); - process_uncomp(tmpbuf[2], out_buf, out_buf_size); - } - } - nReadedBytes =0; - - return EOD; - } - - (*ch) = (unsigned char)in_buf[nReadedBytes++]; - - return 0; -} -//----------------------------------------------------------- -int rle_decode ( - unsigned char *in_buf, int in_buf_size, - unsigned char *out_buf, int out_buf_size - ) -{ - nDecodedBytes=0; - nReadedBytes=0; - - int ch, i; - while (1) - { - - if (nReadedBytes>=in_buf_size) - break; - else - ch=in_buf[nReadedBytes]; - nReadedBytes++; - - if (ch > 127) - { - 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 - for ( ; i ; i--) - { - if (nDecodedBytes=in_buf_size) - break; - else - ch=in_buf[nReadedBytes]; - nReadedBytes++; - - if (nDecodedBytesgrab(); -} - - -CMY3DMeshFileLoader::~CMY3DMeshFileLoader() -{ - if (FileSystem) - FileSystem->drop(); -} - - -bool CMY3DMeshFileLoader::isALoadableFileExtension(const io::path& filename) const -{ - return core::hasFileExtension ( filename, "my3d" ); -} - - -IAnimatedMesh* CMY3DMeshFileLoader::createMesh(io::IReadFile* file) -{ - MaterialEntry.clear(); - MeshBufferEntry.clear(); - ChildNodes.clear(); - - // working directory (from which we load the scene) - core::stringc filepath = FileSystem->getFileDir(file->getFileName()); - if (filepath==".") - filepath=""; - else - filepath.append("/"); - - // read file into memory - SMyFileHeader fileHeader; - file->read(&fileHeader, sizeof(SMyFileHeader)); -#ifdef __BIG_ENDIAN__ - fileHeader.MyId = os::Byteswap::byteswap(fileHeader.MyId); - fileHeader.Ver = os::Byteswap::byteswap(fileHeader.Ver); -#endif - - if (fileHeader.MyId!=MY3D_ID || fileHeader.Ver!=MY3D_VER) - { - os::Printer::log("Bad MY3D file header, loading failed!", ELL_ERROR); - return 0; - } - - u16 id; - - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - if (id!=MY3D_SCENE_HEADER_ID) - { - os::Printer::log("Cannot find MY3D_SCENE_HEADER_ID, loading failed!", ELL_ERROR); - return 0; - } - - SMySceneHeader sceneHeader; - file->read(&sceneHeader, sizeof(SMySceneHeader)); -#ifdef __BIG_ENDIAN__ - sceneHeader.MaterialCount = os::Byteswap::byteswap(sceneHeader.MaterialCount); - sceneHeader.MeshCount = os::Byteswap::byteswap(sceneHeader.MeshCount); -#endif - - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - if (id!=MY3D_MAT_LIST_ID) - { - os::Printer::log("Can not find MY3D_MAT_LIST_ID, loading failed!", ELL_ERROR); - return 0; - } - - core::stringc texturePath = - SceneManager->getParameters()->getAttributeAsString(MY3D_TEXTURE_PATH); - - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - c8 namebuf[256]; - for (s32 m=0; mread(&(me.Header), sizeof(SMyMaterialHeader)); - - // read next identificator - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - bool gotLightMap=false, gotMainMap=false; - - for (u32 t=0; tread(namebuf, 256); - else - { - me.Texture2 = readEmbeddedLightmap(file, namebuf); - if (!me.Texture2) - return 0; - gotLightMap = true; - } - - const core::stringc name(namebuf); - const s32 pos = name.findLast('.'); - const core::stringc LightingMapStr = "LightingMap"; - const s32 ls = LightingMapStr.size(); - const bool isSubString = (LightingMapStr == name.subString(core::max_(0, (pos - ls)), ls)); - if ((isSubString || (name[pos-1]=='m' && - name[pos-2]=='l' && name[pos-3]=='_')) && - !gotLightMap) - { - const bool oldMipMapState = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); - SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); - - me.Texture2FileName = texturePath.size() ? texturePath : filepath; - me.Texture2FileName.append("Lightmaps/"); - me.Texture2FileName.append(name); - - if (name.size()) - me.Texture2 = SceneManager->getVideoDriver()->getTexture(me.Texture2FileName); - - me.MaterialType = video::EMT_LIGHTMAP_M2; - gotLightMap = true; - - SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState); - } - else - if (!gotLightMap && gotMainMap) - { - me.Texture2FileName = texturePath.size() ? texturePath : filepath; - me.Texture2FileName.append(name); - - if (name.size()) - me.Texture2 = SceneManager->getVideoDriver()->getTexture(me.Texture2FileName); - - me.MaterialType = video::EMT_REFLECTION_2_LAYER; - } - else - if (!gotMainMap && !gotLightMap) - { - me.Texture1FileName = filepath; - me.Texture1FileName.append(name); - if (name.size()) - me.Texture1 = SceneManager->getVideoDriver()->getTexture(me.Texture1FileName); - - gotMainMap = true; - me.MaterialType = video::EMT_SOLID; - } - else - if (gotLightMap) - { - me.MaterialType = video::EMT_LIGHTMAP_M2; - } - - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - } - - // override material types based on their names - if (!strncmp(me.Header.Name, "AlphaChannel-", 13)) - me.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - else - if (!strncmp(me.Header.Name, "SphereMap-", 10)) - me.MaterialType = video::EMT_SPHERE_MAP; - } - - // loading meshes - - if (id!=MY3D_MESH_LIST_ID) - { - os::Printer::log("Can not find MY3D_MESH_LIST_ID, loading failed!", ELL_ERROR); - return 0; - } - - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - for (s32 mesh_id=0; mesh_idread(&meshHeader, sizeof(SMyMeshHeader)); - - core::array Vertex; - core::array Face; - core::array TVertex1, TVertex2; - core::array TFace1, TFace2; - - s32 vertsNum=0; - s32 facesNum=0; - - // vertices - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - if (id!=MY3D_VERTS_ID) - { - os::Printer::log("Can not find MY3D_VERTS_ID, loading failed!", ELL_ERROR); - return 0; - } - - file->read(&vertsNum, sizeof(vertsNum)); - Vertex.set_used(vertsNum); - file->read(Vertex.pointer(), sizeof(SMyVertex)*vertsNum); - - // faces - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - if (id!=MY3D_FACES_ID) - { - os::Printer::log("Can not find MY3D_FACES_ID, loading failed!", ELL_ERROR); - return 0; - } - - file->read(&facesNum, sizeof(facesNum)); - Face.set_used(facesNum); - file->read(Face.pointer(), sizeof(SMyFace)*facesNum); - - // reading texture channels - for (s32 tex=0; tex<(s32)meshHeader.TChannelCnt; tex++) - { - // Max 2 texture channels allowed (but in format .my3d can be more) - s32 tVertsNum=0, tFacesNum=0; - - // reading texture coords - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - if (id!=MY3D_TVERTS_ID) - { - core::stringc msg="Can not find MY3D_TVERTS_ID ("; - msg.append(core::stringc(tex)); - msg.append("texture channel), loading failed!"); - os::Printer::log(msg.c_str(), ELL_ERROR); - return 0; - } - - file->read(&tVertsNum, sizeof(tVertsNum)); - - if (tex==0) - { - // 1st texture channel - TVertex1.set_used(tVertsNum); - file->read(TVertex1.pointer(), sizeof(SMyTVertex)*tVertsNum); - } - else - if (tex==1) - { - // 2nd texture channel - TVertex2.set_used(tVertsNum); - file->read(TVertex2.pointer(), sizeof(SMyTVertex)*tVertsNum); - } - else - { - // skip other texture channels - file->seek(file->getPos()+sizeof(SMyTVertex)*tVertsNum); - } - - // reading texture faces - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - - if (id!=MY3D_TFACES_ID) - { - core::stringc msg="Can not find MY3D_TFACES_ID ("; - msg.append(core::stringc(tex)); - msg.append("texture channel), loading failed!"); - os::Printer::log(msg.c_str(), ELL_ERROR); - return 0; - } - - file->read(&tFacesNum, sizeof(tFacesNum)); - - if (tex==0) - { - // 1st texture channel - TFace1.set_used(tFacesNum); - file->read(TFace1.pointer(), sizeof(SMyFace)*tFacesNum); - } - else if (tex==1) - { - // 2nd texture channel - TFace2.set_used(tFacesNum); - file->read(TFace2.pointer(), sizeof(SMyFace)*tFacesNum); - } - else - { - // skip other texture channels - file->seek(file->getPos()+sizeof(SMyFace)*tFacesNum); - } - } - - // trying to find material - - SMyMaterialEntry* matEnt = getMaterialEntryByIndex(meshHeader.MatIndex); - - // creating geometry for the mesh - - // trying to find mesh buffer for this material - SMeshBufferLightMap* buffer = getMeshBufferByMaterialIndex(meshHeader.MatIndex); - - if (!buffer || - (buffer->Vertices.size()+vertsNum) > SceneManager->getVideoDriver()->getMaximalPrimitiveCount()) - { - // creating new mesh buffer for this material - buffer = new scene::SMeshBufferLightMap(); - - buffer->Material.MaterialType = video::EMT_LIGHTMAP_M2; // EMT_LIGHTMAP_M4 also possible - buffer->Material.Wireframe = false; - buffer->Material.Lighting = false; - - if (matEnt) - { - buffer->Material.MaterialType = matEnt->MaterialType; - - if (buffer->Material.MaterialType == video::EMT_REFLECTION_2_LAYER) - { - buffer->Material.Lighting = true; - buffer->Material.setTexture(1, matEnt->Texture1); - buffer->Material.setTexture(0, matEnt->Texture2); - } - else - { - buffer->Material.setTexture(0, matEnt->Texture1); - buffer->Material.setTexture(1, matEnt->Texture2); - } - - if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL) - { - buffer->Material.BackfaceCulling = true; - buffer->Material.Lighting = true; - } - else - if (buffer->Material.MaterialType == video::EMT_SPHERE_MAP) - { - buffer->Material.Lighting = true; - } - - buffer->Material.AmbientColor = video::SColor( - matEnt->Header.AmbientColor.A, matEnt->Header.AmbientColor.R, - matEnt->Header.AmbientColor.G, matEnt->Header.AmbientColor.B - ); - buffer->Material.DiffuseColor = video::SColor( - matEnt->Header.DiffuseColor.A, matEnt->Header.DiffuseColor.R, - matEnt->Header.DiffuseColor.G, matEnt->Header.DiffuseColor.B - ); - buffer->Material.EmissiveColor = video::SColor( - matEnt->Header.EmissiveColor.A, matEnt->Header.EmissiveColor.R, - matEnt->Header.EmissiveColor.G, matEnt->Header.EmissiveColor.B - ); - buffer->Material.SpecularColor = video::SColor( - matEnt->Header.SpecularColor.A, matEnt->Header.SpecularColor.R, - matEnt->Header.SpecularColor.G, matEnt->Header.SpecularColor.B - ); - } - else - { - buffer->Material.setTexture(0, 0); - buffer->Material.setTexture(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); - } - - if (matEnt && matEnt->Header.Transparency!=0) - { - if (buffer->Material.MaterialType == video::EMT_REFLECTION_2_LAYER ) - { - buffer->Material.MaterialType = video::EMT_TRANSPARENT_REFLECTION_2_LAYER; - buffer->Material.Lighting = true; - buffer->Material.BackfaceCulling = true; - } - else - { - buffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; - buffer->Material.Lighting = false; - buffer->Material.BackfaceCulling = false; - } - } - else if ( - !buffer->Material.getTexture(1) && - buffer->Material.MaterialType != video::EMT_TRANSPARENT_ALPHA_CHANNEL && - buffer->Material.MaterialType != video::EMT_SPHERE_MAP) - { - buffer->Material.MaterialType = video::EMT_SOLID; - buffer->Material.Lighting = true; - } - - MeshBufferEntry.push_back( - SMyMeshBufferEntry(meshHeader.MatIndex, buffer)); - } - - video::S3DVertex2TCoords VertexA, VertexB, VertexC; - - // vertices (A, B, C) color - video::SColor vert_color; - if (matEnt && - (buffer->Material.MaterialType == video::EMT_TRANSPARENT_VERTEX_ALPHA || - buffer->Material.MaterialType == video::EMT_TRANSPARENT_REFLECTION_2_LAYER)) - { - video::SColor color( - matEnt->Header.DiffuseColor.A, matEnt->Header.DiffuseColor.R, - matEnt->Header.DiffuseColor.G, matEnt->Header.DiffuseColor.B); - - vert_color = color.getInterpolated(video::SColor(0,0,0,0), - 1-matEnt->Header.Transparency); - } - else - { - vert_color = buffer->Material.DiffuseColor; - } - - VertexA.Color = VertexB.Color = VertexC.Color = vert_color; - - if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL) - { - buffer->Indices.reallocate(buffer->Indices.size()+6*facesNum); - buffer->Vertices.reallocate(buffer->Vertices.size()+6*facesNum); - } - else - { - buffer->Indices.reallocate(buffer->Indices.size()+3*facesNum); - buffer->Vertices.reallocate(buffer->Vertices.size()+3*facesNum); - } - for (int f=0; f0) - { - VertexA.TCoords.X = TVertex1[TFace1[f].C].TCoord.X; - VertexA.TCoords.Y = TVertex1[TFace1[f].C].TCoord.Y; - } - - if (meshHeader.TChannelCnt>1) - { - VertexA.TCoords2.X = TVertex2[TFace2[f].C].TCoord.X; - VertexA.TCoords2.Y = TVertex2[TFace2[f].C].TCoord.Y; - } - - // vertex B - - VertexB.Pos.X = Vertex[Face[f].B].Coord.X; - VertexB.Pos.Y = Vertex[Face[f].B].Coord.Y; - VertexB.Pos.Z = Vertex[Face[f].B].Coord.Z; - - VertexB.Normal.X = Vertex[Face[f].B].Normal.X; - VertexB.Normal.Y = Vertex[Face[f].B].Normal.Y; - VertexB.Normal.Z = Vertex[Face[f].B].Normal.Z; - - if (meshHeader.TChannelCnt>0) - { - VertexB.TCoords.X = TVertex1[TFace1[f].B].TCoord.X; - VertexB.TCoords.Y = TVertex1[TFace1[f].B].TCoord.Y; - } - - if (meshHeader.TChannelCnt>1) - { - VertexB.TCoords2.X = TVertex2[TFace2[f].B].TCoord.X; - VertexB.TCoords2.Y = TVertex2[TFace2[f].B].TCoord.Y; - } - - // vertex C - - VertexC.Pos.X = Vertex[Face[f].A].Coord.X; - VertexC.Pos.Y = Vertex[Face[f].A].Coord.Y; - VertexC.Pos.Z = Vertex[Face[f].A].Coord.Z; - - VertexC.Normal.X = Vertex[Face[f].A].Normal.X; - VertexC.Normal.Y = Vertex[Face[f].A].Normal.Y; - VertexC.Normal.Z = Vertex[Face[f].A].Normal.Z; - - if (meshHeader.TChannelCnt>0) - { - VertexC.TCoords.X = TVertex1[TFace1[f].A].TCoord.X; - VertexC.TCoords.Y = TVertex1[TFace1[f].A].TCoord.Y; - } - if (meshHeader.TChannelCnt>1) - { - VertexC.TCoords2.X = TVertex2[TFace2[f].A].TCoord.X; - VertexC.TCoords2.Y = TVertex2[TFace2[f].A].TCoord.Y; - } - - // store 3d data in mesh buffer - - buffer->Indices.push_back(buffer->Vertices.size()); - buffer->Vertices.push_back(VertexA); - - buffer->Indices.push_back(buffer->Vertices.size()); - buffer->Vertices.push_back(VertexB); - - buffer->Indices.push_back(buffer->Vertices.size()); - buffer->Vertices.push_back(VertexC); - - //***************************************************************** - // !!!!!! W A R N I N G !!!!!!! - //***************************************************************** - // For materials with alpha channel we duplicate all faces. - // This has be done for proper lighting calculation of the back faces. - // So you must remember this while you creating your models !!!!! - //***************************************************************** - // !!!!!! W A R N I N G !!!!!!! - //***************************************************************** - - if (buffer->Material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL) - { - VertexA.Normal = core::vector3df(-VertexA.Normal.X, -VertexA.Normal.Y, -VertexA.Normal.Z); - VertexB.Normal = core::vector3df(-VertexB.Normal.X, -VertexB.Normal.Y, -VertexB.Normal.Z); - VertexC.Normal = core::vector3df(-VertexC.Normal.X, -VertexC.Normal.Y, -VertexC.Normal.Z); - - buffer->Indices.push_back(buffer->Vertices.size()); - buffer->Vertices.push_back(VertexC); - - buffer->Indices.push_back(buffer->Vertices.size()); - buffer->Vertices.push_back(VertexB); - - buffer->Indices.push_back(buffer->Vertices.size()); - buffer->Vertices.push_back(VertexA); - } - } - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - } - - // creating mesh - SMesh* mesh = new SMesh(); - - for (u32 num=0; numaddMeshBuffer(buffer); - - buffer->recalculateBoundingBox(); - buffer->drop(); - } - - mesh->recalculateBoundingBox(); - - if (id != MY3D_FILE_END_ID) - os::Printer::log("Loading finished, but can not find MY3D_FILE_END_ID token.", ELL_WARNING); - - SAnimatedMesh* am = new SAnimatedMesh(); - - am->addMesh(mesh); - mesh->drop(); - am->recalculateBoundingBox(); - - return am; -} - - -video::ITexture* CMY3DMeshFileLoader::readEmbeddedLightmap(io::IReadFile* file, char* namebuf) -{ - static int LightMapIndex=0; - u16 id; - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - if (id!=MY3D_TEXDATA_HEADER_ID) - { - os::Printer::log("Can not find MY3D_TEXDATA_HEADER_ID, loading failed!", ELL_ERROR); - return 0; - } - - SMyTexDataHeader texDataHeader; - - file->read(&texDataHeader, sizeof(SMyTexDataHeader)); - - strcpy(texDataHeader.Name, namebuf); - - char LightMapName[255]; - sprintf(LightMapName,"My3D.Lightmap.%d",++LightMapIndex); - - core::stringc pixFormatStr; - if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24) - pixFormatStr = "24bit,"; - else - if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_16) - pixFormatStr = "16bit,"; - else - { - core::stringc msg="Unknown format of image data ("; - msg.append(LightMapName); - msg.append("), loading failed!"); - os::Printer::log(msg.c_str(), ELL_ERROR); - return 0; - } - - if (texDataHeader.ComprMode != MY3D_TEXDATA_COMPR_NONE_ID && - texDataHeader.ComprMode != MY3D_TEXDATA_COMPR_RLE_ID && - texDataHeader.ComprMode != MY3D_TEXDATA_COMPR_SIMPLE_ID ) - { - os::Printer::log("Unknown method of compression image data, loading failed!", ELL_ERROR); - return 0; - } - - const u32 num_pixels = texDataHeader.Width*texDataHeader.Height; - - void* data = 0; - - if (texDataHeader.ComprMode==MY3D_TEXDATA_COMPR_NONE_ID) - { - // none compressed image data - if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24) - { - 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==MY3D_TEXDATA_COMPR_RLE_ID) - { - // read RLE header identificator - file->read(&id, sizeof(id)); -#ifdef __BIG_ENDIAN__ - id = os::Byteswap::byteswap(id); -#endif - if (id!=MY3D_TEXDATA_RLE_HEADER_ID) - { - os::Printer::log("Can not find MY3D_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==MY3D_TEXDATA_COMPR_SIMPLE_ID) - { - // simple compressed image data - if (texDataHeader.PixelFormat == MY3D_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 == MY3D_PIXEL_FORMAT_24) - { - SMyPixelColor24 col24; - file->read(&col24, sizeof(SMyPixelColor24)); - for (u32 p=0; pread(&col16, sizeof(SMyPixelColor16)); - for (u32 p=0; p= num_pixels) - break; - } - - if (nReadedPixels != num_pixels) - { - os::Printer::log("Image data seems to be corrupted, loading failed!", ELL_ERROR); - return 0; - } - } - - //! Creates a software image from a byte array. - video::IImage* light_img = 0; - - if (texDataHeader.PixelFormat == MY3D_PIXEL_FORMAT_24) - { - // 24 bit lightmap format - light_img = SceneManager->getVideoDriver()->createImageFromData( - video::ECF_R8G8B8, - core::dimension2d(texDataHeader.Width, texDataHeader.Height), - data, true); - } - else - { - // 16 bit lightmap format - light_img = SceneManager->getVideoDriver()->createImageFromData( - video::ECF_A1R5G5B5, - core::dimension2d(texDataHeader.Width, texDataHeader.Height), - data, true); - } - - const bool oldMipMapState = SceneManager->getVideoDriver()->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); - SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); - video::ITexture* lmtex = SceneManager->getVideoDriver()->addTexture(LightMapName, light_img); - SceneManager->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, oldMipMapState); - - light_img->drop(); - return lmtex; -} - - -CMY3DMeshFileLoader::SMyMaterialEntry* CMY3DMeshFileLoader::getMaterialEntryByIndex(u32 matInd) -{ - for (u32 m=0; m& CMY3DMeshFileLoader::getChildNodes() const -{ - return ChildNodes; -} - - -} // end namespace scnene -} // end namespace irr - -#endif // _IRR_COMPILE_WITH_MY3D_LOADER_ - diff --git a/lib/irrlicht/source/Irrlicht/CMY3DMeshFileLoader.h b/lib/irrlicht/source/Irrlicht/CMY3DMeshFileLoader.h deleted file mode 100644 index 716478db3..000000000 --- a/lib/irrlicht/source/Irrlicht/CMY3DMeshFileLoader.h +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (C) 2002-2012 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. -// I (Nikolaus Gebhardt) did some few changes to this: -// - replaced logging calls to their os:: counterparts -// - removed some logging calls -// - removed setTexture path and replaced it with the directory of the mesh -// - added EAMT_MY3D file type -// - fixed a memory leak when decompressing RLE data. -// - cleaned multi character constant problems with gcc -// - removed octree child scene node generation because irrlicht is now able to draw -// scene nodes with transparent and sold materials in them at the same time. (see changes.txt) -// Thanks a lot to ZDimitor for his work on this and that he gave me -// his permission to add it into Irrlicht. - -//-------------------------------------------------------------------------------- -// This tool created by ZDimitor everyone can use it as wants -//-------------------------------------------------------------------------------- - -#ifndef __CMY3D_MESH_FILE_LOADER_H_INCLUDED__ -#define __CMY3D_MESH_FILE_LOADER_H_INCLUDED__ - - -#ifdef _MSC_VER -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 -#endif - - -#include "IMeshLoader.h" -#include "SMesh.h" -#include "SMeshBufferLightMap.h" -#include "IFileSystem.h" -#include "IVideoDriver.h" -#include "irrString.h" -#include "ISceneManager.h" - -namespace irr -{ -namespace scene -{ - -// byte-align structures -#include "irrpack.h" - -struct SMyColor -{ SMyColor () {;} - SMyColor (s32 __R, s32 __G, s32 __B, s32 __A) - : R(__R), G(__G), B(__B), A(__A) {} - s32 R, G, B, A; -} PACK_STRUCT; - -// material header -struct SMyMaterialHeader -{ c8 Name[256]; // material name - u32 Index; - SMyColor AmbientColor; - SMyColor DiffuseColor; - SMyColor EmissiveColor; - SMyColor SpecularColor; - f32 Shininess; - f32 Transparency; - u32 TextureCount; // texture count -} PACK_STRUCT; - -// Default alignment -#include "irrunpack.h" - -class CMY3DMeshFileLoader : public IMeshLoader -{ -public: - CMY3DMeshFileLoader(ISceneManager *scmgr, io::IFileSystem* fs); - virtual ~CMY3DMeshFileLoader(); - - virtual bool isALoadableFileExtension(const io::path& filename) const; - - virtual IAnimatedMesh* createMesh(io::IReadFile* file); - - //! getting access to the nodes (with transparent material), creating - //! while loading .my3d file - const core::array& getChildNodes() const; - -private: - - video::ITexture* readEmbeddedLightmap(io::IReadFile* file, char* namebuf); - - scene::ISceneManager* SceneManager; - io::IFileSystem* FileSystem; - - struct SMyMaterialEntry - { - SMyMaterialEntry () - : Texture1FileName("null"), Texture2FileName("null"), - Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {} - - SMyMaterialHeader Header; - core::stringc Texture1FileName; - core::stringc Texture2FileName; - video::ITexture *Texture1; - video::ITexture *Texture2; - video::E_MATERIAL_TYPE MaterialType; - }; - - struct SMyMeshBufferEntry - { - SMyMeshBufferEntry() : MaterialIndex(-1), MeshBuffer(0) {} - SMyMeshBufferEntry(s32 mi, SMeshBufferLightMap* mb) - : MaterialIndex(mi), MeshBuffer(mb) {} - - s32 MaterialIndex; - SMeshBufferLightMap* MeshBuffer; - }; - - SMyMaterialEntry* getMaterialEntryByIndex (u32 matInd); - SMeshBufferLightMap* getMeshBufferByMaterialIndex(u32 matInd); - - core::array MaterialEntry; - core::array MeshBufferEntry; - - core::array ChildNodes; -}; - - -} // end namespace scene -} // end namespace irr - - -#endif // __CMY3D_MESH_FILE_LOADER_H_INCLUDED__ diff --git a/lib/irrlicht/source/Irrlicht/CSceneManager.cpp b/lib/irrlicht/source/Irrlicht/CSceneManager.cpp index 204a44d30..ce82551a5 100644 --- a/lib/irrlicht/source/Irrlicht/CSceneManager.cpp +++ b/lib/irrlicht/source/Irrlicht/CSceneManager.cpp @@ -56,10 +56,6 @@ #include "CLMTSMeshFileLoader.h" #endif -#ifdef _IRR_COMPILE_WITH_MY3D_LOADER_ -#include "CMY3DMeshFileLoader.h" -#endif - #ifdef _IRR_COMPILE_WITH_OGRE_LOADER_ #include "COgreMeshFileLoader.h" #endif @@ -208,9 +204,6 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, #ifdef _IRR_COMPILE_WITH_STL_LOADER_ MeshLoaderList.push_back(new CSTLMeshFileLoader()); #endif - #ifdef _IRR_COMPILE_WITH_MY3D_LOADER_ - MeshLoaderList.push_back(new CMY3DMeshFileLoader(this, FileSystem)); - #endif #ifdef _IRR_COMPILE_WITH_OGRE_LOADER_ MeshLoaderList.push_back(new COgreMeshFileLoader(FileSystem, Driver)); #endif