mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-14 12:13:46 +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,8 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
// internal headers
|
||||
#include "STLLoader.h"
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include "ParsingUtils.h"
|
||||
#include "fast_atof.h"
|
||||
#include <memory>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/scene.h>
|
||||
|
|
@ -90,9 +89,6 @@ static bool IsBinarySTL(const char* buffer, unsigned int fileSize) {
|
|||
return expectedBinaryFileSize == fileSize;
|
||||
}
|
||||
|
||||
static const size_t BufferSize = 500;
|
||||
static const char UnicodeBoundary = 127;
|
||||
|
||||
// An ascii STL buffer will begin with "solid NAME", where NAME is optional.
|
||||
// Note: The "solid NAME" check is necessary, but not sufficient, to determine
|
||||
// if the buffer is ASCII; a binary header could also begin with "solid NAME".
|
||||
|
|
@ -111,10 +107,10 @@ static bool IsAsciiSTL(const char* buffer, unsigned int fileSize) {
|
|||
bool isASCII( strncmp( buffer, "solid", 5 ) == 0 );
|
||||
if( isASCII ) {
|
||||
// A lot of importers are write solid even if the file is binary. So we have to check for ASCII-characters.
|
||||
if( fileSize >= BufferSize) {
|
||||
if( fileSize >= 500 ) {
|
||||
isASCII = true;
|
||||
for( unsigned int i = 0; i < BufferSize; i++ ) {
|
||||
if( buffer[ i ] > UnicodeBoundary) {
|
||||
for( unsigned int i = 0; i < 500; i++ ) {
|
||||
if( buffer[ i ] > 127 ) {
|
||||
isASCII = false;
|
||||
break;
|
||||
}
|
||||
|
|
@ -289,14 +285,14 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
|
|||
if(!SkipSpacesAndLineEnd(&sz))
|
||||
{
|
||||
// seems we're finished although there was no end marker
|
||||
ASSIMP_LOG_WARN("STL: unexpected EOF. \'endsolid\' keyword was expected");
|
||||
DefaultLogger::get()->warn("STL: unexpected EOF. \'endsolid\' keyword was expected");
|
||||
break;
|
||||
}
|
||||
// facet normal -0.13 -0.13 -0.98
|
||||
if (!strncmp(sz,"facet",5) && IsSpaceOrNewLine(*(sz+5)) && *(sz + 5) != '\0') {
|
||||
|
||||
if (faceVertexCounter != 3) {
|
||||
ASSIMP_LOG_WARN("STL: A new facet begins but the old is not yet complete");
|
||||
DefaultLogger::get()->warn("STL: A new facet begins but the old is not yet complete");
|
||||
}
|
||||
faceVertexCounter = 0;
|
||||
normalBuffer.push_back(aiVector3D());
|
||||
|
|
@ -305,7 +301,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
|
|||
sz += 6;
|
||||
SkipSpaces(&sz);
|
||||
if (strncmp(sz,"normal",6)) {
|
||||
ASSIMP_LOG_WARN("STL: a facet normal vector was expected but not found");
|
||||
DefaultLogger::get()->warn("STL: a facet normal vector was expected but not found");
|
||||
} else {
|
||||
if (sz[6] == '\0') {
|
||||
throw DeadlyImportError("STL: unexpected EOF while parsing facet");
|
||||
|
|
@ -322,7 +318,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
|
|||
}
|
||||
} else if (!strncmp(sz,"vertex",6) && ::IsSpaceOrNewLine(*(sz+6))) { // vertex 1.50000 1.50000 0.00000
|
||||
if (faceVertexCounter >= 3) {
|
||||
ASSIMP_LOG_ERROR("STL: a facet with more than 3 vertices has been found");
|
||||
DefaultLogger::get()->error("STL: a facet with more than 3 vertices has been found");
|
||||
++sz;
|
||||
} else {
|
||||
if (sz[6] == '\0') {
|
||||
|
|
@ -355,7 +351,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
|
|||
|
||||
if (positionBuffer.empty()) {
|
||||
pMesh->mNumFaces = 0;
|
||||
ASSIMP_LOG_WARN("STL: mesh is empty or invalid; no data loaded");
|
||||
throw DeadlyImportError("STL: ASCII file is empty or invalid; no data loaded");
|
||||
}
|
||||
if (positionBuffer.size() % 3 != 0) {
|
||||
pMesh->mNumFaces = 0;
|
||||
|
|
@ -365,23 +361,14 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
|
|||
pMesh->mNumFaces = 0;
|
||||
throw DeadlyImportError("Normal buffer size does not match position buffer size");
|
||||
}
|
||||
|
||||
// only process positionbuffer when filled, else exception when accessing with index operator
|
||||
// see line 353: only warning is triggered
|
||||
// see line 373(now): access to empty positionbuffer with index operator forced exception
|
||||
if (!positionBuffer.empty()) {
|
||||
pMesh->mNumFaces = static_cast<unsigned int>(positionBuffer.size() / 3);
|
||||
pMesh->mNumVertices = static_cast<unsigned int>(positionBuffer.size());
|
||||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
|
||||
positionBuffer.clear();
|
||||
}
|
||||
// also only process normalBuffer when filled, else exception when accessing with index operator
|
||||
if (!normalBuffer.empty()) {
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
|
||||
normalBuffer.clear();
|
||||
}
|
||||
pMesh->mNumFaces = static_cast<unsigned int>(positionBuffer.size() / 3);
|
||||
pMesh->mNumVertices = static_cast<unsigned int>(positionBuffer.size());
|
||||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
|
||||
positionBuffer.clear();
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
|
||||
normalBuffer.clear();
|
||||
|
||||
// now copy faces
|
||||
addFacesToMesh(pMesh);
|
||||
|
|
@ -430,7 +417,7 @@ bool STLImporter::LoadBinaryFile()
|
|||
|
||||
// read the default vertex color for facets
|
||||
bIsMaterialise = true;
|
||||
ASSIMP_LOG_INFO("STL: Taking code path for Materialise files");
|
||||
DefaultLogger::get()->info("STL: Taking code path for Materialise files");
|
||||
const ai_real invByte = (ai_real)1.0 / ( ai_real )255.0;
|
||||
clrColorDefault.r = (*sz2++) * invByte;
|
||||
clrColorDefault.g = (*sz2++) * invByte;
|
||||
|
|
@ -457,47 +444,28 @@ bool STLImporter::LoadBinaryFile()
|
|||
|
||||
pMesh->mNumVertices = pMesh->mNumFaces*3;
|
||||
|
||||
|
||||
aiVector3D *vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
aiVector3D *vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
aiVector3D* vp,*vn;
|
||||
vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
|
||||
for (unsigned int i = 0; i < pMesh->mNumFaces;++i) {
|
||||
|
||||
typedef aiVector3t<float> aiVector3F;
|
||||
aiVector3F* theVec;
|
||||
aiVector3F theVec3F;
|
||||
|
||||
for ( unsigned int i = 0; i < pMesh->mNumFaces; ++i ) {
|
||||
// NOTE: Blender sometimes writes empty normals ... this is not
|
||||
// our fault ... the RemoveInvalidData helper step should fix that
|
||||
|
||||
// There's one normal for the face in the STL; use it three times
|
||||
// for vertex normals
|
||||
theVec = (aiVector3F*) sz;
|
||||
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
|
||||
vn->x = theVec3F.x; vn->y = theVec3F.y; vn->z = theVec3F.z;
|
||||
*vn = *((aiVector3D*)sz);
|
||||
sz += sizeof(aiVector3D);
|
||||
*(vn+1) = *vn;
|
||||
*(vn+2) = *vn;
|
||||
++theVec;
|
||||
vn += 3;
|
||||
|
||||
// vertex 1
|
||||
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
|
||||
vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z;
|
||||
++theVec;
|
||||
++vp;
|
||||
*vp++ = *((aiVector3D*)sz);
|
||||
sz += sizeof(aiVector3D);
|
||||
|
||||
// vertex 2
|
||||
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
|
||||
vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z;
|
||||
++theVec;
|
||||
++vp;
|
||||
*vp++ = *((aiVector3D*)sz);
|
||||
sz += sizeof(aiVector3D);
|
||||
|
||||
// vertex 3
|
||||
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
|
||||
vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z;
|
||||
++theVec;
|
||||
++vp;
|
||||
|
||||
sz = (const unsigned char*) theVec;
|
||||
*vp++ = *((aiVector3D*)sz);
|
||||
sz += sizeof(aiVector3D);
|
||||
|
||||
uint16_t color = *((uint16_t*)sz);
|
||||
sz += 2;
|
||||
|
|
@ -512,7 +480,7 @@ bool STLImporter::LoadBinaryFile()
|
|||
*pMesh->mColors[0]++ = this->clrColorDefault;
|
||||
pMesh->mColors[0] -= pMesh->mNumVertices;
|
||||
|
||||
ASSIMP_LOG_INFO("STL: Mesh has vertex colors");
|
||||
DefaultLogger::get()->info("STL: Mesh has vertex colors");
|
||||
}
|
||||
aiColor4D* clr = &pMesh->mColors[0][i*3];
|
||||
clr->a = 1.0;
|
||||
|
|
@ -538,21 +506,11 @@ bool STLImporter::LoadBinaryFile()
|
|||
// now copy faces
|
||||
addFacesToMesh(pMesh);
|
||||
|
||||
aiNode* root = pScene->mRootNode;
|
||||
|
||||
// allocate one node
|
||||
aiNode* node = new aiNode();
|
||||
node->mParent = root;
|
||||
|
||||
root->mNumChildren = 1u;
|
||||
root->mChildren = new aiNode*[root->mNumChildren];
|
||||
root->mChildren[0] = node;
|
||||
|
||||
// add all created meshes to the single node
|
||||
node->mNumMeshes = pScene->mNumMeshes;
|
||||
node->mMeshes = new unsigned int[pScene->mNumMeshes];
|
||||
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
||||
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
||||
for (unsigned int i = 0; i < pScene->mNumMeshes; i++)
|
||||
node->mMeshes[i] = i;
|
||||
pScene->mRootNode->mMeshes[i] = i;
|
||||
|
||||
if (bIsMaterialise && !pMesh->mColors[0])
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue