irrlicht/source/Irrlicht/CLWOMeshFileLoader.cpp

2085 lines
52 KiB
C++
Raw Normal View History

// Copyright (C) 2007-2009 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CLWOMeshFileLoader.h"
#include "os.h"
#include "SAnimatedMesh.h"
#include "SMesh.h"
#include "IReadFile.h"
#include "ISceneManager.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "IMeshManipulator.h"
namespace irr
{
namespace scene
{
#ifdef _DEBUG
#define LWO_READER_DEBUG
#endif
#define charsToUIntD(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
inline unsigned int charsToUInt(const char *str)
{
return (str[0] << 24) | (str[1] << 16) | (str[2] << 8) | str[3];
}
struct tLWOTextureInfo
{
tLWOTextureInfo() : UVTag(0), DUVTag(0), Flags(0), WidthWrap(2),
HeightWrap(2), OpacType(0), Color(0xffffffff),
Value(0.0f), AntiAliasing(1.0f), Opacity(1.0f),
Axis(255), Projection(0), Active(false) {}
core::stringc Type;
core::stringc Map;
core::stringc AlphaMap;
core::stringc UVname;
u16 UVTag;
u16 DUVTag;
u16 Flags;
u16 WidthWrap;
u16 HeightWrap;
u16 OpacType;
u16 IParam[3];
core::vector3df Size;
core::vector3df Center;
core::vector3df Falloff;
core::vector3df Velocity;
video::SColor Color;
f32 Value;
f32 AntiAliasing;
f32 Opacity;
f32 FParam[3];
u8 Axis;
u8 Projection;
bool Active;
};
struct CLWOMeshFileLoader::tLWOMaterial
{
tLWOMaterial() : Meshbuffer(0), TagType(0), Flags(0), ReflMode(3), TranspMode(3),
Glow(0), AlphaMode(2), Luminance(0.0f), Diffuse(1.0f), Specular(0.0f),
Reflection(0.0f), Transparency(0.0f), Translucency(0.0f),
Sharpness(0.0f), ReflSeamAngle(0.0f), ReflBlur(0.0f),
RefrIndex(1.0f), TranspBlur(0.0f), SmoothingAngle(0.0f),
EdgeTransparency(0.0f), HighlightColor(0.0f), ColorFilter(0.0f),
AdditiveTransparency(0.0f), GlowIntensity(0.0f), GlowSize(0.0f),
AlphaValue(0.0f), VertexColorIntensity(0.0f), VertexColor() {}
core::stringc Name;
scene::SMeshBuffer *Meshbuffer;
core::stringc ReflMap;
u16 TagType;
u16 Flags;
u16 ReflMode;
u16 TranspMode;
u16 Glow;
u16 AlphaMode;
f32 Luminance;
f32 Diffuse;
f32 Specular;
f32 Reflection;
f32 Transparency;
f32 Translucency;
f32 Sharpness;
f32 ReflSeamAngle;
f32 ReflBlur;
f32 RefrIndex;
f32 TranspBlur;
f32 SmoothingAngle;
f32 EdgeTransparency;
f32 HighlightColor;
f32 ColorFilter;
f32 AdditiveTransparency;
f32 GlowIntensity;
f32 GlowSize;
f32 AlphaValue;
f32 VertexColorIntensity;
video::SColorf VertexColor;
u32 Envelope[23];
tLWOTextureInfo Texture[7];
};
struct tLWOLayerInfo
{
u16 Number;
u16 Parent;
u16 Flags;
bool Active;
core::stringc Name;
core::vector3df Pivot;
};
//! Constructor
CLWOMeshFileLoader::CLWOMeshFileLoader(scene::ISceneManager* smgr,
io::IFileSystem* fs)
: SceneManager(smgr), FileSystem(fs), File(0), Mesh(0)
{
#ifdef _DEBUG
setDebugName("CLWOMeshFileLoader");
#endif
}
//! destructor
CLWOMeshFileLoader::~CLWOMeshFileLoader()
{
if (Mesh)
Mesh->drop();
}
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".bsp")
Changes in version 1.6, TA - FileSystem 2.0 SUPER MASTER MAJOR API CHANGE !!! The FileSystem is know build internally like for e.q the texture-, and the meshloaders. There exists a known list of ArchiveLoader, which know how to produce a Archive. The Loaders and the Archive can be attached/detached on runtime. The FileNames are now stored as core::string<c16>. where c16 is toggled between char/wchar with the #define flag _IRR_WCHAR_FILESYSTEM, to supported unicode backends (default:off) I replaced all (const c8* filename) to string references. Basically the FileSystem is divided into two regions. Native and Virtual. Native means using the backend OS. Virtual means only use currently attach IArchives. Browsing each FileSystem has it's own workdirectory and it's own methods to - create a FileTree - add/remove files & directory ( to be done ) Hint: store a savegame in a zip archive... basic browsing for all archives is implemented. Example 21. Quake3Explorer shows this TODO: - a file filter should be implemented. - The IArchive should have a function to create a filetree for now CFileList is used. Class Hiarchy: IArchiveLoader: is able to produce a IFileArchive - ZipLoader - PakLoader - MountPointReader ( formaly known as CUnzipReader ) IFileArchive: -ZipArchive -PakArchive -MountPoint (known as FolderFile) IFileSystem - addArchiveLoader - changed implementation of isALoadableFileExtension in all loaders to have consistent behavior - added a parameter to IFileList * createFileList setFileListSystem allows to query files in any of the game archives standard behavior listtype = SYSTEM ( default) - CLimitReadFile added multiple file random-access support. solved problems with mixed compressed & uncompressed files in a zip TODO: - Big Big Testing!! - Linux Version ( minor ) - remove all double loader interfaces where only the filename differs (IReadFile/const char *filename). This blows up the the interface - many loaders use their own private filesearching we should rework this - there are a lot of helper function ( getAbsolutePath, getFileDir ) which should be adapted to the virtual filesystem - IrrlichtDevice added: virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ) = 0; virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue ) = 0; and calculating methods to DeviceStub. implemented in Win32, TODO: other Devices - irrlicht.h changed exported irrlicht.dll routines createDevice, createDeviceEx, IdentityMatrix to extern "C" name mangling. for easier dynamically loading the irrlicht library and different versions - ParticleSystem removed the private (old?,wrong?) interface from the ParticleEffectors to match the parent class irr::io::IAttributeExchangingObject::deserializeAttributes TODO: please test if the serialization works! - Generic - vector3d<T>& normalize() #if 0 f32 length = (f32)(X*X + Y*Y + Z*Z); if (core::equals(length, 0.f)) return *this; length = core::reciprocal_squareroot ( (f32)length ); #else const T length = core::reciprocal_squareroot ( (X*X + Y*Y + Z*Z) ); #endif Weak checking on zero?!?! just to avoid a sqrt?. mhm, maybe not;-) added reciprocal_squareroot for f64 - dimension2d added operator dimension2d<T>& operator=(const dimension2d<U>& other) to cast between different types - vector2d bugfix: vector2d<T>& operator+=(const dimension2d<T>& other) { X += other.Width; Y += other.Width; return *this; } to vector2d<T>& operator+=(const dimension2d<T>& other) { X += other.Width; Y += other.Height; return *this; } - C3DMeshLoader renamed chunks const u16 to a enum removing "variable declared but never used warning" - added a global const identity Material changed all references *((video::SMaterial*)0) to point to IdentityMaterial removed warning: "a NULL reference is not allowed" - modified IRRLICHT_MATH to not support reciprocal stuff but to use faster float-to-int conversion. gcc troubles may they are. i'm using intel-compiler..;-) - core::matrix4 USE_MATRIX_TEST i tried to optimize the identity-check ( in means of performance) i didn't succeed so well, so i made a define for the matrix isIdentity -check for now it's sometimes faster to always calculate versus identity-check but if there are a lot of scenenodes/ particles one can profit from the fast_inverse matrix, when no scaling is used. further approvement could be done on inverse for just tranlastion! ( many static scenenodes are not rotated, they are just placed somewhere in the world) one thing to take in account is that sizeof(matrix) is 64 byte and with the additional bool/u32 makes it 66 byte which is not really cache-friendly.. - added buildRotateFromTo Builds a matrix that rotates from one vector to another - irr::array. changed allocating routine in push_back okt, 2008. it's only allowed to alloc one element, if default constructor has to be called. removes existing crashes. ( MD3 Mesh ) and possible others ones. A new list template should be made. one with constructor/destructor calls ( safe_array ) and one without. like the array since the beginning of irrlicht. currently the array/string is extremly slow.. also a hint for the user has to be done, so that a struct T of array<T> must have a copy constructor of type T ( const T&other ). i needed hours to track that down... added a new method setAllocStrategy, safe ( used + 1 ), double ( used * 2 + 1) better default strategies will be implemented - removed binary_search_const i added it quite a long time ago, but it doesnt make real sense a call to a sort method should happen always. i just wanted to safe a few cycles.. - added binary_search_multi searches for a multi-set ( more than 1 entry in the sorted array) returns start and end-index - changed some identity matrix settings to use core::IdentityMatrix - added deletePathFromFilename to generic string functions in coreutil.h and removed from CZipReader and CPakReader - s32 deserializeAttributes used instead of virtual void deserializeAttributes in ParticleSystem ( wrong virtual was used) - strings & Locale - started to add locale support - added verify to string - added some helper functions - XBOX i have access to a XBOX development machine now. I started to compile for the XBOX. Question: Who did the previous implementation?. There is no XBOX-Device inhere. maybe it's forbidden because of using the offical Microsoft XDK. I will implement a native or sdl device based on opendk. irrlicht compiles without errors on the xbox but can't be used. TODO: - native XBOX Device - Windows Mobile reworked a little. added the mobile example to the windows solution for cross development. added maximal 128x128 texture size for windows mobile ( memory issues ) - Collision Speed Up The Collision Speed Up greatly improves with many small static child-nodes - added COctTreeTriangleSelector::getTriangles for 3dline from user Piraaate - modified createOctTreeTriangleSelector and createTriangleSelector to allow node == 0, to be added to a meta selector - CSceneNodeAnimatorCollisionResponse has the same problem as CSceneNodeAnimatorFPS on first update: Problem. you start setting the map. (setWorld). First update cames 4000 ms later. The Animator applies the missing force... big problem... changed to react on first update like camera. - add Variable FirstUpdate. if set to true ( on all changes ) then position, lasttime, and falling are initialized -added #define OCTTREE_USE_HARDWARE in Octree.h if defined octtree uses internally a derived scene::MeshBuffer which has the possibility to use the Hardware Vertex Buffer for static vertices and dirty indices;-) if defined OCTTREE_USE_HARDWARE octree uses internally a derived scene::CMeshBuffer so it's not just a replacement inside the octree. It also in the OctTreeSceneNode. #if defined (OCTTREE_USE_HARDWARE) driver->drawMeshBuffer ( &LightMapMeshes[i] ); #else driver->drawIndexedTriangleList( &LightMapMeshes[i].Vertices[0], LightMapMeshes[i].Vertices.size(), d[i].Indices, d[i].CurrentSize / 3); #endif #define OCTTREE_PARENTTEST is also used. It's skip testing on fully outside and takes everything on fully inside - virtual void ISceneNode::updateAbsolutePosition() - changed inline CMatrix4<T> CMatrix4<T>::operator*(const CMatrix4<T>& m2) const all two matrices have to be checked by isIdentity() to let the isIdentity work always -changed inline bool CMatrix4<T>::isIdentity() const on full identityCheck-> to look first on Translation, because this is the most challenging element which will likely not to be identity.. - virtual core::matrix4 getRelativeTransformation() const Hiarchy on Identity-Check 1) ->getRelativeTransform -> 9 floating point checks to be passed as Identity 2) ->isIdentity () -> 16 floating point checks to be passed as Identity - inline void CMatrix4<T>::transformBoxEx(core::aabbox3d<f32>& box) const added isIdentity() check - changed CSceneNodeAnimatorCollisionResponse - added CSceneNodeAnimatorCollisionResponse::setGravity needed to set the differents Forces for the Animator. for eq. water.. - added CSceneNodeAnimatorCollisionResponse::setAnimateTarget - added CSceneNodeAnimatorCollisionResponse::getAnimateTarget - changed CSceneNodeAnimatorCollisionResponse::animateNode to react on FirstUpdate - changad Gravity to - TODO: set Gravity to Physically frame independent values.. current response uses an frame depdended acceleration vector. ~9.81 m/s^2 was achieved at around 50 fps with a setting of -0.03 may effect existing application.. - SceneNodes - CSkyDomeSceneNode moved radius ( default 1000 ) to constructor added Normals added DebugInfo added Material.ZBuffer, added SceneMaanager - CVolumeLightSceneNode: changed default blending OneTextureBlendgl_src_color gl_src_alpha to EMT_TRANSPARENT_ADD_COLOR ( gl_src_color gl_one ) which gives the same effect on non-transparent-materials. Following the unspoken guide-line, lowest effect as default - added LensFlareSceneNode (from forum user gammaray, modified to work ) showing in example special fx - changed SceneNode Skydome f64 to f32, - AnimatedMesh -Debug Data: mesh normals didn't rotate with the scenenode fixed ( matrix-multiplication order) - Camera SceneNode setPosition Camera now finally allow to change position and target and updates all effected animators.. a call to OnAnimate ( ) lastime < time or OnAnimate ( 0 ) will reset the camera and fr. the collision animator to a new position - Device: added the current mousebutton state to the Mouse Event so i need to get the current mouse state from the OS -a dded to CIrrDeviceWin32 TODO: - Linux and SDL Device - GUI - CGUIFont: - added virtual void setInvisibleCharacters( const wchar_t *s ) = 0; define which characters should not be drawn ( send to driver) by the font. for example " " would not draw any space which is usually blank in most fonts and saves rendering of ususally full blank alpha-sprites. This saves a lot of rendering... default: setInvisibleCharacters ( L" " ); - added MultiLine rendering should avoid to us CStaticText breaking text in future - CGUIListBox - changed Scrollbar LargeStepSize to ItemHeight which easy enables to scroll line by line - CGUIScrollBar bug: Create a Window and inside a listbox with a scrollbar or a windowed irrlicht application Click & hold Scrollbar Slider. move outside it's region. Release Mouse. Go Back to Scrollbar.. it's moving always... it's generally missing the event PRESSED_MOVED, which leads to problem when an element is dragging, has a focus, or position loose and gets focus back again. ( think of a drunken mouse sliding left&right during tracking ) so added the mouse Input Buttonstates on every mouse event IrrDeviceWin32: added event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON | MK_MBUTTON ); TODO: Linux & SDL so now i can do this case irr::EMIE_MOUSE_MOVED: if ( !event.MouseInput.isLeftPressed () ) { Dragging = false; } - bug: Scrollbar notifyListBox notify when the scrollbar is clicked. - changed timed event in draw to OnPostRender Why the hell is a gui element firing a timed event in a draw routine!!!!!. This should be corrected for all gui-elements. - added GUI Image List from Reinhard Ostermeier, modified to work added GUI Tree View from Reinhard Ostermeier, modified to work shown in the Quake3MapShader Example TODO: Spritebanks - FileOpenDialog changed the static text for the filename to an edit box. - changed the interface for addEditBox to match with addStaticText - changed the interface for addSpinBox to match with addEditBox - added MouseWheel to Spinbox - changed CGUITable CLICK_AREA from 3 to 12 to enable clicking on the visible marker - CGUISpritebank removed some crashes with empty Sprite banks - IGUIScrollBar added SetMin before min was always 0 changed ScrollWheel Direction on horizontal to move right on wheel up, left on wheel down - IComboBox -added ItemData - removed IsVisbile check in IGUIElement::draw - Image Loaders - added TGA file type 2 ( grayscale uncompressed ) - added TGA file type (1) 8 Bit indexed color uncompressed ColorConverter: - added convert_B8G8R8toA8R8G8B8 - added convert_B8G8R8A8toA8R8G8B8 - Media Files - added missing shaders and textures to map-20kdm2. Taken from free implementation - ball.wav. adjusted DC-Offset, amplified to -4dB, trim cross-zero - impact.wav clip-restoration, trim cross-zero - added gun.md2, gun.pcx to media-files copyright issues!. i don't know from where this file came from... i hope this is not from original quake2.. - added new irrlicht logo irrlicht3.png i've taken the new layout. i should ask niko to use it. - added Skydome picture to media files (skydome2.jpg) half/sphere - OctTree -added #define OCTTREE_PARENTTEST ( default: disabled ) used to leave-out children test if the parent passed a complete frustum. plus: leaves out children test minus: all edges have to be checked - added MesBuffer Hardware Hint Vertex to octtree - CQuake3ShaderSceneNode: - removed function releaseMesh Shader doesn't copy the original mesh anymore ( saving memory ) so therefore this (for others often misleading ) function was removed - changed constructor to take a (shared) destination meshbuffer for rendering reducing vertex-memory to a half - don't copy the original vertices anymore - added deformvertexes autosprite - added deformvertexes move - added support for RTCW and Raven BSPs ( qmap2 ) - added polygonoffset (TODO: not perfect) - added added nomipmaps - added rgbgen const - added alphagen - added MesBuffer Hardware Hint Vertex/Index to Quake3: static geometry, dynamic indices - added Quake3Explorer examples - added wave noise - added tcmod transform - added whiteimage - added collision to Quake3Explorer - renamed SMD3QuaterionTag* to SMD3QuaternionTag* ( typo ) - updated quake3:blendfunc - added crouch to Quake3Explorer (modifying the ellipsiodRadius of the camera animator ) added crouch to CSceneNodeAnimatorCameraFPS still problems with stand up and collision - Quake3MapLoader modified memory allocation for faster loading - Quake3LoadParam added Parameter to the Mesh-Loader - added The still existing missing caulking of curved surfaces. using round in the coordinates doesn't solve the problem. but for the demo bsp mesh it solves the problem... (luck) so for now it's switchable. TJUNCTION_SOLVER_ROUND default:off - BurningVideo - pushed BurningsVideo to 0.40 - added blendfunc gl_one_minus_dst_alpha gl_one - added blendfunc gl_dst_color gl_zero - added blendfunc gl_dst_color src_alpha - modified AlphaChannel_Ref renderer to support alpha test lessequal - addded 32 Bit Index Buffer - added sourceRect/destRect check to 2D-Blitter ( slower, but resolves crash ) - added setTextureCreationFlag video::ETCF_ALLOW_NON_POWER_2 Burning checks this flag and when set, it bypasses the power2 size check, which is necessary on 3D but can be avoided on 2D. used on fonts automatically. - added Support for Destination Alpha - OpenGL - Fixed a bug in COpenGLExtensenionHandler where a glint was downcasted to u8!!!!!! MaxTextureSize=static_cast<u32>(num); - TODO: COpenGLMaterialRenderer_ONETEXTURE_BLEND to work as expected - Direct3D8 - compile and links again - added 32 Bit Index Buffer - D3DSAMP_MIPMAPLODBIAS doesnt compile!. it is d3d9 i think. - compile for XBOX - Direc3D9 - fixed crash on RTT Textures DepthBuffer freed twice. added deleteAllTextures to destuctor - NullDriver - removeallTextures. added setMaterial ( SMaterial() ) to clean pointers for freed textures git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2147 dfc29bdd-3216-0410-991c-e03cc46cb475
2009-01-27 07:53:53 -08:00
bool CLWOMeshFileLoader::isALoadableFileExtension(const core::string<c16>& filename) const
{
return core::hasFileExtension(filename, "lwo");
}
//! creates/loads an animated mesh from the file.
IAnimatedMesh* CLWOMeshFileLoader::createMesh(io::IReadFile* file)
{
File = file;
if (Mesh)
Mesh->drop();
Mesh = new SMesh();
if (!readFileHeader())
return false;
if (!readChunks())
return false;
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Creating geometry.");
os::Printer::log("LWO loader: Assigning UV maps.");
#endif
u32 i;
for (i=0; i<Materials.size(); ++i)
{
u16 uvTag;
for (u32 j=0; j<2; ++j) // max 2 texture coords
{
if (Materials[i]->Texture[j].UVname.size())
{
for (uvTag=0; uvTag<UvName.size(); ++uvTag)
{
if (Materials[i]->Texture[j].UVname == UvName[uvTag])
{
Materials[i]->Texture[j].UVTag=uvTag;
break;
}
}
for (uvTag=0; uvTag<DUvName.size(); ++uvTag)
{
if (Materials[i]->Texture[j].UVname == DUvName[uvTag])
{
Materials[i]->Texture[j].DUVTag=uvTag;
break;
}
}
}
}
}
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Creating polys.");
#endif
// create actual geometry for lwo2
if (FormatVersion==2)
{
core::array<u32>vertexCount;
vertexCount.reallocate(Materials.size());
for (i=0; i<Materials.size(); ++i)
vertexCount.push_back(0);
for (u32 polyIndex=0; polyIndex<Indices.size(); ++polyIndex)
vertexCount[MaterialMapping[polyIndex]] += Indices[polyIndex].size();
for (i=0; i<Materials.size(); ++i)
{
Materials[i]->Meshbuffer->Vertices.reallocate(vertexCount[i]);
Materials[i]->Meshbuffer->Indices.reallocate(vertexCount[i]);
}
}
// create actual geometry for lwo2
for (u32 polyIndex=0; polyIndex<Indices.size(); ++polyIndex)
{
const u16 tag = MaterialMapping[polyIndex];
scene::SMeshBuffer *mb=Materials[tag]->Meshbuffer;
const core::array<u32>& poly = Indices[polyIndex];
const u32 polySize=poly.size();
const u16 uvTag = Materials[tag]->Texture[0].UVTag;
const u16 duvTag = Materials[tag]->Texture[0].DUVTag;
video::S3DVertex vertex;
const u32 vertCount=mb->Vertices.size();
for (u32 i=0; i<polySize; ++i)
{
const u32 j=poly[i];
vertex.Pos=Points[j];
if (uvTag<UvIndex.size())
{
for (u32 uvsearch=0; uvsearch < UvIndex[uvTag].size(); ++uvsearch)
{
if(j==UvIndex[uvTag][uvsearch])
{
vertex.TCoords=TCoords[uvTag][uvsearch];
break;
}
}
if (duvTag<DUvName.size())
{
for (u32 polysearch = 0; polysearch < VmPolyPointsIndex[duvTag].size(); polysearch += 2)
{
if (polyIndex==VmPolyPointsIndex[duvTag][polysearch] && j==VmPolyPointsIndex[duvTag][polysearch+1])
{
vertex.TCoords=VmCoordsIndex[duvTag][polysearch/2];
break;
}
}
}
}
mb->Vertices.push_back(vertex);
}
// triangulate as trifan
if (polySize>2)
{
for (u32 i=1; i<polySize-1; ++i)
{
mb->Indices.push_back(vertCount);
mb->Indices.push_back(vertCount+i);
mb->Indices.push_back(vertCount+i+1);
}
}
}
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Fixing meshbuffers.");
#endif
for (u32 i=0; i<Materials.size(); ++i)
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Material name", Materials[i]->Name);
os::Printer::log("LWO loader: Vertex count", core::stringc(Materials[i]->Meshbuffer->Vertices.size()));
#endif
for (u32 j=0; j<Materials[i]->Meshbuffer->Vertices.size(); ++j)
Materials[i]->Meshbuffer->Vertices[j].Color=Materials[i]->Meshbuffer->Material.DiffuseColor;
Materials[i]->Meshbuffer->recalculateBoundingBox();
// cope with planar mapping texture coords
if (Materials[i]->Texture[0].Projection != 5)
{
if (FormatVersion!=2)
{
if (Materials[i]->Texture[0].Flags&1)
Materials[i]->Texture[0].Axis=0;
else if (Materials[i]->Texture[0].Flags&2)
Materials[i]->Texture[0].Axis=1;
else if (Materials[i]->Texture[0].Flags&4)
Materials[i]->Texture[0].Axis=2;
}
// if no axis given choose the dominant one
else if (Materials[i]->Texture[0].Axis>2)
{
if (Materials[i]->Meshbuffer->getBoundingBox().getExtent().Y<Materials[i]->Meshbuffer->getBoundingBox().getExtent().X)
{
if (Materials[i]->Meshbuffer->getBoundingBox().getExtent().Y<Materials[i]->Meshbuffer->getBoundingBox().getExtent().Z)
Materials[i]->Texture[0].Axis=1;
else
Materials[i]->Texture[0].Axis=2;
}
else
{
if (Materials[i]->Meshbuffer->getBoundingBox().getExtent().X<Materials[i]->Meshbuffer->getBoundingBox().getExtent().Z)
Materials[i]->Texture[0].Axis=0;
else
Materials[i]->Texture[0].Axis=2;
}
}
// get the resolution for this axis
f32 resolutionS = 1.f/Materials[i]->Meshbuffer->getBoundingBox().getExtent().Y;
f32 resolutionT = -1.f/Materials[i]->Meshbuffer->getBoundingBox().getExtent().Z;
if (Materials[i]->Texture[0].Axis==1)
{
resolutionS = 1.f/Materials[i]->Meshbuffer->getBoundingBox().getExtent().X;
resolutionT = -1.f/Materials[i]->Meshbuffer->getBoundingBox().getExtent().Z;
}
else if (Materials[i]->Texture[0].Axis==2)
{
resolutionS = 1.f/Materials[i]->Meshbuffer->getBoundingBox().getExtent().X;
resolutionT = -1.f/Materials[i]->Meshbuffer->getBoundingBox().getExtent().Y;
}
// use the two-way planar mapping
SceneManager->getMeshManipulator()->makePlanarTextureMapping(Materials[i]->Meshbuffer, resolutionS, resolutionT, Materials[i]->Texture[0].Axis);
}
// add bump maps
if (Materials[i]->Meshbuffer->Material.MaterialType==video::EMT_NORMAL_MAP_SOLID)
{
SMesh tmpmesh;
tmpmesh.addMeshBuffer(Materials[i]->Meshbuffer);
SceneManager->getMeshManipulator()->createMeshWithTangents(&tmpmesh, true, true);
Mesh->addMeshBuffer(tmpmesh.getMeshBuffer(0));
}
else
{
SceneManager->getMeshManipulator()->recalculateNormals(Materials[i]->Meshbuffer);
Mesh->addMeshBuffer(Materials[i]->Meshbuffer);
}
Mesh->getMeshBuffer(Mesh->getMeshBufferCount()-1)->drop();
// clear the material array elements
delete Materials[i];
}
Mesh->recalculateBoundingBox();
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_3DS;
am->addMesh(Mesh);
am->recalculateBoundingBox();
Mesh->drop();
Mesh = 0;
Points.clear();
Indices.clear();
MaterialMapping.clear();
TCoords.clear();
Materials.clear();
Images.clear();
VmPolyPointsIndex.clear();
VmCoordsIndex.clear();
UvIndex.clear();
UvName.clear();
return am;
}
bool CLWOMeshFileLoader::readChunks()
{
s32 lastPos;
u32 size;
unsigned int uiType;
char type[5];
type[4]=0;
tLWOLayerInfo layer;
while(File->getPos()<File->getSize())
{
File->read(&type, 4);
//Convert 4-char string to 4-byte integer
//Makes it possible to do a switch statement
uiType = charsToUInt(type);
File->read(&size, 4);
#ifndef __BIG_ENDIAN__
size=os::Byteswap::byteswap(size);
#endif
lastPos=File->getPos();
switch(uiType)
{
case charsToUIntD('L','A','Y','R'):
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading layer.");
#endif
u16 tmp16;
File->read(&tmp16, 2); // number
File->read(&tmp16, 2); // flags
size -= 4;
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
if (((FormatVersion==1)&&(tmp16!=1)) ||
((FormatVersion==2)&&(tmp16&1)))
layer.Active=false;
else
layer.Active=true;
if (FormatVersion==2)
size -= readVec(layer.Pivot);
size -= readString(layer.Name);
if (size)
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
layer.Parent = tmp16;
}
}
break;
case charsToUIntD('P','N','T','S'):
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading points.");
#endif
core::vector3df vec;
Points.clear();
const u32 tmpsize = size/12;
Points.reallocate(tmpsize);
for (u32 i=0; i<tmpsize; ++i)
{
readVec(vec);
Points.push_back(vec);
}
}
break;
case charsToUIntD('V','M','A','P'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading Vertex mapping.");
#endif
readVertexMapping(size);
break;
case charsToUIntD('P','O','L','S'):
case charsToUIntD('P','T','C','H'): // TODO: should be a subdivison mesh
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading polygons.");
#endif
if (FormatVersion!=2)
readObj1(size);
else
readObj2(size);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Done loading polygons.");
#endif
break;
case charsToUIntD('T','A','G','S'):
case charsToUIntD('S','R','F','S'):
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading surface names.");
#endif
while (size!=0)
{
tLWOMaterial *mat=new tLWOMaterial();
mat->Name="";
mat->Meshbuffer=new scene::SMeshBuffer();
size -= readString(mat->Name);
if (FormatVersion!=2)
mat->TagType = 1; // format 2 has more types
Materials.push_back(mat);
}
}
break;
case charsToUIntD('P','T','A','G'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading tag mapping.");
#endif
readTagMapping(size);
break;
case charsToUIntD('V','M','A','D'): // discontinuous vertex mapping, i.e. additional texcoords
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading Vertex mapping VMAD.");
#endif
readDiscVertexMapping(size);
// case charsToUIntD('V','M','P','A'):
// case charsToUIntD('E','N','V','L'):
break;
case charsToUIntD('C','L','I','P'):
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading clips.");
#endif
u32 index;
u16 subsize;
File->read(&index, 4);
#ifndef __BIG_ENDIAN__
index=os::Byteswap::byteswap(index);
#endif
size -= 4;
while (size != 0)
{
File->read(&type, 4);
File->read(&subsize, 2);
#ifndef __BIG_ENDIAN__
subsize=os::Byteswap::byteswap(subsize);
#endif
size -= 6;
if (strncmp(type, "STIL", 4))
{
File->seek(subsize, true);
size -= subsize;
continue;
}
core::stringc path;
size -= readString(path, subsize);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loaded clip", path.c_str());
#endif
Images.push_back(path);
}
}
break;
case charsToUIntD('S','U','R','F'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading material.");
#endif
readMat(size);
break;
case charsToUIntD('B','B','O','X'):
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading bbox.");
#endif
// not stored
core::vector3df vec;
for (u32 i=0; i<2; ++i)
readVec(vec);
size -= 24;
}
break;
case charsToUIntD('D','E','S','C'):
case charsToUIntD('T','E','X','T'):
{
core::stringc text;
size -= readString(text, size);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader text", text);
#endif
}
break;
// not needed
case charsToUIntD('I','C','O','N'):
// not yet supported
case charsToUIntD('P','C','H','S'):
case charsToUIntD('C','R','V','S'):
default:
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: skipping ", type);
#endif
//Go to next chunk
File->seek(lastPos + size, false);
break;
}
}
return true;
}
void CLWOMeshFileLoader::readObj1(u32 size)
{
u32 pos;
u16 numVerts, vertIndex;
s16 material;
video::S3DVertex vertex;
while (size!=0)
{
File->read(&numVerts, 2);
#ifndef __BIG_ENDIAN__
numVerts=os::Byteswap::byteswap(numVerts);
#endif
pos=File->getPos();
// skip forward to material number
File->seek(2*numVerts, true);
File->read(&material, 2);
#ifndef __BIG_ENDIAN__
material=os::Byteswap::byteswap(material);
#endif
size -=2*numVerts+4;
// detail meshes ?
scene::SMeshBuffer *mb;
if (material<0)
mb=Materials[-material-1]->Meshbuffer;
else
mb=Materials[material-1]->Meshbuffer;
// back to vertex list start
File->seek(pos, false);
const u16 vertCount=mb->Vertices.size();
for (u16 i=0; i<numVerts; ++i)
{
File->read(&vertIndex, 2);
#ifndef __BIG_ENDIAN__
vertIndex=os::Byteswap::byteswap(vertIndex);
#endif
vertex.Pos=Points[vertIndex];
mb->Vertices.push_back(vertex);
}
for (u16 i=1; i<numVerts-1; ++i)
{
mb->Indices.push_back(vertCount);
mb->Indices.push_back(vertCount+i);
mb->Indices.push_back(vertCount+i+1);
}
// skip material number and detail surface count
// detail surface can be read just as a normal one now
if (material<0)
File->read(&material, 2);
File->read(&material, 2);
}
}
void CLWOMeshFileLoader::readVertexMapping(u32 size)
{
char type[5]={0};
u16 dimension;
core::stringc name;
File->read(&type, 4);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Vertex map type", type);
#endif
File->read(&dimension,2);
#ifndef __BIG_ENDIAN__
dimension=os::Byteswap::byteswap(dimension);
#endif
size -= 6;
size -= readString(name);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Vertex map", name.c_str());
#endif
if (strncmp(type, "TXUV", 4)) // also support RGB, RGBA, WGHT, ...
{
File->seek(size, true);
return;
}
UvName.push_back(name);
TCoords.push_back(core::array<core::vector2df>());
core::array<core::vector2df>& UvCoords=TCoords.getLast();
UvCoords.reallocate(Points.size());
UvIndex.push_back(core::array<u32>());
core::array<u32>& UvPointsArray=UvIndex.getLast();
UvPointsArray.reallocate(Points.size());
u32 index;
core::vector2df tcoord;
while (size)
{
size -= readVX(index);
File->read(&tcoord.X, 4);
File->read(&tcoord.Y, 4);
size -= 8;
#ifndef __BIG_ENDIAN__
index=os::Byteswap::byteswap(index);
tcoord.X=os::Byteswap::byteswap(tcoord.X);
tcoord.Y=os::Byteswap::byteswap(tcoord.Y);
#endif
UvCoords.push_back(tcoord);
UvPointsArray.push_back(index);
}
}
void CLWOMeshFileLoader::readDiscVertexMapping(u32 size)
{
char type[5]={0};
u16 dimension;
core::stringc name;
File->read(&type, 4);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Discontinuous vertex map type", type);
#endif
File->read(&dimension,2);
#ifndef __BIG_ENDIAN__
dimension=os::Byteswap::byteswap(dimension);
#endif
size -= 6;
size -= readString(name);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: Discontinuous vertex map", name.c_str());
#endif
if (strncmp(type, "TXUV", 4))
{
File->seek(size, true);
return;
}
DUvName.push_back(name);
VmPolyPointsIndex.push_back(core::array<u32>());
core::array<u32>& VmPolyPoints=VmPolyPointsIndex.getLast();
VmCoordsIndex.push_back(core::array<core::vector2df>());
core::array<core::vector2df>& VmCoords=VmCoordsIndex.getLast();
u32 vmpolys;
u32 vmpoints;
core::vector2df vmcoords;
while (size)
{
size-=readVX(vmpoints);
size-=readVX(vmpolys);
File->read(&vmcoords.X, 4);
File->read(&vmcoords.Y, 4);
size -= 8;
#ifndef __BIG_ENDIAN__
vmpoints=os::Byteswap::byteswap(vmpoints);
vmpolys=os::Byteswap::byteswap(vmpolys);
vmcoords.X=os::Byteswap::byteswap(vmcoords.X);
vmcoords.Y=os::Byteswap::byteswap(vmcoords.Y);
#endif
VmCoords.push_back(vmcoords);
VmPolyPoints.push_back(vmpolys);
VmPolyPoints.push_back(vmpoints);
}
}
void CLWOMeshFileLoader::readTagMapping(u32 size)
{
char type[5];
type[4]=0;
File->read(&type, 4);
size -= 4;
if ((strncmp(type, "SURF", 4))||(Indices.size()==0))
{
File->seek(size, true);
return;
}
while (size!=0)
{
u16 tag;
u32 polyIndex;
size-=readVX(polyIndex);
File->read(&tag, 2);
#ifndef __BIG_ENDIAN__
tag=os::Byteswap::byteswap(tag);
#endif
size -= 2;
MaterialMapping[polyIndex]=tag;
Materials[tag]->TagType=1;
}
}
void CLWOMeshFileLoader::readObj2(u32 size)
{
char type[5];
type[4]=0;
File->read(&type, 4);
size -= 4;
Indices.clear();
if (strncmp(type, "FACE", 4)) // also possible are splines, subdivision patches, metaballs, and bones
{
File->seek(size, true);
return;
}
u16 numVerts=0;
while (size!=0)
{
File->read(&numVerts, 2);
#ifndef __BIG_ENDIAN__
numVerts=os::Byteswap::byteswap(numVerts);
#endif
// mask out flags
numVerts &= 0x03FF;
size -= 2;
Indices.push_back(core::array<u32>());
u32 vertIndex;
core::array<u32>& polyArray = Indices.getLast();
polyArray.reallocate(numVerts);
for (u16 i=0; i<numVerts; ++i)
{
size -= readVX(vertIndex);
polyArray.push_back(vertIndex);
}
}
MaterialMapping.reallocate(Indices.size());
for (u32 j=0; j<Indices.size(); ++j)
MaterialMapping.push_back(0);
}
void CLWOMeshFileLoader::readMat(u32 size)
{
core::stringc name;
tLWOMaterial* mat=0;
size -= readString(name);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: material name", name.c_str());
#endif
for (u32 i=0; i<Materials.size(); ++i)
{
if ((Materials[i]->TagType==1) && (Materials[i]->Name==name))
{
mat=Materials[i];
break;
}
}
if (!mat)
{
File->seek(size, true);
return;
}
if (FormatVersion==2)
size -= readString(name);
video::SMaterial& irrMat=mat->Meshbuffer->Material;
u8 currTexture=0;
while (size!=0)
{
char type[5];
type[4]=0;
u32 uiType;
u32 tmp32;
u16 subsize, tmp16;
f32 tmpf32;
File->read(&type, 4);
//Convert 4-char string to 4-byte integer
//Makes it possible to do a switch statement
uiType = charsToUInt(type);
File->read(&subsize, 2);
#ifndef __BIG_ENDIAN__
subsize=os::Byteswap::byteswap(subsize);
#endif
size -= 6;
switch (uiType)
{
case charsToUIntD('C','O','L','R'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading Ambient color.");
#endif
{
s32 colSize = readColor(irrMat.DiffuseColor);
irrMat.AmbientColor=irrMat.DiffuseColor;
size -= colSize;
subsize -= colSize;
if (FormatVersion==2)
size -= readVX(mat->Envelope[0]);
}
break;
case charsToUIntD('D','I','F','F'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading Diffuse color.");
#endif
{
if (FormatVersion==2)
{
File->read(&mat->Diffuse, 4);
#ifndef __BIG_ENDIAN__
mat->Diffuse=os::Byteswap::byteswap(mat->Diffuse);
#endif
size -= 4;
subsize -= 4;
size -= readVX(mat->Envelope[1]);
}
else
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Diffuse=tmp16/256.0f;
size -= 2;
subsize -= 2;
}
}
break;
case charsToUIntD('V','D','I','F'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading Diffuse color.");
#endif
{
File->read(&mat->Diffuse, 4);
#ifndef __BIG_ENDIAN__
mat->Diffuse=os::Byteswap::byteswap(mat->Diffuse);
#endif
size -= 4;
}
break;
case charsToUIntD('L','U','M','I'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading luminance.");
#endif
{
if (FormatVersion==2)
{
File->read(&mat->Luminance, 4);
#ifndef __BIG_ENDIAN__
mat->Luminance=os::Byteswap::byteswap(mat->Luminance);
#endif
size -= 4;
subsize -= 4;
size -= readVX(mat->Envelope[2]);
}
else
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Luminance=tmp16/256.0f;
size -= 2;
subsize -= 2;
} }
break;
case charsToUIntD('V','L','U','M'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading luminance.");
#endif
{
File->read(&mat->Luminance, 4);
#ifndef __BIG_ENDIAN__
mat->Luminance=os::Byteswap::byteswap(mat->Luminance);
#endif
size -= 4;
}
break;
case charsToUIntD('S','P','E','C'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading specular.");
#endif
{
if (FormatVersion==2)
{
File->read(&mat->Specular, 4);
#ifndef __BIG_ENDIAN__
mat->Specular=os::Byteswap::byteswap(mat->Specular);
#endif
size -= 4;
subsize -= 4;
size -= readVX(mat->Envelope[3]);
}
else
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Specular=tmp16/256.0f;;
size -= 2;
subsize -= 2;
}
}
break;
case charsToUIntD('V','S','P','C'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading specular.");
#endif
{
File->read(&mat->Specular, 4);
#ifndef __BIG_ENDIAN__
mat->Specular=os::Byteswap::byteswap(mat->Specular);
#endif
size -= 4;
}
break;
case charsToUIntD('R','E','F','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection.");
#endif
{
if (FormatVersion==2)
{
File->read(&mat->Reflection, 4);
#ifndef __BIG_ENDIAN__
mat->Reflection=os::Byteswap::byteswap(mat->Reflection);
#endif
size -= 4;
subsize -= 4;
size -= readVX(mat->Envelope[4]);
}
else
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Reflection=tmp16/256.0f;
size -= 2;
subsize -= 2;
}
}
break;
case charsToUIntD('V','R','F','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection.");
#endif
{
File->read(&mat->Reflection, 4);
#ifndef __BIG_ENDIAN__
mat->Reflection=os::Byteswap::byteswap(mat->Reflection);
#endif
size -= 4;
}
break;
case charsToUIntD('T','R','A','N'):
{
if (FormatVersion==2)
{
File->read(&mat->Transparency, 4);
#ifndef __BIG_ENDIAN__
mat->Transparency=os::Byteswap::byteswap(mat->Transparency);
#endif
size -= 4;
subsize -= 4;
size -= readVX(mat->Envelope[5]);
}
else
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Transparency=tmp16/256.0f;
size -= 2;
subsize -= 2;
}
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading transparency", core::stringc(mat->Transparency).c_str());
#endif
}
break;
case charsToUIntD('V','T','R','N'):
{
File->read(&mat->Transparency, 4);
#ifndef __BIG_ENDIAN__
mat->Transparency=os::Byteswap::byteswap(mat->Transparency);
#endif
size -= 4;
}
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading transparency", core::stringc(mat->Transparency).c_str());
#endif
break;
case charsToUIntD('T','R','N','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading translucency.");
#endif
{
File->read(&mat->Translucency, 4);
#ifndef __BIG_ENDIAN__
mat->Translucency=os::Byteswap::byteswap(mat->Translucency);
#endif
size -= 4;
subsize -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[6]);
}
break;
case charsToUIntD('G','L','O','S'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading glossy.");
#endif
{
if (FormatVersion == 2)
{
File->read(&irrMat.Shininess, 4);
#ifndef __BIG_ENDIAN__
irrMat.Shininess=os::Byteswap::byteswap(irrMat.Shininess);
#endif
size -= 4;
subsize -= 4;
size -= readVX(mat->Envelope[7]);
}
else
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
irrMat.Shininess=tmp16/16.f;
size -= 2;
subsize -= 2;
}
}
break;
case charsToUIntD('S','H','R','P'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading sharpness.");
#endif
{
File->read(&mat->Sharpness, 4);
#ifndef __BIG_ENDIAN__
mat->Sharpness=os::Byteswap::byteswap(mat->Sharpness);
#endif
size -= 4;
subsize -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[8]);
}
break;
case charsToUIntD('B','U','M','P'):
case charsToUIntD('T','A','M','P'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading bumpiness.");
#endif
{
File->read(&tmpf32, 4);
#ifndef __BIG_ENDIAN__
tmpf32=os::Byteswap::byteswap(tmpf32);
#endif
if (currTexture==6)
irrMat.MaterialTypeParam=tmpf32;
size -= 4;
subsize -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[9]);
}
break;
case charsToUIntD('S','I','D','E'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading backface culled.");
#endif
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
if (tmp16==1)
irrMat.BackfaceCulling=true;
else if (tmp16==3)
irrMat.BackfaceCulling=false;
size -= 2;
}
break;
case charsToUIntD('S','M','A','N'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading smoothing angle.");
#endif
{
File->read(&mat->SmoothingAngle, 4);
#ifndef __BIG_ENDIAN__
mat->SmoothingAngle=os::Byteswap::byteswap(mat->SmoothingAngle);
#endif
size -= 4;
}
break;
case charsToUIntD('R','F','O','P'):
case charsToUIntD('R','F','L','T'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection mode.");
#endif
{
File->read(&mat->ReflMode, 2);
#ifndef __BIG_ENDIAN__
mat->ReflMode=os::Byteswap::byteswap(mat->ReflMode);
#endif
size -= 2;
}
break;
case charsToUIntD('R','I','M','G'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection map.");
#endif
{
if (FormatVersion==2)
{
size -= readVX(tmp32);
if (tmp32)
mat->ReflMap=Images[tmp32-1];
}
else
size -= readString(mat->ReflMap, size);
}
break;
case charsToUIntD('R','S','A','N'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection seam angle.");
#endif
{
File->read(&mat->ReflSeamAngle, 4);
#ifndef __BIG_ENDIAN__
mat->ReflSeamAngle=os::Byteswap::byteswap(mat->ReflSeamAngle);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[10]);
}
break;
case charsToUIntD('R','B','L','R'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection blur.");
#endif
{
File->read(&mat->ReflBlur, 4);
#ifndef __BIG_ENDIAN__
mat->ReflBlur=os::Byteswap::byteswap(mat->ReflBlur);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[11]);
}
break;
case charsToUIntD('R','I','N','D'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading refraction index.");
#endif
{
File->read(&mat->RefrIndex, 4);
#ifndef __BIG_ENDIAN__
mat->RefrIndex=os::Byteswap::byteswap(mat->RefrIndex);
#endif
size -= 4;
subsize -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[12]);
}
break;
case charsToUIntD('T','R','O','P'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading refraction options.");
#endif
{
File->read(&mat->TranspMode, 2);
#ifndef __BIG_ENDIAN__
mat->TranspMode=os::Byteswap::byteswap(mat->TranspMode);
#endif
size -= 2;
}
break;
case charsToUIntD('T','I','M','G'):
{
if (FormatVersion==2)
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading refraction map.");
#endif
size -= readVX(tmp32);
#ifndef __BIG_ENDIAN__
tmp32=os::Byteswap::byteswap(tmp32);
#endif
if (tmp32)
mat->Texture[currTexture].Map=Images[tmp32-1];
}
else
{
size -= readString(mat->Texture[currTexture].Map, size);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading image", mat->Texture[currTexture].Map.c_str());
#endif
}
}
break;
case charsToUIntD('T','B','L','R'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading transparency blur.");
#endif
{
File->read(&mat->TranspBlur, 4);
#ifndef __BIG_ENDIAN__
mat->TranspBlur=os::Byteswap::byteswap(mat->TranspBlur);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[13]);
}
break;
case charsToUIntD('C','L','R','H'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading highlight color.");
#endif
{
File->read(&mat->HighlightColor, 4);
#ifndef __BIG_ENDIAN__
mat->HighlightColor=os::Byteswap::byteswap(mat->HighlightColor);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[14]);
}
break;
case charsToUIntD('C','L','R','F'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading color filter.");
#endif
{
File->read(&mat->ColorFilter, 4);
#ifndef __BIG_ENDIAN__
mat->ColorFilter=os::Byteswap::byteswap(mat->ColorFilter);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[15]);
}
break;
case charsToUIntD('A','D','T','R'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading additive transparency.");
#endif
{
File->read(&mat->AdditiveTransparency, 4);
#ifndef __BIG_ENDIAN__
mat->AdditiveTransparency=os::Byteswap::byteswap(mat->AdditiveTransparency);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[16]);
}
break;
case charsToUIntD('G','L','O','W'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading glow.");
#endif
{
File->read(&mat->Glow, 2);
#ifndef __BIG_ENDIAN__
mat->Glow=os::Byteswap::byteswap(mat->Glow);
#endif
size -= 2;
File->read(&mat->GlowIntensity, 4);
#ifndef __BIG_ENDIAN__
mat->GlowIntensity=os::Byteswap::byteswap(mat->GlowIntensity);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[17]);
File->read(&mat->GlowSize, 4);
#ifndef __BIG_ENDIAN__
mat->GlowSize=os::Byteswap::byteswap(mat->GlowSize);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[18]);
}
break;
case charsToUIntD('G','V','A','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading glow intensity.");
#endif
{
File->read(&mat->GlowIntensity, 4);
#ifndef __BIG_ENDIAN__
mat->GlowIntensity=os::Byteswap::byteswap(mat->GlowIntensity);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[17]);
}
break;
case charsToUIntD('L','I','N','E'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading isWireframe.");
#endif
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
if (tmp16&1)
irrMat.Wireframe=true;
size -= 2;
if (size!=0)
{
File->read(&irrMat.Thickness, 4);
#ifndef __BIG_ENDIAN__
irrMat.Thickness=os::Byteswap::byteswap(irrMat.Thickness);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[19]);
}
if (size!=0)
{
video::SColor lineColor;
size -= readColor(lineColor);
if (FormatVersion==2)
size -= readVX(mat->Envelope[20]);
}
}
break;
case charsToUIntD('A','L','P','H'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading alpha mode.");
#endif
{
File->read(&mat->AlphaMode, 2);
#ifndef __BIG_ENDIAN__
mat->AlphaMode=os::Byteswap::byteswap(mat->AlphaMode);
#endif
size -= 2;
File->read(&mat->AlphaValue, 4);
#ifndef __BIG_ENDIAN__
mat->AlphaValue=os::Byteswap::byteswap(mat->AlphaValue);
#endif
size -= 4;
}
break;
case charsToUIntD('V','C','O','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading vertex color.");
#endif
{
File->read(&mat->VertexColorIntensity, 4);
#ifndef __BIG_ENDIAN__
mat->VertexColorIntensity=os::Byteswap::byteswap(mat->VertexColorIntensity);
#endif
size -= 4;
if (FormatVersion==2)
size -= readVX(mat->Envelope[21]);
File->read(&tmp32, 4); // skip type
size -= 4;
core::stringc tmpname;
size -= readString(tmpname, size);
// mat->VertexColor = getColorVMAP(tmpname);
}
break;
case charsToUIntD('F','L','A','G'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading flag.");
#endif
{
File->read(&mat->Flags, 2);
#ifndef __BIG_ENDIAN__
mat->Flags=os::Byteswap::byteswap(mat->Flags);
#endif
if (mat->Flags&1)
mat->Luminance=1.0f;
if (mat->Flags&256)
irrMat.BackfaceCulling=false;
size -= 2;
}
break;
case charsToUIntD('E','D','G','E'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading edge.");
#endif
{
File->read(&mat->EdgeTransparency, 4);
#ifndef __BIG_ENDIAN__
mat->EdgeTransparency=os::Byteswap::byteswap(mat->EdgeTransparency);
#endif
size -= 4;
}
break;
case charsToUIntD('C','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading ctex.");
#endif
currTexture=0;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('D','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading dtex.");
#endif
currTexture=1;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('S','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading stex.");
#endif
currTexture=2;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('R','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading rtex.");
#endif
currTexture=3;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('T','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading ttex.");
#endif
currTexture=4;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('L','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading ltex.");
#endif
currTexture=5;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('B','T','E','X'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading btex.");
#endif
currTexture=6;
size -= readString(mat->Texture[currTexture].Type, size);
break;
case charsToUIntD('T','A','L','P'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading alpha map.");
#endif
size -= readString(mat->Texture[currTexture].AlphaMap, size);
break;
case charsToUIntD('T','F','L','G'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture flag.");
#endif
{
File->read(&mat->Texture[currTexture].Flags, 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].Flags=os::Byteswap::byteswap(mat->Texture[currTexture].Flags);
#endif
size -= 2;
}
break;
case charsToUIntD('E','N','A','B'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading isEnabled.");
#endif
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Texture[currTexture].Active=(tmp16!=0);
size -= 2;
}
break;
case charsToUIntD('W','R','A','P'):
case charsToUIntD('T','W','R','P'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture wrap.");
#endif
{
File->read(&mat->Texture[currTexture].WidthWrap, 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].WidthWrap=os::Byteswap::byteswap(mat->Texture[currTexture].WidthWrap);
#endif
File->read(&mat->Texture[currTexture].HeightWrap, 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].HeightWrap=os::Byteswap::byteswap(mat->Texture[currTexture].HeightWrap);
#endif
size -= 4;
}
break;
case charsToUIntD('T','V','E','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture velocity.");
#endif
size -= readVec(mat->Texture[currTexture].Velocity);
break;
case charsToUIntD('T','C','L','R'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture color.");
#endif
size -= readColor(mat->Texture[currTexture].Color);
break;
case charsToUIntD('A','A','S','T'):
case charsToUIntD('T','A','A','S'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture antialias.");
#endif
{
tmp16=0;
if (FormatVersion==2)
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
size -= 2;
}
File->read(&mat->Texture[currTexture].AntiAliasing, 4);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].AntiAliasing=os::Byteswap::byteswap(mat->Texture[currTexture].AntiAliasing);
#endif
if (tmp16 & ~0x01)
mat->Texture[currTexture].AntiAliasing=0.0f; // disabled
size -= 4;
}
break;
case charsToUIntD('T','O','P','C'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture opacity.");
#endif
{
File->read(&mat->Texture[currTexture].Opacity, 4);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].Opacity=os::Byteswap::byteswap(mat->Texture[currTexture].Opacity);
#endif
size -= 4;
}
break;
case charsToUIntD('O','P','A','C'):
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture opacity and type.");
#endif
File->read(&mat->Texture[currTexture].OpacType, 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].OpacType=os::Byteswap::byteswap(mat->Texture[currTexture].OpacType);
#endif
File->read(&mat->Texture[currTexture].Opacity, 4);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].Opacity=os::Byteswap::byteswap(mat->Texture[currTexture].Opacity);
#endif
size -= 6;
subsize -= 6;
if (FormatVersion==2)
size -= readVX(mat->Envelope[22]);
}
break;
case charsToUIntD('A','X','I','S'):
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Texture[currTexture].Axis=(u8)tmp16;
size -= 2;
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading axis value", core::stringc(tmp16).c_str());
#endif
}
break;
case charsToUIntD('T','M','A','P'): // empty separation chunk
break;
case charsToUIntD('T','C','T','R'):
case charsToUIntD('C','N','T','R'):
{
core::vector3df& center=mat->Texture[currTexture].Center;
size -= readVec(center);
if (FormatVersion==2)
size -= readVX(mat->Envelope[22]);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture center", (core::stringc(center.X)+" "+core::stringc(center.Y)+" "+core::stringc(center.Z)).c_str());
#endif
}
break;
case charsToUIntD('T','S','I','Z'):
case charsToUIntD('S','I','Z','E'):
{
core::vector3df& tsize=mat->Texture[currTexture].Size;
size -= readVec(tsize);
if (FormatVersion==2)
size -= readVX(mat->Envelope[22]);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture size", (core::stringc(tsize.X)+" "+core::stringc(tsize.Y)+" "+core::stringc(tsize.Z)).c_str());
#endif
}
break;
case charsToUIntD('R','O','T','A'):
{
core::vector3df rotation;
size -= readVec(rotation);
if (FormatVersion==2)
size -= readVX(mat->Envelope[22]);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture rotation", (core::stringc(rotation.X)+" "+core::stringc(rotation.Y)+" "+core::stringc(rotation.Z)).c_str());
#endif
}
break;
case charsToUIntD('O','R','E','F'):
{
core::stringc tmpname;
size -= readString(tmpname);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: texture reference object", tmpname.c_str());
#endif
}
break;
case charsToUIntD('T','F','A','L'):
case charsToUIntD('F','A','L','L'):
{
if (FormatVersion==2)
{
u16 tmp16;
File->read(&tmp16, 2);
size -= 2;
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
}
core::vector3df& falloff=mat->Texture[currTexture].Falloff;
size -= readVec(falloff);
if (FormatVersion==2)
size -= readVX(mat->Envelope[22]);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture falloff");
#endif
}
break;
case charsToUIntD('C','S','Y','S'):
{
u16 tmp16;
File->read(&tmp16, 2);
size -= 2;
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: texture coordinate system", tmp16==0?"object coords":"world coords");
#endif
}
break;
case charsToUIntD('T','V','A','L'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture value.");
#endif
{
File->read(&tmp16, 2);
#ifndef __BIG_ENDIAN__
tmp16=os::Byteswap::byteswap(tmp16);
#endif
mat->Texture[currTexture].Value=tmp16/256.0f;
size -= 2;
}
break;
case charsToUIntD('T','F','P','0'):
case charsToUIntD('T','S','P','0'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture param 0.");
#endif
{
File->read(&mat->Texture[currTexture].FParam[0], 4);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].FParam[0]=os::Byteswap::byteswap(mat->Texture[currTexture].FParam[0]);
#endif
size -= 4;
}
break;
case charsToUIntD('T','F','P','1'):
case charsToUIntD('T','S','P','1'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture param 1.");
#endif
{
File->read(&mat->Texture[currTexture].FParam[1], 4);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].FParam[1]=os::Byteswap::byteswap(mat->Texture[currTexture].FParam[1]);
#endif
size -= 4;
}
break;
case charsToUIntD('T','F','P','2'):
case charsToUIntD('T','S','P','2'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture param 2.");
#endif
{
File->read(&mat->Texture[currTexture].FParam[2], 4);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].FParam[2]=os::Byteswap::byteswap(mat->Texture[currTexture].FParam[2]);
#endif
size -= 4;
}
break;
case charsToUIntD('T','F','R','Q'):
case charsToUIntD('T','I','P','0'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture iparam 0.");
#endif
{
File->read(&mat->Texture[currTexture].IParam[0], 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].IParam[0]=os::Byteswap::byteswap(mat->Texture[currTexture].IParam[0]);
#endif
size -= 2;
}
break;
case charsToUIntD('T','I','P','1'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture param 1.");
#endif
{
File->read(&mat->Texture[currTexture].IParam[1], 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].IParam[1]=os::Byteswap::byteswap(mat->Texture[currTexture].IParam[1]);
#endif
size -= 2;
}
break;
case charsToUIntD('T','I','P','2'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading texture param 2.");
#endif
{
File->read(&mat->Texture[currTexture].IParam[2], 2);
#ifndef __BIG_ENDIAN__
mat->Texture[currTexture].IParam[2]=os::Byteswap::byteswap(mat->Texture[currTexture].IParam[2]);
#endif
size -= 2;
}
break;
case charsToUIntD('V','M','A','P'):
{
size -= readString(mat->Texture[currTexture].UVname);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading material vmap binding",mat->Texture[currTexture].UVname.c_str());
#endif
}
break;
case charsToUIntD('B','L','O','K'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading blok.");
#endif
{
core::stringc ordinal;
File->read(&type, 4);
File->read(&subsize, 2);
#ifndef __BIG_ENDIAN__
subsize=os::Byteswap::byteswap(subsize);
#endif
size -= 6;
size -= readString(ordinal, size);
}
break;
case charsToUIntD('C','H','A','N'):
{
File->read(&type, 4);
size -= 4;
if (!strncmp(type, "COLR", 4))
currTexture=0;
else if (!strncmp(type, "DIFF", 4))
currTexture=1;
else if (!strncmp(type, "LUMI", 4))
currTexture=5;
else if (!strncmp(type, "SPEC", 4))
currTexture=2;
else if (!strncmp(type, "REFL", 4))
currTexture=3;
else if (!strncmp(type, "TRAN", 4))
currTexture=4;
else if (!strncmp(type, "BUMP", 4))
currTexture=6;
}
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading channel ", type);
#endif
break;
case charsToUIntD('I','M','A','G'):
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading channel map.");
#endif
{
u16 index;
File->read(&index, 2);
#ifndef __BIG_ENDIAN__
index=os::Byteswap::byteswap(index);
#endif
size -= 2;
if (index)
mat->Texture[currTexture].Map=Images[index-1];
}
break;
case charsToUIntD('P','R','O','J'): // define the projection type
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading channel projection type.");
#endif
{
u16 index;
File->read(&index, 2);
#ifndef __BIG_ENDIAN__
index=os::Byteswap::byteswap(index);
#endif
size -= 2;
#ifdef LWO_READER_DEBUG
if (index != 5)
os::Printer::log("LWO loader: wrong channel projection type", core::stringc(index).c_str());
#endif
mat->Texture[currTexture].Projection=(u8)index;
}
break;
case charsToUIntD('W','R','P','W'): // for cylindrical and spherical projections
case charsToUIntD('W','R','P','H'): // for cylindrical and spherical projections
default:
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: skipping ", core::stringc((char*)&uiType, 4));
#endif
File->seek(subsize, true);
size -= subsize;
}
}
}
if (mat->Texture[0].Map != "") // diffuse
irrMat.setTexture(0,loadTexture(mat->Texture[0].Map));
if (mat->Texture[3].Map != "") // reflection
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading reflection texture.");
#endif
video::ITexture* reflTexture = loadTexture(mat->Texture[3].Map);
if (reflTexture && irrMat.getTexture(0))
irrMat.setTexture(1, irrMat.getTexture(0));
irrMat.setTexture(0, reflTexture);
irrMat.MaterialType=video::EMT_REFLECTION_2_LAYER;
}
if (mat->Texture[4].Map != "") // transparency
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading transparency texture.");
#endif
video::ITexture* transTexture = loadTexture(mat->Texture[4].Map);
if (transTexture && irrMat.getTexture(0))
irrMat.setTexture(1, irrMat.getTexture(0));
irrMat.setTexture(0, transTexture);
irrMat.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
}
if (mat->Texture[6].Map != "") // bump
{
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading bump texture.");
#endif
const u8 pos = irrMat.getTexture(0)?1:0;
irrMat.setTexture(pos, loadTexture(mat->Texture[6].Map));
if (irrMat.getTexture(pos))
{
// SceneManager->getVideoDriver()->makeNormalMapTexture(irrMat.getTexture(1));
// irrMat.MaterialType=video::EMT_NORMAL_MAP_SOLID;
}
}
if (mat->Transparency != 0.f)
{
irrMat.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
}
}
u32 CLWOMeshFileLoader::readColor(video::SColor& color)
{
if (FormatVersion!=2)
{
u8 colorComponent;
File->read(&colorComponent, 1);
color.setRed(colorComponent);
File->read(&colorComponent, 1);
color.setGreen(colorComponent);
File->read(&colorComponent, 1);
color.setBlue(colorComponent);
// unknown value
File->read(&colorComponent, 1);
return 4;
}
else
{
video::SColorf col;
File->read(&col.r, 4);
#ifndef __BIG_ENDIAN__
col.r=os::Byteswap::byteswap(col.r);
#endif
File->read(&col.g, 4);
#ifndef __BIG_ENDIAN__
col.g=os::Byteswap::byteswap(col.g);
#endif
File->read(&col.b, 4);
#ifndef __BIG_ENDIAN__
col.b=os::Byteswap::byteswap(col.b);
#endif
color=col.toSColor();
return 12;
}
}
u32 CLWOMeshFileLoader::readString(core::stringc& name, u32 size)
{
c8 c;
name="";
if (size)
name.reserve(size);
File->read(&c, 1);
while (c)
{
name.append(c);
File->read(&c, 1);
}
// read extra 0 upon odd file position
if (File->getPos() & 0x1)
{
File->read(&c, 1);
return (name.size()+2);
}
return (name.size()+1);
}
u32 CLWOMeshFileLoader::readVec(core::vector3df& vec)
{
File->read(&vec.X, 4);
#ifndef __BIG_ENDIAN__
vec.X=os::Byteswap::byteswap(vec.X);
#endif
File->read(&vec.Y, 4);
#ifndef __BIG_ENDIAN__
vec.Y=os::Byteswap::byteswap(vec.Y);
#endif
File->read(&vec.Z, 4);
#ifndef __BIG_ENDIAN__
vec.Z=os::Byteswap::byteswap(vec.Z);
#endif
return 12;
}
u32 CLWOMeshFileLoader::readVX(u32& num)
{
u16 tmpIndex;
File->read(&tmpIndex, 2);
#ifndef __BIG_ENDIAN__
tmpIndex=os::Byteswap::byteswap(tmpIndex);
#endif
num=tmpIndex;
if (num >= 0xFF00)
{
File->read(&tmpIndex, 2);
#ifndef __BIG_ENDIAN__
tmpIndex=os::Byteswap::byteswap(tmpIndex);
#endif
num=((num << 16)|tmpIndex) & ~0xFF000000;
return 4;
}
return 2;
}
bool CLWOMeshFileLoader::readFileHeader()
{
u32 Id;
File->read(&Id, 4);
#ifndef __BIG_ENDIAN__
Id=os::Byteswap::byteswap(Id);
#endif
if (Id != 0x464f524d) // FORM
return false;
//skip the file length
File->read(&Id, 4);
File->read(&Id, 4);
#ifndef __BIG_ENDIAN__
Id=os::Byteswap::byteswap(Id);
#endif
// Currently supported: LWOB, LWLO, LWO2
switch (Id)
{
case 0x4c574f42:
FormatVersion = 0; // LWOB
break;
case 0x4c574c4f:
FormatVersion = 1; // LWLO
break;
case 0x4c574f32:
FormatVersion = 2; // LWO2
break;
default:
return false; // unsupported
}
return true;
}
video::ITexture* CLWOMeshFileLoader::loadTexture(const core::stringc& file)
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
Changes in version 1.6, TA - FileSystem 2.0 SUPER MASTER MAJOR API CHANGE !!! The FileSystem is know build internally like for e.q the texture-, and the meshloaders. There exists a known list of ArchiveLoader, which know how to produce a Archive. The Loaders and the Archive can be attached/detached on runtime. The FileNames are now stored as core::string<c16>. where c16 is toggled between char/wchar with the #define flag _IRR_WCHAR_FILESYSTEM, to supported unicode backends (default:off) I replaced all (const c8* filename) to string references. Basically the FileSystem is divided into two regions. Native and Virtual. Native means using the backend OS. Virtual means only use currently attach IArchives. Browsing each FileSystem has it's own workdirectory and it's own methods to - create a FileTree - add/remove files & directory ( to be done ) Hint: store a savegame in a zip archive... basic browsing for all archives is implemented. Example 21. Quake3Explorer shows this TODO: - a file filter should be implemented. - The IArchive should have a function to create a filetree for now CFileList is used. Class Hiarchy: IArchiveLoader: is able to produce a IFileArchive - ZipLoader - PakLoader - MountPointReader ( formaly known as CUnzipReader ) IFileArchive: -ZipArchive -PakArchive -MountPoint (known as FolderFile) IFileSystem - addArchiveLoader - changed implementation of isALoadableFileExtension in all loaders to have consistent behavior - added a parameter to IFileList * createFileList setFileListSystem allows to query files in any of the game archives standard behavior listtype = SYSTEM ( default) - CLimitReadFile added multiple file random-access support. solved problems with mixed compressed & uncompressed files in a zip TODO: - Big Big Testing!! - Linux Version ( minor ) - remove all double loader interfaces where only the filename differs (IReadFile/const char *filename). This blows up the the interface - many loaders use their own private filesearching we should rework this - there are a lot of helper function ( getAbsolutePath, getFileDir ) which should be adapted to the virtual filesystem - IrrlichtDevice added: virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ) = 0; virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue ) = 0; and calculating methods to DeviceStub. implemented in Win32, TODO: other Devices - irrlicht.h changed exported irrlicht.dll routines createDevice, createDeviceEx, IdentityMatrix to extern "C" name mangling. for easier dynamically loading the irrlicht library and different versions - ParticleSystem removed the private (old?,wrong?) interface from the ParticleEffectors to match the parent class irr::io::IAttributeExchangingObject::deserializeAttributes TODO: please test if the serialization works! - Generic - vector3d<T>& normalize() #if 0 f32 length = (f32)(X*X + Y*Y + Z*Z); if (core::equals(length, 0.f)) return *this; length = core::reciprocal_squareroot ( (f32)length ); #else const T length = core::reciprocal_squareroot ( (X*X + Y*Y + Z*Z) ); #endif Weak checking on zero?!?! just to avoid a sqrt?. mhm, maybe not;-) added reciprocal_squareroot for f64 - dimension2d added operator dimension2d<T>& operator=(const dimension2d<U>& other) to cast between different types - vector2d bugfix: vector2d<T>& operator+=(const dimension2d<T>& other) { X += other.Width; Y += other.Width; return *this; } to vector2d<T>& operator+=(const dimension2d<T>& other) { X += other.Width; Y += other.Height; return *this; } - C3DMeshLoader renamed chunks const u16 to a enum removing "variable declared but never used warning" - added a global const identity Material changed all references *((video::SMaterial*)0) to point to IdentityMaterial removed warning: "a NULL reference is not allowed" - modified IRRLICHT_MATH to not support reciprocal stuff but to use faster float-to-int conversion. gcc troubles may they are. i'm using intel-compiler..;-) - core::matrix4 USE_MATRIX_TEST i tried to optimize the identity-check ( in means of performance) i didn't succeed so well, so i made a define for the matrix isIdentity -check for now it's sometimes faster to always calculate versus identity-check but if there are a lot of scenenodes/ particles one can profit from the fast_inverse matrix, when no scaling is used. further approvement could be done on inverse for just tranlastion! ( many static scenenodes are not rotated, they are just placed somewhere in the world) one thing to take in account is that sizeof(matrix) is 64 byte and with the additional bool/u32 makes it 66 byte which is not really cache-friendly.. - added buildRotateFromTo Builds a matrix that rotates from one vector to another - irr::array. changed allocating routine in push_back okt, 2008. it's only allowed to alloc one element, if default constructor has to be called. removes existing crashes. ( MD3 Mesh ) and possible others ones. A new list template should be made. one with constructor/destructor calls ( safe_array ) and one without. like the array since the beginning of irrlicht. currently the array/string is extremly slow.. also a hint for the user has to be done, so that a struct T of array<T> must have a copy constructor of type T ( const T&other ). i needed hours to track that down... added a new method setAllocStrategy, safe ( used + 1 ), double ( used * 2 + 1) better default strategies will be implemented - removed binary_search_const i added it quite a long time ago, but it doesnt make real sense a call to a sort method should happen always. i just wanted to safe a few cycles.. - added binary_search_multi searches for a multi-set ( more than 1 entry in the sorted array) returns start and end-index - changed some identity matrix settings to use core::IdentityMatrix - added deletePathFromFilename to generic string functions in coreutil.h and removed from CZipReader and CPakReader - s32 deserializeAttributes used instead of virtual void deserializeAttributes in ParticleSystem ( wrong virtual was used) - strings & Locale - started to add locale support - added verify to string - added some helper functions - XBOX i have access to a XBOX development machine now. I started to compile for the XBOX. Question: Who did the previous implementation?. There is no XBOX-Device inhere. maybe it's forbidden because of using the offical Microsoft XDK. I will implement a native or sdl device based on opendk. irrlicht compiles without errors on the xbox but can't be used. TODO: - native XBOX Device - Windows Mobile reworked a little. added the mobile example to the windows solution for cross development. added maximal 128x128 texture size for windows mobile ( memory issues ) - Collision Speed Up The Collision Speed Up greatly improves with many small static child-nodes - added COctTreeTriangleSelector::getTriangles for 3dline from user Piraaate - modified createOctTreeTriangleSelector and createTriangleSelector to allow node == 0, to be added to a meta selector - CSceneNodeAnimatorCollisionResponse has the same problem as CSceneNodeAnimatorFPS on first update: Problem. you start setting the map. (setWorld). First update cames 4000 ms later. The Animator applies the missing force... big problem... changed to react on first update like camera. - add Variable FirstUpdate. if set to true ( on all changes ) then position, lasttime, and falling are initialized -added #define OCTTREE_USE_HARDWARE in Octree.h if defined octtree uses internally a derived scene::MeshBuffer which has the possibility to use the Hardware Vertex Buffer for static vertices and dirty indices;-) if defined OCTTREE_USE_HARDWARE octree uses internally a derived scene::CMeshBuffer so it's not just a replacement inside the octree. It also in the OctTreeSceneNode. #if defined (OCTTREE_USE_HARDWARE) driver->drawMeshBuffer ( &LightMapMeshes[i] ); #else driver->drawIndexedTriangleList( &LightMapMeshes[i].Vertices[0], LightMapMeshes[i].Vertices.size(), d[i].Indices, d[i].CurrentSize / 3); #endif #define OCTTREE_PARENTTEST is also used. It's skip testing on fully outside and takes everything on fully inside - virtual void ISceneNode::updateAbsolutePosition() - changed inline CMatrix4<T> CMatrix4<T>::operator*(const CMatrix4<T>& m2) const all two matrices have to be checked by isIdentity() to let the isIdentity work always -changed inline bool CMatrix4<T>::isIdentity() const on full identityCheck-> to look first on Translation, because this is the most challenging element which will likely not to be identity.. - virtual core::matrix4 getRelativeTransformation() const Hiarchy on Identity-Check 1) ->getRelativeTransform -> 9 floating point checks to be passed as Identity 2) ->isIdentity () -> 16 floating point checks to be passed as Identity - inline void CMatrix4<T>::transformBoxEx(core::aabbox3d<f32>& box) const added isIdentity() check - changed CSceneNodeAnimatorCollisionResponse - added CSceneNodeAnimatorCollisionResponse::setGravity needed to set the differents Forces for the Animator. for eq. water.. - added CSceneNodeAnimatorCollisionResponse::setAnimateTarget - added CSceneNodeAnimatorCollisionResponse::getAnimateTarget - changed CSceneNodeAnimatorCollisionResponse::animateNode to react on FirstUpdate - changad Gravity to - TODO: set Gravity to Physically frame independent values.. current response uses an frame depdended acceleration vector. ~9.81 m/s^2 was achieved at around 50 fps with a setting of -0.03 may effect existing application.. - SceneNodes - CSkyDomeSceneNode moved radius ( default 1000 ) to constructor added Normals added DebugInfo added Material.ZBuffer, added SceneMaanager - CVolumeLightSceneNode: changed default blending OneTextureBlendgl_src_color gl_src_alpha to EMT_TRANSPARENT_ADD_COLOR ( gl_src_color gl_one ) which gives the same effect on non-transparent-materials. Following the unspoken guide-line, lowest effect as default - added LensFlareSceneNode (from forum user gammaray, modified to work ) showing in example special fx - changed SceneNode Skydome f64 to f32, - AnimatedMesh -Debug Data: mesh normals didn't rotate with the scenenode fixed ( matrix-multiplication order) - Camera SceneNode setPosition Camera now finally allow to change position and target and updates all effected animators.. a call to OnAnimate ( ) lastime < time or OnAnimate ( 0 ) will reset the camera and fr. the collision animator to a new position - Device: added the current mousebutton state to the Mouse Event so i need to get the current mouse state from the OS -a dded to CIrrDeviceWin32 TODO: - Linux and SDL Device - GUI - CGUIFont: - added virtual void setInvisibleCharacters( const wchar_t *s ) = 0; define which characters should not be drawn ( send to driver) by the font. for example " " would not draw any space which is usually blank in most fonts and saves rendering of ususally full blank alpha-sprites. This saves a lot of rendering... default: setInvisibleCharacters ( L" " ); - added MultiLine rendering should avoid to us CStaticText breaking text in future - CGUIListBox - changed Scrollbar LargeStepSize to ItemHeight which easy enables to scroll line by line - CGUIScrollBar bug: Create a Window and inside a listbox with a scrollbar or a windowed irrlicht application Click & hold Scrollbar Slider. move outside it's region. Release Mouse. Go Back to Scrollbar.. it's moving always... it's generally missing the event PRESSED_MOVED, which leads to problem when an element is dragging, has a focus, or position loose and gets focus back again. ( think of a drunken mouse sliding left&right during tracking ) so added the mouse Input Buttonstates on every mouse event IrrDeviceWin32: added event.MouseInput.ButtonStates = wParam & ( MK_LBUTTON | MK_RBUTTON | MK_MBUTTON ); TODO: Linux & SDL so now i can do this case irr::EMIE_MOUSE_MOVED: if ( !event.MouseInput.isLeftPressed () ) { Dragging = false; } - bug: Scrollbar notifyListBox notify when the scrollbar is clicked. - changed timed event in draw to OnPostRender Why the hell is a gui element firing a timed event in a draw routine!!!!!. This should be corrected for all gui-elements. - added GUI Image List from Reinhard Ostermeier, modified to work added GUI Tree View from Reinhard Ostermeier, modified to work shown in the Quake3MapShader Example TODO: Spritebanks - FileOpenDialog changed the static text for the filename to an edit box. - changed the interface for addEditBox to match with addStaticText - changed the interface for addSpinBox to match with addEditBox - added MouseWheel to Spinbox - changed CGUITable CLICK_AREA from 3 to 12 to enable clicking on the visible marker - CGUISpritebank removed some crashes with empty Sprite banks - IGUIScrollBar added SetMin before min was always 0 changed ScrollWheel Direction on horizontal to move right on wheel up, left on wheel down - IComboBox -added ItemData - removed IsVisbile check in IGUIElement::draw - Image Loaders - added TGA file type 2 ( grayscale uncompressed ) - added TGA file type (1) 8 Bit indexed color uncompressed ColorConverter: - added convert_B8G8R8toA8R8G8B8 - added convert_B8G8R8A8toA8R8G8B8 - Media Files - added missing shaders and textures to map-20kdm2. Taken from free implementation - ball.wav. adjusted DC-Offset, amplified to -4dB, trim cross-zero - impact.wav clip-restoration, trim cross-zero - added gun.md2, gun.pcx to media-files copyright issues!. i don't know from where this file came from... i hope this is not from original quake2.. - added new irrlicht logo irrlicht3.png i've taken the new layout. i should ask niko to use it. - added Skydome picture to media files (skydome2.jpg) half/sphere - OctTree -added #define OCTTREE_PARENTTEST ( default: disabled ) used to leave-out children test if the parent passed a complete frustum. plus: leaves out children test minus: all edges have to be checked - added MesBuffer Hardware Hint Vertex to octtree - CQuake3ShaderSceneNode: - removed function releaseMesh Shader doesn't copy the original mesh anymore ( saving memory ) so therefore this (for others often misleading ) function was removed - changed constructor to take a (shared) destination meshbuffer for rendering reducing vertex-memory to a half - don't copy the original vertices anymore - added deformvertexes autosprite - added deformvertexes move - added support for RTCW and Raven BSPs ( qmap2 ) - added polygonoffset (TODO: not perfect) - added added nomipmaps - added rgbgen const - added alphagen - added MesBuffer Hardware Hint Vertex/Index to Quake3: static geometry, dynamic indices - added Quake3Explorer examples - added wave noise - added tcmod transform - added whiteimage - added collision to Quake3Explorer - renamed SMD3QuaterionTag* to SMD3QuaternionTag* ( typo ) - updated quake3:blendfunc - added crouch to Quake3Explorer (modifying the ellipsiodRadius of the camera animator ) added crouch to CSceneNodeAnimatorCameraFPS still problems with stand up and collision - Quake3MapLoader modified memory allocation for faster loading - Quake3LoadParam added Parameter to the Mesh-Loader - added The still existing missing caulking of curved surfaces. using round in the coordinates doesn't solve the problem. but for the demo bsp mesh it solves the problem... (luck) so for now it's switchable. TJUNCTION_SOLVER_ROUND default:off - BurningVideo - pushed BurningsVideo to 0.40 - added blendfunc gl_one_minus_dst_alpha gl_one - added blendfunc gl_dst_color gl_zero - added blendfunc gl_dst_color src_alpha - modified AlphaChannel_Ref renderer to support alpha test lessequal - addded 32 Bit Index Buffer - added sourceRect/destRect check to 2D-Blitter ( slower, but resolves crash ) - added setTextureCreationFlag video::ETCF_ALLOW_NON_POWER_2 Burning checks this flag and when set, it bypasses the power2 size check, which is necessary on 3D but can be avoided on 2D. used on fonts automatically. - added Support for Destination Alpha - OpenGL - Fixed a bug in COpenGLExtensenionHandler where a glint was downcasted to u8!!!!!! MaxTextureSize=static_cast<u32>(num); - TODO: COpenGLMaterialRenderer_ONETEXTURE_BLEND to work as expected - Direct3D8 - compile and links again - added 32 Bit Index Buffer - D3DSAMP_MIPMAPLODBIAS doesnt compile!. it is d3d9 i think. - compile for XBOX - Direc3D9 - fixed crash on RTT Textures DepthBuffer freed twice. added deleteAllTextures to destuctor - NullDriver - removeallTextures. added setMaterial ( SMaterial() ) to clean pointers for freed textures git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2147 dfc29bdd-3216-0410-991c-e03cc46cb475
2009-01-27 07:53:53 -08:00
if (FileSystem->existFile(file))
return driver->getTexture(file);
core::stringc strippedName=FileSystem->getFileBasename(file);
if (FileSystem->existFile(strippedName))
return driver->getTexture(strippedName);
core::stringc newpath = FileSystem->getFileDir(File->getFileName());
newpath.append("/");
newpath.append(strippedName);
if (FileSystem->existFile(newpath))
return driver->getTexture(newpath);
os::Printer::log("Could not load texture", file.c_str(), ELL_WARNING);
return 0;
}
} // end namespace scene
} // end namespace irr