mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-16 13:13:53 +00:00
Just the functional assimp lib rather than the entire assimp repository unnecessarily.
This commit is contained in:
parent
0f7641a282
commit
e9ea38eda3
1747 changed files with 9012 additions and 925008 deletions
|
|
@ -3,8 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2018, assimp team
|
||||
|
||||
Copyright (c) 2006-2017, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,235 +47,262 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
// internal headers
|
||||
#include "PlyLoader.h"
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <assimp/Macros.h>
|
||||
#include "IOStreamBuffer.h"
|
||||
#include "Macros.h"
|
||||
#include <memory>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
|
||||
using namespace ::Assimp;
|
||||
using namespace Assimp;
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Stanford Polygon Library (PLY) Importer",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportTextFlavour,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"ply"
|
||||
"Stanford Polygon Library (PLY) Importer",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportTextFlavour,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"ply"
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Internal stuff
|
||||
namespace {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Checks that property index is within range
|
||||
template <class T>
|
||||
inline
|
||||
const T &GetProperty(const std::vector<T> &props, int idx) {
|
||||
if (static_cast<size_t>(idx) >= props.size()) {
|
||||
throw DeadlyImportError("Invalid .ply file: Property index is out of range.");
|
||||
}
|
||||
|
||||
return props[idx];
|
||||
namespace
|
||||
{
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Checks that property index is within range
|
||||
template <class T>
|
||||
const T &GetProperty(const std::vector<T> &props, int idx)
|
||||
{
|
||||
if (static_cast<size_t>(idx) >= props.size()) {
|
||||
throw DeadlyImportError("Invalid .ply file: Property index is out of range.");
|
||||
}
|
||||
|
||||
return props[idx];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
PLYImporter::PLYImporter()
|
||||
: mBuffer(nullptr)
|
||||
, pcDOM(nullptr)
|
||||
, mGeneratedMesh(nullptr) {
|
||||
// empty
|
||||
: mBuffer()
|
||||
, pcDOM()
|
||||
, mGeneratedMesh(NULL){
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
PLYImporter::~PLYImporter() {
|
||||
// empty
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool PLYImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
|
||||
const std::string extension = GetExtension(pFile);
|
||||
bool PLYImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
||||
{
|
||||
const std::string extension = GetExtension(pFile);
|
||||
|
||||
if ( extension == "ply" ) {
|
||||
return true;
|
||||
} else if (!extension.length() || checkSig) {
|
||||
if ( !pIOHandler ) {
|
||||
return true;
|
||||
}
|
||||
static const char* tokens[] = { "ply" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
if (extension == "ply")
|
||||
return true;
|
||||
else if (!extension.length() || checkSig)
|
||||
{
|
||||
if (!pIOHandler)return true;
|
||||
const char* tokens[] = { "ply" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiImporterDesc* PLYImporter::GetInfo() const {
|
||||
return &desc;
|
||||
const aiImporterDesc* PLYImporter::GetInfo() const
|
||||
{
|
||||
return &desc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static bool isBigEndian(const char* szMe) {
|
||||
ai_assert(nullptr != szMe);
|
||||
ai_assert(NULL != szMe);
|
||||
|
||||
// binary_little_endian
|
||||
// binary_big_endian
|
||||
bool isBigEndian(false);
|
||||
// binary_little_endian
|
||||
// binary_big_endian
|
||||
bool isBigEndian(false);
|
||||
#if (defined AI_BUILD_BIG_ENDIAN)
|
||||
if ( 'l' == *szMe || 'L' == *szMe ) {
|
||||
isBigEndian = true;
|
||||
}
|
||||
if ( 'l' == *szMe || 'L' == *szMe ) {
|
||||
isBigEndian = true;
|
||||
}
|
||||
#else
|
||||
if ('b' == *szMe || 'B' == *szMe) {
|
||||
isBigEndian = true;
|
||||
}
|
||||
if ('b' == *szMe || 'B' == *szMe) {
|
||||
isBigEndian = true;
|
||||
}
|
||||
#endif // ! AI_BUILD_BIG_ENDIAN
|
||||
|
||||
return isBigEndian;
|
||||
return isBigEndian;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void PLYImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) {
|
||||
const std::string mode = "rb";
|
||||
std::unique_ptr<IOStream> fileStream(pIOHandler->Open(pFile, mode));
|
||||
if (!fileStream.get()) {
|
||||
throw DeadlyImportError("Failed to open file " + pFile + ".");
|
||||
}
|
||||
void PLYImporter::InternReadFile(const std::string& pFile,
|
||||
aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
static const std::string mode = "rb";
|
||||
std::unique_ptr<IOStream> fileStream(pIOHandler->Open(pFile, mode));
|
||||
if (!fileStream.get()) {
|
||||
throw DeadlyImportError("Failed to open file " + pFile + ".");
|
||||
}
|
||||
|
||||
// Get the file-size
|
||||
const size_t fileSize( fileStream->FileSize() );
|
||||
if ( 0 == fileSize ) {
|
||||
throw DeadlyImportError("File " + pFile + " is empty.");
|
||||
}
|
||||
// Get the file-size
|
||||
size_t fileSize = fileStream->FileSize();
|
||||
if ( 0 == fileSize ) {
|
||||
throw DeadlyImportError("File " + pFile + " is empty.");
|
||||
}
|
||||
|
||||
IOStreamBuffer<char> streamedBuffer(1024 * 1024);
|
||||
streamedBuffer.open(fileStream.get());
|
||||
IOStreamBuffer<char> streamedBuffer(1024 * 1024);
|
||||
streamedBuffer.open(fileStream.get());
|
||||
|
||||
// the beginning of the file must be PLY - magic, magic
|
||||
std::vector<char> headerCheck;
|
||||
streamedBuffer.getNextLine(headerCheck);
|
||||
// the beginning of the file must be PLY - magic, magic
|
||||
std::vector<char> headerCheck;
|
||||
streamedBuffer.getNextLine(headerCheck);
|
||||
|
||||
if ((headerCheck.size() < 3) ||
|
||||
(headerCheck[0] != 'P' && headerCheck[0] != 'p') ||
|
||||
(headerCheck[1] != 'L' && headerCheck[1] != 'l') ||
|
||||
(headerCheck[2] != 'Y' && headerCheck[2] != 'y') ) {
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Magic number \'ply\' is no there");
|
||||
}
|
||||
|
||||
std::vector<char> mBuffer2;
|
||||
streamedBuffer.getNextLine(mBuffer2);
|
||||
mBuffer = (unsigned char*)&mBuffer2[0];
|
||||
|
||||
char* szMe = (char*)&this->mBuffer[0];
|
||||
SkipSpacesAndLineEnd(szMe, (const char**)&szMe);
|
||||
|
||||
// determine the format of the file data and construct the aiMesh
|
||||
PLY::DOM sPlyDom;
|
||||
this->pcDOM = &sPlyDom;
|
||||
|
||||
if (TokenMatch(szMe, "format", 6)) {
|
||||
if (TokenMatch(szMe, "ascii", 5)) {
|
||||
SkipLine(szMe, (const char**)&szMe);
|
||||
if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this)) {
|
||||
if (mGeneratedMesh != nullptr) {
|
||||
delete(mGeneratedMesh);
|
||||
mGeneratedMesh = nullptr;
|
||||
}
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#1)");
|
||||
}
|
||||
} else if (!::strncmp(szMe, "binary_", 7)) {
|
||||
szMe += 7;
|
||||
const bool bIsBE(isBigEndian(szMe));
|
||||
|
||||
// skip the line, parse the rest of the header and build the DOM
|
||||
if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE)) {
|
||||
if (mGeneratedMesh != nullptr) {
|
||||
delete(mGeneratedMesh);
|
||||
mGeneratedMesh = nullptr;
|
||||
}
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#2)");
|
||||
}
|
||||
} else {
|
||||
if (mGeneratedMesh != nullptr) {
|
||||
delete(mGeneratedMesh);
|
||||
mGeneratedMesh = nullptr;
|
||||
}
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Unknown file format");
|
||||
}
|
||||
} else {
|
||||
AI_DEBUG_INVALIDATE_PTR(this->mBuffer);
|
||||
if (mGeneratedMesh != nullptr) {
|
||||
delete(mGeneratedMesh);
|
||||
mGeneratedMesh = nullptr;
|
||||
}
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Missing format specification");
|
||||
}
|
||||
|
||||
//free the file buffer
|
||||
if ((headerCheck.size() < 3) ||
|
||||
(headerCheck[0] != 'P' && headerCheck[0] != 'p') ||
|
||||
(headerCheck[1] != 'L' && headerCheck[1] != 'l') ||
|
||||
(headerCheck[2] != 'Y' && headerCheck[2] != 'y') )
|
||||
{
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Magic number \'ply\' is no there");
|
||||
}
|
||||
|
||||
if (mGeneratedMesh == nullptr) {
|
||||
throw DeadlyImportError("Invalid .ply file: Unable to extract mesh data ");
|
||||
std::vector<char> mBuffer2;
|
||||
streamedBuffer.getNextLine(mBuffer2);
|
||||
mBuffer = (unsigned char*)&mBuffer2[0];
|
||||
|
||||
char* szMe = (char*)&this->mBuffer[0];
|
||||
SkipSpacesAndLineEnd(szMe, (const char**)&szMe);
|
||||
|
||||
// determine the format of the file data and construct the aimesh
|
||||
PLY::DOM sPlyDom;
|
||||
this->pcDOM = &sPlyDom;
|
||||
|
||||
if (TokenMatch(szMe, "format", 6)) {
|
||||
if (TokenMatch(szMe, "ascii", 5)) {
|
||||
SkipLine(szMe, (const char**)&szMe);
|
||||
if (!PLY::DOM::ParseInstance(streamedBuffer, &sPlyDom, this))
|
||||
{
|
||||
if (mGeneratedMesh != NULL)
|
||||
delete(mGeneratedMesh);
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#1)");
|
||||
}
|
||||
}
|
||||
else if (!::strncmp(szMe, "binary_", 7))
|
||||
{
|
||||
szMe += 7;
|
||||
const bool bIsBE(isBigEndian(szMe));
|
||||
|
||||
// skip the line, parse the rest of the header and build the DOM
|
||||
if (!PLY::DOM::ParseInstanceBinary(streamedBuffer, &sPlyDom, this, bIsBE))
|
||||
{
|
||||
if (mGeneratedMesh != NULL)
|
||||
delete(mGeneratedMesh);
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Unable to build DOM (#2)");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mGeneratedMesh != NULL)
|
||||
delete(mGeneratedMesh);
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Unknown file format");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AI_DEBUG_INVALIDATE_PTR(this->mBuffer);
|
||||
if (mGeneratedMesh != NULL)
|
||||
delete(mGeneratedMesh);
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Missing format specification");
|
||||
}
|
||||
|
||||
//free the file buffer
|
||||
streamedBuffer.close();
|
||||
|
||||
if (mGeneratedMesh == NULL)
|
||||
{
|
||||
throw DeadlyImportError("Invalid .ply file: Unable to extract mesh data ");
|
||||
}
|
||||
|
||||
// if no face list is existing we assume that the vertex
|
||||
// list is containing a list of points
|
||||
bool pointsOnly = mGeneratedMesh->mFaces == NULL ? true : false;
|
||||
if (pointsOnly)
|
||||
{
|
||||
if (mGeneratedMesh->mNumVertices < 3)
|
||||
{
|
||||
if (mGeneratedMesh != NULL)
|
||||
delete(mGeneratedMesh);
|
||||
|
||||
streamedBuffer.close();
|
||||
throw DeadlyImportError("Invalid .ply file: Not enough "
|
||||
"vertices to build a proper face list. ");
|
||||
}
|
||||
|
||||
// if no face list is existing we assume that the vertex
|
||||
// list is containing a list of points
|
||||
bool pointsOnly = mGeneratedMesh->mFaces == nullptr ? true : false;
|
||||
if (pointsOnly) {
|
||||
mGeneratedMesh->mPrimitiveTypes = aiPrimitiveType::aiPrimitiveType_POINT;
|
||||
const unsigned int iNum = (unsigned int)mGeneratedMesh->mNumVertices / 3;
|
||||
mGeneratedMesh->mNumFaces = iNum;
|
||||
mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces];
|
||||
|
||||
for (unsigned int i = 0; i < iNum; ++i)
|
||||
{
|
||||
mGeneratedMesh->mFaces[i].mNumIndices = 3;
|
||||
mGeneratedMesh->mFaces[i].mIndices = new unsigned int[3];
|
||||
mGeneratedMesh->mFaces[i].mIndices[0] = (i * 3);
|
||||
mGeneratedMesh->mFaces[i].mIndices[1] = (i * 3) + 1;
|
||||
mGeneratedMesh->mFaces[i].mIndices[2] = (i * 3) + 2;
|
||||
}
|
||||
}
|
||||
|
||||
// now load a list of all materials
|
||||
std::vector<aiMaterial*> avMaterials;
|
||||
std::string defaultTexture;
|
||||
LoadMaterial(&avMaterials, defaultTexture, pointsOnly);
|
||||
// now load a list of all materials
|
||||
std::vector<aiMaterial*> avMaterials;
|
||||
std::string defaultTexture;
|
||||
LoadMaterial(&avMaterials, defaultTexture, pointsOnly);
|
||||
|
||||
// now generate the output scene object. Fill the material list
|
||||
pScene->mNumMaterials = (unsigned int)avMaterials.size();
|
||||
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
||||
for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) {
|
||||
pScene->mMaterials[i] = avMaterials[i];
|
||||
}
|
||||
// now generate the output scene object. Fill the material list
|
||||
pScene->mNumMaterials = (unsigned int)avMaterials.size();
|
||||
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
||||
for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) {
|
||||
pScene->mMaterials[i] = avMaterials[i];
|
||||
}
|
||||
|
||||
// fill the mesh list
|
||||
pScene->mNumMeshes = 1;
|
||||
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
||||
pScene->mMeshes[0] = mGeneratedMesh;
|
||||
mGeneratedMesh = nullptr;
|
||||
// fill the mesh list
|
||||
pScene->mNumMeshes = 1;
|
||||
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
||||
pScene->mMeshes[0] = mGeneratedMesh;
|
||||
|
||||
// generate a simple node structure
|
||||
pScene->mRootNode = new aiNode();
|
||||
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
||||
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
||||
// generate a simple node structure
|
||||
pScene->mRootNode = new aiNode();
|
||||
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
||||
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
||||
|
||||
for (unsigned int i = 0; i < pScene->mRootNode->mNumMeshes; ++i) {
|
||||
pScene->mRootNode->mMeshes[i] = i;
|
||||
}
|
||||
for (unsigned int i = 0; i < pScene->mRootNode->mNumMeshes; ++i) {
|
||||
pScene->mRootNode->mMeshes[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
void PLYImporter::LoadVertex(const PLY::Element* pcElement, const PLY::ElementInstance* instElement, unsigned int pos) {
|
||||
ai_assert(nullptr != pcElement);
|
||||
ai_assert(nullptr != instElement);
|
||||
ai_assert(NULL != pcElement);
|
||||
ai_assert(NULL != instElement);
|
||||
|
||||
ai_uint aiPositions[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
|
||||
PLY::EDataType aiTypes[3] = { EDT_Char, EDT_Char, EDT_Char };
|
||||
|
|
@ -414,7 +440,7 @@ void PLYImporter::LoadVertex(const PLY::Element* pcElement, const PLY::ElementIn
|
|||
haveColor = true;
|
||||
}
|
||||
|
||||
// assume 1.0 for the alpha channel if it is not set
|
||||
// assume 1.0 for the alpha channel ifit is not set
|
||||
if (0xFFFFFFFF == aiColors[3]) {
|
||||
cOut.a = 1.0;
|
||||
} else {
|
||||
|
|
@ -478,206 +504,228 @@ void PLYImporter::LoadVertex(const PLY::Element* pcElement, const PLY::ElementIn
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert a color component to [0...1]
|
||||
ai_real PLYImporter::NormalizeColorValue(PLY::PropertyInstance::ValueUnion val, PLY::EDataType eType) {
|
||||
switch (eType) {
|
||||
case EDT_Float:
|
||||
return val.fFloat;
|
||||
case EDT_Double:
|
||||
return (ai_real)val.fDouble;
|
||||
case EDT_UChar:
|
||||
return (ai_real)val.iUInt / (ai_real)0xFF;
|
||||
case EDT_Char:
|
||||
return (ai_real)(val.iInt + (0xFF / 2)) / (ai_real)0xFF;
|
||||
case EDT_UShort:
|
||||
return (ai_real)val.iUInt / (ai_real)0xFFFF;
|
||||
case EDT_Short:
|
||||
return (ai_real)(val.iInt + (0xFFFF / 2)) / (ai_real)0xFFFF;
|
||||
case EDT_UInt:
|
||||
return (ai_real)val.iUInt / (ai_real)0xFFFF;
|
||||
case EDT_Int:
|
||||
return ((ai_real)val.iInt / (ai_real)0xFF) + 0.5f;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ai_real PLYImporter::NormalizeColorValue(PLY::PropertyInstance::ValueUnion val,
|
||||
PLY::EDataType eType)
|
||||
{
|
||||
switch (eType)
|
||||
{
|
||||
case EDT_Float:
|
||||
return val.fFloat;
|
||||
case EDT_Double:
|
||||
return (ai_real)val.fDouble;
|
||||
|
||||
return 0.0f;
|
||||
case EDT_UChar:
|
||||
return (ai_real)val.iUInt / (ai_real)0xFF;
|
||||
case EDT_Char:
|
||||
return (ai_real)(val.iInt + (0xFF / 2)) / (ai_real)0xFF;
|
||||
case EDT_UShort:
|
||||
return (ai_real)val.iUInt / (ai_real)0xFFFF;
|
||||
case EDT_Short:
|
||||
return (ai_real)(val.iInt + (0xFFFF / 2)) / (ai_real)0xFFFF;
|
||||
case EDT_UInt:
|
||||
return (ai_real)val.iUInt / (ai_real)0xFFFF;
|
||||
case EDT_Int:
|
||||
return ((ai_real)val.iInt / (ai_real)0xFF) + 0.5f;
|
||||
default:;
|
||||
};
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Try to extract proper faces from the PLY DOM
|
||||
void PLYImporter::LoadFace(const PLY::Element* pcElement, const PLY::ElementInstance* instElement,
|
||||
unsigned int pos) {
|
||||
ai_assert(nullptr != pcElement);
|
||||
ai_assert(nullptr != instElement);
|
||||
void PLYImporter::LoadFace(const PLY::Element* pcElement, const PLY::ElementInstance* instElement, unsigned int pos)
|
||||
{
|
||||
ai_assert(NULL != pcElement);
|
||||
ai_assert(NULL != instElement);
|
||||
|
||||
if (mGeneratedMesh == nullptr) {
|
||||
throw DeadlyImportError("Invalid .ply file: Vertices should be declared before faces");
|
||||
if (mGeneratedMesh == NULL)
|
||||
throw DeadlyImportError("Invalid .ply file: Vertices should be declared before faces");
|
||||
|
||||
bool bOne = false;
|
||||
|
||||
// index of the vertex index list
|
||||
unsigned int iProperty = 0xFFFFFFFF;
|
||||
PLY::EDataType eType = EDT_Char;
|
||||
bool bIsTriStrip = false;
|
||||
|
||||
// index of the material index property
|
||||
//unsigned int iMaterialIndex = 0xFFFFFFFF;
|
||||
//PLY::EDataType eType2 = EDT_Char;
|
||||
|
||||
// texture coordinates
|
||||
unsigned int iTextureCoord = 0xFFFFFFFF;
|
||||
PLY::EDataType eType3 = EDT_Char;
|
||||
|
||||
// face = unique number of vertex indices
|
||||
if (PLY::EEST_Face == pcElement->eSemantic)
|
||||
{
|
||||
unsigned int _a = 0;
|
||||
for (std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
||||
a != pcElement->alProperties.end(); ++a, ++_a)
|
||||
{
|
||||
if (PLY::EST_VertexIndex == (*a).Semantic)
|
||||
{
|
||||
// must be a dynamic list!
|
||||
if (!(*a).bIsList)
|
||||
continue;
|
||||
|
||||
iProperty = _a;
|
||||
bOne = true;
|
||||
eType = (*a).eType;
|
||||
}
|
||||
/*else if (PLY::EST_MaterialIndex == (*a).Semantic)
|
||||
{
|
||||
if ((*a).bIsList)
|
||||
continue;
|
||||
iMaterialIndex = _a;
|
||||
bOne = true;
|
||||
eType2 = (*a).eType;
|
||||
}*/
|
||||
else if (PLY::EST_TextureCoordinates == (*a).Semantic)
|
||||
{
|
||||
// must be a dynamic list!
|
||||
if (!(*a).bIsList)
|
||||
continue;
|
||||
iTextureCoord = _a;
|
||||
bOne = true;
|
||||
eType3 = (*a).eType;
|
||||
}
|
||||
}
|
||||
}
|
||||
// triangle strip
|
||||
// TODO: triangle strip and material index support???
|
||||
else if (PLY::EEST_TriStrip == pcElement->eSemantic)
|
||||
{
|
||||
unsigned int _a = 0;
|
||||
for (std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
||||
a != pcElement->alProperties.end(); ++a, ++_a)
|
||||
{
|
||||
// must be a dynamic list!
|
||||
if (!(*a).bIsList)
|
||||
continue;
|
||||
iProperty = _a;
|
||||
bOne = true;
|
||||
bIsTriStrip = true;
|
||||
eType = (*a).eType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check whether we have at least one per-face information set
|
||||
if (bOne)
|
||||
{
|
||||
if (mGeneratedMesh->mFaces == NULL)
|
||||
{
|
||||
mGeneratedMesh->mNumFaces = pcElement->NumOccur;
|
||||
mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces];
|
||||
}
|
||||
|
||||
bool bOne = false;
|
||||
if (!bIsTriStrip)
|
||||
{
|
||||
// parse the list of vertex indices
|
||||
if (0xFFFFFFFF != iProperty)
|
||||
{
|
||||
const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iProperty).avList.size();
|
||||
mGeneratedMesh->mFaces[pos].mNumIndices = iNum;
|
||||
mGeneratedMesh->mFaces[pos].mIndices = new unsigned int[iNum];
|
||||
|
||||
// index of the vertex index list
|
||||
unsigned int iProperty = 0xFFFFFFFF;
|
||||
PLY::EDataType eType = EDT_Char;
|
||||
bool bIsTriStrip = false;
|
||||
std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator p =
|
||||
GetProperty(instElement->alProperties, iProperty).avList.begin();
|
||||
|
||||
// index of the material index property
|
||||
//unsigned int iMaterialIndex = 0xFFFFFFFF;
|
||||
//PLY::EDataType eType2 = EDT_Char;
|
||||
|
||||
// texture coordinates
|
||||
unsigned int iTextureCoord = 0xFFFFFFFF;
|
||||
PLY::EDataType eType3 = EDT_Char;
|
||||
|
||||
// face = unique number of vertex indices
|
||||
if (PLY::EEST_Face == pcElement->eSemantic) {
|
||||
unsigned int _a = 0;
|
||||
for (std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
||||
a != pcElement->alProperties.end(); ++a, ++_a) {
|
||||
if (PLY::EST_VertexIndex == (*a).Semantic) {
|
||||
// must be a dynamic list!
|
||||
if (!(*a).bIsList) {
|
||||
continue;
|
||||
}
|
||||
|
||||
iProperty = _a;
|
||||
bOne = true;
|
||||
eType = (*a).eType;
|
||||
} else if (PLY::EST_TextureCoordinates == (*a).Semantic) {
|
||||
// must be a dynamic list!
|
||||
if (!(*a).bIsList) {
|
||||
continue;
|
||||
}
|
||||
iTextureCoord = _a;
|
||||
bOne = true;
|
||||
eType3 = (*a).eType;
|
||||
}
|
||||
}
|
||||
}
|
||||
// triangle strip
|
||||
// TODO: triangle strip and material index support???
|
||||
else if (PLY::EEST_TriStrip == pcElement->eSemantic) {
|
||||
unsigned int _a = 0;
|
||||
for (std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
||||
a != pcElement->alProperties.end(); ++a, ++_a) {
|
||||
// must be a dynamic list!
|
||||
if (!(*a).bIsList) {
|
||||
continue;
|
||||
}
|
||||
iProperty = _a;
|
||||
bOne = true;
|
||||
bIsTriStrip = true;
|
||||
eType = (*a).eType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check whether we have at least one per-face information set
|
||||
if (bOne) {
|
||||
if (mGeneratedMesh->mFaces == nullptr) {
|
||||
mGeneratedMesh->mNumFaces = pcElement->NumOccur;
|
||||
mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces];
|
||||
}
|
||||
|
||||
if (!bIsTriStrip) {
|
||||
// parse the list of vertex indices
|
||||
if (0xFFFFFFFF != iProperty) {
|
||||
const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iProperty).avList.size();
|
||||
mGeneratedMesh->mFaces[pos].mNumIndices = iNum;
|
||||
mGeneratedMesh->mFaces[pos].mIndices = new unsigned int[iNum];
|
||||
|
||||
std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator p =
|
||||
GetProperty(instElement->alProperties, iProperty).avList.begin();
|
||||
|
||||
for (unsigned int a = 0; a < iNum; ++a, ++p) {
|
||||
mGeneratedMesh->mFaces[pos].mIndices[a] = PLY::PropertyInstance::ConvertTo<unsigned int>(*p, eType);
|
||||
}
|
||||
}
|
||||
|
||||
// parse the material index
|
||||
// cannot be handled without processing the whole file first
|
||||
/*if (0xFFFFFFFF != iMaterialIndex)
|
||||
for (unsigned int a = 0; a < iNum; ++a, ++p)
|
||||
{
|
||||
mGeneratedMesh->mFaces[pos]. = PLY::PropertyInstance::ConvertTo<unsigned int>(
|
||||
GetProperty(instElement->alProperties, iMaterialIndex).avList.front(), eType2);
|
||||
}*/
|
||||
|
||||
if (0xFFFFFFFF != iTextureCoord) {
|
||||
const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iTextureCoord).avList.size();
|
||||
|
||||
//should be 6 coords
|
||||
std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator p =
|
||||
GetProperty(instElement->alProperties, iTextureCoord).avList.begin();
|
||||
|
||||
if ((iNum / 3) == 2) // X Y coord
|
||||
{
|
||||
for (unsigned int a = 0; a < iNum; ++a, ++p) {
|
||||
unsigned int vindex = mGeneratedMesh->mFaces[pos].mIndices[a / 2];
|
||||
if (vindex < mGeneratedMesh->mNumVertices) {
|
||||
if (mGeneratedMesh->mTextureCoords[0] == nullptr ) {
|
||||
mGeneratedMesh->mNumUVComponents[0] = 2;
|
||||
mGeneratedMesh->mTextureCoords[0] = new aiVector3D[mGeneratedMesh->mNumVertices];
|
||||
}
|
||||
|
||||
if (a % 2 == 0) {
|
||||
mGeneratedMesh->mTextureCoords[0][vindex].x = PLY::PropertyInstance::ConvertTo<ai_real>(*p, eType3);
|
||||
} else {
|
||||
mGeneratedMesh->mTextureCoords[0][vindex].y = PLY::PropertyInstance::ConvertTo<ai_real>(*p, eType3);
|
||||
}
|
||||
|
||||
mGeneratedMesh->mTextureCoords[0][vindex].z = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // triangle strips
|
||||
// normally we have only one triangle strip instance where
|
||||
// a value of -1 indicates a restart of the strip
|
||||
bool flip = false;
|
||||
const std::vector<PLY::PropertyInstance::ValueUnion>& quak = GetProperty(instElement->alProperties, iProperty).avList;
|
||||
//pvOut->reserve(pvOut->size() + quak.size() + (quak.size()>>2u)); //Limits memory consumption
|
||||
|
||||
int aiTable[2] = { -1, -1 };
|
||||
for (std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator a = quak.begin(); a != quak.end(); ++a) {
|
||||
const int p = PLY::PropertyInstance::ConvertTo<int>(*a, eType);
|
||||
|
||||
if (-1 == p) {
|
||||
// restart the strip ...
|
||||
aiTable[0] = aiTable[1] = -1;
|
||||
flip = false;
|
||||
continue;
|
||||
}
|
||||
if (-1 == aiTable[0]) {
|
||||
aiTable[0] = p;
|
||||
continue;
|
||||
}
|
||||
if (-1 == aiTable[1]) {
|
||||
aiTable[1] = p;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mGeneratedMesh->mFaces == nullptr) {
|
||||
mGeneratedMesh->mNumFaces = pcElement->NumOccur;
|
||||
mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces];
|
||||
}
|
||||
|
||||
mGeneratedMesh->mFaces[pos].mNumIndices = 3;
|
||||
mGeneratedMesh->mFaces[pos].mIndices = new unsigned int[3];
|
||||
mGeneratedMesh->mFaces[pos].mIndices[0] = aiTable[0];
|
||||
mGeneratedMesh->mFaces[pos].mIndices[1] = aiTable[1];
|
||||
mGeneratedMesh->mFaces[pos].mIndices[2] = p;
|
||||
|
||||
// every second pass swap the indices.
|
||||
flip = !flip;
|
||||
if ( flip ) {
|
||||
std::swap(mGeneratedMesh->mFaces[pos].mIndices[0], mGeneratedMesh->mFaces[pos].mIndices[1]);
|
||||
}
|
||||
|
||||
aiTable[0] = aiTable[1];
|
||||
aiTable[1] = p;
|
||||
}
|
||||
mGeneratedMesh->mFaces[pos].mIndices[a] = PLY::PropertyInstance::ConvertTo<unsigned int>(*p, eType);
|
||||
}
|
||||
}
|
||||
|
||||
// parse the material index
|
||||
// cannot be handled without processing the whole file first
|
||||
/*if (0xFFFFFFFF != iMaterialIndex)
|
||||
{
|
||||
mGeneratedMesh->mFaces[pos]. = PLY::PropertyInstance::ConvertTo<unsigned int>(
|
||||
GetProperty(instElement->alProperties, iMaterialIndex).avList.front(), eType2);
|
||||
}*/
|
||||
|
||||
if (0xFFFFFFFF != iTextureCoord)
|
||||
{
|
||||
const unsigned int iNum = (unsigned int)GetProperty(instElement->alProperties, iTextureCoord).avList.size();
|
||||
|
||||
//should be 6 coords
|
||||
std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator p =
|
||||
GetProperty(instElement->alProperties, iTextureCoord).avList.begin();
|
||||
|
||||
if ((iNum / 3) == 2) // X Y coord
|
||||
{
|
||||
for (unsigned int a = 0; a < iNum; ++a, ++p)
|
||||
{
|
||||
unsigned int vindex = mGeneratedMesh->mFaces[pos].mIndices[a / 2];
|
||||
if (vindex < mGeneratedMesh->mNumVertices)
|
||||
{
|
||||
if (mGeneratedMesh->mTextureCoords[0] == NULL)
|
||||
{
|
||||
mGeneratedMesh->mNumUVComponents[0] = 2;
|
||||
mGeneratedMesh->mTextureCoords[0] = new aiVector3D[mGeneratedMesh->mNumVertices];
|
||||
}
|
||||
|
||||
if (a % 2 == 0)
|
||||
mGeneratedMesh->mTextureCoords[0][vindex].x = PLY::PropertyInstance::ConvertTo<ai_real>(*p, eType3);
|
||||
else
|
||||
mGeneratedMesh->mTextureCoords[0][vindex].y = PLY::PropertyInstance::ConvertTo<ai_real>(*p, eType3);
|
||||
|
||||
mGeneratedMesh->mTextureCoords[0][vindex].z = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // triangle strips
|
||||
{
|
||||
// normally we have only one triangle strip instance where
|
||||
// a value of -1 indicates a restart of the strip
|
||||
bool flip = false;
|
||||
const std::vector<PLY::PropertyInstance::ValueUnion>& quak = GetProperty(instElement->alProperties, iProperty).avList;
|
||||
//pvOut->reserve(pvOut->size() + quak.size() + (quak.size()>>2u)); //Limits memory consumption
|
||||
|
||||
int aiTable[2] = { -1, -1 };
|
||||
for (std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator a = quak.begin(); a != quak.end(); ++a) {
|
||||
const int p = PLY::PropertyInstance::ConvertTo<int>(*a, eType);
|
||||
|
||||
if (-1 == p) {
|
||||
// restart the strip ...
|
||||
aiTable[0] = aiTable[1] = -1;
|
||||
flip = false;
|
||||
continue;
|
||||
}
|
||||
if (-1 == aiTable[0]) {
|
||||
aiTable[0] = p;
|
||||
continue;
|
||||
}
|
||||
if (-1 == aiTable[1]) {
|
||||
aiTable[1] = p;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mGeneratedMesh->mFaces == NULL)
|
||||
{
|
||||
mGeneratedMesh->mNumFaces = pcElement->NumOccur;
|
||||
mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces];
|
||||
}
|
||||
|
||||
mGeneratedMesh->mFaces[pos].mNumIndices = 3;
|
||||
mGeneratedMesh->mFaces[pos].mIndices = new unsigned int[3];
|
||||
mGeneratedMesh->mFaces[pos].mIndices[0] = aiTable[0];
|
||||
mGeneratedMesh->mFaces[pos].mIndices[1] = aiTable[1];
|
||||
mGeneratedMesh->mFaces[pos].mIndices[2] = p;
|
||||
|
||||
if ((flip = !flip)) {
|
||||
std::swap(mGeneratedMesh->mFaces[pos].mIndices[0], mGeneratedMesh->mFaces[pos].mIndices[1]);
|
||||
}
|
||||
|
||||
aiTable[0] = aiTable[1];
|
||||
aiTable[1] = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue