Initial pass at adding logging

pull/3232/head
Malcolm Tyrrell 2020-05-14 17:43:31 +01:00
parent b7de061749
commit 6be0ce1ec9
9 changed files with 72 additions and 39 deletions

View File

@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdint.h>
#include <assimp/Exceptional.h>
#include <assimp/ByteSwapper.h>
#include <assimp/DefaultLogger.hpp>
namespace Assimp {
namespace FBX {
@ -426,7 +427,8 @@ bool ReadScope(TokenList& output_tokens, const char* input, const char*& cursor,
// TODO: Test FBX Binary files newer than the 7500 version to check if the 64 bits address behaviour is consistent
void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length)
{
ai_assert(input);
ai_assert(input);
ASSIMP_FBX_LOG_DEBUG("Tokenizing binary FBX file");
if(length < 0x1b) {
TokenizeError("file is too short",0);
@ -451,6 +453,7 @@ void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length)
/*Result ignored*/ ReadByte(input, cursor, input + length);
/*Result ignored*/ ReadByte(input, cursor, input + length);
const uint32_t version = ReadWord(input, cursor, input + length);
ASSIMP_FBX_LOG_DEBUG_F("FBX version: ", version);
const bool is64bits = version >= 7500;
const char *end = input + length;
while (cursor < end ) {

View File

@ -75,4 +75,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# endif
#endif
#ifndef ASSIMP_FBX_LOG_DEBUG
// These require the DefaultLogger header.
#define ASSIMP_FBX_LOG_DEBUG ASSIMP_LOG_DEBUG
#define ASSIMP_FBX_LOG_DEBUG_F ASSIMP_LOG_DEBUG_F
#endif
#endif // INCLUDED_AI_FBX_COMPILECONFIG_H

View File

@ -412,7 +412,7 @@ private:
// ------------------------------------------------------------------------------------------------
// FBX file could have embedded textures not connected to anything
void ConvertOrphantEmbeddedTextures();
void ConvertOrphanedEmbeddedTextures();
private:
// 0: not assigned yet, others: index is value - 1

View File

@ -55,6 +55,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FBXDocumentUtil.h"
#include "FBXProperties.h"
#include <assimp/DefaultLogger.hpp>
#include <memory>
#include <functional>
#include <map>
@ -264,6 +266,8 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
: settings(settings)
, parser(parser)
{
ASSIMP_FBX_LOG_DEBUG("Creating FBX Document");
// Cannot use array default initialization syntax because vc8 fails on it
for (auto &timeStamp : creationTimeStamp) {
timeStamp = 0;
@ -308,6 +312,7 @@ void Document::ReadHeader() {
const Scope& shead = *ehead->Compound();
fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
ASSIMP_FBX_LOG_DEBUG_F("FBX Version: ", fbxVersion);
// While we may have some success with newer files, we don't support
// the older 6.n fbx format

View File

@ -146,6 +146,8 @@ void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
ThrowException("Could not open file for reading");
}
ASSIMP_FBX_LOG_DEBUG("Reading FBX file");
// read entire file into memory - no streaming for this, fbx
// files can grow large, but the assimp output data structure
// then becomes very large, too. Assimp doesn't support

View File

@ -59,6 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/ParsingUtils.h>
#include <assimp/fast_atof.h>
#include <assimp/ByteSwapper.h>
#include <assimp/DefaultLogger.hpp>
#include <iostream>
@ -220,6 +221,7 @@ Parser::Parser (const TokenList& tokens, bool is_binary)
, cursor(tokens.begin())
, is_binary(is_binary)
{
ASSIMP_FBX_LOG_DEBUG("Parsing FBX tokens");
root.reset(new Scope(*this,true));
}

View File

@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FBXTokenizer.h"
#include "FBXUtil.h"
#include <assimp/Exceptional.h>
#include <assimp/DefaultLogger.hpp>
namespace Assimp {
namespace FBX {
@ -134,7 +135,8 @@ void ProcessDataToken( TokenList& output_tokens, const char*& start, const char*
// ------------------------------------------------------------------------------------------------
void Tokenize(TokenList& output_tokens, const char* input)
{
ai_assert(input);
ai_assert(input);
ASSIMP_FBX_LOG_DEBUG("Tokenizing ascii FBX file");
// line and column numbers numbers are one-based
unsigned int line = 1;

View File

@ -286,6 +286,7 @@ static aiMaterial *ImportMaterial(std::vector<int> &embeddedTexIdxs, Asset &r, M
void glTF2Importer::ImportMaterials(glTF2::Asset &r) {
const unsigned int numImportedMaterials = unsigned(r.materials.Size());
ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numImportedMaterials, " materials");
Material defaultMaterial;
mScene->mNumMaterials = numImportedMaterials + 1;
@ -333,6 +334,7 @@ static inline bool CheckValidFacesIndices(aiFace *faces, unsigned nFaces, unsign
#endif // ASSIMP_BUILD_DEBUG
void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
ASSIMP_GLTF_LOG_DEBUG_F("Importing ", r.meshes.Size(), " meshes");
std::vector<aiMesh *> meshes;
unsigned int k = 0;
@ -662,10 +664,12 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
void glTF2Importer::ImportCameras(glTF2::Asset &r) {
if (!r.cameras.Size()) return;
mScene->mNumCameras = r.cameras.Size();
mScene->mCameras = new aiCamera *[r.cameras.Size()];
const unsigned int numCameras = r.cameras.Size();
ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numCameras, " cameras");
mScene->mNumCameras = numCameras;
mScene->mCameras = new aiCamera *[numCameras];
for (size_t i = 0; i < r.cameras.Size(); ++i) {
for (size_t i = 0; i < numCameras; ++i) {
Camera &cam = r.cameras[i];
aiCamera *aicam = mScene->mCameras[i] = new aiCamera();
@ -696,10 +700,12 @@ void glTF2Importer::ImportLights(glTF2::Asset &r) {
if (!r.lights.Size())
return;
mScene->mNumLights = r.lights.Size();
mScene->mLights = new aiLight *[r.lights.Size()];
const unsigned int numLights = r.lights.Size();
ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numLights, " lights");
mScene->mNumLights = numLights;
mScene->mLights = new aiLight *[numLights];
for (size_t i = 0; i < r.lights.Size(); ++i) {
for (size_t i = 0; i < numLights; ++i) {
Light &light = r.lights[i];
aiLight *ail = mScene->mLights[i] = new aiLight();
@ -958,6 +964,7 @@ void glTF2Importer::ImportNodes(glTF2::Asset &r) {
if (!r.scene) {
throw DeadlyImportError("GLTF: No scene");
}
ASSIMP_GLTF_LOG_DEBUG("Importing nodes");
std::vector<Ref<Node>> rootNodes = r.scene->nodes;
@ -1137,13 +1144,15 @@ std::unordered_map<unsigned int, AnimationSamplers> GatherSamplers(Animation &an
void glTF2Importer::ImportAnimations(glTF2::Asset &r) {
if (!r.scene) return;
mScene->mNumAnimations = r.animations.Size();
const unsigned numAnimations = r.animations.Size();
ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numAnimations, " animations");
mScene->mNumAnimations = numAnimations;
if (mScene->mNumAnimations == 0) {
return;
}
mScene->mAnimations = new aiAnimation *[mScene->mNumAnimations];
for (unsigned int i = 0; i < r.animations.Size(); ++i) {
mScene->mAnimations = new aiAnimation *[numAnimations];
for (unsigned int i = 0; i < numAnimations; ++i) {
Animation &anim = r.animations[i];
aiAnimation *ai_anim = new aiAnimation();
@ -1249,6 +1258,8 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
if (numEmbeddedTexs == 0)
return;
ASSIMP_GLTF_LOG_DEBUG_F("Importing ", numEmbeddedTexs, " embedded textures");
mScene->mTextures = new aiTexture *[numEmbeddedTexs];
// Add the embedded textures
@ -1288,6 +1299,7 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
}
void glTF2Importer::ImportCommonMetadata(glTF2::Asset& a) {
ASSIMP_GLTF_LOG_DEBUG("Importing metadata");
ai_assert(mScene->mMetaData == nullptr);
const bool hasVersion = !a.asset.version.empty();
const bool hasGenerator = !a.asset.generator.empty();
@ -1307,6 +1319,9 @@ void glTF2Importer::ImportCommonMetadata(glTF2::Asset& a) {
}
void glTF2Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
ASSIMP_GLTF_LOG_DEBUG("Reading GLTF file");
// clean all member arrays
meshOffsets.clear();
embeddedTexIdxs.clear();

View File

@ -273,33 +273,31 @@ void Logger::info(const std::string &message) {
return info(message.c_str());
}
// ------------------------------------------------------------------------------------------------
#define ASSIMP_LOG_WARN_F(string,...)\
DefaultLogger::get()->warn((Formatter::format(string),__VA_ARGS__))
#define ASSIMP_LOG_ERROR_F(string,...)\
DefaultLogger::get()->error((Formatter::format(string),__VA_ARGS__))
#define ASSIMP_LOG_DEBUG_F(string,...)\
DefaultLogger::get()->debug((Formatter::format(string),__VA_ARGS__))
#define ASSIMP_LOG_INFO_F(string,...)\
DefaultLogger::get()->info((Formatter::format(string),__VA_ARGS__))
#define ASSIMP_LOG_WARN(string)\
DefaultLogger::get()->warn(string)
#define ASSIMP_LOG_ERROR(string)\
DefaultLogger::get()->error(string)
#define ASSIMP_LOG_DEBUG(string)\
DefaultLogger::get()->debug(string)
#define ASSIMP_LOG_INFO(string)\
DefaultLogger::get()->info(string)
} // Namespace Assimp
// ------------------------------------------------------------------------------------------------
#define ASSIMP_LOG_WARN_F(string, ...) \
Assimp::DefaultLogger::get()->warn((Assimp::Formatter::format(string), __VA_ARGS__))
#define ASSIMP_LOG_ERROR_F(string, ...) \
Assimp::DefaultLogger::get()->error((Assimp::Formatter::format(string), __VA_ARGS__))
#define ASSIMP_LOG_DEBUG_F(string, ...) \
Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__))
#define ASSIMP_LOG_INFO_F(string, ...) \
Assimp::DefaultLogger::get()->info((Assimp::Formatter::format(string), __VA_ARGS__))
#define ASSIMP_LOG_WARN(string) \
Assimp::DefaultLogger::get()->warn(string)
#define ASSIMP_LOG_ERROR(string) \
Assimp::DefaultLogger::get()->error(string)
#define ASSIMP_LOG_DEBUG(string) \
Assimp::DefaultLogger::get()->debug(string)
#define ASSIMP_LOG_INFO(string) \
Assimp::DefaultLogger::get()->info(string)
#endif // !! INCLUDED_AI_LOGGER_H