Added PLY writer and added VC9 project for mesh converter

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2248 dfc29bdd-3216-0410-991c-e03cc46cb475
master
bitplane 2009-03-02 11:46:47 +00:00
parent 69e7d0bd59
commit 00be4fed05
16 changed files with 933 additions and 446 deletions

View File

@ -1,5 +1,11 @@
Changes in 1.6
- Added PLY mesh writer
- Ensure ListBox on combo box doesn't hang off the bottom of the GUI root, by Matthias Specht
- Made IGUIElements recalculate clipping rectangle after setNotClipped, reported by Aelis440
- Bug fix for the combo box where it showed white text instead of skin colour before being focused, fix posted by drewbacca
- EGDS_MESSAGE_BOX_HEIGHT is now honoured, bug reported by Spkka

View File

@ -18,7 +18,7 @@ namespace scene
name clashes with external mesh writers.*/
enum EMESH_WRITER_TYPE
{
//! Irrlicht Native mesh writer, for static .irrmesh files.
//! Irrlicht native mesh writer, for static .irrmesh files.
EMWT_IRR_MESH = MAKE_IRR_ID('i','r','r','m'),
//! COLLADA mesh writer for .dae and .xml files
@ -28,7 +28,10 @@ namespace scene
EMWT_STL = MAKE_IRR_ID('s','t','l',0),
//! OBJ mesh writer for .obj files
EMWT_OBJ = MAKE_IRR_ID('o','b','j',0)
EMWT_OBJ = MAKE_IRR_ID('o','b','j',0),
//! PLY mesh writer for .ply files
EMWT_PLY = MAKE_IRR_ID('p','l','y',0)
};
@ -41,7 +44,7 @@ namespace scene
//! write lightmap textures out if possible
EMWF_WRITE_LIGHTMAPS = 0x1,
//! write in a way that does consume less disk space
//! write in a way that consumes less disk space
EMWF_WRITE_COMPRESSED = 0x2
};

View File

@ -275,6 +275,8 @@ B3D, MS3D or X meshes */
#define _IRR_COMPILE_WITH_STL_WRITER_
//! Define _IRR_COMPILE_WITH_OBJ_WRITER_ if you want to write .obj files
#define _IRR_COMPILE_WITH_OBJ_WRITER_
//! Define _IRR_COMPILE_WITH_PLY_WRITER_ if you want to write .ply files
#define _IRR_COMPILE_WITH_PLY_WRITER_
//! Define _IRR_COMPILE_WITH_BMP_LOADER_ if you want to load .bmp files
//! Disabling this loader will also disable the built-in font

View File

@ -0,0 +1,183 @@
// Copyright (C) 2008-2009 Christian Stehno
// 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_PLY_WRITER_
#include "CPLYMeshWriter.h"
#include "os.h"
#include "IMesh.h"
#include "IMeshBuffer.h"
#include "IWriteFile.h"
namespace irr
{
namespace scene
{
CPLYMeshWriter::CPLYMeshWriter()
{
#ifdef _DEBUG
setDebugName("CPLYMeshWriter");
#endif
}
//! Returns the type of the mesh writer
EMESH_WRITER_TYPE CPLYMeshWriter::getType() const
{
return EMWT_PLY;
}
//! writes a mesh
bool CPLYMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags)
{
if (!file || !mesh)
return false;
os::Printer::log("Writing mesh", file->getFileName());
// write PLY header
core::stringc header =
"ply\n"
"format ascii 1.0\n"
"comment Irrlicht Engine ";
header += IRRLICHT_SDK_VERSION;
// get vertex and triangle counts
u32 VertexCount = 0;
u32 TriangleCount = 0;
for (u32 i=0; i < mesh->getMeshBufferCount(); ++i)
{
VertexCount += mesh->getMeshBuffer(i)->getVertexCount();
TriangleCount += mesh->getMeshBuffer(i)->getIndexCount() / 3;
}
// vertex definition
header += "\nelement vertex ";
header += VertexCount;
header += "\n"
"property float x\n"
"property float y\n"
"property float z\n"
"property float nx\n"
"property float ny\n"
"property float nz\n";
// todo: writer flags for extended (r,g,b,u,v) and non-standard (alpha,u1,uv,tx,ty,tz) properties
// "property uchar red\n"
// "property uchar green\n"
// "property uchar blue\n"
// "property uchar alpha\n"
// "property float u\n"
// "property float v\n";
// "property float u1\n
// "property float v1\n"
// "property float tx\n"
// "property float ty\n"
// "property float tz\n"
// face definition
header += "element face ";
header += TriangleCount;
header += "\n"
"property list uchar int vertex_indices\n"
"end_header\n";
// write header
file->write(header.c_str(), header.size());
// write vertices
c8 outLine[1024];
for (u32 i=0; i < mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
for (u32 j=0; j < mb->getVertexCount(); ++j)
{
const core::vector3df& pos = mb->getPosition(j);
const core::vector3df& n = mb->getNormal(j);
const core::vector2df& tc = mb->getTCoords(j);
u8 *buf = (u8*)mb->getVertices();
switch(mb->getVertexType())
{
case video::EVT_STANDARD:
buf += sizeof(video::S3DVertex)*j;
break;
case video::EVT_2TCOORDS:
buf += sizeof(video::S3DVertex2TCoords)*j;
break;
case video::EVT_TANGENTS:
buf += sizeof(video::S3DVertexTangents)*j;
break;
}
video::SColor &col = ( (video::S3DVertex*)buf )->Color;
// x y z nx ny nz red green blue alpha u v [u1 v1 | tx ty tz]\n
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);
// write the line
file->write(outLine, strlen(outLine));
}
}
// index of the first vertex in the current mesh buffer
u32 StartOffset = 0;
// write triangles
for (u32 i=0; i < mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
for (u32 j=0; j < mb->getIndexCount(); j+=3)
{
// y and z are flipped so triangles are reversed
u32 a=StartOffset,
b=StartOffset,
c=StartOffset;
switch(mb->getIndexType())
{
case video::EIT_16BIT:
a += mb->getIndices()[j+0];
c += mb->getIndices()[j+1];
b += mb->getIndices()[j+2];
break;
case video::EIT_32BIT:
a += ((u32*)mb->getIndices()) [j+0];
c += ((u32*)mb->getIndices()) [j+0];
b += ((u32*)mb->getIndices()) [j+0];
break;
}
// count a b c\n
snprintf(outLine, 1024, "3 %u %u %u\n", a, b, c);
// write the line
file->write(outLine, strlen(outLine));
}
// increment offset
StartOffset += mb->getVertexCount();
}
// all done!
return true;
}
} // end namespace
} // end namespace
#endif

View File

@ -0,0 +1,35 @@
// 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 __IRR_PLY_MESH_WRITER_H_INCLUDED__
#define __IRR_PLY_MESH_WRITER_H_INCLUDED__
#include "IMeshWriter.h"
namespace irr
{
namespace scene
{
class IMeshBuffer;
//! class to write PLY mesh files
class CPLYMeshWriter : public IMeshWriter
{
public:
CPLYMeshWriter();
//! 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);
};
} // end namespace
} // end namespace
#endif

View File

@ -105,6 +105,10 @@
#include "COBJMeshWriter.h"
#endif
#ifdef _IRR_COMPILE_WITH_PLY_WRITER_
#include "CPLYMeshWriter.h"
#endif
#include "CCubeSceneNode.h"
#include "CSphereSceneNode.h"
#include "CAnimatedMeshSceneNode.h"
@ -2498,6 +2502,13 @@ IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type)
#else
return 0;
#endif
case EMWT_PLY:
#ifdef _IRR_COMPILE_WITH_PLY_WRITER_
return new CPLYMeshWriter();
#else
return 0;
#endif
}
return 0;

View File

@ -584,6 +584,8 @@
<Unit filename="COpenGLShaderMaterialRenderer.h" />
<Unit filename="COpenGLTexture.cpp" />
<Unit filename="COpenGLTexture.h" />
<Unit filename="CPLYMeshWriter.cpp" />
<Unit filename="CPLYMeshWriter.h" />
<Unit filename="CPakReader.cpp" />
<Unit filename="CPakReader.h" />
<Unit filename="CParticleAnimatedMeshSceneNodeEmitter.cpp" />

View File

@ -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=613
UnitCount=615
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=
@ -6177,3 +6177,23 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit614]
FileName=CPLYMeshWriter.cpp
CompileCpp=1
Folder=scene_impl/mesh/writers
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit615]
FileName=CPLYMeshWriter.h
CompileCpp=1
Folder=scene_impl/mesh/writers
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

View File

@ -1906,16 +1906,22 @@
RelativePath="CIrrMeshWriter.h">
</File>
<File
RelativePath=".\COBJMeshWriter.cpp">
RelativePath="COBJMeshWriter.cpp">
</File>
<File
RelativePath=".\COBJMeshWriter.h">
RelativePath="COBJMeshWriter.h">
</File>
<File
RelativePath=".\CSTLMeshWriter.cpp">
RelativePath="CPLYMeshWriter.cpp">
</File>
<File
RelativePath=".\CSTLMeshWriter.h">
RelativePath="CPLYMeshWriter.h">
</File>
<File
RelativePath="CSTLMeshWriter.cpp">
</File>
<File
RelativePath="CSTLMeshWriter.h">
</File>
</Filter>
</Filter>
@ -2000,12 +2006,10 @@
<Filter
Name="irr impl">
<File
RelativePath="CIrrDeviceConsole.cpp"
>
RelativePath="CIrrDeviceConsole.cpp">
</File>
<File
RelativePath="CIrrDeviceConsole.h"
>
RelativePath="CIrrDeviceConsole.h">
</File>
<File
RelativePath="CIrrDeviceLinux.cpp">

View File

@ -2657,6 +2657,14 @@
RelativePath="COBJMeshWriter.h"
>
</File>
<File
RelativePath="CPLYMeshWriter.cpp"
>
</File>
<File
RelativePath="CPLYMeshWriter.h"
>
</File>
<File
RelativePath="CSTLMeshWriter.cpp"
>

View File

@ -2649,6 +2649,14 @@
RelativePath="COBJMeshWriter.h"
>
</File>
<File
RelativePath=".\CPLYMeshWriter.cpp"
>
</File>
<File
RelativePath=".\CPLYMeshWriter.h"
>
</File>
<File
RelativePath="CSTLMeshWriter.cpp"
>

File diff suppressed because it is too large Load Diff

View File

@ -943,12 +943,10 @@
RelativePath=".\CGeometryCreator.h">
</File>
<File
RelativePath=".\CIrrDeviceConsole.cpp"
>
RelativePath=".\CIrrDeviceConsole.cpp">
</File>
<File
RelativePath=".\CIrrDeviceConsole.h"
>
RelativePath=".\CIrrDeviceConsole.h">
</File>
<File
RelativePath=".\CIrrDeviceLinux.cpp">
@ -1090,6 +1088,13 @@
</File>
<File
RelativePath=".\COBJMeshWriter.h">
</File>
<File
RelativePath=".\CPLYMeshWriter.cpp">
</File>
<File
RelativePath="CPLYMeshWriter.h">
</File>
<File
RelativePath=".\COCTLoader.cpp">

View File

@ -20,7 +20,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
IRRMESHWRITER = CColladaMeshWriter.o CIrrMeshWriter.o CSTLMeshWriter.o COBJMeshWriter.o
IRRMESHWRITER = CColladaMeshWriter.o CIrrMeshWriter.o CSTLMeshWriter.o COBJMeshWriter.o CPLYMeshWriter.o
IRRMESHOBJ = $(IRRMESHLOADER) $(IRRMESHWRITER) \
CSkinnedMesh.o CBoneSceneNode.o CMeshSceneNode.o \
CAnimatedMeshSceneNode.o CAnimatedMeshMD2.o CAnimatedMeshMD3.o \

View File

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="Mesh Converter"
ProjectGUID="{853A396E-C031-4C26-A716-5B4E176BE11D}"
RootNamespace="GUI Editor"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
FavorSizeOrSpeed="0"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions=" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glu32.lib opengl32.lib "
OutputFile="../../bin/Win32-visualstudio/MeshConverter.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;..\..\lib\Win32-visualstudio&quot;"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/TestProject.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="../../bin/Win32-visualstudio/GUIEditor.exe"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -18,7 +18,7 @@ void usage(const char* name)
std::cerr << "Usage: " << name << " [options] <srcFile> <destFile>" << std::endl;
std::cerr << " where options are" << std::endl;
std::cerr << " --createTangents: convert to tangents mesh is possible." << std::endl;
std::cerr << " --format=[irrmesh|collada|stl|obj]: Choose target format" << std::endl;
std::cerr << " --format=[irrmesh|collada|stl|obj|ply]: Choose target format" << std::endl;
}
int main(int argc, char* argv[])
@ -31,9 +31,9 @@ int main(int argc, char* argv[])
}
IrrlichtDevice *device = createDevice( video::EDT_NULL,
dimension2d<s32>(800, 600), 32, false, false, false, 0);
dimension2d<u32>(800, 600), 32, false, false, false, 0);
device->setWindowCaption(L"Image Converter");
device->setWindowCaption(L"Mesh Converter");
scene::EMESH_WRITER_TYPE type = EMWT_IRR_MESH;
u32 i=1;
@ -52,6 +52,8 @@ int main(int argc, char* argv[])
type = EMWT_STL;
else if (format=="obj")
type = EMWT_OBJ;
else if (format=="ply")
type = EMWT_PLY;
else
type = EMWT_IRR_MESH;
}
@ -96,9 +98,10 @@ int main(int argc, char* argv[])
IMeshWriter* mw = device->getSceneManager()->createMeshWriter(type);
IWriteFile* file = device->getFileSystem()->createAndWriteFile(argv[destmesh]);
mw->writeMesh(file, mesh);
mesh->drop();
file->drop();
mw->drop();
device->drop();
return 0;
}