Remove IrrScene loader
This commit is contained in:
parent
7dd48f4d3b
commit
a012a3a14f
@ -78,7 +78,6 @@ source/Irrlicht/CParticleGravityAffector.cpp
|
||||
source/Irrlicht/CGUISkin.cpp
|
||||
source/Irrlicht/CBoneSceneNode.cpp
|
||||
source/Irrlicht/CNPKReader.cpp
|
||||
source/Irrlicht/CIrrMeshFileLoader.cpp
|
||||
source/Irrlicht/COpenGLSLMaterialRenderer.cpp
|
||||
source/Irrlicht/CParticleRotationAffector.cpp
|
||||
source/Irrlicht/CDepthBuffer.cpp
|
||||
@ -156,7 +155,6 @@ source/Irrlicht/CIrrDeviceSDL.cpp
|
||||
source/Irrlicht/COSOperator.cpp
|
||||
source/Irrlicht/CImageLoaderJPG.cpp
|
||||
source/Irrlicht/CMD3MeshFileLoader.cpp
|
||||
source/Irrlicht/CIrrMeshWriter.cpp
|
||||
source/Irrlicht/COpenGLExtensionHandler.cpp
|
||||
source/Irrlicht/CImageLoaderWAL.cpp
|
||||
source/Irrlicht/CXMLWriter.cpp
|
||||
@ -212,7 +210,6 @@ source/Irrlicht/CIrrDeviceConsole.h
|
||||
source/Irrlicht/CTerrainSceneNode.h
|
||||
source/Irrlicht/CSceneNodeAnimatorCollisionResponse.h
|
||||
source/Irrlicht/CImageLoaderWAL.h
|
||||
source/Irrlicht/CIrrMeshFileLoader.h
|
||||
source/Irrlicht/CSceneLoaderIrr.h
|
||||
source/Irrlicht/CImageLoaderBMP.h
|
||||
source/Irrlicht/CSkinnedMesh.h
|
||||
@ -344,7 +341,6 @@ source/Irrlicht/CGUIInOutFader.h
|
||||
source/Irrlicht/CGUIFont.h
|
||||
source/Irrlicht/CGUIImageList.h
|
||||
source/Irrlicht/CAnimatedMeshMD2.h
|
||||
source/Irrlicht/CIrrMeshWriter.h
|
||||
source/Irrlicht/COBJMeshFileLoader.h
|
||||
source/Irrlicht/CFileSystem.h
|
||||
source/Irrlicht/CQ3LevelMesh.h
|
||||
|
@ -307,11 +307,6 @@ B3D, MS3D or X meshes */
|
||||
#endif
|
||||
#endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_
|
||||
|
||||
//! Define _IRR_COMPILE_WITH_IRR_MESH_LOADER_ if you want to load Irrlicht Engine .irrmesh files
|
||||
#define _IRR_COMPILE_WITH_IRR_MESH_LOADER_
|
||||
#ifdef NO_IRR_COMPILE_WITH_IRR_MESH_LOADER_
|
||||
#undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
|
||||
#endif
|
||||
//! Define _IRR_COMPILE_WITH_MD2_LOADER_ if you want to load Quake 2 animated files
|
||||
#define _IRR_COMPILE_WITH_MD2_LOADER_
|
||||
#ifdef NO_IRR_COMPILE_WITH_MD2_LOADER_
|
||||
@ -383,16 +378,6 @@ B3D, MS3D or X meshes */
|
||||
#undef _IRR_COMPILE_WITH_SMF_LOADER_
|
||||
#endif
|
||||
|
||||
//! Define _IRR_COMPILE_WITH_IRR_WRITER_ if you want to write static .irrMesh files
|
||||
//#define _IRR_COMPILE_WITH_IRR_WRITER_
|
||||
#ifdef NO_IRR_COMPILE_WITH_IRR_WRITER_
|
||||
#undef _IRR_COMPILE_WITH_IRR_WRITER_
|
||||
#endif
|
||||
//! Define _IRR_COMPILE_WITH_COLLADA_WRITER_ if you want to write Collada files
|
||||
//#define _IRR_COMPILE_WITH_COLLADA_WRITER_
|
||||
#ifdef NO_IRR_COMPILE_WITH_COLLADA_WRITER_
|
||||
#undef _IRR_COMPILE_WITH_COLLADA_WRITER_
|
||||
#endif
|
||||
//! Define _IRR_COMPILE_WITH_STL_WRITER_ if you want to write .stl files
|
||||
//#define _IRR_COMPILE_WITH_STL_WRITER_
|
||||
#ifdef NO_IRR_COMPILE_WITH_STL_WRITER_
|
||||
|
@ -1,554 +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
|
||||
|
||||
#include "IrrCompileConfig.h"
|
||||
#ifdef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
|
||||
|
||||
#include "CIrrMeshFileLoader.h"
|
||||
#include "os.h"
|
||||
#include "IXMLReader.h"
|
||||
#include "SAnimatedMesh.h"
|
||||
#include "fast_atof.h"
|
||||
#include "IReadFile.h"
|
||||
#include "IAttributes.h"
|
||||
#include "IMeshSceneNode.h"
|
||||
#include "CDynamicMeshBuffer.h"
|
||||
#include "SMeshBufferLightMap.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene
|
||||
{
|
||||
|
||||
|
||||
//! Constructor
|
||||
CIrrMeshFileLoader::CIrrMeshFileLoader(scene::ISceneManager* smgr,
|
||||
io::IFileSystem* fs)
|
||||
: SceneManager(smgr), FileSystem(fs)
|
||||
{
|
||||
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CIrrMeshFileLoader");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! Returns true if the file maybe is able to be loaded by this class.
|
||||
/** This decision should be based only on the file extension (e.g. ".cob") */
|
||||
bool CIrrMeshFileLoader::isALoadableFileExtension(const io::path& filename) const
|
||||
{
|
||||
return core::hasFileExtension ( filename, "xml", "irrmesh" );
|
||||
}
|
||||
|
||||
|
||||
//! creates/loads an animated mesh from the file.
|
||||
//! \return Pointer to the created mesh. Returns 0 if loading failed.
|
||||
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
|
||||
//! See IReferenceCounted::drop() for more information.
|
||||
IAnimatedMesh* CIrrMeshFileLoader::createMesh(io::IReadFile* file)
|
||||
{
|
||||
io::IXMLReader* reader = FileSystem->createXMLReader(file);
|
||||
if (!reader)
|
||||
return 0;
|
||||
|
||||
// read until mesh section, skip other parts
|
||||
|
||||
const core::stringc meshTagName = "mesh";
|
||||
IAnimatedMesh* mesh = 0;
|
||||
|
||||
while(reader->read())
|
||||
{
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT)
|
||||
{
|
||||
if (meshTagName == reader->getNodeName())
|
||||
{
|
||||
mesh = readMesh(reader);
|
||||
break;
|
||||
}
|
||||
else
|
||||
skipSection(reader, true); // unknown section
|
||||
}
|
||||
}
|
||||
|
||||
reader->drop();
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
|
||||
//! reads a mesh sections and creates a mesh from it
|
||||
IAnimatedMesh* CIrrMeshFileLoader::readMesh(io::IXMLReader* reader)
|
||||
{
|
||||
SAnimatedMesh* animatedmesh = new SAnimatedMesh();
|
||||
SMesh* mesh = new SMesh();
|
||||
|
||||
animatedmesh->addMesh(mesh);
|
||||
mesh->drop();
|
||||
|
||||
core::stringc bbSectionName = "boundingBox";
|
||||
core::stringc bufferSectionName = "buffer";
|
||||
core::stringc meshSectionName = "mesh";
|
||||
|
||||
if (!reader->isEmptyElement())
|
||||
while(reader->read())
|
||||
{
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT)
|
||||
{
|
||||
const wchar_t* nodeName = reader->getNodeName();
|
||||
if (bbSectionName == nodeName)
|
||||
{
|
||||
// inside a bounding box, ignore it for now because
|
||||
// we are calculating this anyway ourselves later.
|
||||
}
|
||||
else
|
||||
if (bufferSectionName == nodeName)
|
||||
{
|
||||
// we've got a mesh buffer
|
||||
|
||||
IMeshBuffer* buffer = readMeshBuffer(reader);
|
||||
if (buffer)
|
||||
{
|
||||
mesh->addMeshBuffer(buffer);
|
||||
buffer->drop();
|
||||
}
|
||||
}
|
||||
else
|
||||
skipSection(reader, true); // unknown section
|
||||
|
||||
} // end if node type is element
|
||||
else
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT_END)
|
||||
{
|
||||
if (meshSectionName == reader->getNodeName())
|
||||
{
|
||||
// end of mesh section reached, cancel out
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // end while reader->read();
|
||||
|
||||
mesh->recalculateBoundingBox();
|
||||
animatedmesh->recalculateBoundingBox();
|
||||
|
||||
return animatedmesh;
|
||||
}
|
||||
|
||||
|
||||
//! reads a mesh sections and creates a mesh buffer from it
|
||||
IMeshBuffer* CIrrMeshFileLoader::readMeshBuffer(io::IXMLReader* reader)
|
||||
{
|
||||
CDynamicMeshBuffer* buffer = 0;
|
||||
|
||||
core::stringc verticesSectionName = "vertices";
|
||||
core::stringc bbSectionName = "boundingBox";
|
||||
core::stringc materialSectionName = "material";
|
||||
core::stringc indicesSectionName = "indices";
|
||||
core::stringc bufferSectionName = "buffer";
|
||||
|
||||
bool insideVertexSection = false;
|
||||
bool insideIndexSection = false;
|
||||
|
||||
int vertexCount = 0;
|
||||
int indexCount = 0;
|
||||
|
||||
video::SMaterial material;
|
||||
|
||||
if (!reader->isEmptyElement())
|
||||
while(reader->read())
|
||||
{
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT)
|
||||
{
|
||||
const wchar_t* nodeName = reader->getNodeName();
|
||||
if (bbSectionName == nodeName)
|
||||
{
|
||||
// inside a bounding box, ignore it for now because
|
||||
// we are calculating this anyway ourselves later.
|
||||
}
|
||||
else
|
||||
if (materialSectionName == nodeName)
|
||||
{
|
||||
//we've got a material
|
||||
|
||||
io::IAttributes* attributes = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver());
|
||||
attributes->read(reader, true, L"material");
|
||||
|
||||
SceneManager->getVideoDriver()->fillMaterialStructureFromAttributes(material, attributes);
|
||||
attributes->drop();
|
||||
}
|
||||
else
|
||||
if (verticesSectionName == nodeName)
|
||||
{
|
||||
// vertices section
|
||||
|
||||
const core::stringc vertexTypeName1 = "standard";
|
||||
const core::stringc vertexTypeName2 = "2tcoords";
|
||||
const core::stringc vertexTypeName3 = "tangents";
|
||||
|
||||
const wchar_t* vertexType = reader->getAttributeValue(L"type");
|
||||
vertexCount = reader->getAttributeValueAsInt(L"vertexCount");
|
||||
|
||||
insideVertexSection = true;
|
||||
|
||||
video::E_INDEX_TYPE itype = (vertexCount > 65536)?irr::video::EIT_32BIT:irr::video::EIT_16BIT;
|
||||
if (vertexTypeName1 == vertexType)
|
||||
{
|
||||
buffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, itype);
|
||||
|
||||
}
|
||||
else
|
||||
if (vertexTypeName2 == vertexType)
|
||||
{
|
||||
buffer = new CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, itype);
|
||||
}
|
||||
else
|
||||
if (vertexTypeName3 == vertexType)
|
||||
{
|
||||
buffer = new CDynamicMeshBuffer(irr::video::EVT_TANGENTS, itype);
|
||||
}
|
||||
buffer->getVertexBuffer().reallocate(vertexCount);
|
||||
buffer->Material = material;
|
||||
}
|
||||
else
|
||||
if (indicesSectionName == nodeName)
|
||||
{
|
||||
// indices section
|
||||
|
||||
indexCount = reader->getAttributeValueAsInt(L"indexCount");
|
||||
insideIndexSection = true;
|
||||
}
|
||||
|
||||
} // end if node type is element
|
||||
else
|
||||
if (reader->getNodeType() == io::EXN_TEXT)
|
||||
{
|
||||
// read vertex data
|
||||
if (insideVertexSection)
|
||||
{
|
||||
readMeshBuffer(reader, vertexCount, buffer);
|
||||
insideVertexSection = false;
|
||||
|
||||
} // end reading vertex array
|
||||
else
|
||||
if (insideIndexSection)
|
||||
{
|
||||
readIndices(reader, indexCount, buffer->getIndexBuffer());
|
||||
insideIndexSection = false;
|
||||
}
|
||||
|
||||
} // end if node type is text
|
||||
else
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT_END)
|
||||
{
|
||||
if (bufferSectionName == reader->getNodeName())
|
||||
{
|
||||
// end of buffer section reached, cancel out
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // end while reader->read();
|
||||
|
||||
if (buffer)
|
||||
buffer->recalculateBoundingBox();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
//! read indices
|
||||
void CIrrMeshFileLoader::readIndices(io::IXMLReader* reader, int indexCount, IIndexBuffer& indices)
|
||||
{
|
||||
indices.reallocate(indexCount);
|
||||
|
||||
core::stringc data = reader->getNodeData();
|
||||
const c8* p = &data[0];
|
||||
|
||||
for (int i=0; i<indexCount && *p; ++i)
|
||||
{
|
||||
findNextNoneWhiteSpace(&p);
|
||||
indices.push_back(readInt(&p));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CIrrMeshFileLoader::readMeshBuffer(io::IXMLReader* reader, int vertexCount, CDynamicMeshBuffer* sbuffer)
|
||||
{
|
||||
core::stringc data = reader->getNodeData();
|
||||
const c8* p = &data[0];
|
||||
scene::IVertexBuffer& Vertices = sbuffer->getVertexBuffer();
|
||||
video::E_VERTEX_TYPE vType = Vertices.getType();
|
||||
|
||||
if (sbuffer)
|
||||
{
|
||||
for (int i=0; i<vertexCount && *p; ++i)
|
||||
{
|
||||
switch(vType)
|
||||
{
|
||||
case video::EVT_STANDARD:
|
||||
{
|
||||
video::S3DVertex vtx;
|
||||
// position
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.Z = readFloat(&p);
|
||||
|
||||
// normal
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.Z = readFloat(&p);
|
||||
|
||||
// color
|
||||
|
||||
u32 col;
|
||||
findNextNoneWhiteSpace(&p);
|
||||
sscanf(p, "%08x", &col);
|
||||
vtx.Color.set(col);
|
||||
skipCurrentNoneWhiteSpace(&p);
|
||||
|
||||
// tcoord1
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords.Y = readFloat(&p);
|
||||
|
||||
Vertices.push_back(vtx);
|
||||
}
|
||||
break;
|
||||
case video::EVT_2TCOORDS:
|
||||
{
|
||||
video::S3DVertex2TCoords vtx;
|
||||
// position
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.Z = readFloat(&p);
|
||||
|
||||
// normal
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.Z = readFloat(&p);
|
||||
|
||||
// color
|
||||
|
||||
u32 col;
|
||||
findNextNoneWhiteSpace(&p);
|
||||
sscanf(p, "%08x", &col);
|
||||
vtx.Color.set(col);
|
||||
skipCurrentNoneWhiteSpace(&p);
|
||||
|
||||
// tcoord1
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords.Y = readFloat(&p);
|
||||
|
||||
// tcoord2
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords2.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords2.Y = readFloat(&p);
|
||||
|
||||
Vertices.push_back(vtx);
|
||||
}
|
||||
break;
|
||||
|
||||
case video::EVT_TANGENTS:
|
||||
{
|
||||
video::S3DVertexTangents vtx;
|
||||
// position
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Pos.Z = readFloat(&p);
|
||||
|
||||
// normal
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Normal.Z = readFloat(&p);
|
||||
|
||||
// color
|
||||
|
||||
u32 col;
|
||||
findNextNoneWhiteSpace(&p);
|
||||
sscanf(p, "%08x", &col);
|
||||
vtx.Color.set(col);
|
||||
skipCurrentNoneWhiteSpace(&p);
|
||||
|
||||
// tcoord1
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.TCoords.Y = readFloat(&p);
|
||||
|
||||
// tangent
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Tangent.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Tangent.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Tangent.Z = readFloat(&p);
|
||||
|
||||
// binormal
|
||||
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Binormal.X = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Binormal.Y = readFloat(&p);
|
||||
findNextNoneWhiteSpace(&p);
|
||||
vtx.Binormal.Z = readFloat(&p);
|
||||
|
||||
Vertices.push_back(vtx);
|
||||
}
|
||||
break;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! skips an (unknown) section in the irrmesh document
|
||||
void CIrrMeshFileLoader::skipSection(io::IXMLReader* reader, bool reportSkipping)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
os::Printer::log("irrMesh skipping section", core::stringc(reader->getNodeName()).c_str());
|
||||
#endif
|
||||
|
||||
// skip if this element is empty anyway.
|
||||
if (reader->isEmptyElement())
|
||||
return;
|
||||
|
||||
// read until we've reached the last element in this section
|
||||
u32 tagCounter = 1;
|
||||
|
||||
while(tagCounter && reader->read())
|
||||
{
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT &&
|
||||
!reader->isEmptyElement())
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (reportSkipping)
|
||||
os::Printer::log("irrMesh unknown element:", core::stringc(reader->getNodeName()).c_str());
|
||||
#endif
|
||||
|
||||
++tagCounter;
|
||||
}
|
||||
else
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT_END)
|
||||
--tagCounter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! parses a float from a char pointer and moves the pointer
|
||||
//! to the end of the parsed float
|
||||
inline f32 CIrrMeshFileLoader::readFloat(const c8** p)
|
||||
{
|
||||
f32 ftmp;
|
||||
*p = core::fast_atof_move(*p, ftmp);
|
||||
return ftmp;
|
||||
}
|
||||
|
||||
|
||||
//! parses an int from a char pointer and moves the pointer to
|
||||
//! the end of the parsed float
|
||||
inline s32 CIrrMeshFileLoader::readInt(const c8** p)
|
||||
{
|
||||
return (s32)readFloat(p);
|
||||
}
|
||||
|
||||
|
||||
//! places pointer to next begin of a token
|
||||
void CIrrMeshFileLoader::skipCurrentNoneWhiteSpace(const c8** start)
|
||||
{
|
||||
const c8* p = *start;
|
||||
|
||||
while(*p && !(*p==' ' || *p=='\n' || *p=='\r' || *p=='\t'))
|
||||
++p;
|
||||
|
||||
// TODO: skip comments <!-- -->
|
||||
|
||||
*start = p;
|
||||
}
|
||||
|
||||
//! places pointer to next begin of a token
|
||||
void CIrrMeshFileLoader::findNextNoneWhiteSpace(const c8** start)
|
||||
{
|
||||
const c8* p = *start;
|
||||
|
||||
while(*p && (*p==' ' || *p=='\n' || *p=='\r' || *p=='\t'))
|
||||
++p;
|
||||
|
||||
// TODO: skip comments <!-- -->
|
||||
|
||||
*start = p;
|
||||
}
|
||||
|
||||
|
||||
//! reads floats from inside of xml element until end of xml element
|
||||
void CIrrMeshFileLoader::readFloatsInsideElement(io::IXMLReader* reader, f32* floats, u32 count)
|
||||
{
|
||||
if (reader->isEmptyElement())
|
||||
return;
|
||||
|
||||
while(reader->read())
|
||||
{
|
||||
// TODO: check for comments inside the element
|
||||
// and ignore them.
|
||||
|
||||
if (reader->getNodeType() == io::EXN_TEXT)
|
||||
{
|
||||
// parse float data
|
||||
core::stringc data = reader->getNodeData();
|
||||
const c8* p = &data[0];
|
||||
|
||||
for (u32 i=0; i<count; ++i)
|
||||
{
|
||||
findNextNoneWhiteSpace(&p);
|
||||
if (*p)
|
||||
floats[i] = readFloat(&p);
|
||||
else
|
||||
floats[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (reader->getNodeType() == io::EXN_ELEMENT_END)
|
||||
break; // end parsing text
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // end namespace scene
|
||||
} // end namespace irr
|
||||
|
||||
#endif // _IRR_COMPILE_WITH_IRR_MESH_LOADER_
|
@ -1,90 +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
|
||||
|
||||
#ifndef __C_IRR_MESH_FILE_LOADER_H_INCLUDED__
|
||||
#define __C_IRR_MESH_FILE_LOADER_H_INCLUDED__
|
||||
|
||||
#include "IMeshLoader.h"
|
||||
#include "IFileSystem.h"
|
||||
#include "IVideoDriver.h"
|
||||
#include "irrString.h"
|
||||
#include "SMesh.h"
|
||||
#include "SMeshBuffer.h"
|
||||
#include "CDynamicMeshBuffer.h"
|
||||
#include "ISceneManager.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene
|
||||
{
|
||||
|
||||
|
||||
//! Meshloader capable of loading .irrmesh meshes, the Irrlicht Engine mesh format for static meshes
|
||||
class CIrrMeshFileLoader : public IMeshLoader
|
||||
{
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
CIrrMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
|
||||
|
||||
//! returns true if the file maybe is able to be loaded by this class
|
||||
//! based on the file extension (e.g. ".cob")
|
||||
virtual bool isALoadableFileExtension(const io::path& filename) const;
|
||||
|
||||
//! creates/loads an animated mesh from the file.
|
||||
//! \return Pointer to the created mesh. Returns 0 if loading failed.
|
||||
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
|
||||
//! See IReferenceCounted::drop() for more information.
|
||||
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
|
||||
|
||||
private:
|
||||
|
||||
//! reads a mesh sections and creates a mesh from it
|
||||
IAnimatedMesh* readMesh(io::IXMLReader* reader);
|
||||
|
||||
//! reads a mesh sections and creates a mesh buffer from it
|
||||
IMeshBuffer* readMeshBuffer(io::IXMLReader* reader);
|
||||
|
||||
//! skips an (unknown) section in the irrmesh file
|
||||
void skipSection(io::IXMLReader* reader, bool reportSkipping);
|
||||
|
||||
//! reads a <material> element and stores it in the material section
|
||||
void readMaterial(io::IXMLReader* reader);
|
||||
|
||||
//! parses a float from a char pointer and moves the pointer to
|
||||
//! the end of the parsed float
|
||||
inline f32 readFloat(const c8** p);
|
||||
|
||||
//! parses an int from a char pointer and moves the pointer to
|
||||
//! the end of the parsed float
|
||||
inline s32 readInt(const c8** p);
|
||||
|
||||
//! places pointer to next begin of a token
|
||||
void findNextNoneWhiteSpace(const c8** p);
|
||||
|
||||
//! places pointer to next begin of a token
|
||||
void skipCurrentNoneWhiteSpace(const c8** p);
|
||||
|
||||
//! reads floats from inside of xml element until end of xml element
|
||||
void readFloatsInsideElement(io::IXMLReader* reader, f32* floats, u32 count);
|
||||
|
||||
//! read the mesh buffers
|
||||
void readMeshBuffer(io::IXMLReader* reader, int vertexCount, CDynamicMeshBuffer* sbuffer);
|
||||
|
||||
//! read indices
|
||||
void readIndices(io::IXMLReader* reader, int indexCount, IIndexBuffer& indices);
|
||||
|
||||
|
||||
// member variables
|
||||
|
||||
scene::ISceneManager* SceneManager;
|
||||
io::IFileSystem* FileSystem;
|
||||
};
|
||||
|
||||
|
||||
} // end namespace scene
|
||||
} // end namespace irr
|
||||
|
||||
#endif
|
||||
|
@ -1,315 +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
|
||||
|
||||
#include "IrrCompileConfig.h"
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_IRR_WRITER_
|
||||
|
||||
#include "CIrrMeshWriter.h"
|
||||
#include "os.h"
|
||||
#include "IWriteFile.h"
|
||||
#include "IXMLWriter.h"
|
||||
#include "IMesh.h"
|
||||
#include "IAttributes.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene
|
||||
{
|
||||
|
||||
|
||||
CIrrMeshWriter::CIrrMeshWriter(video::IVideoDriver* driver,
|
||||
io::IFileSystem* fs)
|
||||
: FileSystem(fs), VideoDriver(driver), Writer(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CIrrMeshWriter");
|
||||
#endif
|
||||
|
||||
if (VideoDriver)
|
||||
VideoDriver->grab();
|
||||
|
||||
if (FileSystem)
|
||||
FileSystem->grab();
|
||||
}
|
||||
|
||||
|
||||
CIrrMeshWriter::~CIrrMeshWriter()
|
||||
{
|
||||
if (VideoDriver)
|
||||
VideoDriver->drop();
|
||||
|
||||
if (FileSystem)
|
||||
FileSystem->drop();
|
||||
}
|
||||
|
||||
|
||||
//! Returns the type of the mesh writer
|
||||
EMESH_WRITER_TYPE CIrrMeshWriter::getType() const
|
||||
{
|
||||
return EMWT_IRR_MESH;
|
||||
}
|
||||
|
||||
|
||||
//! writes a mesh
|
||||
bool CIrrMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags)
|
||||
{
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
Writer = FileSystem->createXMLWriter(file);
|
||||
|
||||
if (!Writer)
|
||||
{
|
||||
os::Printer::log("Could not write file", file->getFileName());
|
||||
return false;
|
||||
}
|
||||
|
||||
os::Printer::log("Writing mesh", file->getFileName());
|
||||
|
||||
// write IRR MESH header
|
||||
|
||||
Writer->writeXMLHeader();
|
||||
|
||||
Writer->writeElement(L"mesh", false,
|
||||
L"xmlns", L"http://irrlicht.sourceforge.net/IRRMESH_09_2007",
|
||||
L"version", L"1.0");
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// add some informational comment. Add a space after and before the comment
|
||||
// tags so that some braindead xml parsers (AS anyone?) are able to parse this too.
|
||||
|
||||
core::stringw infoComment = L" This file contains a static mesh in the Irrlicht Engine format with ";
|
||||
infoComment += core::stringw(mesh->getMeshBufferCount());
|
||||
infoComment += L" materials.";
|
||||
|
||||
Writer->writeComment(infoComment.c_str());
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// write mesh bounding box
|
||||
|
||||
writeBoundingBox(mesh->getBoundingBox());
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// write mesh buffers
|
||||
|
||||
for (int i=0; i<(int)mesh->getMeshBufferCount(); ++i)
|
||||
{
|
||||
scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i);
|
||||
if (buffer)
|
||||
{
|
||||
writeMeshBuffer(buffer);
|
||||
Writer->writeLineBreak();
|
||||
}
|
||||
}
|
||||
|
||||
Writer->writeClosingTag(L"mesh");
|
||||
|
||||
Writer->drop();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CIrrMeshWriter::writeBoundingBox(const core::aabbox3df& box)
|
||||
{
|
||||
Writer->writeElement(L"boundingBox", true,
|
||||
L"minEdge", getVectorAsStringLine(box.MinEdge).c_str(),
|
||||
L"maxEdge", getVectorAsStringLine(box.MaxEdge).c_str());
|
||||
}
|
||||
|
||||
|
||||
core::stringw CIrrMeshWriter::getVectorAsStringLine(const core::vector3df& v) const
|
||||
{
|
||||
core::stringw str;
|
||||
|
||||
str = core::stringw(v.X);
|
||||
str += L" ";
|
||||
str += core::stringw(v.Y);
|
||||
str += L" ";
|
||||
str += core::stringw(v.Z);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
core::stringw CIrrMeshWriter::getVectorAsStringLine(const core::vector2df& v) const
|
||||
{
|
||||
core::stringw str;
|
||||
|
||||
str = core::stringw(v.X);
|
||||
str += L" ";
|
||||
str += core::stringw(v.Y);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
void CIrrMeshWriter::writeMeshBuffer(const scene::IMeshBuffer* buffer)
|
||||
{
|
||||
Writer->writeElement(L"buffer", false);
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// write bounding box
|
||||
|
||||
writeBoundingBox(buffer->getBoundingBox());
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// write material
|
||||
|
||||
writeMaterial(buffer->getMaterial());
|
||||
|
||||
// write vertices
|
||||
|
||||
const core::stringw vertexTypeStr = video::sBuiltInVertexTypeNames[buffer->getVertexType()];
|
||||
|
||||
Writer->writeElement(L"vertices", false,
|
||||
L"type", vertexTypeStr.c_str(),
|
||||
L"vertexCount", core::stringw(buffer->getVertexCount()).c_str());
|
||||
|
||||
Writer->writeLineBreak();
|
||||
|
||||
u32 vertexCount = buffer->getVertexCount();
|
||||
|
||||
switch(buffer->getVertexType())
|
||||
{
|
||||
case video::EVT_STANDARD:
|
||||
{
|
||||
video::S3DVertex* vtx = (video::S3DVertex*)buffer->getVertices();
|
||||
for (u32 j=0; j<vertexCount; ++j)
|
||||
{
|
||||
core::stringw str = getVectorAsStringLine(vtx[j].Pos);
|
||||
str += L" ";
|
||||
str += getVectorAsStringLine(vtx[j].Normal);
|
||||
|
||||
char tmp[12];
|
||||
sprintf(tmp, " %02x%02x%02x%02x ", vtx[j].Color.getAlpha(), vtx[j].Color.getRed(), vtx[j].Color.getGreen(), vtx[j].Color.getBlue());
|
||||
str += tmp;
|
||||
|
||||
str += getVectorAsStringLine(vtx[j].TCoords);
|
||||
|
||||
Writer->writeText(str.c_str());
|
||||
Writer->writeLineBreak();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case video::EVT_2TCOORDS:
|
||||
{
|
||||
video::S3DVertex2TCoords* vtx = (video::S3DVertex2TCoords*)buffer->getVertices();
|
||||
for (u32 j=0; j<vertexCount; ++j)
|
||||
{
|
||||
core::stringw str = getVectorAsStringLine(vtx[j].Pos);
|
||||
str += L" ";
|
||||
str += getVectorAsStringLine(vtx[j].Normal);
|
||||
|
||||
char tmp[12];
|
||||
sprintf(tmp, " %02x%02x%02x%02x ", vtx[j].Color.getAlpha(), vtx[j].Color.getRed(), vtx[j].Color.getGreen(), vtx[j].Color.getBlue());
|
||||
str += tmp;
|
||||
|
||||
str += getVectorAsStringLine(vtx[j].TCoords);
|
||||
str += L" ";
|
||||
str += getVectorAsStringLine(vtx[j].TCoords2);
|
||||
|
||||
Writer->writeText(str.c_str());
|
||||
Writer->writeLineBreak();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case video::EVT_TANGENTS:
|
||||
{
|
||||
video::S3DVertexTangents* vtx = (video::S3DVertexTangents*)buffer->getVertices();
|
||||
for (u32 j=0; j<vertexCount; ++j)
|
||||
{
|
||||
core::stringw str = getVectorAsStringLine(vtx[j].Pos);
|
||||
str += L" ";
|
||||
str += getVectorAsStringLine(vtx[j].Normal);
|
||||
|
||||
char tmp[12];
|
||||
sprintf(tmp, " %02x%02x%02x%02x ", vtx[j].Color.getAlpha(), vtx[j].Color.getRed(), vtx[j].Color.getGreen(), vtx[j].Color.getBlue());
|
||||
str += tmp;
|
||||
|
||||
str += getVectorAsStringLine(vtx[j].TCoords);
|
||||
str += L" ";
|
||||
str += getVectorAsStringLine(vtx[j].Tangent);
|
||||
str += L" ";
|
||||
str += getVectorAsStringLine(vtx[j].Binormal);
|
||||
|
||||
Writer->writeText(str.c_str());
|
||||
Writer->writeLineBreak();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Writer->writeClosingTag(L"vertices");
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// write indices
|
||||
|
||||
Writer->writeElement(L"indices", false,
|
||||
L"indexCount", core::stringw(buffer->getIndexCount()).c_str());
|
||||
|
||||
Writer->writeLineBreak();
|
||||
|
||||
int indexCount = (int)buffer->getIndexCount();
|
||||
|
||||
video::E_INDEX_TYPE iType = buffer->getIndexType();
|
||||
|
||||
const u16* idx16 = buffer->getIndices();
|
||||
const u32* idx32 = (u32*) buffer->getIndices();
|
||||
const int maxIndicesPerLine = 25;
|
||||
|
||||
for (int i=0; i<indexCount; ++i)
|
||||
{
|
||||
if(iType == video::EIT_16BIT)
|
||||
{
|
||||
core::stringw str((int)idx16[i]);
|
||||
Writer->writeText(str.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
core::stringw str((int)idx32[i]);
|
||||
Writer->writeText(str.c_str());
|
||||
}
|
||||
|
||||
if (i % maxIndicesPerLine != maxIndicesPerLine)
|
||||
{
|
||||
if (i % maxIndicesPerLine == maxIndicesPerLine-1)
|
||||
Writer->writeLineBreak();
|
||||
else
|
||||
Writer->writeText(L" ");
|
||||
}
|
||||
}
|
||||
|
||||
if ((indexCount-1) % maxIndicesPerLine != maxIndicesPerLine-1)
|
||||
Writer->writeLineBreak();
|
||||
|
||||
Writer->writeClosingTag(L"indices");
|
||||
Writer->writeLineBreak();
|
||||
|
||||
// close buffer tag
|
||||
|
||||
Writer->writeClosingTag(L"buffer");
|
||||
}
|
||||
|
||||
|
||||
void CIrrMeshWriter::writeMaterial(const video::SMaterial& material)
|
||||
{
|
||||
// simply use irrlichts built-in attribute serialization capabilities here:
|
||||
|
||||
io::IAttributes* attributes =
|
||||
VideoDriver->createAttributesFromMaterial(material);
|
||||
|
||||
if (attributes)
|
||||
{
|
||||
attributes->write(Writer, false, L"material");
|
||||
attributes->drop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
#endif
|
||||
|
@ -1,63 +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
|
||||
|
||||
#ifndef __IRR_IRR_MESH_WRITER_H_INCLUDED__
|
||||
#define __IRR_IRR_MESH_WRITER_H_INCLUDED__
|
||||
|
||||
#include "IMeshWriter.h"
|
||||
#include "S3DVertex.h"
|
||||
#include "IVideoDriver.h"
|
||||
#include "IFileSystem.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
class IXMLWriter;
|
||||
}
|
||||
namespace scene
|
||||
{
|
||||
class IMeshBuffer;
|
||||
|
||||
|
||||
//! class to write meshes, implementing a IrrMesh (.irrmesh, .xml) writer
|
||||
/** This writer implementation has been originally developed for irrEdit and then
|
||||
merged out to the Irrlicht Engine */
|
||||
class CIrrMeshWriter : public IMeshWriter
|
||||
{
|
||||
public:
|
||||
|
||||
CIrrMeshWriter(video::IVideoDriver* driver, io::IFileSystem* fs);
|
||||
virtual ~CIrrMeshWriter();
|
||||
|
||||
//! Returns the type of the mesh writer
|
||||
virtual EMESH_WRITER_TYPE getType() const;
|
||||
|
||||
//! writes a mesh
|
||||
virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE);
|
||||
|
||||
protected:
|
||||
|
||||
void writeBoundingBox(const core::aabbox3df& box);
|
||||
|
||||
void writeMeshBuffer(const scene::IMeshBuffer* buffer);
|
||||
|
||||
void writeMaterial(const video::SMaterial& material);
|
||||
|
||||
core::stringw getVectorAsStringLine(const core::vector3df& v) const;
|
||||
|
||||
core::stringw getVectorAsStringLine(const core::vector2df& v) const;
|
||||
|
||||
// member variables:
|
||||
|
||||
io::IFileSystem* FileSystem;
|
||||
video::IVideoDriver* VideoDriver;
|
||||
io::IXMLWriter* Writer;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user