Refactor: Expand tabs to 4 spaces

This commit is contained in:
Richard
2015-05-18 21:57:13 -06:00
parent a96a595a7a
commit 83de707587
324 changed files with 78951 additions and 78956 deletions

View File

@@ -54,36 +54,36 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp;
namespace Assimp {
namespace Assimp {
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
{
// invoke the exporter
PlyExporter exporter(pFile, pScene);
// invoke the exporter
PlyExporter exporter(pFile, pScene);
// we're still here - export successfully completed. Write the file.
boost::scoped_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt"));
if(outfile == NULL) {
throw DeadlyExportError("could not open output .ply file: " + std::string(pFile));
}
// we're still here - export successfully completed. Write the file.
boost::scoped_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt"));
if(outfile == NULL) {
throw DeadlyExportError("could not open output .ply file: " + std::string(pFile));
}
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
}
void ExportScenePlyBinary(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
{
// invoke the exporter
PlyExporter exporter(pFile, pScene, true);
// invoke the exporter
PlyExporter exporter(pFile, pScene, true);
// we're still here - export successfully completed. Write the file.
boost::scoped_ptr<IOStream> outfile(pIOSystem->Open(pFile, "wb"));
if (outfile == NULL) {
throw DeadlyExportError("could not open output .ply file: " + std::string(pFile));
}
// we're still here - export successfully completed. Write the file.
boost::scoped_ptr<IOStream> outfile(pIOSystem->Open(pFile, "wb"));
if (outfile == NULL) {
throw DeadlyExportError("could not open output .ply file: " + std::string(pFile));
}
outfile->Write(exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()), 1);
outfile->Write(exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()), 1);
}
} // end of namespace Assimp
@@ -98,260 +98,260 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina
: filename(_filename)
, endl("\n")
{
// make sure that all formatting happens using the standard, C locale and not the user's current locale
const std::locale& l = std::locale("C");
mOutput.imbue(l);
// make sure that all formatting happens using the standard, C locale and not the user's current locale
const std::locale& l = std::locale("C");
mOutput.imbue(l);
unsigned int faces = 0u, vertices = 0u, components = 0u;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
const aiMesh& m = *pScene->mMeshes[i];
faces += m.mNumFaces;
vertices += m.mNumVertices;
unsigned int faces = 0u, vertices = 0u, components = 0u;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
const aiMesh& m = *pScene->mMeshes[i];
faces += m.mNumFaces;
vertices += m.mNumVertices;
if (m.HasNormals()) {
components |= PLY_EXPORT_HAS_NORMALS;
}
if (m.HasTangentsAndBitangents()) {
components |= PLY_EXPORT_HAS_TANGENTS_BITANGENTS;
}
for (unsigned int t = 0; m.HasTextureCoords(t); ++t) {
components |= PLY_EXPORT_HAS_TEXCOORDS << t;
}
for (unsigned int t = 0; m.HasVertexColors(t); ++t) {
components |= PLY_EXPORT_HAS_COLORS << t;
}
}
if (m.HasNormals()) {
components |= PLY_EXPORT_HAS_NORMALS;
}
if (m.HasTangentsAndBitangents()) {
components |= PLY_EXPORT_HAS_TANGENTS_BITANGENTS;
}
for (unsigned int t = 0; m.HasTextureCoords(t); ++t) {
components |= PLY_EXPORT_HAS_TEXCOORDS << t;
}
for (unsigned int t = 0; m.HasVertexColors(t); ++t) {
components |= PLY_EXPORT_HAS_COLORS << t;
}
}
mOutput << "ply" << endl;
if (binary) {
mOutput << "ply" << endl;
if (binary) {
#if (defined AI_BUILD_BIG_ENDIAN)
mOutput << "format binary_big_endian 1.0" << endl;
mOutput << "format binary_big_endian 1.0" << endl;
#else
mOutput << "format binary_little_endian 1.0" << endl;
mOutput << "format binary_little_endian 1.0" << endl;
#endif
}
else {
mOutput << "format ascii 1.0" << endl;
}
mOutput << "comment Created by Open Asset Import Library - http://assimp.sf.net (v"
<< aiGetVersionMajor() << '.' << aiGetVersionMinor() << '.'
<< aiGetVersionRevision() << ")" << endl;
}
else {
mOutput << "format ascii 1.0" << endl;
}
mOutput << "comment Created by Open Asset Import Library - http://assimp.sf.net (v"
<< aiGetVersionMajor() << '.' << aiGetVersionMinor() << '.'
<< aiGetVersionRevision() << ")" << endl;
mOutput << "element vertex " << vertices << endl;
mOutput << "property float x" << endl;
mOutput << "property float y" << endl;
mOutput << "property float z" << endl;
mOutput << "element vertex " << vertices << endl;
mOutput << "property float x" << endl;
mOutput << "property float y" << endl;
mOutput << "property float z" << endl;
if(components & PLY_EXPORT_HAS_NORMALS) {
mOutput << "property float nx" << endl;
mOutput << "property float ny" << endl;
mOutput << "property float nz" << endl;
}
if(components & PLY_EXPORT_HAS_NORMALS) {
mOutput << "property float nx" << endl;
mOutput << "property float ny" << endl;
mOutput << "property float nz" << endl;
}
// write texcoords first, just in case an importer does not support tangents
// bitangents and just skips over the rest of the line upon encountering
// unknown fields (Ply leaves pretty much every vertex component open,
// but in reality most importers only know about vertex positions, normals
// and texture coordinates).
for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) {
if (!c) {
mOutput << "property float s" << endl;
mOutput << "property float t" << endl;
}
else {
mOutput << "property float s" << c << endl;
mOutput << "property float t" << c << endl;
}
}
// write texcoords first, just in case an importer does not support tangents
// bitangents and just skips over the rest of the line upon encountering
// unknown fields (Ply leaves pretty much every vertex component open,
// but in reality most importers only know about vertex positions, normals
// and texture coordinates).
for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) {
if (!c) {
mOutput << "property float s" << endl;
mOutput << "property float t" << endl;
}
else {
mOutput << "property float s" << c << endl;
mOutput << "property float t" << c << endl;
}
}
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
if (!c) {
mOutput << "property float r" << endl;
mOutput << "property float g" << endl;
mOutput << "property float b" << endl;
mOutput << "property float a" << endl;
}
else {
mOutput << "property float r" << c << endl;
mOutput << "property float g" << c << endl;
mOutput << "property float b" << c << endl;
mOutput << "property float a" << c << endl;
}
}
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
if (!c) {
mOutput << "property float r" << endl;
mOutput << "property float g" << endl;
mOutput << "property float b" << endl;
mOutput << "property float a" << endl;
}
else {
mOutput << "property float r" << c << endl;
mOutput << "property float g" << c << endl;
mOutput << "property float b" << c << endl;
mOutput << "property float a" << c << endl;
}
}
if(components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
mOutput << "property float tx" << endl;
mOutput << "property float ty" << endl;
mOutput << "property float tz" << endl;
mOutput << "property float bx" << endl;
mOutput << "property float by" << endl;
mOutput << "property float bz" << endl;
}
if(components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
mOutput << "property float tx" << endl;
mOutput << "property float ty" << endl;
mOutput << "property float tz" << endl;
mOutput << "property float bx" << endl;
mOutput << "property float by" << endl;
mOutput << "property float bz" << endl;
}
mOutput << "element face " << faces << endl;
mOutput << "property list uint uint vertex_index" << endl;
mOutput << "end_header" << endl;
mOutput << "element face " << faces << endl;
mOutput << "property list uint uint vertex_index" << endl;
mOutput << "end_header" << endl;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
if (binary) {
WriteMeshVertsBinary(pScene->mMeshes[i], components);
}
else {
WriteMeshVerts(pScene->mMeshes[i], components);
}
}
for (unsigned int i = 0, ofs = 0; i < pScene->mNumMeshes; ++i) {
if (binary) {
WriteMeshIndicesBinary(pScene->mMeshes[i], ofs);
}
else {
WriteMeshIndices(pScene->mMeshes[i], ofs);
}
ofs += pScene->mMeshes[i]->mNumVertices;
}
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
if (binary) {
WriteMeshVertsBinary(pScene->mMeshes[i], components);
}
else {
WriteMeshVerts(pScene->mMeshes[i], components);
}
}
for (unsigned int i = 0, ofs = 0; i < pScene->mNumMeshes; ++i) {
if (binary) {
WriteMeshIndicesBinary(pScene->mMeshes[i], ofs);
}
else {
WriteMeshIndices(pScene->mMeshes[i], ofs);
}
ofs += pScene->mMeshes[i]->mNumVertices;
}
}
// ------------------------------------------------------------------------------------------------
void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components)
{
static const float inf = std::numeric_limits<float>::infinity();
static const float inf = std::numeric_limits<float>::infinity();
// If a component (for instance normal vectors) is present in at least one mesh in the scene,
// then default values are written for meshes that do not contain this component.
for (unsigned int i = 0; i < m->mNumVertices; ++i) {
mOutput <<
m->mVertices[i].x << " " <<
m->mVertices[i].y << " " <<
m->mVertices[i].z
;
if(components & PLY_EXPORT_HAS_NORMALS) {
if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::fabs(m->mNormals[i].x) != inf) {
mOutput <<
" " << m->mNormals[i].x <<
" " << m->mNormals[i].y <<
" " << m->mNormals[i].z;
}
else {
mOutput << " 0.0 0.0 0.0";
}
}
// If a component (for instance normal vectors) is present in at least one mesh in the scene,
// then default values are written for meshes that do not contain this component.
for (unsigned int i = 0; i < m->mNumVertices; ++i) {
mOutput <<
m->mVertices[i].x << " " <<
m->mVertices[i].y << " " <<
m->mVertices[i].z
;
if(components & PLY_EXPORT_HAS_NORMALS) {
if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::fabs(m->mNormals[i].x) != inf) {
mOutput <<
" " << m->mNormals[i].x <<
" " << m->mNormals[i].y <<
" " << m->mNormals[i].z;
}
else {
mOutput << " 0.0 0.0 0.0";
}
}
for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) {
if (m->HasTextureCoords(c)) {
mOutput <<
" " << m->mTextureCoords[c][i].x <<
" " << m->mTextureCoords[c][i].y;
}
else {
mOutput << " -1.0 -1.0";
}
}
for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) {
if (m->HasTextureCoords(c)) {
mOutput <<
" " << m->mTextureCoords[c][i].x <<
" " << m->mTextureCoords[c][i].y;
}
else {
mOutput << " -1.0 -1.0";
}
}
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
if (m->HasVertexColors(c)) {
mOutput <<
" " << m->mColors[c][i].r <<
" " << m->mColors[c][i].g <<
" " << m->mColors[c][i].b <<
" " << m->mColors[c][i].a;
}
else {
mOutput << " -1.0 -1.0 -1.0 -1.0";
}
}
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
if (m->HasVertexColors(c)) {
mOutput <<
" " << m->mColors[c][i].r <<
" " << m->mColors[c][i].g <<
" " << m->mColors[c][i].b <<
" " << m->mColors[c][i].a;
}
else {
mOutput << " -1.0 -1.0 -1.0 -1.0";
}
}
if(components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
if (m->HasTangentsAndBitangents()) {
mOutput <<
" " << m->mTangents[i].x <<
" " << m->mTangents[i].y <<
" " << m->mTangents[i].z <<
" " << m->mBitangents[i].x <<
" " << m->mBitangents[i].y <<
" " << m->mBitangents[i].z
;
}
else {
mOutput << " 0.0 0.0 0.0 0.0 0.0 0.0";
}
}
if(components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
if (m->HasTangentsAndBitangents()) {
mOutput <<
" " << m->mTangents[i].x <<
" " << m->mTangents[i].y <<
" " << m->mTangents[i].z <<
" " << m->mBitangents[i].x <<
" " << m->mBitangents[i].y <<
" " << m->mBitangents[i].z
;
}
else {
mOutput << " 0.0 0.0 0.0 0.0 0.0 0.0";
}
}
mOutput << endl;
}
mOutput << endl;
}
}
// ------------------------------------------------------------------------------------------------
void PlyExporter::WriteMeshVertsBinary(const aiMesh* m, unsigned int components)
{
// If a component (for instance normal vectors) is present in at least one mesh in the scene,
// then default values are written for meshes that do not contain this component.
aiVector3D defaultNormal(0, 0, 0);
aiVector2D defaultUV(-1, -1);
aiColor4D defaultColor(-1, -1, -1, -1);
for (unsigned int i = 0; i < m->mNumVertices; ++i) {
mOutput.write(reinterpret_cast<const char*>(&m->mVertices[i].x), 12);
if (components & PLY_EXPORT_HAS_NORMALS) {
if (m->HasNormals()) {
mOutput.write(reinterpret_cast<const char*>(&m->mNormals[i].x), 12);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultNormal.x), 12);
}
}
// If a component (for instance normal vectors) is present in at least one mesh in the scene,
// then default values are written for meshes that do not contain this component.
aiVector3D defaultNormal(0, 0, 0);
aiVector2D defaultUV(-1, -1);
aiColor4D defaultColor(-1, -1, -1, -1);
for (unsigned int i = 0; i < m->mNumVertices; ++i) {
mOutput.write(reinterpret_cast<const char*>(&m->mVertices[i].x), 12);
if (components & PLY_EXPORT_HAS_NORMALS) {
if (m->HasNormals()) {
mOutput.write(reinterpret_cast<const char*>(&m->mNormals[i].x), 12);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultNormal.x), 12);
}
}
for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) {
if (m->HasTextureCoords(c)) {
mOutput.write(reinterpret_cast<const char*>(&m->mTextureCoords[c][i].x), 6);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultUV.x), 6);
}
}
for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) {
if (m->HasTextureCoords(c)) {
mOutput.write(reinterpret_cast<const char*>(&m->mTextureCoords[c][i].x), 6);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultUV.x), 6);
}
}
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
if (m->HasVertexColors(c)) {
mOutput.write(reinterpret_cast<const char*>(&m->mColors[c][i].r), 16);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultColor.r), 16);
}
}
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
if (m->HasVertexColors(c)) {
mOutput.write(reinterpret_cast<const char*>(&m->mColors[c][i].r), 16);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultColor.r), 16);
}
}
if (components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
if (m->HasTangentsAndBitangents()) {
mOutput.write(reinterpret_cast<const char*>(&m->mTangents[i].x), 12);
mOutput.write(reinterpret_cast<const char*>(&m->mBitangents[i].x), 12);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultNormal.x), 12);
mOutput.write(reinterpret_cast<const char*>(&defaultNormal.x), 12);
}
}
}
if (components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
if (m->HasTangentsAndBitangents()) {
mOutput.write(reinterpret_cast<const char*>(&m->mTangents[i].x), 12);
mOutput.write(reinterpret_cast<const char*>(&m->mBitangents[i].x), 12);
}
else {
mOutput.write(reinterpret_cast<const char*>(&defaultNormal.x), 12);
mOutput.write(reinterpret_cast<const char*>(&defaultNormal.x), 12);
}
}
}
}
// ------------------------------------------------------------------------------------------------
void PlyExporter::WriteMeshIndices(const aiMesh* m, unsigned int offset)
{
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
const aiFace& f = m->mFaces[i];
mOutput << f.mNumIndices << " ";
for(unsigned int c = 0; c < f.mNumIndices; ++c) {
mOutput << (f.mIndices[c] + offset) << (c == f.mNumIndices-1 ? endl : " ");
}
}
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
const aiFace& f = m->mFaces[i];
mOutput << f.mNumIndices << " ";
for(unsigned int c = 0; c < f.mNumIndices; ++c) {
mOutput << (f.mIndices[c] + offset) << (c == f.mNumIndices-1 ? endl : " ");
}
}
}
void PlyExporter::WriteMeshIndicesBinary(const aiMesh* m, unsigned int offset)
{
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
const aiFace& f = m->mFaces[i];
mOutput.write(reinterpret_cast<const char*>(&f.mNumIndices), 4);
for (unsigned int c = 0; c < f.mNumIndices; ++c) {
unsigned int index = f.mIndices[c] + offset;
mOutput.write(reinterpret_cast<const char*>(&index), 4);
}
}
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
const aiFace& f = m->mFaces[i];
mOutput.write(reinterpret_cast<const char*>(&f.mNumIndices), 4);
for (unsigned int c = 0; c < f.mNumIndices; ++c) {
unsigned int index = f.mIndices[c] + offset;
mOutput.write(reinterpret_cast<const char*>(&index), 4);
}
}
}
#endif