mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-19 14:43:47 +00:00
Updated assimp to latest
This commit is contained in:
parent
25ce4477ce
commit
161bf7f83b
461 changed files with 34662 additions and 30165 deletions
|
|
@ -3,7 +3,8 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2017, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -51,12 +52,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
// internal headers
|
||||
#include "3DSLoader.h"
|
||||
#include "Macros.h"
|
||||
#include <assimp/Macros.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include "StringComparison.h"
|
||||
#include <assimp/StringComparison.h>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
|
|
@ -70,7 +71,7 @@ static const aiImporterDesc desc = {
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
"3ds prj"
|
||||
"3ds prj"
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -105,29 +106,31 @@ static const aiImporterDesc desc = {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
Discreet3DSImporter::Discreet3DSImporter()
|
||||
: stream(),
|
||||
mLastNodeIndex(),
|
||||
mCurrentNode(),
|
||||
mRootNode(),
|
||||
mScene(),
|
||||
mMasterScale(),
|
||||
bHasBG(),
|
||||
bIsPrj()
|
||||
{}
|
||||
: stream()
|
||||
, mLastNodeIndex()
|
||||
, mCurrentNode()
|
||||
, mRootNode()
|
||||
, mScene()
|
||||
, mMasterScale()
|
||||
, bHasBG()
|
||||
, bIsPrj() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
Discreet3DSImporter::~Discreet3DSImporter()
|
||||
{}
|
||||
Discreet3DSImporter::~Discreet3DSImporter() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool Discreet3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
||||
{
|
||||
bool Discreet3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
|
||||
std::string extension = GetExtension(pFile);
|
||||
if(extension == "3ds" || extension == "prj" ) {
|
||||
if(extension == "3ds" || extension == "prj") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!extension.length() || checkSig) {
|
||||
uint16_t token[3];
|
||||
token[0] = 0x4d4d;
|
||||
|
|
@ -158,19 +161,21 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
|
|||
aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
StreamReaderLE stream(pIOHandler->Open(pFile,"rb"));
|
||||
this->stream = &stream;
|
||||
|
||||
// We should have at least one chunk
|
||||
if (stream.GetRemainingSize() < 16) {
|
||||
throw DeadlyImportError("3DS file is either empty or corrupt: " + pFile);
|
||||
}
|
||||
this->stream = &stream;
|
||||
|
||||
// Allocate our temporary 3DS representation
|
||||
mScene = new D3DS::Scene();
|
||||
D3DS::Scene _scene;
|
||||
mScene = &_scene;
|
||||
|
||||
// Initialize members
|
||||
D3DS::Node _rootNode("UNNAMED");
|
||||
mLastNodeIndex = -1;
|
||||
mCurrentNode = new D3DS::Node();
|
||||
mCurrentNode = &_rootNode;
|
||||
mRootNode = mCurrentNode;
|
||||
mRootNode->mHierarchyPos = -1;
|
||||
mRootNode->mHierarchyIndex = -1;
|
||||
|
|
@ -190,7 +195,6 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
|
|||
// file.
|
||||
for (auto &mesh : mScene->mMeshes) {
|
||||
if (mesh.mFaces.size() > 0 && mesh.mPositions.size() == 0) {
|
||||
delete mScene;
|
||||
throw DeadlyImportError("3DS file contains faces but no vertices: " + pFile);
|
||||
}
|
||||
CheckIndices(mesh);
|
||||
|
|
@ -198,7 +202,7 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
|
|||
ComputeNormalsWithSmoothingsGroups<D3DS::Face>(mesh);
|
||||
}
|
||||
|
||||
// Replace all occurrences of the default material with a
|
||||
// Replace all occurences of the default material with a
|
||||
// valid material. Generate it if no material containing
|
||||
// DEFAULT in its name has been found in the file
|
||||
ReplaceDefaultMaterial();
|
||||
|
|
@ -209,16 +213,14 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
|
|||
ConvertScene(pScene);
|
||||
|
||||
// Generate the node graph for the scene. This is a little bit
|
||||
// tricky since we'll need to split some meshes into submeshes
|
||||
// tricky since we'll need to split some meshes into sub-meshes
|
||||
GenerateNodeGraph(pScene);
|
||||
|
||||
// Now apply the master scaling factor to the scene
|
||||
ApplyMasterScale(pScene);
|
||||
|
||||
// Delete our internal scene representation and the root
|
||||
// node, so the whole hierarchy will follow
|
||||
delete mRootNode;
|
||||
delete mScene;
|
||||
// Our internal scene representation and the root
|
||||
// node will be automatically deleted, so the whole hierarchy will follow
|
||||
|
||||
AI_DEBUG_INVALIDATE_PTR(mRootNode);
|
||||
AI_DEBUG_INVALIDATE_PTR(mScene);
|
||||
|
|
@ -247,16 +249,18 @@ void Discreet3DSImporter::ApplyMasterScale(aiScene* pScene)
|
|||
// Reads a new chunk from the file
|
||||
void Discreet3DSImporter::ReadChunk(Discreet3DS::Chunk* pcOut)
|
||||
{
|
||||
ai_assert(pcOut != NULL);
|
||||
ai_assert(pcOut != nullptr);
|
||||
|
||||
pcOut->Flag = stream->GetI2();
|
||||
pcOut->Size = stream->GetI4();
|
||||
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSize())
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSize()) {
|
||||
throw DeadlyImportError("Chunk is too large");
|
||||
}
|
||||
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSizeToLimit())
|
||||
DefaultLogger::get()->error("3DS: Chunk overflow");
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSizeToLimit()) {
|
||||
ASSIMP_LOG_ERROR("3DS: Chunk overflow");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -317,7 +321,7 @@ void Discreet3DSImporter::ParseEditorChunk()
|
|||
// print the version number
|
||||
char buff[10];
|
||||
ASSIMP_itoa10(buff,stream->GetI2());
|
||||
DefaultLogger::get()->info(std::string("3DS file format version: ") + buff);
|
||||
ASSIMP_LOG_INFO_F(std::string("3DS file format version: "), buff);
|
||||
}
|
||||
break;
|
||||
};
|
||||
|
|
@ -346,7 +350,7 @@ void Discreet3DSImporter::ParseObjectChunk()
|
|||
case Discreet3DS::CHUNK_MAT_MATERIAL:
|
||||
|
||||
// Add a new material to the list
|
||||
mScene->mMaterials.push_back(D3DS::Material());
|
||||
mScene->mMaterials.push_back(D3DS::Material(std::string("UNNAMED_" + to_string(mScene->mMaterials.size()))));
|
||||
ParseMaterialChunk();
|
||||
break;
|
||||
|
||||
|
|
@ -358,7 +362,7 @@ void Discreet3DSImporter::ParseObjectChunk()
|
|||
if (is_qnan(mClrAmbient.r))
|
||||
{
|
||||
// We failed to read the ambient base color.
|
||||
DefaultLogger::get()->error("3DS: Failed to read ambient base color");
|
||||
ASSIMP_LOG_ERROR("3DS: Failed to read ambient base color");
|
||||
mClrAmbient.r = mClrAmbient.g = mClrAmbient.b = 0.0f;
|
||||
}
|
||||
break;
|
||||
|
|
@ -402,11 +406,7 @@ void Discreet3DSImporter::ParseChunk(const char* name, unsigned int num)
|
|||
case Discreet3DS::CHUNK_TRIMESH:
|
||||
{
|
||||
// this starts a new triangle mesh
|
||||
mScene->mMeshes.push_back(D3DS::Mesh());
|
||||
D3DS::Mesh& m = mScene->mMeshes.back();
|
||||
|
||||
// Setup the name of the mesh
|
||||
m.mName = std::string(name, num);
|
||||
mScene->mMeshes.push_back(D3DS::Mesh(std::string(name, num)));
|
||||
|
||||
// Read mesh chunks
|
||||
ParseMeshChunk();
|
||||
|
|
@ -464,7 +464,7 @@ void Discreet3DSImporter::ParseChunk(const char* name, unsigned int num)
|
|||
if (len < 1e-5) {
|
||||
|
||||
// There are some files with lookat == position. Don't know why or whether it's ok or not.
|
||||
DefaultLogger::get()->error("3DS: Unable to read proper camera look-at vector");
|
||||
ASSIMP_LOG_ERROR("3DS: Unable to read proper camera look-at vector");
|
||||
camera->mLookAt = aiVector3D(0.0,1.0,0.0);
|
||||
|
||||
}
|
||||
|
|
@ -630,9 +630,9 @@ void Discreet3DSImporter::SkipTCBInfo()
|
|||
if (!flags) {
|
||||
// Currently we can't do anything with these values. They occur
|
||||
// quite rare, so it wouldn't be worth the effort implementing
|
||||
// them. 3DS ist not really suitable for complex animations,
|
||||
// them. 3DS is not really suitable for complex animations,
|
||||
// so full support is not required.
|
||||
DefaultLogger::get()->warn("3DS: Skipping TCB animation info");
|
||||
ASSIMP_LOG_WARN("3DS: Skipping TCB animation info");
|
||||
}
|
||||
|
||||
if (flags & Discreet3DS::KEY_USE_TENS) {
|
||||
|
|
@ -690,8 +690,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
|
|||
pcNode->mInstanceCount++;
|
||||
instanceNumber = pcNode->mInstanceCount;
|
||||
}
|
||||
pcNode = new D3DS::Node();
|
||||
pcNode->mName = name;
|
||||
pcNode = new D3DS::Node(name);
|
||||
pcNode->mInstanceNumber = instanceNumber;
|
||||
|
||||
// There are two unknown values which we can safely ignore
|
||||
|
|
@ -734,7 +733,6 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
|
|||
|
||||
// If object name is DUMMY, take this one instead
|
||||
if (mCurrentNode->mName == "$$$DUMMY") {
|
||||
//DefaultLogger::get()->warn("3DS: Skipping dummy object name for non-dummy object");
|
||||
mCurrentNode->mName = std::string(sz);
|
||||
break;
|
||||
}
|
||||
|
|
@ -745,7 +743,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
|
|||
|
||||
if ( Discreet3DS::CHUNK_TRACKINFO != parent)
|
||||
{
|
||||
DefaultLogger::get()->warn("3DS: Skipping pivot subchunk for non usual object");
|
||||
ASSIMP_LOG_WARN("3DS: Skipping pivot subchunk for non usual object");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -807,7 +805,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
|
|||
{
|
||||
// roll keys are accepted for cameras only
|
||||
if (parent != Discreet3DS::CHUNK_TRACKCAMERA) {
|
||||
DefaultLogger::get()->warn("3DS: Ignoring roll track for non-camera object");
|
||||
ASSIMP_LOG_WARN("3DS: Ignoring roll track for non-camera object");
|
||||
break;
|
||||
}
|
||||
bool sortKeys = false;
|
||||
|
|
@ -847,7 +845,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
|
|||
// CAMERA FOV KEYFRAME
|
||||
case Discreet3DS::CHUNK_TRACKFOV:
|
||||
{
|
||||
DefaultLogger::get()->error("3DS: Skipping FOV animation track. "
|
||||
ASSIMP_LOG_ERROR("3DS: Skipping FOV animation track. "
|
||||
"This is not supported");
|
||||
}
|
||||
break;
|
||||
|
|
@ -987,7 +985,7 @@ void Discreet3DSImporter::ParseFaceChunk()
|
|||
}
|
||||
}
|
||||
if (0xcdcdcdcd == idx) {
|
||||
DefaultLogger::get()->error(std::string("3DS: Unknown material: ") + sz);
|
||||
ASSIMP_LOG_ERROR_F( "3DS: Unknown material: ", sz);
|
||||
}
|
||||
|
||||
// Now continue and read all material indices
|
||||
|
|
@ -997,7 +995,7 @@ void Discreet3DSImporter::ParseFaceChunk()
|
|||
|
||||
// check range
|
||||
if (fidx >= mMesh.mFaceMaterials.size()) {
|
||||
DefaultLogger::get()->error("3DS: Invalid face index in face material list");
|
||||
ASSIMP_LOG_ERROR("3DS: Invalid face index in face material list");
|
||||
}
|
||||
else mMesh.mFaceMaterials[fidx] = idx;
|
||||
}}
|
||||
|
|
@ -1112,7 +1110,7 @@ void Discreet3DSImporter::ParseMaterialChunk()
|
|||
|
||||
if (!cnt) {
|
||||
// This may not be, we use the default name instead
|
||||
DefaultLogger::get()->error("3DS: Empty material name");
|
||||
ASSIMP_LOG_ERROR("3DS: Empty material name");
|
||||
}
|
||||
else mScene->mMaterials.back().mName = std::string(sz,cnt);
|
||||
}
|
||||
|
|
@ -1125,7 +1123,7 @@ void Discreet3DSImporter::ParseMaterialChunk()
|
|||
ParseColorChunk(pc);
|
||||
if (is_qnan(pc->r)) {
|
||||
// color chunk is invalid. Simply ignore it
|
||||
DefaultLogger::get()->error("3DS: Unable to read DIFFUSE chunk");
|
||||
ASSIMP_LOG_ERROR("3DS: Unable to read DIFFUSE chunk");
|
||||
pc->r = pc->g = pc->b = 1.0f;
|
||||
}}
|
||||
break;
|
||||
|
|
@ -1137,7 +1135,7 @@ void Discreet3DSImporter::ParseMaterialChunk()
|
|||
ParseColorChunk(pc);
|
||||
if (is_qnan(pc->r)) {
|
||||
// color chunk is invalid. Simply ignore it
|
||||
DefaultLogger::get()->error("3DS: Unable to read SPECULAR chunk");
|
||||
ASSIMP_LOG_ERROR("3DS: Unable to read SPECULAR chunk");
|
||||
pc->r = pc->g = pc->b = 1.0f;
|
||||
}}
|
||||
break;
|
||||
|
|
@ -1149,7 +1147,7 @@ void Discreet3DSImporter::ParseMaterialChunk()
|
|||
ParseColorChunk(pc);
|
||||
if (is_qnan(pc->r)) {
|
||||
// color chunk is invalid. Simply ignore it
|
||||
DefaultLogger::get()->error("3DS: Unable to read AMBIENT chunk");
|
||||
ASSIMP_LOG_ERROR("3DS: Unable to read AMBIENT chunk");
|
||||
pc->r = pc->g = pc->b = 0.0f;
|
||||
}}
|
||||
break;
|
||||
|
|
@ -1161,7 +1159,7 @@ void Discreet3DSImporter::ParseMaterialChunk()
|
|||
ParseColorChunk(pc);
|
||||
if (is_qnan(pc->r)) {
|
||||
// color chunk is invalid. Simply ignore it
|
||||
DefaultLogger::get()->error("3DS: Unable to read EMISSIVE chunk");
|
||||
ASSIMP_LOG_ERROR("3DS: Unable to read EMISSIVE chunk");
|
||||
pc->r = pc->g = pc->b = 0.0f;
|
||||
}}
|
||||
break;
|
||||
|
|
@ -1295,7 +1293,7 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut)
|
|||
pcOut->mScaleU = stream->GetF4();
|
||||
if (0.0f == pcOut->mScaleU)
|
||||
{
|
||||
DefaultLogger::get()->warn("Texture coordinate scaling in the x direction is zero. Assuming 1.");
|
||||
ASSIMP_LOG_WARN("Texture coordinate scaling in the x direction is zero. Assuming 1.");
|
||||
pcOut->mScaleU = 1.0f;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1304,7 +1302,7 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut)
|
|||
pcOut->mScaleV = stream->GetF4();
|
||||
if (0.0f == pcOut->mScaleV)
|
||||
{
|
||||
DefaultLogger::get()->warn("Texture coordinate scaling in the y direction is zero. Assuming 1.");
|
||||
ASSIMP_LOG_WARN("Texture coordinate scaling in the y direction is zero. Assuming 1.");
|
||||
pcOut->mScaleV = 1.0f;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1346,15 +1344,16 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut)
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Read a percentage chunk
|
||||
ai_real Discreet3DSImporter::ParsePercentageChunk()
|
||||
{
|
||||
ai_real Discreet3DSImporter::ParsePercentageChunk() {
|
||||
Discreet3DS::Chunk chunk;
|
||||
ReadChunk(&chunk);
|
||||
|
||||
if (Discreet3DS::CHUNK_PERCENTF == chunk.Flag)
|
||||
return stream->GetF4();
|
||||
else if (Discreet3DS::CHUNK_PERCENTW == chunk.Flag)
|
||||
if (Discreet3DS::CHUNK_PERCENTF == chunk.Flag) {
|
||||
return stream->GetF4() * ai_real(100) / ai_real(0xFFFF);
|
||||
} else if (Discreet3DS::CHUNK_PERCENTW == chunk.Flag) {
|
||||
return (ai_real)((uint16_t)stream->GetI2()) / (ai_real)0xFFFF;
|
||||
}
|
||||
|
||||
return get_qnan();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue