aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp366
1 files changed, 183 insertions, 183 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp
index c9f05c8..1393e9d 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CPLYMeshWriter.cpp
@@ -1,183 +1,183 @@
1// Copyright (C) 2008-2012 Christian Stehno 1// Copyright (C) 2008-2012 Christian Stehno
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "IrrCompileConfig.h" 5#include "IrrCompileConfig.h"
6 6
7#ifdef _IRR_COMPILE_WITH_PLY_WRITER_ 7#ifdef _IRR_COMPILE_WITH_PLY_WRITER_
8 8
9#include "CPLYMeshWriter.h" 9#include "CPLYMeshWriter.h"
10#include "os.h" 10#include "os.h"
11#include "IMesh.h" 11#include "IMesh.h"
12#include "IMeshBuffer.h" 12#include "IMeshBuffer.h"
13#include "IWriteFile.h" 13#include "IWriteFile.h"
14 14
15namespace irr 15namespace irr
16{ 16{
17namespace scene 17namespace scene
18{ 18{
19 19
20CPLYMeshWriter::CPLYMeshWriter() 20CPLYMeshWriter::CPLYMeshWriter()
21{ 21{
22 #ifdef _DEBUG 22 #ifdef _DEBUG
23 setDebugName("CPLYMeshWriter"); 23 setDebugName("CPLYMeshWriter");
24 #endif 24 #endif
25} 25}
26 26
27 27
28//! Returns the type of the mesh writer 28//! Returns the type of the mesh writer
29EMESH_WRITER_TYPE CPLYMeshWriter::getType() const 29EMESH_WRITER_TYPE CPLYMeshWriter::getType() const
30{ 30{
31 return EMWT_PLY; 31 return EMWT_PLY;
32} 32}
33 33
34//! writes a mesh 34//! writes a mesh
35bool CPLYMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags) 35bool CPLYMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags)
36{ 36{
37 if (!file || !mesh) 37 if (!file || !mesh)
38 return false; 38 return false;
39 39
40 os::Printer::log("Writing mesh", file->getFileName()); 40 os::Printer::log("Writing mesh", file->getFileName());
41 41
42 // write PLY header 42 // write PLY header
43 core::stringc header = 43 core::stringc header =
44 "ply\n" 44 "ply\n"
45 "format ascii 1.0\n" 45 "format ascii 1.0\n"
46 "comment Irrlicht Engine "; 46 "comment Irrlicht Engine ";
47 header += IRRLICHT_SDK_VERSION; 47 header += IRRLICHT_SDK_VERSION;
48 48
49 // get vertex and triangle counts 49 // get vertex and triangle counts
50 u32 VertexCount = 0; 50 u32 VertexCount = 0;
51 u32 TriangleCount = 0; 51 u32 TriangleCount = 0;
52 52
53 for (u32 i=0; i < mesh->getMeshBufferCount(); ++i) 53 for (u32 i=0; i < mesh->getMeshBufferCount(); ++i)
54 { 54 {
55 VertexCount += mesh->getMeshBuffer(i)->getVertexCount(); 55 VertexCount += mesh->getMeshBuffer(i)->getVertexCount();
56 TriangleCount += mesh->getMeshBuffer(i)->getIndexCount() / 3; 56 TriangleCount += mesh->getMeshBuffer(i)->getIndexCount() / 3;
57 } 57 }
58 58
59 // vertex definition 59 // vertex definition
60 header += "\nelement vertex "; 60 header += "\nelement vertex ";
61 header += VertexCount; 61 header += VertexCount;
62 62
63 header += "\n" 63 header += "\n"
64 "property float x\n" 64 "property float x\n"
65 "property float y\n" 65 "property float y\n"
66 "property float z\n" 66 "property float z\n"
67 "property float nx\n" 67 "property float nx\n"
68 "property float ny\n" 68 "property float ny\n"
69 "property float nz\n"; 69 "property float nz\n";
70 // todo: writer flags for extended (r,g,b,u,v) and non-standard (alpha,u1,uv,tx,ty,tz) properties 70 // todo: writer flags for extended (r,g,b,u,v) and non-standard (alpha,u1,uv,tx,ty,tz) properties
71 // "property uchar red\n" 71 // "property uchar red\n"
72 // "property uchar green\n" 72 // "property uchar green\n"
73 // "property uchar blue\n" 73 // "property uchar blue\n"
74 // "property uchar alpha\n" 74 // "property uchar alpha\n"
75 // "property float u\n" 75 // "property float u\n"
76 // "property float v\n"; 76 // "property float v\n";
77 // "property float u1\n 77 // "property float u1\n
78 // "property float v1\n" 78 // "property float v1\n"
79 // "property float tx\n" 79 // "property float tx\n"
80 // "property float ty\n" 80 // "property float ty\n"
81 // "property float tz\n" 81 // "property float tz\n"
82 82
83 // face definition 83 // face definition
84 84
85 header += "element face "; 85 header += "element face ";
86 header += TriangleCount; 86 header += TriangleCount;
87 header += "\n" 87 header += "\n"
88 "property list uchar int vertex_indices\n" 88 "property list uchar int vertex_indices\n"
89 "end_header\n"; 89 "end_header\n";
90 90
91 // write header 91 // write header
92 file->write(header.c_str(), header.size()); 92 file->write(header.c_str(), header.size());
93 93
94 // write vertices 94 // write vertices
95 95
96 c8 outLine[1024]; 96 c8 outLine[1024];
97 97
98 for (u32 i=0; i < mesh->getMeshBufferCount(); ++i) 98 for (u32 i=0; i < mesh->getMeshBufferCount(); ++i)
99 { 99 {
100 scene::IMeshBuffer* mb = mesh->getMeshBuffer(i); 100 scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
101 for (u32 j=0; j < mb->getVertexCount(); ++j) 101 for (u32 j=0; j < mb->getVertexCount(); ++j)
102 { 102 {
103 const core::vector3df& pos = mb->getPosition(j); 103 const core::vector3df& pos = mb->getPosition(j);
104 const core::vector3df& n = mb->getNormal(j); 104 const core::vector3df& n = mb->getNormal(j);
105// const core::vector2df& tc = mb->getTCoords(j); 105// const core::vector2df& tc = mb->getTCoords(j);
106 106
107 u8 *buf = (u8*)mb->getVertices(); 107 u8 *buf = (u8*)mb->getVertices();
108 switch(mb->getVertexType()) 108 switch(mb->getVertexType())
109 { 109 {
110 case video::EVT_STANDARD: 110 case video::EVT_STANDARD:
111 buf += sizeof(video::S3DVertex)*j; 111 buf += sizeof(video::S3DVertex)*j;
112 break; 112 break;
113 case video::EVT_2TCOORDS: 113 case video::EVT_2TCOORDS:
114 buf += sizeof(video::S3DVertex2TCoords)*j; 114 buf += sizeof(video::S3DVertex2TCoords)*j;
115 break; 115 break;
116 case video::EVT_TANGENTS: 116 case video::EVT_TANGENTS:
117 buf += sizeof(video::S3DVertexTangents)*j; 117 buf += sizeof(video::S3DVertexTangents)*j;
118 break; 118 break;
119 } 119 }
120// video::SColor &col = ( (video::S3DVertex*)buf )->Color; 120// video::SColor &col = ( (video::S3DVertex*)buf )->Color;
121 121
122 // x y z nx ny nz red green blue alpha u v [u1 v1 | tx ty tz]\n 122 // x y z nx ny nz red green blue alpha u v [u1 v1 | tx ty tz]\n
123 snprintf(outLine, 1024, 123 snprintf(outLine, 1024,
124 "%f %f %f %f %f %f\n",// %u %u %u %u %f %f\n", 124 "%f %f %f %f %f %f\n",// %u %u %u %u %f %f\n",
125 pos.X, pos.Z, pos.Y, // Y and Z are flipped 125 pos.X, pos.Z, pos.Y, // Y and Z are flipped
126 n.X, n.Z, n.Y); 126 n.X, n.Z, n.Y);
127 /*col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha(), 127 /*col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha(),
128 tc.X, tc.Y);*/ 128 tc.X, tc.Y);*/
129 129
130 // write the line 130 // write the line
131 file->write(outLine, strlen(outLine)); 131 file->write(outLine, strlen(outLine));
132 } 132 }
133 } 133 }
134 134
135 // index of the first vertex in the current mesh buffer 135 // index of the first vertex in the current mesh buffer
136 u32 StartOffset = 0; 136 u32 StartOffset = 0;
137 137
138 // write triangles 138 // write triangles
139 for (u32 i=0; i < mesh->getMeshBufferCount(); ++i) 139 for (u32 i=0; i < mesh->getMeshBufferCount(); ++i)
140 { 140 {
141 scene::IMeshBuffer* mb = mesh->getMeshBuffer(i); 141 scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
142 for (u32 j=0; j < mb->getIndexCount(); j+=3) 142 for (u32 j=0; j < mb->getIndexCount(); j+=3)
143 { 143 {
144 // y and z are flipped so triangles are reversed 144 // y and z are flipped so triangles are reversed
145 u32 a=StartOffset, 145 u32 a=StartOffset,
146 b=StartOffset, 146 b=StartOffset,
147 c=StartOffset; 147 c=StartOffset;
148 148
149 switch(mb->getIndexType()) 149 switch(mb->getIndexType())
150 { 150 {
151 case video::EIT_16BIT: 151 case video::EIT_16BIT:
152 a += mb->getIndices()[j+0]; 152 a += mb->getIndices()[j+0];
153 c += mb->getIndices()[j+1]; 153 c += mb->getIndices()[j+1];
154 b += mb->getIndices()[j+2]; 154 b += mb->getIndices()[j+2];
155 break; 155 break;
156 case video::EIT_32BIT: 156 case video::EIT_32BIT:
157 a += ((u32*)mb->getIndices()) [j+0]; 157 a += ((u32*)mb->getIndices()) [j+0];
158 c += ((u32*)mb->getIndices()) [j+0]; 158 c += ((u32*)mb->getIndices()) [j+0];
159 b += ((u32*)mb->getIndices()) [j+0]; 159 b += ((u32*)mb->getIndices()) [j+0];
160 break; 160 break;
161 } 161 }
162 162
163 // count a b c\n 163 // count a b c\n
164 snprintf(outLine, 1024, "3 %u %u %u\n", a, b, c); 164 snprintf(outLine, 1024, "3 %u %u %u\n", a, b, c);
165 // write the line 165 // write the line
166 file->write(outLine, strlen(outLine)); 166 file->write(outLine, strlen(outLine));
167 } 167 }
168 168
169 // increment offset 169 // increment offset
170 StartOffset += mb->getVertexCount(); 170 StartOffset += mb->getVertexCount();
171 } 171 }
172 172
173 // all done! 173 // all done!
174 174
175 175
176 return true; 176 return true;
177} 177}
178 178
179} // end namespace 179} // end namespace
180} // end namespace 180} // end namespace
181 181
182#endif // _IRR_COMPILE_WITH_PLY_WRITER_ 182#endif // _IRR_COMPILE_WITH_PLY_WRITER_
183 183