PLYImporter: - optimize memory and speed on ply importer / change parser to use a file stream - manage texture path in ply import - manage texture coords on faces in ply import - correction on point cloud faces generation

IFC :
 - update poly2tri to avoid crash on some IFC files

Collada :
 - manage missing texture reference in collada import
This commit is contained in:
Arkeon
2017-06-02 13:48:57 +02:00
parent dcc5887817
commit f84851e893
19 changed files with 2237 additions and 2062 deletions
+12 -4
View File
@@ -1726,6 +1726,8 @@ void ColladaLoader::BuildMaterials( ColladaParser& pParser, aiScene* /*pScene*/)
aiString ColladaLoader::FindFilenameForEffectTexture( const ColladaParser& pParser,
const Collada::Effect& pEffect, const std::string& pName)
{
aiString result;
// recurse through the param references until we end up at an image
std::string name = pName;
while( 1)
@@ -1744,11 +1746,17 @@ aiString ColladaLoader::FindFilenameForEffectTexture( const ColladaParser& pPars
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find( name);
if( imIt == pParser.mImageLibrary.end())
{
throw DeadlyImportError( format() <<
"Collada: Unable to resolve effect texture entry \"" << pName << "\", ended up at ID \"" << name << "\"." );
}
//missing texture should not stop the conversion
//throw DeadlyImportError( format() <<
// "Collada: Unable to resolve effect texture entry \"" << pName << "\", ended up at ID \"" << name << "\"." );
aiString result;
DefaultLogger::get()->warn("Collada: Unable to resolve effect texture entry \"" + pName + "\", ended up at ID \"" + name + "\".");
//set default texture file name
result.Set(name + ".jpg");
ConvertPath(result);
return result;
}
// if this is an embedded texture image setup an aiTexture for it
if (imIt->second.mFileName.empty())
+22
View File
@@ -100,6 +100,11 @@ public:
/// @return true if successful.
bool getNextDataLine( std::vector<T> &buffer, T continuationToken );
/// @brief Will read the next block.
/// @param buffer The buffer for the next block.
/// @return true if successful.
bool getNextBlock( std::vector<T> &buffer );
private:
IOStream *m_stream;
size_t m_filesize;
@@ -274,4 +279,21 @@ bool IOStreamBuffer<T>::getNextDataLine( std::vector<T> &buffer, T continuationT
return true;
}
template<class T>
inline
bool IOStreamBuffer<T>::getNextBlock( std::vector<T> &buffer) {
//just return the last blockvalue if getNextLine was used before
if ( m_cachePos != 0) {
buffer = std::vector<T>(m_cache.begin() + m_cachePos, m_cache.end());
m_cachePos = 0;
}
else {
if ( !readNextBlock() )
return false;
buffer = std::vector<T>(m_cache.begin(), m_cache.end());
}
return true;
}
} // !ns Assimp
+884 -941
View File
File diff suppressed because it is too large Load Diff
+14 -47
View File
@@ -68,7 +68,6 @@ public:
PLYImporter();
~PLYImporter();
public:
// -------------------------------------------------------------------
@@ -78,6 +77,16 @@ public:
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
bool checkSig) const;
// -------------------------------------------------------------------
/** Extract a vertex from the DOM
*/
void LoadVertex(const PLY::Element* pcElement, const PLY::ElementInstance* instElement, unsigned int pos);
// -------------------------------------------------------------------
/** Extract a face from the DOM
*/
void LoadFace(const PLY::Element* pcElement, const PLY::ElementInstance* instElement, unsigned int pos);
protected:
// -------------------------------------------------------------------
@@ -94,53 +103,10 @@ protected:
IOSystem* pIOHandler);
protected:
// -------------------------------------------------------------------
/** Extract vertices from the DOM
*/
void LoadVertices(std::vector<aiVector3D>* pvOut,
bool p_bNormals = false);
// -------------------------------------------------------------------
/** Extract vertex color channels from the DOM
*/
void LoadVertexColor(std::vector<aiColor4D>* pvOut);
// -------------------------------------------------------------------
/** Extract texture coordinate channels from the DOM
*/
void LoadTextureCoordinates(std::vector<aiVector2D>* pvOut);
// -------------------------------------------------------------------
/** Extract a face list from the DOM
*/
void LoadFaces(std::vector<PLY::Face>* pvOut);
// -------------------------------------------------------------------
/** Extract a material list from the DOM
*/
void LoadMaterial(std::vector<aiMaterial*>* pvOut);
// -------------------------------------------------------------------
/** Validate material indices, replace default material identifiers
*/
void ReplaceDefaultMaterial(std::vector<PLY::Face>* avFaces,
std::vector<aiMaterial*>* avMaterials);
// -------------------------------------------------------------------
/** Convert all meshes into our ourer representation
*/
void ConvertMeshes(std::vector<PLY::Face>* avFaces,
const std::vector<aiVector3D>* avPositions,
const std::vector<aiVector3D>* avNormals,
const std::vector<aiColor4D>* avColors,
const std::vector<aiVector2D>* avTexCoords,
const std::vector<aiMaterial*>* avMaterials,
std::vector<aiMesh*>* avOut);
void LoadMaterial(std::vector<aiMaterial*>* pvOut, std::string &defaultTexture, const bool pointsOnly);
// -------------------------------------------------------------------
/** Static helper to parse a color from four single channels in
@@ -151,7 +117,6 @@ protected:
PLY::EDataType aiTypes[4],
aiColor4D* clrOut);
// -------------------------------------------------------------------
/** Static helper to parse a color channel value. The input value
* is normalized to 0-1.
@@ -160,12 +125,14 @@ protected:
PLY::PropertyInstance::ValueUnion val,
PLY::EDataType eType);
/** Buffer to hold the loaded file */
unsigned char* mBuffer;
/** Document object model representation extracted from the file */
PLY::DOM* pcDOM;
/** Mesh generated by loader */
aiMesh* mGeneratedMesh;
};
} // end of namespace Assimp
+984 -808
View File
File diff suppressed because it is too large Load Diff
+39 -56
View File
@@ -3,7 +3,6 @@ Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2017, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -46,19 +45,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ParsingUtils.h"
#include "IOStreamBuffer.h"
#include <vector>
namespace Assimp
{
//pre-declaration
class PLYImporter;
// http://local.wasp.uwa.edu.au/~pbourke/dataformats/ply/
// http://w3.impa.br/~lvelho/outgoing/sossai/old/ViHAP_D4.4.2_PLY_format_v1.1.pdf
// http://www.okino.com/conv/exp_ply.htm
namespace PLY
{
// ---------------------------------------------------------------------------------
/*
name type number of bytes
@@ -197,6 +198,9 @@ enum EElementSemantic
//! The element is a material description
EEST_Material,
//! texture path
EEST_TextureFile,
//! Marks invalid entries
EEST_INVALID
};
@@ -238,16 +242,15 @@ public:
//! string is either '\n', '\r' or '\0'. Return value is false
//! if the input string is NOT a valid property (E.g. does
//! not start with the "property" keyword)
static bool ParseProperty (const char* pCur, const char** pCurOut,
Property* pOut);
static bool ParseProperty(std::vector<char> &buffer, Property* pOut);
// -------------------------------------------------------------------
//! Parse a data type from a string
static EDataType ParseDataType(const char* pCur,const char** pCurOut);
static EDataType ParseDataType(std::vector<char> &buffer);
// -------------------------------------------------------------------
//! Parse a semantic from a string
static ESemantic ParseSemantic(const char* pCur,const char** pCurOut);
static ESemantic ParseSemantic(std::vector<char> &buffer);
};
// ---------------------------------------------------------------------------------
@@ -285,13 +288,11 @@ public:
//! Parse an element from a string.
//! The function will parse all properties contained in the
//! element, too.
static bool ParseElement (const char* pCur, const char** pCurOut,
Element* pOut);
static bool ParseElement(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer, Element* pOut);
// -------------------------------------------------------------------
//! Parse a semantic from a string
static EElementSemantic ParseSemantic(const char* pCur,
const char** pCurOut);
static EElementSemantic ParseSemantic(std::vector<char> &buffer);
};
// ---------------------------------------------------------------------------------
@@ -331,13 +332,13 @@ public:
// -------------------------------------------------------------------
//! Parse a property instance
static bool ParseInstance (const char* pCur,const char** pCurOut,
static bool ParseInstance(const char* &pCur,
const Property* prop, PropertyInstance* p_pcOut);
// -------------------------------------------------------------------
//! Parse a property instance in binary format
static bool ParseInstanceBinary (const char* pCur,const char** pCurOut,
const Property* prop, PropertyInstance* p_pcOut,bool p_bBE);
static bool ParseInstanceBinary(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer,
const char* &pCur, unsigned int &bufferSize, const Property* prop, PropertyInstance* p_pcOut, bool p_bBE);
// -------------------------------------------------------------------
//! Get the default value for a given data type
@@ -345,13 +346,12 @@ public:
// -------------------------------------------------------------------
//! Parse a value
static bool ParseValue(const char* pCur,const char** pCurOut,
EDataType eType,ValueUnion* out);
static bool ParseValue(const char* &pCur, EDataType eType, ValueUnion* out);
// -------------------------------------------------------------------
//! Parse a binary value
static bool ParseValueBinary(const char* pCur,const char** pCurOut,
EDataType eType,ValueUnion* out,bool p_bBE);
static bool ParseValueBinary(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer,
const char* &pCur, unsigned int &bufferSize, EDataType eType, ValueUnion* out, bool p_bBE);
// -------------------------------------------------------------------
//! Convert a property value to a given type TYPE
@@ -375,13 +375,13 @@ public:
// -------------------------------------------------------------------
//! Parse an element instance
static bool ParseInstance (const char* pCur,const char** pCurOut,
static bool ParseInstance(const char* &pCur,
const Element* pcElement, ElementInstance* p_pcOut);
// -------------------------------------------------------------------
//! Parse a binary element instance
static bool ParseInstanceBinary (const char* pCur,const char** pCurOut,
const Element* pcElement, ElementInstance* p_pcOut,bool p_bBE);
static bool ParseInstanceBinary(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer,
const char* &pCur, unsigned int &bufferSize, const Element* pcElement, ElementInstance* p_pcOut, bool p_bBE);
};
// ---------------------------------------------------------------------------------
@@ -400,13 +400,13 @@ public:
// -------------------------------------------------------------------
//! Parse an element instance list
static bool ParseInstanceList (const char* pCur,const char** pCurOut,
const Element* pcElement, ElementInstanceList* p_pcOut);
static bool ParseInstanceList(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer,
const Element* pcElement, ElementInstanceList* p_pcOut, PLYImporter* loader);
// -------------------------------------------------------------------
//! Parse a binary element instance list
static bool ParseInstanceListBinary (const char* pCur,const char** pCurOut,
const Element* pcElement, ElementInstanceList* p_pcOut,bool p_bBE);
static bool ParseInstanceListBinary(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer,
const char* &pCur, unsigned int &bufferSize, const Element* pcElement, ElementInstanceList* p_pcOut, PLYImporter* loader, bool p_bBE);
};
// ---------------------------------------------------------------------------------
/** \brief Class to represent the document object model of an ASCII or binary
@@ -428,50 +428,33 @@ public:
//! Parse the DOM for a PLY file. The input string is assumed
//! to be terminated with zero
static bool ParseInstance (const char* pCur,DOM* p_pcOut);
static bool ParseInstanceBinary (const char* pCur,
DOM* p_pcOut,bool p_bBE);
static bool ParseInstance(IOStreamBuffer<char> &streamBuffer, DOM* p_pcOut, PLYImporter* loader);
static bool ParseInstanceBinary(IOStreamBuffer<char> &streamBuffer, DOM* p_pcOut, PLYImporter* loader, bool p_bBE);
//! Skip all comment lines after this
static bool SkipComments (const char* pCur,const char** pCurOut);
static bool SkipComments(std::vector<char> &buffer);
static bool SkipSpaces(std::vector<char> &buffer);
static bool SkipLine(std::vector<char> &buffer);
static bool TokenMatch(std::vector<char> &buffer, const char* token, unsigned int len);
static bool SkipSpacesAndLineEnd(std::vector<char> &buffer);
private:
// -------------------------------------------------------------------
//! Handle the file header and read all element descriptions
bool ParseHeader (const char* pCur,const char** pCurOut, bool p_bBE);
bool ParseHeader(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer, bool p_bBE);
// -------------------------------------------------------------------
//! Read in all element instance lists
bool ParseElementInstanceLists (const char* pCur,const char** pCurOut);
bool ParseElementInstanceLists(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer, PLYImporter* loader);
// -------------------------------------------------------------------
//! Read in all element instance lists for a binary file format
bool ParseElementInstanceListsBinary (const char* pCur,
const char** pCurOut,bool p_bBE);
};
// ---------------------------------------------------------------------------------
/** \brief Helper class to represent a loaded PLY face
*/
class Face
{
public:
Face()
: iMaterialIndex(0xFFFFFFFF)
{
// set all indices to zero by default
mIndices.resize(3,0);
}
public:
//! List of vertex indices
std::vector<unsigned int> mIndices;
//! Material index
unsigned int iMaterialIndex;
bool ParseElementInstanceListsBinary(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer, const char* &pCur, unsigned int &bufferSize, PLYImporter* loader, bool p_bBE);
};
// ---------------------------------------------------------------------------------
+3 -3
View File
@@ -211,20 +211,20 @@ void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
for (unsigned int i = 0; i < pScene->mNumMeshes; i++)
pScene->mRootNode->mMeshes[i] = i;
// create a single default material, using a light gray diffuse color for consistency with
// create a single default material, using a white diffuse color for consistency with
// other geometric types (e.g., PLY).
aiMaterial* pcMat = new aiMaterial();
aiString s;
s.Set(AI_DEFAULT_MATERIAL_NAME);
pcMat->AddProperty(&s, AI_MATKEY_NAME);
aiColor4D clrDiffuse(ai_real(0.6),ai_real(0.6),ai_real(0.6),ai_real(1.0));
aiColor4D clrDiffuse(ai_real(1.0),ai_real(1.0),ai_real(1.0),ai_real(1.0));
if (bMatClr) {
clrDiffuse = clrColorDefault;
}
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_DIFFUSE);
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_SPECULAR);
clrDiffuse = aiColor4D( ai_real( 0.05), ai_real( 0.05), ai_real( 0.05), ai_real( 1.0));
clrDiffuse = aiColor4D( ai_real(1.0), ai_real(1.0), ai_real(1.0), ai_real(1.0));
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_AMBIENT);
pScene->mNumMaterials = 1;