2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2019-01-30 08:41:39 +00:00
|
|
|
Copyright (c) 2006-2019, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(ASSIMP_BUILD_NO_EXPORT) && !defined(ASSIMP_BUILD_NO_PLY_EXPORTER)
|
|
|
|
|
|
|
|
#include "PlyExporter.h"
|
2016-04-05 21:23:53 +00:00
|
|
|
#include <memory>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <cmath>
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/Exceptional.h>
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/version.h>
|
|
|
|
#include <assimp/IOSystem.hpp>
|
|
|
|
#include <assimp/Exporter.hpp>
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/qnan.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
|
2016-01-14 19:44:09 +00:00
|
|
|
//using namespace Assimp;
|
2015-05-19 03:57:13 +00:00
|
|
|
namespace Assimp {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2016-07-25 13:33:25 +00:00
|
|
|
// make sure type_of returns consistent output across different platforms
|
2016-07-16 08:22:01 +00:00
|
|
|
// also consider using: typeid(VAR).name()
|
2016-07-25 13:33:25 +00:00
|
|
|
template <typename T> const char* type_of(T&) { return "unknown"; }
|
|
|
|
template<> const char* type_of(float&) { return "float"; }
|
|
|
|
template<> const char* type_of(double&) { return "double"; }
|
2016-07-16 08:22:01 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp
|
2017-11-02 10:13:52 +00:00
|
|
|
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
// invoke the exporter
|
|
|
|
PlyExporter exporter(pFile, pScene);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2017-10-09 13:47:17 +00:00
|
|
|
if (exporter.mOutput.fail()) {
|
|
|
|
throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile));
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// we're still here - export successfully completed. Write the file.
|
2016-04-05 21:23:53 +00:00
|
|
|
std::unique_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt"));
|
2015-05-19 03:57:13 +00:00
|
|
|
if(outfile == NULL) {
|
|
|
|
throw DeadlyExportError("could not open output .ply file: " + std::string(pFile));
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 10:13:52 +00:00
|
|
|
void ExportScenePlyBinary(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
// invoke the exporter
|
|
|
|
PlyExporter exporter(pFile, pScene, true);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// we're still here - export successfully completed. Write the file.
|
2016-04-05 21:23:53 +00:00
|
|
|
std::unique_ptr<IOStream> outfile(pIOSystem->Open(pFile, "wb"));
|
2015-05-19 03:57:13 +00:00
|
|
|
if (outfile == NULL) {
|
|
|
|
throw DeadlyExportError("could not open output .ply file: " + std::string(pFile));
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
outfile->Write(exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()), 1);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PLY_EXPORT_HAS_NORMALS 0x1
|
|
|
|
#define PLY_EXPORT_HAS_TANGENTS_BITANGENTS 0x2
|
|
|
|
#define PLY_EXPORT_HAS_TEXCOORDS 0x4
|
|
|
|
#define PLY_EXPORT_HAS_COLORS (PLY_EXPORT_HAS_TEXCOORDS << AI_MAX_NUMBER_OF_TEXTURECOORDS)
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool binary)
|
|
|
|
: filename(_filename)
|
|
|
|
, endl("\n")
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
// 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);
|
2019-06-20 17:11:11 +00:00
|
|
|
mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mOutput << "ply" << endl;
|
|
|
|
if (binary) {
|
2015-05-19 03:48:29 +00:00
|
|
|
#if (defined AI_BUILD_BIG_ENDIAN)
|
2015-05-19 03:57:13 +00:00
|
|
|
mOutput << "format binary_big_endian 1.0" << endl;
|
2015-05-19 03:48:29 +00:00
|
|
|
#else
|
2015-05-19 03:57:13 +00:00
|
|
|
mOutput << "format binary_little_endian 1.0" << endl;
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mOutput << "format ascii 1.0" << endl;
|
|
|
|
}
|
|
|
|
mOutput << "comment Created by Open Asset Import Library - http://assimp.sf.net (v"
|
|
|
|
<< aiGetVersionMajor() << '.' << aiGetVersionMinor() << '.'
|
|
|
|
<< aiGetVersionRevision() << ")" << endl;
|
|
|
|
|
2018-03-06 19:50:02 +00:00
|
|
|
// Look through materials for a diffuse texture, and add it if found
|
|
|
|
for ( unsigned int i = 0; i < pScene->mNumMaterials; ++i )
|
|
|
|
{
|
|
|
|
const aiMaterial* const mat = pScene->mMaterials[i];
|
|
|
|
aiString s;
|
|
|
|
if ( AI_SUCCESS == mat->Get( AI_MATKEY_TEXTURE_DIFFUSE( 0 ), s ) )
|
|
|
|
{
|
|
|
|
mOutput << "comment TextureFile " << s.data << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 08:22:01 +00:00
|
|
|
// TODO: probably want to check here rather than just assume something
|
|
|
|
// definitely not good to always write float even if we might have double precision
|
|
|
|
|
|
|
|
ai_real tmp = 0.0;
|
2016-07-25 13:33:25 +00:00
|
|
|
const char * typeName = type_of(tmp);
|
2016-07-16 08:22:01 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
mOutput << "element vertex " << vertices << endl;
|
2016-07-16 08:22:01 +00:00
|
|
|
mOutput << "property " << typeName << " x" << endl;
|
|
|
|
mOutput << "property " << typeName << " y" << endl;
|
|
|
|
mOutput << "property " << typeName << " z" << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if(components & PLY_EXPORT_HAS_NORMALS) {
|
2016-07-16 08:22:01 +00:00
|
|
|
mOutput << "property " << typeName << " nx" << endl;
|
|
|
|
mOutput << "property " << typeName << " ny" << endl;
|
|
|
|
mOutput << "property " << typeName << " nz" << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2016-07-16 08:22:01 +00:00
|
|
|
mOutput << "property " << typeName << " s" << endl;
|
|
|
|
mOutput << "property " << typeName << " t" << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-16 08:22:01 +00:00
|
|
|
mOutput << "property " << typeName << " s" << c << endl;
|
|
|
|
mOutput << "property " << typeName << " t" << c << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
|
|
|
|
if (!c) {
|
2018-04-27 20:11:36 +00:00
|
|
|
mOutput << "property " << "uchar" << " red" << endl;
|
|
|
|
mOutput << "property " << "uchar" << " green" << endl;
|
|
|
|
mOutput << "property " << "uchar" << " blue" << endl;
|
|
|
|
mOutput << "property " << "uchar" << " alpha" << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-04-27 20:11:36 +00:00
|
|
|
mOutput << "property " << "uchar" << " red" << c << endl;
|
|
|
|
mOutput << "property " << "uchar" << " green" << c << endl;
|
|
|
|
mOutput << "property " << "uchar" << " blue" << c << endl;
|
|
|
|
mOutput << "property " << "uchar" << " alpha" << c << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) {
|
2016-07-16 08:22:01 +00:00
|
|
|
mOutput << "property " << typeName << " tx" << endl;
|
|
|
|
mOutput << "property " << typeName << " ty" << endl;
|
|
|
|
mOutput << "property " << typeName << " tz" << endl;
|
|
|
|
mOutput << "property " << typeName << " bx" << endl;
|
|
|
|
mOutput << "property " << typeName << " by" << endl;
|
|
|
|
mOutput << "property " << typeName << " bz" << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mOutput << "element face " << faces << endl;
|
2015-08-06 11:30:49 +00:00
|
|
|
|
|
|
|
// uchar seems to be the most common type for the number of indices per polygon and int seems to be most common for the vertex indices.
|
|
|
|
// For instance, MeshLab fails to load meshes in which both types are uint. Houdini seems to have problems as well.
|
2015-08-13 11:22:21 +00:00
|
|
|
// Obviously, using uchar will not work for meshes with polygons with more than 255 indices, but how realistic is this case?
|
2015-08-06 11:30:49 +00:00
|
|
|
mOutput << "property list uchar int vertex_index" << endl;
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 19:44:09 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
PlyExporter::~PlyExporter() {
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components)
|
|
|
|
{
|
2016-07-15 03:20:16 +00:00
|
|
|
static const ai_real inf = std::numeric_limits<ai_real>::infinity();
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// 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_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) {
|
|
|
|
if (m->HasVertexColors(c)) {
|
|
|
|
mOutput <<
|
2018-04-27 20:11:36 +00:00
|
|
|
" " << (int)(m->mColors[c][i].r * 255) <<
|
|
|
|
" " << (int)(m->mColors[c][i].g * 255) <<
|
|
|
|
" " << (int)(m->mColors[c][i].b * 255) <<
|
|
|
|
" " << (int)(m->mColors[c][i].a * 255);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-04-27 20:11:36 +00:00
|
|
|
mOutput << " 0 0 0";
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void PlyExporter::WriteMeshVertsBinary(const aiMesh* m, unsigned int components)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
// 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)) {
|
2016-04-22 19:09:45 +00:00
|
|
|
mOutput.write(reinterpret_cast<const char*>(&m->mTextureCoords[c][i].x), 8);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-04-22 19:09:45 +00:00
|
|
|
mOutput.write(reinterpret_cast<const char*>(&defaultUV.x), 8);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void PlyExporter::WriteMeshIndices(const aiMesh* m, unsigned int offset)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
|
|
|
|
const aiFace& f = m->mFaces[i];
|
2020-01-06 13:57:59 +00:00
|
|
|
mOutput << f.mNumIndices;
|
2015-05-19 03:57:13 +00:00
|
|
|
for(unsigned int c = 0; c < f.mNumIndices; ++c) {
|
2020-01-06 13:57:59 +00:00
|
|
|
mOutput << " " << (f.mIndices[c] + offset);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-01-06 13:57:59 +00:00
|
|
|
mOutput << endl;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 11:30:49 +00:00
|
|
|
// Generic method in case we want to use different data types for the indices or make this configurable.
|
|
|
|
template<typename NumIndicesType, typename IndexType>
|
|
|
|
void WriteMeshIndicesBinary_Generic(const aiMesh* m, unsigned int offset, std::ostringstream& output)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int i = 0; i < m->mNumFaces; ++i) {
|
|
|
|
const aiFace& f = m->mFaces[i];
|
2015-08-06 11:30:49 +00:00
|
|
|
NumIndicesType numIndices = static_cast<NumIndicesType>(f.mNumIndices);
|
|
|
|
output.write(reinterpret_cast<const char*>(&numIndices), sizeof(NumIndicesType));
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int c = 0; c < f.mNumIndices; ++c) {
|
2015-08-06 11:30:49 +00:00
|
|
|
IndexType index = f.mIndices[c] + offset;
|
|
|
|
output.write(reinterpret_cast<const char*>(&index), sizeof(IndexType));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 11:30:49 +00:00
|
|
|
void PlyExporter::WriteMeshIndicesBinary(const aiMesh* m, unsigned int offset)
|
|
|
|
{
|
|
|
|
WriteMeshIndicesBinary_Generic<unsigned char, int>(m, offset, mOutput);
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:44:09 +00:00
|
|
|
} // end of namespace Assimp
|
|
|
|
|
|
|
|
#endif // !defined(ASSIMP_BUILD_NO_EXPORT) && !defined(ASSIMP_BUILD_NO_PLY_EXPORTER)
|