Commit ce44c10f authored by bitplane's avatar bitplane

Added PLY reader, currently only supports ascii and little-endian binary files.

Added mesh writer flag for binary export, not used yet.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2251 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 00be4fed
Changes in 1.6
- Added PLY mesh writer
- Added PLY mesh reader and writer
- Ensure ListBox on combo box doesn't hang off the bottom of the GUI root, by Matthias Specht
......
......@@ -45,7 +45,10 @@ namespace scene
EMWF_WRITE_LIGHTMAPS = 0x1,
//! write in a way that consumes less disk space
EMWF_WRITE_COMPRESSED = 0x2
EMWF_WRITE_COMPRESSED = 0x2,
//! write in binary format rather than text
EMWF_WRITE_BINARY = 0x4
};
} // end namespace scene
......
......@@ -264,10 +264,12 @@ B3D, MS3D or X meshes */
#define _IRR_COMPILE_WITH_OGRE_LOADER_
//! Define _IRR_COMPILE_WITH_LWO_LOADER_ if you want to load Lightwave3D files
#define _IRR_COMPILE_WITH_LWO_LOADER_
//! Define _IRR_COMPILE_WITH_STL_LOADER_ if you want to load .stl files
//! Define _IRR_COMPILE_WITH_STL_LOADER_ if you want to load stereolithography files
#define _IRR_COMPILE_WITH_STL_LOADER_
//! Define _IRR_COMPILE_WITH_PLY_LOADER_ if you want to load Polygon (Stanford Triangle) files
#define _IRR_COMPILE_WITH_PLY_LOADER_
//! Define _IRR_COMPILE_WITH_IRR_WRITER_ if you want to write static .irr files
//! Define _IRR_COMPILE_WITH_IRR_WRITER_ if you want to write static .irrMesh files
#define _IRR_COMPILE_WITH_IRR_WRITER_
//! Define _IRR_COMPILE_WITH_COLLADA_WRITER_ if you want to write Collada files
#define _IRR_COMPILE_WITH_COLLADA_WRITER_
......
This diff is collapsed.
// Copyright (C) 2009 Gaz Davidson
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_PLY_MESH_FILE_LOADER_H_INCLUDED__
#define __C_PLY_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "CDynamicMeshBuffer.h"
namespace irr
{
namespace scene
{
//! Meshloader capable of loading obj meshes.
class CPLYMeshFileLoader : public IMeshLoader
{
public:
//! Constructor
CPLYMeshFileLoader();
//! Destructor
virtual ~CPLYMeshFileLoader();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".ply")
virtual bool isALoadableFileExtension(const core::string<c16>& filename) const;
//! creates/loads an animated mesh from the file.
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
private:
enum E_PLY_PROPERTY_TYPE
{
EPLYPT_INT8 = 0,
EPLYPT_INT16,
EPLYPT_INT32,
EPLYPT_FLOAT32,
EPLYPT_FLOAT64,
EPLYPT_LIST,
EPLYPT_UNKNOWN
};
struct SPLYProperty
{
core::stringc Name;
E_PLY_PROPERTY_TYPE Type;
union
{
u8 Int8;
u16 Int16;
u32 Int32;
f32 Float32;
f64 Double;
struct SPLYListProperty
{
E_PLY_PROPERTY_TYPE CountType;
E_PLY_PROPERTY_TYPE ItemType;
} List;
} Data;
inline u32 size() const
{
switch(Type)
{
case EPLYPT_INT8:
return 1;
case EPLYPT_INT16:
return 2;
case EPLYPT_INT32:
case EPLYPT_FLOAT32:
return 4;
case EPLYPT_FLOAT64:
return 8;
case EPLYPT_LIST:
case EPLYPT_UNKNOWN:
default:
return 0;
}
}
inline bool isFloat() const
{
switch(Type)
{
case EPLYPT_FLOAT32:
case EPLYPT_FLOAT64:
return true;
case EPLYPT_INT8:
case EPLYPT_INT16:
case EPLYPT_INT32:
case EPLYPT_LIST:
case EPLYPT_UNKNOWN:
default:
return false;
}
}
};
struct SPLYElement
{
// name of the element. We only want "vertex" and "face" elements
// but we have to parse the others anyway.
core::stringc Name;
// The number of elements in the file
u32 Count;
// Properties of this element
core::array<SPLYProperty> Properties;
// in binary files, true if this is a fixed size
bool IsFixedWidth;
// known size in bytes, 0 if unknown
u32 KnownSize;
};
bool allocateBuffer();
c8* getNextLine();
c8* getNextWord();
void fillBuffer();
E_PLY_PROPERTY_TYPE getPropertyType(const c8* typeString) const;
bool readVertex(const SPLYElement &Element, scene::CDynamicMeshBuffer* mb);
bool readFace(const SPLYElement &Element, scene::CDynamicMeshBuffer* mb);
void skipElement(const SPLYElement &Element);
void skipProperty(const SPLYProperty &Property);
f32 getFloat(E_PLY_PROPERTY_TYPE t);
u32 getInt(E_PLY_PROPERTY_TYPE t);
void moveForward(u32 bytes);
core::array<SPLYElement*> ElementList;
io::IReadFile *File;
c8 *Buffer;
bool IsBinaryFile, IsWrongEndian, EndOfFile;
s32 LineLength, WordLength;
c8 *StartPointer, *EndPointer, *LineEndPointer;
};
} // end namespace scene
} // end namespace irr
#endif
......@@ -123,9 +123,9 @@ bool CPLYMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla
snprintf(outLine, 1024,
"%f %f %f %f %f %f\n",// %u %u %u %u %f %f\n",
pos.X, pos.Z, pos.Y, // Y and Z are flipped
n.X, n.Z, n.Y,
col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha(),
tc.X, tc.Y);
n.X, n.Z, n.Y);
/*col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha(),
tc.X, tc.Y);*/
// write the line
file->write(outLine, strlen(outLine));
......@@ -179,5 +179,5 @@ bool CPLYMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla
} // end namespace
} // end namespace
#endif
#endif // _IRR_COMPILE_WITH_PLY_WRITER_
......@@ -89,6 +89,10 @@
#include "CSTLMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_PLY_LOADER_
#include "CPLYMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_COLLADA_WRITER_
#include "CColladaMeshWriter.h"
#endif
......@@ -252,6 +256,9 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
#ifdef _IRR_COMPILE_WITH_STL_LOADER_
MeshLoaderList.push_back(new CSTLMeshFileLoader());
#endif
#ifdef _IRR_COMPILE_WITH_PLY_LOADER_
MeshLoaderList.push_back(new CPLYMeshFileLoader());
#endif
// factories
ISceneNodeFactory* factory = new CDefaultSceneNodeFactory(this);
......
......@@ -584,6 +584,8 @@
<Unit filename="COpenGLShaderMaterialRenderer.h" />
<Unit filename="COpenGLTexture.cpp" />
<Unit filename="COpenGLTexture.h" />
<Unit filename="CPLYMeshFileLoader.cpp" />
<Unit filename="CPLYMeshFileLoader.h" />
<Unit filename="CPLYMeshWriter.cpp" />
<Unit filename="CPLYMeshWriter.h" />
<Unit filename="CPakReader.cpp" />
......
......@@ -9,7 +9,7 @@ CppCompiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL -DIR
Includes=..\..\include;zlib
Linker=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lwinmm -lopengl32_@@_
Libs=
UnitCount=615
UnitCount=617
Folders=doc,gui_impl,include,include/core,include/gui,include/io,include/scene,include/video,io_impl,other_impl,other_impl/extern,other_impl/extern/jpeglib,other_impl/extern/libpng,other_impl/extern/zlib,scene_impl,scene_impl/animators,scene_impl/collision,scene_impl/mesh,scene_impl/mesh/loaders,scene_impl/mesh/writers,scene_impl/nodes,scene_impl/nodes/particles,video_impl,"video_impl/Burning Video",video_impl/DirectX8,video_impl/DirectX9,video_impl/Null,video_impl/OpenGL,video_impl/Software
ObjFiles=
PrivateResource=
......@@ -6197,3 +6197,23 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit616]
FileName=CPLYMeshFileLoader.cpp
CompileCpp=1
Folder=scene_impl/mesh/loaders
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit617]
FileName=CPLYMeshFileLoader.h
CompileCpp=1
Folder=scene_impl/mesh/loaders
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
......@@ -1583,6 +1583,12 @@
<File
RelativePath=".\COgreMeshFileLoader.h">
</File>
<File
RelativePath=".\CPLYMeshFileLoader.cpp">
</File>
<File
RelativePath=".\CPLYMeshFileLoader.h">
</File>
<File
RelativePath=".\CQ3LevelMesh.cpp">
</File>
......
......@@ -2213,6 +2213,14 @@
RelativePath=".\COgreMeshFileLoader.cpp"
>
</File>
<File
RelativePath=".\CPLYMeshFileLoader.cpp"
>
</File>
<File
RelativePath=".\CPLYMeshFileLoader.h"
>
</File>
<File
RelativePath=".\COgreMeshFileLoader.h"
>
......
......@@ -2193,6 +2193,14 @@
RelativePath="COgreMeshFileLoader.h"
>
</File>
<File
RelativePath="CPLYMeshFileLoader.cpp"
>
</File>
<File
RelativePath="CPLYMeshFileLoader.h"
>
</File>
<File
RelativePath="CQ3LevelMesh.cpp"
>
......
......@@ -1868,6 +1868,14 @@
RelativePath="COgreMeshFileLoader.h"
>
</File>
<File
RelativePath="CPLYMeshFileLoader.cpp"
>
</File>
<File
RelativePath="CPLYMeshFileLoader.h"
>
</File>
<File
RelativePath="CQ3LevelMesh.cpp"
>
......
......@@ -1114,6 +1114,12 @@
<File
RelativePath=".\COgreMeshFileLoader.h">
</File>
<File
RelativePath=".\CPLYMeshFileLoader.cpp">
</File>
<File
RelativePath=".\CPLYMeshFileLoader.h">
</File>
<File
RelativePath=".\COSOperator.cpp">
</File>
......
......@@ -19,7 +19,7 @@ VERSION = 1.5
#
#List of object files, separated based on engine architecture
IRRMESHLOADER = CBSPMeshFileLoader.o CMD2MeshFileLoader.o CMD3MeshFileLoader.o CMS3DMeshFileLoader.o CB3DMeshFileLoader.o C3DSMeshFileLoader.o COgreMeshFileLoader.o COBJMeshFileLoader.o CColladaFileLoader.o CCSMLoader.o CDMFLoader.o CLMTSMeshFileLoader.o CMY3DMeshFileLoader.o COCTLoader.o CXMeshFileLoader.o CIrrMeshFileLoader.o CSTLMeshFileLoader.o CLWOMeshFileLoader.o
IRRMESHLOADER = CBSPMeshFileLoader.o CMD2MeshFileLoader.o CMD3MeshFileLoader.o CMS3DMeshFileLoader.o CB3DMeshFileLoader.o C3DSMeshFileLoader.o COgreMeshFileLoader.o COBJMeshFileLoader.o CColladaFileLoader.o CCSMLoader.o CDMFLoader.o CLMTSMeshFileLoader.o CMY3DMeshFileLoader.o COCTLoader.o CXMeshFileLoader.o CIrrMeshFileLoader.o CSTLMeshFileLoader.o CLWOMeshFileLoader.o CPLYMeshFileLoader.o
IRRMESHWRITER = CColladaMeshWriter.o CIrrMeshWriter.o CSTLMeshWriter.o COBJMeshWriter.o CPLYMeshWriter.o
IRRMESHOBJ = $(IRRMESHLOADER) $(IRRMESHWRITER) \
CSkinnedMesh.o CBoneSceneNode.o CMeshSceneNode.o \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment