mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
update assimp lib
This commit is contained in:
parent
03a348deb7
commit
d3f8fee74e
1725 changed files with 196314 additions and 62009 deletions
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -162,8 +162,11 @@ void AnimResolver::UpdateAnimRangeSetup() {
|
|||
const double my_last = (*it).keys.back().time;
|
||||
|
||||
const double delta = my_last - my_first;
|
||||
const size_t old_size = (*it).keys.size();
|
||||
if (delta == 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t old_size = (*it).keys.size();
|
||||
const float value_delta = (*it).keys.back().value - (*it).keys.front().value;
|
||||
|
||||
// NOTE: We won't handle reset, linear and constant here.
|
||||
|
|
@ -176,8 +179,7 @@ void AnimResolver::UpdateAnimRangeSetup() {
|
|||
case LWO::PrePostBehaviour_Oscillate: {
|
||||
const double start_time = delta - std::fmod(my_first - first, delta);
|
||||
std::vector<LWO::Key>::iterator n = std::find_if((*it).keys.begin(), (*it).keys.end(),
|
||||
[start_time](double t) { return start_time > t; }),
|
||||
m;
|
||||
[start_time](double t) { return start_time > t; }), m;
|
||||
|
||||
size_t ofs = 0;
|
||||
if (n != (*it).keys.end()) {
|
||||
|
|
@ -463,7 +465,7 @@ void AnimResolver::GetKeys(std::vector<aiVectorKey> &out,
|
|||
cur_z = envl_z->keys.begin();
|
||||
|
||||
end_x = end_y = end_z = false;
|
||||
while (1) {
|
||||
while (true) {
|
||||
|
||||
aiVectorKey fill;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
|
||||
|
|
@ -51,65 +51,56 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "LWOLoader.h"
|
||||
using namespace Assimp;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LWOImporter::LoadLWOBFile()
|
||||
{
|
||||
void LWOImporter::LoadLWOBFile() {
|
||||
LE_NCONST uint8_t* const end = mFileBuffer + fileSize;
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
if (mFileBuffer + sizeof(IFF::ChunkHeader) > end)break;
|
||||
while (running) {
|
||||
if (mFileBuffer + sizeof(IFF::ChunkHeader) > end)
|
||||
break;
|
||||
const IFF::ChunkHeader head = IFF::LoadChunk(mFileBuffer);
|
||||
|
||||
if (mFileBuffer + head.length > end)
|
||||
{
|
||||
if (mFileBuffer + head.length > end) {
|
||||
throw DeadlyImportError("LWOB: Invalid chunk length");
|
||||
break;
|
||||
}
|
||||
uint8_t* const next = mFileBuffer+head.length;
|
||||
switch (head.type)
|
||||
{
|
||||
switch (head.type) {
|
||||
// vertex list
|
||||
case AI_LWO_PNTS:
|
||||
{
|
||||
case AI_LWO_PNTS: {
|
||||
if (!mCurLayer->mTempPoints.empty())
|
||||
ASSIMP_LOG_WARN("LWO: PNTS chunk encountered twice");
|
||||
else LoadLWOPoints(head.length);
|
||||
break;
|
||||
}
|
||||
// face list
|
||||
case AI_LWO_POLS:
|
||||
{
|
||||
else
|
||||
LoadLWOPoints(head.length);
|
||||
} break;
|
||||
case AI_LWO_POLS: { // face list
|
||||
if (!mCurLayer->mFaces.empty())
|
||||
ASSIMP_LOG_WARN("LWO: POLS chunk encountered twice");
|
||||
else
|
||||
LoadLWOBPolygons(head.length);
|
||||
} break;
|
||||
|
||||
case AI_LWO_SRFS: // list of tags
|
||||
{
|
||||
if (!mTags->empty())
|
||||
ASSIMP_LOG_WARN("LWO: SRFS chunk encountered twice");
|
||||
else
|
||||
LoadLWOTags(head.length);
|
||||
} break;
|
||||
|
||||
if (!mCurLayer->mFaces.empty())
|
||||
ASSIMP_LOG_WARN("LWO: POLS chunk encountered twice");
|
||||
else LoadLWOBPolygons(head.length);
|
||||
break;
|
||||
}
|
||||
// list of tags
|
||||
case AI_LWO_SRFS:
|
||||
{
|
||||
if (!mTags->empty())
|
||||
ASSIMP_LOG_WARN("LWO: SRFS chunk encountered twice");
|
||||
else LoadLWOTags(head.length);
|
||||
break;
|
||||
}
|
||||
case AI_LWO_SURF: // surface chunk
|
||||
{
|
||||
LoadLWOBSurface(head.length);
|
||||
} break;
|
||||
|
||||
// surface chunk
|
||||
case AI_LWO_SURF:
|
||||
{
|
||||
LoadLWOBSurface(head.length);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
mFileBuffer = next;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LWOImporter::LoadLWOBPolygons(unsigned int length)
|
||||
{
|
||||
void LWOImporter::LoadLWOBPolygons(unsigned int length) {
|
||||
// first find out how many faces and vertices we'll finally need
|
||||
LE_NCONST uint16_t* const end = (LE_NCONST uint16_t*)(mFileBuffer+length);
|
||||
LE_NCONST uint16_t* cursor = (LE_NCONST uint16_t*)mFileBuffer;
|
||||
|
|
@ -124,8 +115,7 @@ void LWOImporter::LoadLWOBPolygons(unsigned int length)
|
|||
CountVertsAndFacesLWOB(iNumVertices,iNumFaces,cursor,end);
|
||||
|
||||
// allocate the output array and copy face indices
|
||||
if (iNumFaces)
|
||||
{
|
||||
if (iNumFaces) {
|
||||
cursor = (LE_NCONST uint16_t*)mFileBuffer;
|
||||
|
||||
mCurLayer->mFaces.resize(iNumFaces);
|
||||
|
|
@ -136,10 +126,8 @@ void LWOImporter::LoadLWOBPolygons(unsigned int length)
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& faces,
|
||||
LE_NCONST uint16_t*& cursor, const uint16_t* const end, unsigned int max)
|
||||
{
|
||||
while (cursor < end && max--)
|
||||
{
|
||||
LE_NCONST uint16_t*& cursor, const uint16_t* const end, unsigned int max) {
|
||||
while (cursor < end && max--) {
|
||||
uint16_t numIndices;
|
||||
// must have 2 shorts left for numIndices and surface
|
||||
if (end - cursor < 2) {
|
||||
|
|
@ -155,8 +143,7 @@ void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& face
|
|||
cursor += numIndices;
|
||||
int16_t surface;
|
||||
::memcpy(&surface, cursor++, 2);
|
||||
if (surface < 0)
|
||||
{
|
||||
if (surface < 0) {
|
||||
// there are detail polygons
|
||||
::memcpy(&numIndices, cursor++, 2);
|
||||
CountVertsAndFacesLWOB(verts,faces,cursor,end,numIndices);
|
||||
|
|
@ -165,21 +152,17 @@ void LWOImporter::CountVertsAndFacesLWOB(unsigned int& verts, unsigned int& face
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it,
|
||||
void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator &it,
|
||||
LE_NCONST uint16_t*& cursor,
|
||||
const uint16_t* const end,
|
||||
unsigned int max)
|
||||
{
|
||||
while (cursor < end && max--)
|
||||
{
|
||||
unsigned int max) {
|
||||
while (cursor < end && max--) {
|
||||
LWO::Face& face = *it;++it;
|
||||
uint16_t numIndices;
|
||||
::memcpy(&numIndices, cursor++, 2);
|
||||
face.mNumIndices = numIndices;
|
||||
if(face.mNumIndices)
|
||||
{
|
||||
if (cursor + face.mNumIndices >= end)
|
||||
{
|
||||
if(face.mNumIndices) {
|
||||
if (cursor + face.mNumIndices >= end) {
|
||||
break;
|
||||
}
|
||||
face.mIndices = new unsigned int[face.mNumIndices];
|
||||
|
|
@ -188,8 +171,7 @@ void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it,
|
|||
uint16_t index;
|
||||
::memcpy(&index, cursor++, 2);
|
||||
mi = index;
|
||||
if (mi > mCurLayer->mTempPoints.size())
|
||||
{
|
||||
if (mi > mCurLayer->mTempPoints.size()) {
|
||||
ASSIMP_LOG_WARN("LWOB: face index is out of range");
|
||||
mi = (unsigned int)mCurLayer->mTempPoints.size()-1;
|
||||
}
|
||||
|
|
@ -199,15 +181,13 @@ void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it,
|
|||
}
|
||||
int16_t surface;
|
||||
::memcpy(&surface, cursor++, 2);
|
||||
if (surface < 0)
|
||||
{
|
||||
if (surface < 0) {
|
||||
surface = -surface;
|
||||
|
||||
// there are detail polygons.
|
||||
uint16_t numPolygons;
|
||||
::memcpy(&numPolygons, cursor++, 2);
|
||||
if (cursor < end)
|
||||
{
|
||||
if (cursor < end) {
|
||||
CopyFaceIndicesLWOB(it,cursor,end,numPolygons);
|
||||
}
|
||||
}
|
||||
|
|
@ -216,8 +196,7 @@ void LWOImporter::CopyFaceIndicesLWOB(FaceList::iterator& it,
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned int size)
|
||||
{
|
||||
LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned int size) {
|
||||
list.emplace_back();
|
||||
LWO::Texture* tex = &list.back();
|
||||
|
||||
|
|
@ -225,8 +204,7 @@ LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned i
|
|||
GetS0(type,size);
|
||||
const char* s = type.c_str();
|
||||
|
||||
if(strstr(s, "Image Map"))
|
||||
{
|
||||
if(strstr(s, "Image Map")) {
|
||||
// Determine mapping type
|
||||
if(strstr(s, "Planar"))
|
||||
tex->mapMode = LWO::Texture::Planar;
|
||||
|
|
@ -238,9 +216,7 @@ LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned i
|
|||
tex->mapMode = LWO::Texture::Cubic;
|
||||
else if(strstr(s, "Front"))
|
||||
tex->mapMode = LWO::Texture::FrontProjection;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// procedural or gradient, not supported
|
||||
ASSIMP_LOG_ERROR("LWOB: Unsupported legacy texture: ", type);
|
||||
}
|
||||
|
|
@ -249,8 +225,7 @@ LWO::Texture* LWOImporter::SetupNewTextureLWOB(LWO::TextureList& list,unsigned i
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LWOImporter::LoadLWOBSurface(unsigned int size)
|
||||
{
|
||||
void LWOImporter::LoadLWOBSurface(unsigned int size) {
|
||||
LE_NCONST uint8_t* const end = mFileBuffer + size;
|
||||
|
||||
mSurfaces->push_back( LWO::Surface () );
|
||||
|
|
@ -278,148 +253,147 @@ void LWOImporter::LoadLWOBSurface(unsigned int size)
|
|||
}
|
||||
|
||||
uint8_t* const next = mFileBuffer+head.length;
|
||||
switch (head.type)
|
||||
{
|
||||
// diffuse color
|
||||
case AI_LWO_COLR:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,COLR,3);
|
||||
surf.mColor.r = GetU1() / 255.0f;
|
||||
surf.mColor.g = GetU1() / 255.0f;
|
||||
surf.mColor.b = GetU1() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// diffuse strength ...
|
||||
case AI_LWO_DIFF:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,DIFF,2);
|
||||
surf.mDiffuseValue = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// specular strength ...
|
||||
case AI_LWO_SPEC:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SPEC,2);
|
||||
surf.mSpecularValue = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// luminosity ...
|
||||
case AI_LWO_LUMI:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,LUMI,2);
|
||||
surf.mLuminosity = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// transparency
|
||||
case AI_LWO_TRAN:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TRAN,2);
|
||||
surf.mTransparency = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// surface flags
|
||||
case AI_LWO_FLAG:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,FLAG,2);
|
||||
uint16_t flag = GetU2();
|
||||
if (flag & 0x4 ) surf.mMaximumSmoothAngle = 1.56207f;
|
||||
if (flag & 0x8 ) surf.mColorHighlights = 1.f;
|
||||
if (flag & 0x100) surf.bDoubleSided = true;
|
||||
break;
|
||||
}
|
||||
// maximum smoothing angle
|
||||
case AI_LWO_SMAN:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SMAN,4);
|
||||
surf.mMaximumSmoothAngle = std::fabs( GetF4() );
|
||||
break;
|
||||
}
|
||||
// glossiness
|
||||
case AI_LWO_GLOS:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,GLOS,2);
|
||||
surf.mGlossiness = (float)GetU2();
|
||||
break;
|
||||
}
|
||||
// color texture
|
||||
case AI_LWO_CTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mColorTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// diffuse texture
|
||||
case AI_LWO_DTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mDiffuseTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// specular texture
|
||||
case AI_LWO_STEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mSpecularTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// bump texture
|
||||
case AI_LWO_BTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mBumpTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// transparency texture
|
||||
case AI_LWO_TTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mOpacityTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// texture path
|
||||
case AI_LWO_TIMG:
|
||||
{
|
||||
if (pTex) {
|
||||
GetS0(pTex->mFileName,head.length);
|
||||
} else {
|
||||
ASSIMP_LOG_WARN("LWOB: Unexpected TIMG chunk");
|
||||
switch (head.type) {
|
||||
// diffuse color
|
||||
case AI_LWO_COLR:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,COLR,3);
|
||||
surf.mColor.r = GetU1() / 255.0f;
|
||||
surf.mColor.g = GetU1() / 255.0f;
|
||||
surf.mColor.b = GetU1() / 255.0f;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// texture strength
|
||||
case AI_LWO_TVAL:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TVAL,1);
|
||||
if (pTex) {
|
||||
pTex->mStrength = (float)GetU1()/ 255.f;
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("LWOB: Unexpected TVAL chunk");
|
||||
// diffuse strength ...
|
||||
case AI_LWO_DIFF:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,DIFF,2);
|
||||
surf.mDiffuseValue = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// texture flags
|
||||
case AI_LWO_TFLG:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TFLG,2);
|
||||
|
||||
if (nullptr != pTex) {
|
||||
const uint16_t s = GetU2();
|
||||
if (s & 1)
|
||||
pTex->majorAxis = LWO::Texture::AXIS_X;
|
||||
else if (s & 2)
|
||||
pTex->majorAxis = LWO::Texture::AXIS_Y;
|
||||
else if (s & 4)
|
||||
pTex->majorAxis = LWO::Texture::AXIS_Z;
|
||||
|
||||
if (s & 16) {
|
||||
ASSIMP_LOG_WARN("LWOB: Ignoring \'negate\' flag on texture");
|
||||
// specular strength ...
|
||||
case AI_LWO_SPEC:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SPEC,2);
|
||||
surf.mSpecularValue = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// luminosity ...
|
||||
case AI_LWO_LUMI:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,LUMI,2);
|
||||
surf.mLuminosity = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// transparency
|
||||
case AI_LWO_TRAN:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TRAN,2);
|
||||
surf.mTransparency = GetU2() / 255.0f;
|
||||
break;
|
||||
}
|
||||
// surface flags
|
||||
case AI_LWO_FLAG:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,FLAG,2);
|
||||
uint16_t flag = GetU2();
|
||||
if (flag & 0x4 ) surf.mMaximumSmoothAngle = 1.56207f;
|
||||
if (flag & 0x8 ) surf.mColorHighlights = 1.f;
|
||||
if (flag & 0x100) surf.bDoubleSided = true;
|
||||
break;
|
||||
}
|
||||
// maximum smoothing angle
|
||||
case AI_LWO_SMAN:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SMAN,4);
|
||||
surf.mMaximumSmoothAngle = std::fabs( GetF4() );
|
||||
break;
|
||||
}
|
||||
// glossiness
|
||||
case AI_LWO_GLOS:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,GLOS,2);
|
||||
surf.mGlossiness = (float)GetU2();
|
||||
break;
|
||||
}
|
||||
// color texture
|
||||
case AI_LWO_CTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mColorTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// diffuse texture
|
||||
case AI_LWO_DTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mDiffuseTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// specular texture
|
||||
case AI_LWO_STEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mSpecularTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// bump texture
|
||||
case AI_LWO_BTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mBumpTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// transparency texture
|
||||
case AI_LWO_TTEX:
|
||||
{
|
||||
pTex = SetupNewTextureLWOB(surf.mOpacityTextures,
|
||||
head.length);
|
||||
break;
|
||||
}
|
||||
// texture path
|
||||
case AI_LWO_TIMG:
|
||||
{
|
||||
if (pTex) {
|
||||
GetS0(pTex->mFileName,head.length);
|
||||
} else {
|
||||
ASSIMP_LOG_WARN("LWOB: Unexpected TIMG chunk");
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
ASSIMP_LOG_WARN("LWOB: Unexpected TFLG chunk");
|
||||
// texture strength
|
||||
case AI_LWO_TVAL:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TVAL,1);
|
||||
if (pTex) {
|
||||
pTex->mStrength = (float)GetU1()/ 255.f;
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("LWOB: Unexpected TVAL chunk");
|
||||
}
|
||||
break;
|
||||
}
|
||||
// texture flags
|
||||
case AI_LWO_TFLG:
|
||||
{
|
||||
AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,TFLG,2);
|
||||
|
||||
if (nullptr != pTex) {
|
||||
const uint16_t s = GetU2();
|
||||
if (s & 1)
|
||||
pTex->majorAxis = LWO::Texture::AXIS_X;
|
||||
else if (s & 2)
|
||||
pTex->majorAxis = LWO::Texture::AXIS_Y;
|
||||
else if (s & 4)
|
||||
pTex->majorAxis = LWO::Texture::AXIS_Z;
|
||||
|
||||
if (s & 16) {
|
||||
ASSIMP_LOG_WARN("LWOB: Ignoring \'negate\' flag on texture");
|
||||
}
|
||||
}
|
||||
else {
|
||||
ASSIMP_LOG_WARN("LWOB: Unexpected TFLG chunk");
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
mFileBuffer = next;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -51,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "AssetLib/LWO/LWOLoader.h"
|
||||
#include "PostProcessing/ConvertToLHProcess.h"
|
||||
#include "PostProcessing/ProcessHelper.h"
|
||||
#include "Geometry/GeometryUtils.h"
|
||||
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/SGSpatialSort.h>
|
||||
|
|
@ -135,7 +134,7 @@ void LWOImporter::InternReadFile(const std::string &pFile,
|
|||
std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
|
||||
|
||||
// Check whether we can read from the file
|
||||
if (file.get() == nullptr) {
|
||||
if (file == nullptr) {
|
||||
throw DeadlyImportError("Failed to open LWO file ", pFile, ".");
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +177,7 @@ void LWOImporter::InternReadFile(const std::string &pFile,
|
|||
mLayers->push_back(Layer());
|
||||
mCurLayer = &mLayers->back();
|
||||
mCurLayer->mName = "<LWODefault>";
|
||||
mCurLayer->mIndex = (uint16_t) -1;
|
||||
mCurLayer->mIndex = 1;
|
||||
|
||||
// old lightwave file format (prior to v6)
|
||||
mIsLWO2 = false;
|
||||
|
|
@ -215,7 +214,7 @@ void LWOImporter::InternReadFile(const std::string &pFile,
|
|||
} else {
|
||||
mIsLWO2 = true;
|
||||
}
|
||||
|
||||
|
||||
LoadLWO2File();
|
||||
|
||||
// The newer lightwave format allows the user to configure the
|
||||
|
|
@ -398,14 +397,6 @@ void LWOImporter::InternReadFile(const std::string &pFile,
|
|||
pvVC[w]++;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// process vertex weights. We can't properly reconstruct the whole skeleton for now,
|
||||
// but we can create dummy bones for all weight channels which we have.
|
||||
for (unsigned int w = 0; w < layer.mWeightChannels.size();++w)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
face.mIndices[q] = vert;
|
||||
}
|
||||
pf->mIndices = face.mIndices;
|
||||
|
|
@ -429,7 +420,7 @@ void LWOImporter::InternReadFile(const std::string &pFile,
|
|||
// Generate nodes to render the mesh. Store the source layer in the mParent member of the nodes
|
||||
unsigned int num = static_cast<unsigned int>(apcMeshes.size() - meshStart);
|
||||
if (layer.mName != "<LWODefault>" || num > 0) {
|
||||
aiNode *pcNode = new aiNode();
|
||||
std::unique_ptr<aiNode> pcNode(new aiNode());
|
||||
pcNode->mName.Set(layer.mName);
|
||||
pcNode->mParent = (aiNode *)&layer;
|
||||
pcNode->mNumMeshes = num;
|
||||
|
|
@ -439,7 +430,8 @@ void LWOImporter::InternReadFile(const std::string &pFile,
|
|||
for (unsigned int p = 0; p < pcNode->mNumMeshes; ++p)
|
||||
pcNode->mMeshes[p] = p + meshStart;
|
||||
}
|
||||
apcNodes[layer.mIndex] = pcNode;
|
||||
ASSIMP_LOG_DEBUG("insert apcNode for layer ", layer.mIndex, " \"", layer.mName, "\"");
|
||||
apcNodes[layer.mIndex] = pcNode.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -564,6 +556,7 @@ void LWOImporter::ComputeNormals(aiMesh *mesh, const std::vector<unsigned int> &
|
|||
}
|
||||
}
|
||||
}
|
||||
GeometryUtils::normalizeVectorArray(mesh->mNormals, mesh->mNormals, mesh->mNumVertices);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -572,40 +565,64 @@ void LWOImporter::GenerateNodeGraph(std::map<uint16_t, aiNode *> &apcNodes) {
|
|||
aiNode *root = mScene->mRootNode = new aiNode();
|
||||
root->mName.Set("<LWORoot>");
|
||||
|
||||
//Set parent of all children, inserting pivots
|
||||
std::map<uint16_t, aiNode *> mapPivot;
|
||||
for (auto itapcNodes = apcNodes.begin(); itapcNodes != apcNodes.end(); ++itapcNodes) {
|
||||
|
||||
//Get the parent index
|
||||
LWO::Layer *nodeLayer = (LWO::Layer *)(itapcNodes->second->mParent);
|
||||
uint16_t parentIndex = nodeLayer->mParent;
|
||||
|
||||
//Create pivot node, store it into the pivot map, and set the parent as the pivot
|
||||
aiNode *pivotNode = new aiNode();
|
||||
pivotNode->mName.Set("Pivot-" + std::string(itapcNodes->second->mName.data));
|
||||
itapcNodes->second->mParent = pivotNode;
|
||||
|
||||
//Look for the parent node to attach the pivot to
|
||||
if (apcNodes.find(parentIndex) != apcNodes.end()) {
|
||||
pivotNode->mParent = apcNodes[parentIndex];
|
||||
} else {
|
||||
//If not, attach to the root node
|
||||
pivotNode->mParent = root;
|
||||
}
|
||||
|
||||
//Set the node and the pivot node transformation
|
||||
itapcNodes->second->mTransformation.a4 = -nodeLayer->mPivot.x;
|
||||
itapcNodes->second->mTransformation.b4 = -nodeLayer->mPivot.y;
|
||||
itapcNodes->second->mTransformation.c4 = -nodeLayer->mPivot.z;
|
||||
pivotNode->mTransformation.a4 = nodeLayer->mPivot.x;
|
||||
pivotNode->mTransformation.b4 = nodeLayer->mPivot.y;
|
||||
pivotNode->mTransformation.c4 = nodeLayer->mPivot.z;
|
||||
mapPivot[-(itapcNodes->first + 2)] = pivotNode;
|
||||
ASSIMP_LOG_DEBUG("apcNodes initial size: ", apcNodes.size());
|
||||
if (!apcNodes.empty()) {
|
||||
ASSIMP_LOG_DEBUG("first apcNode is: ", apcNodes.begin()->first, " \"", apcNodes.begin()->second->mName.C_Str(), "\"");
|
||||
}
|
||||
|
||||
//Merge pivot map into node map
|
||||
for (auto itMapPivot = mapPivot.begin(); itMapPivot != mapPivot.end(); ++itMapPivot) {
|
||||
apcNodes[itMapPivot->first] = itMapPivot->second;
|
||||
//Set parent of all children, inserting pivots
|
||||
{
|
||||
std::map<uint16_t, aiNode *> mapPivot;
|
||||
for (auto itapcNodes = apcNodes.begin(); itapcNodes != apcNodes.end(); ++itapcNodes) {
|
||||
|
||||
//Get the parent index
|
||||
LWO::Layer *nodeLayer = (LWO::Layer *)(itapcNodes->second->mParent);
|
||||
uint16_t parentIndex = nodeLayer->mParent;
|
||||
|
||||
//Create pivot node, store it into the pivot map, and set the parent as the pivot
|
||||
std::unique_ptr<aiNode> pivotNode(new aiNode());
|
||||
pivotNode->mName.Set("Pivot-" + std::string(itapcNodes->second->mName.data));
|
||||
itapcNodes->second->mParent = pivotNode.get();
|
||||
|
||||
//Look for the parent node to attach the pivot to
|
||||
if (apcNodes.find(parentIndex) != apcNodes.end()) {
|
||||
pivotNode->mParent = apcNodes[parentIndex];
|
||||
} else {
|
||||
//If not, attach to the root node
|
||||
pivotNode->mParent = root;
|
||||
}
|
||||
|
||||
//Set the node and the pivot node transformation
|
||||
itapcNodes->second->mTransformation.a4 = -nodeLayer->mPivot.x;
|
||||
itapcNodes->second->mTransformation.b4 = -nodeLayer->mPivot.y;
|
||||
itapcNodes->second->mTransformation.c4 = -nodeLayer->mPivot.z;
|
||||
pivotNode->mTransformation.a4 = nodeLayer->mPivot.x;
|
||||
pivotNode->mTransformation.b4 = nodeLayer->mPivot.y;
|
||||
pivotNode->mTransformation.c4 = nodeLayer->mPivot.z;
|
||||
uint16_t pivotNodeId = static_cast<uint16_t>(-(itapcNodes->first + 2));
|
||||
ASSIMP_LOG_DEBUG("insert pivot node: ", pivotNodeId);
|
||||
auto oldNodeIt = mapPivot.find(pivotNodeId);
|
||||
if (oldNodeIt != mapPivot.end()) {
|
||||
ASSIMP_LOG_ERROR("attempted to insert pivot node which already exists in pivot map ", pivotNodeId, " \"", pivotNode->mName.C_Str(), "\"");
|
||||
} else {
|
||||
mapPivot.emplace(pivotNodeId, pivotNode.release());
|
||||
}
|
||||
}
|
||||
|
||||
ASSIMP_LOG_DEBUG("pivot nodes: ", mapPivot.size());
|
||||
//Merge pivot map into node map
|
||||
for (auto itMapPivot = mapPivot.begin(); itMapPivot != mapPivot.end();) {
|
||||
uint16_t pivotNodeId = itMapPivot->first;
|
||||
auto oldApcNodeIt = apcNodes.find(pivotNodeId);
|
||||
if (oldApcNodeIt != apcNodes.end()) {
|
||||
ASSIMP_LOG_ERROR("attempted to insert pivot node which already exists in apc nodes ", pivotNodeId, " \"", itMapPivot->second->mName.C_Str(), "\"");
|
||||
} else {
|
||||
apcNodes.emplace(pivotNodeId, itMapPivot->second);
|
||||
}
|
||||
itMapPivot->second = nullptr;
|
||||
itMapPivot = mapPivot.erase(itMapPivot);
|
||||
}
|
||||
ASSIMP_LOG_DEBUG("total nodes: ", apcNodes.size());
|
||||
}
|
||||
|
||||
//Set children of all parents
|
||||
|
|
@ -627,8 +644,15 @@ void LWOImporter::GenerateNodeGraph(std::map<uint16_t, aiNode *> &apcNodes) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!mScene->mRootNode->mNumChildren)
|
||||
if (!mScene->mRootNode->mNumChildren) {
|
||||
ASSIMP_LOG_DEBUG("All apcNodes:");
|
||||
for (auto nodeIt = apcNodes.begin(); nodeIt != apcNodes.end(); ) {
|
||||
ASSIMP_LOG_DEBUG("Node ", nodeIt->first, " \"", nodeIt->second->mName.C_Str(), "\"");
|
||||
nodeIt->second = nullptr;
|
||||
nodeIt = apcNodes.erase(nodeIt);
|
||||
}
|
||||
throw DeadlyImportError("LWO: Unable to build a valid node graph");
|
||||
}
|
||||
|
||||
// Remove a single root node with no meshes assigned to it ...
|
||||
if (1 == mScene->mRootNode->mNumChildren) {
|
||||
|
|
@ -1462,7 +1486,6 @@ void LWOImporter::LoadLWO2File() {
|
|||
|
||||
if (mFileBuffer + head.length > end) {
|
||||
throw DeadlyImportError("LWO2: Chunk length points behind the file");
|
||||
break;
|
||||
}
|
||||
uint8_t *const next = mFileBuffer + head.length;
|
||||
mFileBuffer += bufOffset;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ void LWOImporter::ConvertMaterial(const LWO::Surface &surf, aiMaterial *pcMat) {
|
|||
|
||||
// (the diffuse value is just a scaling factor)
|
||||
// If a diffuse texture is set, we set this value to 1.0
|
||||
clr = (b && false ? aiColor3D(1.0, 1.0, 1.0) : surf.mColor);
|
||||
clr = (b ? aiColor3D(1.0, 1.0, 1.0) : surf.mColor);
|
||||
clr.r *= surf.mDiffuseValue;
|
||||
clr.g *= surf.mDiffuseValue;
|
||||
clr.b *= surf.mDiffuseValue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue