2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2015-05-19 03:48:29 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file BlenderDNA.h
|
2015-05-19 03:52:10 +00:00
|
|
|
* @brief Blender `DNA` (file format specification embedded in
|
2015-05-19 03:48:29 +00:00
|
|
|
* blend file itself) loader.
|
|
|
|
*/
|
|
|
|
#ifndef INCLUDED_AI_BLEND_DNA_H
|
|
|
|
#define INCLUDED_AI_BLEND_DNA_H
|
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/BaseImporter.h>
|
|
|
|
#include <assimp/StreamReader.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <stdint.h>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2017-02-22 16:20:26 +00:00
|
|
|
#include <map>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <memory>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// enable verbose log output. really verbose, so be careful.
|
|
|
|
#ifdef ASSIMP_BUILD_DEBUG
|
2020-05-02 13:14:38 +00:00
|
|
|
#define ASSIMP_BUILD_BLENDER_DEBUG
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2021-05-05 23:30:29 +00:00
|
|
|
// set this to non-zero to dump BlenderDNA stuff to dna.txt.
|
|
|
|
// you could set it on the assimp build command line too without touching it here.
|
|
|
|
// !!! please make sure this is set to 0 in the repo !!!
|
|
|
|
#ifndef ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
|
|
|
#define ASSIMP_BUILD_BLENDER_DEBUG_DNA 0
|
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// #define ASSIMP_BUILD_BLENDER_NO_STATS
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
namespace Assimp {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
template <bool, bool>
|
|
|
|
class StreamReader;
|
|
|
|
typedef StreamReader<true, true> StreamReaderAny;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2016-07-17 11:54:01 +00:00
|
|
|
namespace Blender {
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
class FileDatabase;
|
2016-07-17 11:54:01 +00:00
|
|
|
struct FileBlockHead;
|
|
|
|
|
|
|
|
template <template <typename> class TOUT>
|
|
|
|
class ObjectCache;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Exception class used by the blender loader to selectively catch exceptions
|
|
|
|
* thrown in its own code (DeadlyImportErrors thrown in general utility
|
|
|
|
* functions are untouched then). If such an exception is not caught by
|
|
|
|
* the loader itself, it will still be caught by Assimp due to its
|
|
|
|
* ancestry. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
struct Error : DeadlyImportError {
|
2020-10-25 09:34:43 +00:00
|
|
|
template <typename... T>
|
|
|
|
explicit Error(T &&...args) :
|
|
|
|
DeadlyImportError(args...) {
|
2016-07-17 11:54:01 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** The only purpose of this structure is to feed a virtual dtor into its
|
|
|
|
* descendents. It serves as base class for all data structure fields. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
struct ElemBase {
|
2020-05-02 13:14:38 +00:00
|
|
|
ElemBase() :
|
|
|
|
dna_type(nullptr) {
|
2017-11-18 14:49:03 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:54:01 +00:00
|
|
|
virtual ~ElemBase() {
|
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
/** Type name of the element. The type
|
|
|
|
* string points is the `c_str` of the `name` attribute of the
|
|
|
|
* corresponding `Structure`, that is, it is only valid as long
|
|
|
|
* as the DNA is not modified. The dna_type is only set if the
|
2016-04-05 21:23:53 +00:00
|
|
|
* data type is not static, i.e. a std::shared_ptr<ElemBase>
|
2015-05-19 03:57:13 +00:00
|
|
|
* in the scene description would have its type resolved
|
|
|
|
* at runtime, so this member is always set. */
|
2020-05-02 13:14:38 +00:00
|
|
|
const char *dna_type;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Represents a generic pointer to a memory location, which can be either 32
|
|
|
|
* or 64 bits. These pointers are loaded from the BLEND file and finally
|
2015-05-19 03:52:10 +00:00
|
|
|
* fixed to point to the real, converted representation of the objects
|
2015-05-19 03:48:29 +00:00
|
|
|
* they used to point to.*/
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
struct Pointer {
|
2020-05-02 13:14:38 +00:00
|
|
|
Pointer() :
|
|
|
|
val() {
|
2016-07-17 11:54:01 +00:00
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
uint64_t val;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Represents a generic offset within a BLEND file */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
struct FileOffset {
|
2020-05-02 13:14:38 +00:00
|
|
|
FileOffset() :
|
|
|
|
val() {
|
2016-07-17 11:54:01 +00:00
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
uint64_t val;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Dummy derivate of std::vector to be able to use it in templates simultaenously
|
2016-04-05 21:23:53 +00:00
|
|
|
* with std::shared_ptr, which takes only one template argument
|
2015-05-19 03:48:29 +00:00
|
|
|
* while std::vector takes three. Also we need to provide some special member
|
|
|
|
* functions of shared_ptr */
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2016-07-17 11:54:01 +00:00
|
|
|
class vector : public std::vector<T> {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
using std::vector<T>::resize;
|
|
|
|
using std::vector<T>::empty;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
void reset() {
|
|
|
|
resize(0);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
operator bool() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return !empty();
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Mixed flags for use in #Field */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
enum FieldFlags {
|
2015-05-19 03:57:13 +00:00
|
|
|
FieldFlag_Pointer = 0x1,
|
2020-05-02 13:14:38 +00:00
|
|
|
FieldFlag_Array = 0x2
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Represents a single member of a data structure in a BLEND file */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
struct Field {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string name;
|
|
|
|
std::string type;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t size;
|
|
|
|
size_t offset;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Size of each array dimension. For flat arrays,
|
|
|
|
* the second dimension is set to 1. */
|
|
|
|
size_t array_sizes[2];
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Any of the #FieldFlags enumerated values */
|
|
|
|
unsigned int flags;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-10-25 09:34:43 +00:00
|
|
|
/** Range of possible behaviors for fields absence in the input file. Some are
|
2015-05-19 03:48:29 +00:00
|
|
|
* mission critical so we need them, while others can silently be default
|
|
|
|
* initialized and no animations are harmed. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
enum ErrorPolicy {
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Substitute default value and ignore */
|
|
|
|
ErrorPolicy_Igno,
|
|
|
|
/** Substitute default value and write to log */
|
|
|
|
ErrorPolicy_Warn,
|
|
|
|
/** Substitute a massive error message and crash the whole matrix. Its time for another zion */
|
|
|
|
ErrorPolicy_Fail
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef ASSIMP_BUILD_BLENDER_DEBUG
|
2020-05-02 13:14:38 +00:00
|
|
|
#define ErrorPolicy_Igno ErrorPolicy_Warn
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Represents a data structure in a BLEND file. A Structure defines n fields
|
2018-02-06 21:36:37 +00:00
|
|
|
* and their locations and encodings the input stream. Usually, every
|
2015-05-19 03:48:29 +00:00
|
|
|
* Structure instance pertains to one equally-named data structure in the
|
|
|
|
* BlenderScene.h header. This class defines various utilities to map a
|
|
|
|
* binary `blob` read from the file to such a structure instance with
|
|
|
|
* meaningful contents. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2016-07-17 11:54:01 +00:00
|
|
|
class Structure {
|
2020-05-02 13:14:38 +00:00
|
|
|
template <template <typename> class>
|
|
|
|
friend class ObjectCache;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
Structure() :
|
|
|
|
cache_idx(static_cast<size_t>(-1)) {
|
2016-07-17 11:54:01 +00:00
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// publicly accessible members
|
|
|
|
std::string name;
|
2020-05-02 13:14:38 +00:00
|
|
|
vector<Field> fields;
|
2015-05-19 03:57:13 +00:00
|
|
|
std::map<std::string, size_t> indices;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
size_t size;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Access a field of the structure by its canonical name. The pointer version
|
2020-06-23 19:05:42 +00:00
|
|
|
* returns nullptr on failure while the reference version raises an import error. */
|
2020-05-02 13:14:38 +00:00
|
|
|
inline const Field &operator[](const std::string &ss) const;
|
|
|
|
inline const Field *Get(const std::string &ss) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Access a field of the structure by its index */
|
2020-05-02 13:14:38 +00:00
|
|
|
inline const Field &operator[](const size_t i) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
inline bool operator==(const Structure &other) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return name == other.name; // name is meant to be an unique identifier
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
inline bool operator!=(const Structure &other) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return name != other.name;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Try to read an instance of the structure from the stream
|
|
|
|
* and attempt to convert to `T`. This is done by
|
|
|
|
* an appropriate specialization. If none is available,
|
|
|
|
* a compiler complain is the result.
|
|
|
|
* @param dest Destination value to be written
|
|
|
|
* @param db File database, including input stream. */
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
void Convert(T &dest, const FileDatabase &db) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// generic converter
|
|
|
|
template <typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
void Convert(std::shared_ptr<ElemBase> in, const FileDatabase &db) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// generic allocator
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
std::shared_ptr<ElemBase> Allocate() const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// field parsing for 1d arrays
|
|
|
|
template <int error_policy, typename T, size_t M>
|
2020-05-02 13:14:38 +00:00
|
|
|
void ReadFieldArray(T (&out)[M], const char *name,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// field parsing for 2d arrays
|
|
|
|
template <int error_policy, typename T, size_t M, size_t N>
|
2020-05-02 13:14:38 +00:00
|
|
|
void ReadFieldArray2(T (&out)[M][N], const char *name,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// field parsing for pointer or dynamic array types
|
2016-04-05 21:23:53 +00:00
|
|
|
// (std::shared_ptr)
|
2015-05-19 03:57:13 +00:00
|
|
|
// The return value indicates whether the data was already cached.
|
|
|
|
template <int error_policy, template <typename> class TOUT, typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ReadFieldPtr(TOUT<T> &out, const char *name,
|
|
|
|
const FileDatabase &db,
|
|
|
|
bool non_recursive = false) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// field parsing for static arrays of pointer or dynamic
|
2016-04-05 21:23:53 +00:00
|
|
|
// array types (std::shared_ptr[])
|
2015-05-19 03:57:13 +00:00
|
|
|
// The return value indicates whether the data was already cached.
|
|
|
|
template <int error_policy, template <typename> class TOUT, typename T, size_t N>
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ReadFieldPtr(TOUT<T> (&out)[N], const char *name,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
// field parsing for `normal` values
|
|
|
|
// The return value indicates whether the data was already cached.
|
|
|
|
template <int error_policy, typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
void ReadField(T &out, const char *name,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2018-06-09 13:45:09 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief field parsing for dynamic vectors
|
|
|
|
* @param[in] out vector of struct to be filled
|
|
|
|
* @param[in] name of field
|
|
|
|
* @param[in] db to access the file, dna, ...
|
|
|
|
* @return true when read was successful
|
|
|
|
*/
|
|
|
|
template <int error_policy, template <typename> class TOUT, typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ReadFieldPtrVector(vector<TOUT<T>> &out, const char *name, const FileDatabase &db) const;
|
2018-06-09 13:45:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief parses raw customdata
|
|
|
|
* @param[in] out shared_ptr to be filled
|
|
|
|
* @param[in] cdtype customdata type to read
|
|
|
|
* @param[in] name of field ptr
|
|
|
|
* @param[in] db to access the file, dna, ...
|
|
|
|
* @return true when read was successful
|
|
|
|
*/
|
|
|
|
template <int error_policy>
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ReadCustomDataPtr(std::shared_ptr<ElemBase> &out, int cdtype, const char *name, const FileDatabase &db) const;
|
2018-06-09 13:45:09 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
template <template <typename> class TOUT, typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ResolvePointer(TOUT<T> &out, const Pointer &ptrval,
|
|
|
|
const FileDatabase &db, const Field &f,
|
|
|
|
bool non_recursive = false) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
template <template <typename> class TOUT, typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ResolvePointer(vector<TOUT<T>> &out, const Pointer &ptrval,
|
|
|
|
const FileDatabase &db, const Field &f, bool) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
bool ResolvePointer(std::shared_ptr<FileOffset> &out, const Pointer &ptrval,
|
|
|
|
const FileDatabase &db, const Field &f, bool) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
inline const FileBlockHead *LocateFileBlockForAddress(
|
|
|
|
const Pointer &ptrval,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
// ------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
T *_allocate(std::shared_ptr<T> &out, size_t &s) const {
|
2016-04-05 21:23:53 +00:00
|
|
|
out = std::shared_ptr<T>(new T());
|
2015-05-19 03:57:13 +00:00
|
|
|
s = 1;
|
|
|
|
return out.get();
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
T *_allocate(vector<T> &out, size_t &s) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
out.resize(s);
|
2020-06-23 19:05:42 +00:00
|
|
|
return s ? &out.front() : nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
template <int error_policy>
|
|
|
|
struct _defaultInitializer {
|
|
|
|
|
|
|
|
template <typename T, unsigned int N>
|
2020-06-23 19:05:42 +00:00
|
|
|
void operator()(T (&out)[N], const char * = nullptr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int i = 0; i < N; ++i) {
|
|
|
|
out[i] = T();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, unsigned int N, unsigned int M>
|
2020-06-23 19:05:42 +00:00
|
|
|
void operator()(T (&out)[N][M], const char * = nullptr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
for (unsigned int i = 0; i < N; ++i) {
|
|
|
|
for (unsigned int j = 0; j < M; ++j) {
|
|
|
|
out[i][j] = T();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-06-23 19:05:42 +00:00
|
|
|
void operator()(T &out, const char * = nullptr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
out = T();
|
|
|
|
}
|
|
|
|
};
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
mutable size_t cache_idx;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// --------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
template <>
|
2020-10-25 09:34:43 +00:00
|
|
|
struct Structure::_defaultInitializer<ErrorPolicy_Warn> {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
template <typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
void operator()(T &out, const char *reason = "<add reason>") {
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_WARN(reason);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// ... and let the show go on
|
|
|
|
_defaultInitializer<0 /*ErrorPolicy_Igno*/>()(out);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
template <>
|
2020-10-25 09:34:43 +00:00
|
|
|
struct Structure::_defaultInitializer<ErrorPolicy_Fail> {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
template <typename T>
|
2022-08-08 10:35:58 +00:00
|
|
|
void operator()(T & /*out*/, const char *message = "") {
|
2015-05-19 03:57:13 +00:00
|
|
|
// obviously, it is crucial that _DefaultInitializer is used
|
|
|
|
// only from within a catch clause.
|
2022-08-08 10:35:58 +00:00
|
|
|
throw DeadlyImportError("Constructing BlenderDNA Structure encountered an error: ", message);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
template <>
|
|
|
|
inline bool Structure ::ResolvePointer<std::shared_ptr, ElemBase>(std::shared_ptr<ElemBase> &out,
|
|
|
|
const Pointer &ptrval,
|
|
|
|
const FileDatabase &db,
|
|
|
|
const Field &f,
|
|
|
|
bool) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2022-11-29 18:38:33 +00:00
|
|
|
template <> bool Structure :: ResolvePointer<std::shared_ptr,ElemBase>(
|
|
|
|
std::shared_ptr<ElemBase>& out, const Pointer & ptrval,
|
|
|
|
const FileDatabase& db, const Field&, bool) const;
|
|
|
|
template <> inline void Structure :: Convert<int> (int& dest,const FileDatabase& db) const;
|
|
|
|
template<> inline void Structure :: Convert<short> (short& dest,const FileDatabase& db) const;
|
|
|
|
template <> inline void Structure :: Convert<char> (char& dest,const FileDatabase& db) const;
|
|
|
|
template <> inline void Structure::Convert<unsigned char>(unsigned char& dest, const FileDatabase& db) const;
|
|
|
|
template <> inline void Structure :: Convert<float> (float& dest,const FileDatabase& db) const;
|
|
|
|
template <> inline void Structure :: Convert<double> (double& dest,const FileDatabase& db) const;
|
|
|
|
template <> inline void Structure :: Convert<Pointer> (Pointer& dest,const FileDatabase& db) const;
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Represents the full data structure information for a single BLEND file.
|
|
|
|
* This data is extracted from the DNA1 chunk in the file.
|
2015-05-19 03:52:10 +00:00
|
|
|
* #DNAParser does the reading and represents currently the only place where
|
2015-05-19 03:48:29 +00:00
|
|
|
* DNA is altered.*/
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
class DNA {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
typedef void (Structure::*ConvertProcPtr)(
|
|
|
|
std::shared_ptr<ElemBase> in,
|
|
|
|
const FileDatabase &) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2016-04-05 21:23:53 +00:00
|
|
|
typedef std::shared_ptr<ElemBase> (
|
2020-05-02 13:14:38 +00:00
|
|
|
Structure::*AllocProcPtr)() const;
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
typedef std::pair<AllocProcPtr, ConvertProcPtr> FactoryPair;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
std::map<std::string, FactoryPair> converters;
|
|
|
|
vector<Structure> structures;
|
2015-05-19 03:57:13 +00:00
|
|
|
std::map<std::string, size_t> indices;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
2020-06-23 19:05:42 +00:00
|
|
|
/** Access a structure by its canonical name, the pointer version returns nullptr on failure
|
2015-05-19 03:57:13 +00:00
|
|
|
* while the reference version raises an error. */
|
2020-05-02 13:14:38 +00:00
|
|
|
inline const Structure &operator[](const std::string &ss) const;
|
|
|
|
inline const Structure *Get(const std::string &ss) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Access a structure by its index */
|
2020-05-02 13:14:38 +00:00
|
|
|
inline const Structure &operator[](const size_t i) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Add structure definitions for all the primitive types,
|
|
|
|
* i.e. integer, short, char, float */
|
|
|
|
void AddPrimitiveStructures();
|
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Fill the @c converters member with converters for all
|
|
|
|
* known data types. The implementation of this method is
|
|
|
|
* in BlenderScene.cpp and is machine-generated.
|
|
|
|
* Converters are used to quickly handle objects whose
|
|
|
|
* exact data type is a runtime-property and not yet
|
2021-10-05 08:59:43 +00:00
|
|
|
* known at compile time (consider Object::data).*/
|
2015-05-19 03:57:13 +00:00
|
|
|
void RegisterConverters();
|
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Take an input blob from the stream, interpret it according to
|
|
|
|
* a its structure name and convert it to the intermediate
|
|
|
|
* representation.
|
|
|
|
* @param structure Destination structure definition
|
|
|
|
* @param db File database.
|
|
|
|
* @return A null pointer if no appropriate converter is available.*/
|
2020-05-02 13:14:38 +00:00
|
|
|
std::shared_ptr<ElemBase> ConvertBlobToStructure(
|
|
|
|
const Structure &structure,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Find a suitable conversion function for a given Structure.
|
|
|
|
* Such a converter function takes a blob from the input
|
|
|
|
* stream, reads as much as it needs, and builds up a
|
|
|
|
* complete object in intermediate representation.
|
|
|
|
* @param structure Destination structure definition
|
|
|
|
* @param db File database.
|
|
|
|
* @return A null pointer in .first if no appropriate converter is available.*/
|
|
|
|
FactoryPair GetBlobToStructureConverter(
|
2020-05-02 13:14:38 +00:00
|
|
|
const Structure &structure,
|
|
|
|
const FileDatabase &db) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2021-05-05 23:30:29 +00:00
|
|
|
#if ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Dump the DNA to a text file. This is for debugging purposes.
|
|
|
|
* The output file is `dna.txt` in the current working folder*/
|
|
|
|
void DumpToFile();
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Extract array dimensions from a C array declaration, such
|
|
|
|
* as `...[4][6]`. Returned string would be `...[][]`.
|
|
|
|
* @param out
|
|
|
|
* @param array_sizes Receive maximally two array dimensions,
|
|
|
|
* the second element is set to 1 if the array is flat.
|
|
|
|
* Both are set to 1 if the input is not an array.
|
|
|
|
* @throw DeadlyImportError if more than 2 dimensions are
|
|
|
|
* encountered. */
|
|
|
|
static void ExtractArraySize(
|
2020-05-02 13:14:38 +00:00
|
|
|
const std::string &out,
|
|
|
|
size_t array_sizes[2]);
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// special converters for primitive types
|
2020-05-02 13:14:38 +00:00
|
|
|
template <>
|
|
|
|
inline void Structure ::Convert<int>(int &dest, const FileDatabase &db) const;
|
|
|
|
template <>
|
|
|
|
inline void Structure ::Convert<short>(short &dest, const FileDatabase &db) const;
|
|
|
|
template <>
|
|
|
|
inline void Structure ::Convert<char>(char &dest, const FileDatabase &db) const;
|
|
|
|
template <>
|
|
|
|
inline void Structure ::Convert<float>(float &dest, const FileDatabase &db) const;
|
|
|
|
template <>
|
|
|
|
inline void Structure ::Convert<double>(double &dest, const FileDatabase &db) const;
|
|
|
|
template <>
|
|
|
|
inline void Structure ::Convert<Pointer>(Pointer &dest, const FileDatabase &db) const;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Describes a master file block header. Each master file sections holds n
|
|
|
|
* elements of a certain SDNA structure (or otherwise unspecified data). */
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
struct FileBlockHead {
|
2015-05-19 03:57:13 +00:00
|
|
|
// points right after the header of the file block
|
|
|
|
StreamReaderAny::pos start;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string id;
|
|
|
|
size_t size;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// original memory address of the data
|
|
|
|
Pointer address;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// index into DNA
|
|
|
|
unsigned int dna_index;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// number of structure instances to follow
|
|
|
|
size_t num;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// file blocks are sorted by address to quickly locate specific memory addresses
|
2020-05-02 13:14:38 +00:00
|
|
|
bool operator<(const FileBlockHead &o) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return address.val < o.address.val;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// for std::upper_bound
|
2020-05-02 13:14:38 +00:00
|
|
|
operator const Pointer &() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return address;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// for std::upper_bound
|
2020-05-02 13:14:38 +00:00
|
|
|
inline bool operator<(const Pointer &a, const Pointer &b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return a.val < b.val;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Utility to read all master file blocks in turn. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
class SectionParser {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** @param stream Inout stream, must point to the
|
|
|
|
* first section in the file. Call Next() once
|
|
|
|
* to have it read.
|
|
|
|
* @param ptr64 Pointer size in file is 64 bits? */
|
2020-05-02 13:14:38 +00:00
|
|
|
SectionParser(StreamReaderAny &stream, bool ptr64) :
|
|
|
|
stream(stream), ptr64(ptr64) {
|
2015-05-19 03:57:13 +00:00
|
|
|
current.size = current.start = 0;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
const FileBlockHead &GetCurrent() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return current;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Advance to the next section.
|
|
|
|
* @throw DeadlyImportError if the last chunk was passed. */
|
|
|
|
void Next();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
FileBlockHead current;
|
2020-05-02 13:14:38 +00:00
|
|
|
StreamReaderAny &stream;
|
2015-05-19 03:57:13 +00:00
|
|
|
bool ptr64;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_BLENDER_NO_STATS
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Import statistics, i.e. number of file blocks read*/
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
class Statistics {
|
|
|
|
|
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
Statistics() :
|
|
|
|
fields_read(), pointers_resolved(), cache_hits()
|
|
|
|
// , blocks_read ()
|
|
|
|
,
|
|
|
|
cached_objects() {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
/** total number of fields we read */
|
|
|
|
unsigned int fields_read;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** total number of resolved pointers */
|
|
|
|
unsigned int pointers_resolved;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** number of pointers resolved from the cache */
|
|
|
|
unsigned int cache_hits;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** number of blocks (from FileDatabase::entries)
|
|
|
|
we did actually read from. */
|
|
|
|
// unsigned int blocks_read;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** objects in FileData::cache */
|
|
|
|
unsigned int cached_objects;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** The object cache - all objects addressed by pointers are added here. This
|
|
|
|
* avoids circular references and avoids object duplication. */
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
template <template <typename> class TOUT>
|
2020-05-02 13:14:38 +00:00
|
|
|
class ObjectCache {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
typedef std::map<Pointer, TOUT<ElemBase>> StructureCache;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
ObjectCache(const FileDatabase &db) :
|
|
|
|
db(db) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// currently there are only ~400 structure records per blend file.
|
|
|
|
// we read only a small part of them and don't cache objects
|
|
|
|
// which we don't need, so this should suffice.
|
|
|
|
caches.reserve(64);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Check whether a specific item is in the cache.
|
|
|
|
* @param s Data type of the item
|
|
|
|
* @param out Output pointer. Unchanged if the
|
2018-05-13 14:35:03 +00:00
|
|
|
* cache doesn't know the item yet.
|
2015-05-19 03:57:13 +00:00
|
|
|
* @param ptr Item address to look for. */
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
void get(
|
|
|
|
const Structure &s,
|
|
|
|
TOUT<T> &out,
|
|
|
|
const Pointer &ptr) const;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Add an item to the cache after the item has
|
|
|
|
* been fully read. Do not insert anything that
|
|
|
|
* may be faulty or might cause the loading
|
|
|
|
* to abort.
|
|
|
|
* @param s Data type of the item
|
|
|
|
* @param out Item to insert into the cache
|
|
|
|
* @param ptr address (cache key) of the item. */
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
void set(const Structure &s,
|
|
|
|
const TOUT<T> &out,
|
|
|
|
const Pointer &ptr);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
mutable vector<StructureCache> caches;
|
2020-05-02 13:14:38 +00:00
|
|
|
const FileDatabase &db;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
template <>
|
|
|
|
class ObjectCache<Blender::vector> {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
ObjectCache(const FileDatabase &) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
template <typename T>
|
|
|
|
void get(const Structure &, vector<T> &, const Pointer &) {}
|
|
|
|
template <typename T>
|
|
|
|
void set(const Structure &, const vector<T> &, const Pointer &) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2020-05-02 13:14:38 +00:00
|
|
|
#pragma warning(disable : 4355)
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Memory representation of a full BLEND file and all its dependencies. The
|
|
|
|
* output aiScene is constructed from an instance of this data structure. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
class FileDatabase {
|
|
|
|
template <template <typename> class TOUT>
|
|
|
|
friend class ObjectCache;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
FileDatabase() :
|
|
|
|
_cacheArrays(*this), _cache(*this), next_cache_idx() {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// publicly accessible fields
|
|
|
|
bool i64bit;
|
|
|
|
bool little;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DNA dna;
|
2020-05-02 13:14:38 +00:00
|
|
|
std::shared_ptr<StreamReaderAny> reader;
|
|
|
|
vector<FileBlockHead> entries;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-02 13:14:38 +00:00
|
|
|
Statistics &stats() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return _stats;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// For all our templates to work on both shared_ptr's and vector's
|
|
|
|
// using the same code, a dummy cache for arrays is provided. Actually,
|
|
|
|
// arrays of objects are never cached because we can't easily
|
|
|
|
// ensure their proper destruction.
|
|
|
|
template <typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
ObjectCache<std::shared_ptr> &cache(std::shared_ptr<T> & /*in*/) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return _cache;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
template <typename T>
|
2020-05-02 13:14:38 +00:00
|
|
|
ObjectCache<vector> &cache(vector<T> & /*in*/) const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return _cacheArrays;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
#ifndef ASSIMP_BUILD_BLENDER_NO_STATS
|
2015-05-19 03:57:13 +00:00
|
|
|
mutable Statistics _stats;
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
mutable ObjectCache<vector> _cacheArrays;
|
2016-04-05 21:23:53 +00:00
|
|
|
mutable ObjectCache<std::shared_ptr> _cache;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
mutable size_t next_cache_idx;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2020-05-02 13:14:38 +00:00
|
|
|
#pragma warning(default : 4355)
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------
|
|
|
|
/** Factory to extract a #DNA from the DNA1 file block in a BLEND file. */
|
|
|
|
// -------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
class DNAParser {
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Bind the parser to a empty DNA and an input stream */
|
2020-05-02 13:14:38 +00:00
|
|
|
DNAParser(FileDatabase &db) :
|
|
|
|
db(db) {}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// --------------------------------------------------------
|
|
|
|
/** Locate the DNA in the file and parse it. The input
|
|
|
|
* stream is expected to point to the beginning of the DN1
|
|
|
|
* chunk at the time this method is called and is
|
|
|
|
* undefined afterwards.
|
|
|
|
* @throw DeadlyImportError if the DNA cannot be read.
|
|
|
|
* @note The position of the stream pointer is undefined
|
|
|
|
* afterwards.*/
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parse();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Obtain a reference to the extracted DNA information */
|
2020-05-02 13:14:38 +00:00
|
|
|
const Blender::DNA &GetDNA() const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return db.dna;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-02 13:14:38 +00:00
|
|
|
FileDatabase &db;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
2018-06-09 18:22:59 +00:00
|
|
|
/**
|
|
|
|
* @brief read CustomData's data to ptr to mem
|
|
|
|
* @param[out] out memory ptr to set
|
|
|
|
* @param[in] cdtype to read
|
|
|
|
* @param[in] cnt cnt of elements to read
|
|
|
|
* @param[in] db to read elements from
|
|
|
|
* @return true when ok
|
|
|
|
*/
|
2018-06-09 21:29:50 +00:00
|
|
|
bool readCustomData(std::shared_ptr<ElemBase> &out, int cdtype, size_t cnt, const FileDatabase &db);
|
2018-06-09 18:22:59 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
} // namespace Blender
|
|
|
|
} // namespace Assimp
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#include "BlenderDNA.inl"
|
|
|
|
|
|
|
|
#endif
|