Merge branch 'assimp:master' into master

pull/4431/head
Terence Russell 2022-03-09 10:15:41 -07:00 committed by GitHub
commit efe92e9ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 130 deletions

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2022, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -68,23 +67,13 @@ namespace FBX {
using namespace Util; using namespace Util;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc) LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc) :
: doc(doc) doc(doc), element(element), id(id), flags() {
, element(element)
, id(id)
, flags() {
// empty // empty
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LazyObject::~LazyObject() const Object* LazyObject::Get(bool dieOnError) {
{
// empty
}
// ------------------------------------------------------------------------------------------------
const Object* LazyObject::Get(bool dieOnError)
{
if(IsBeingConstructed() || FailedToConstruct()) { if(IsBeingConstructed() || FailedToConstruct()) {
return nullptr; return nullptr;
} }
@ -234,17 +223,8 @@ const Object* LazyObject::Get(bool dieOnError)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Object::Object(uint64_t id, const Element& element, const std::string& name) Object::Object(uint64_t id, const Element& element, const std::string& name) :
: element(element) element(element), name(name), id(id) {
, name(name)
, id(id)
{
// empty
}
// ------------------------------------------------------------------------------------------------
Object::~Object()
{
// empty // empty
} }
@ -255,16 +235,8 @@ FileGlobalSettings::FileGlobalSettings(const Document &doc, std::shared_ptr<cons
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
FileGlobalSettings::~FileGlobalSettings() Document::Document(const Parser& parser, const ImportSettings& settings) :
{ settings(settings), parser(parser) {
// empty
}
// ------------------------------------------------------------------------------------------------
Document::Document(const Parser& parser, const ImportSettings& settings)
: settings(settings)
, parser(parser)
{
ASSIMP_LOG_DEBUG("Creating FBX Document"); ASSIMP_LOG_DEBUG("Creating FBX Document");
// Cannot use array default initialization syntax because vc8 fails on it // Cannot use array default initialization syntax because vc8 fails on it
@ -285,8 +257,7 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Document::~Document() Document::~Document() {
{
for(ObjectMap::value_type& v : objects) { for(ObjectMap::value_type& v : objects) {
delete v.second; delete v.second;
} }
@ -348,8 +319,7 @@ void Document::ReadHeader() {
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Document::ReadGlobalSettings() void Document::ReadGlobalSettings() {
{
const Scope& sc = parser.GetRootScope(); const Scope& sc = parser.GetRootScope();
const Element* const ehead = sc["GlobalSettings"]; const Element* const ehead = sc["GlobalSettings"];
if ( nullptr == ehead || !ehead->Compound() ) { if ( nullptr == ehead || !ehead->Compound() ) {
@ -370,8 +340,7 @@ void Document::ReadGlobalSettings()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Document::ReadObjects() void Document::ReadObjects() {
{
// read ID objects from "Objects" section // read ID objects from "Objects" section
const Scope& sc = parser.GetRootScope(); const Scope& sc = parser.GetRootScope();
const Element* const eobjects = sc["Objects"]; const Element* const eobjects = sc["Objects"];
@ -418,8 +387,7 @@ void Document::ReadObjects()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Document::ReadPropertyTemplates() void Document::ReadPropertyTemplates() {
{
const Scope& sc = parser.GetRootScope(); const Scope& sc = parser.GetRootScope();
// read property templates from "Definitions" section // read property templates from "Definitions" section
const Element* const edefs = sc["Definitions"]; const Element* const edefs = sc["Definitions"];
@ -476,8 +444,7 @@ void Document::ReadPropertyTemplates()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Document::ReadConnections() void Document::ReadConnections() {
{
const Scope& sc = parser.GetRootScope(); const Scope& sc = parser.GetRootScope();
// read property templates from "Definitions" section // read property templates from "Definitions" section
const Element* const econns = sc["Connections"]; const Element* const econns = sc["Connections"];
@ -524,8 +491,7 @@ void Document::ReadConnections()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const std::vector<const AnimationStack*>& Document::AnimationStacks() const const std::vector<const AnimationStack*>& Document::AnimationStacks() const {
{
if (!animationStacksResolved.empty() || animationStacks.empty()) { if (!animationStacksResolved.empty() || animationStacks.empty()) {
return animationStacksResolved; return animationStacksResolved;
} }
@ -545,17 +511,15 @@ const std::vector<const AnimationStack*>& Document::AnimationStacks() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LazyObject* Document::GetObject(uint64_t id) const LazyObject* Document::GetObject(uint64_t id) const {
{
ObjectMap::const_iterator it = objects.find(id); ObjectMap::const_iterator it = objects.find(id);
return it == objects.end() ? nullptr : (*it).second; return it == objects.end() ? nullptr : (*it).second;
} }
#define MAX_CLASSNAMES 6 constexpr size_t MAX_CLASSNAMES = 6;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns) const std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns) const {
{
std::vector<const Connection*> temp; std::vector<const Connection*> temp;
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range = const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
@ -573,11 +537,9 @@ std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, co
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src, std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src,
const ConnectionMap& conns, const ConnectionMap& conns,
const char* const* classnames, const char* const* classnames,
size_t count) const size_t count) const {
{
ai_assert(classnames); ai_assert(classnames);
ai_assert( count != 0 ); ai_assert( count != 0 );
ai_assert( count <= MAX_CLASSNAMES); ai_assert( count <= MAX_CLASSNAMES);
@ -622,95 +584,72 @@ std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bo
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const {
{
return GetConnectionsSequenced(source, ConnectionsBySource()); return GetConnectionsSequenced(source, ConnectionsBySource());
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t src, const char* classname) const std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t src, const char* classname) const {
{
const char* arr[] = {classname}; const char* arr[] = {classname};
return GetConnectionsBySourceSequenced(src, arr,1); return GetConnectionsBySourceSequenced(src, arr,1);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source, std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source,
const char* const* classnames, size_t count) const const char* const* classnames, size_t count) const {
{
return GetConnectionsSequenced(source, true, ConnectionsBySource(),classnames, count); return GetConnectionsSequenced(source, true, ConnectionsBySource(),classnames, count);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest, std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
const char* classname) const const char* classname) const {
{
const char* arr[] = {classname}; const char* arr[] = {classname};
return GetConnectionsByDestinationSequenced(dest, arr,1); return GetConnectionsByDestinationSequenced(dest, arr,1);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const {
{
return GetConnectionsSequenced(dest, ConnectionsByDestination()); return GetConnectionsSequenced(dest, ConnectionsByDestination());
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest, std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
const char* const* classnames, size_t count) const const char* const* classnames, size_t count) const {
{
return GetConnectionsSequenced(dest, false, ConnectionsByDestination(),classnames, count); return GetConnectionsSequenced(dest, false, ConnectionsByDestination(),classnames, count);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop,
const Document& doc) const Document& doc) :
insertionOrder(insertionOrder), prop(prop), src(src), dest(dest), doc(doc) {
: insertionOrder(insertionOrder)
, prop(prop)
, src(src)
, dest(dest)
, doc(doc)
{
ai_assert(doc.Objects().find(src) != doc.Objects().end()); ai_assert(doc.Objects().find(src) != doc.Objects().end());
// dest may be 0 (root node) // dest may be 0 (root node)
ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end()); ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end());
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Connection::~Connection() LazyObject& Connection::LazySourceObject() const {
{
// empty
}
// ------------------------------------------------------------------------------------------------
LazyObject& Connection::LazySourceObject() const
{
LazyObject* const lazy = doc.GetObject(src); LazyObject* const lazy = doc.GetObject(src);
ai_assert(lazy); ai_assert(lazy);
return *lazy; return *lazy;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LazyObject& Connection::LazyDestinationObject() const LazyObject& Connection::LazyDestinationObject() const {
{
LazyObject* const lazy = doc.GetObject(dest); LazyObject* const lazy = doc.GetObject(dest);
ai_assert(lazy); ai_assert(lazy);
return *lazy; return *lazy;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Object* Connection::SourceObject() const const Object* Connection::SourceObject() const {
{
LazyObject* const lazy = doc.GetObject(src); LazyObject* const lazy = doc.GetObject(src);
ai_assert(lazy); ai_assert(lazy);
return lazy->Get(); return lazy->Get();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Object* Connection::DestinationObject() const const Object* Connection::DestinationObject() const {
{
LazyObject* const lazy = doc.GetObject(dest); LazyObject* const lazy = doc.GetObject(dest);
ai_assert(lazy); ai_assert(lazy);
return lazy->Get(); return lazy->Get();
@ -719,4 +658,4 @@ const Object* Connection::DestinationObject() const
} // !FBX } // !FBX
} // !Assimp } // !Assimp
#endif #endif // ASSIMP_BUILD_NO_FBX_IMPORTER

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2022, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -89,7 +88,7 @@ class LazyObject {
public: public:
LazyObject(uint64_t id, const Element& element, const Document& doc); LazyObject(uint64_t id, const Element& element, const Document& doc);
~LazyObject(); ~LazyObject() = default;
const Object* Get(bool dieOnError = false); const Object* Get(bool dieOnError = false);
@ -139,7 +138,7 @@ class Object {
public: public:
Object(uint64_t id, const Element& element, const std::string& name); Object(uint64_t id, const Element& element, const std::string& name);
virtual ~Object(); virtual ~Object() = default;
const Element& SourceElement() const { const Element& SourceElement() const {
return element; return element;
@ -267,8 +266,7 @@ public:
Light(uint64_t id, const Element& element, const Document& doc, const std::string& name); Light(uint64_t id, const Element& element, const Document& doc, const std::string& name);
virtual ~Light(); virtual ~Light();
enum Type enum Type {
{
Type_Point, Type_Point,
Type_Directional, Type_Directional,
Type_Spot, Type_Spot,
@ -278,8 +276,7 @@ public:
Type_MAX // end-of-enum sentinel Type_MAX // end-of-enum sentinel
}; };
enum Decay enum Decay {
{
Decay_None, Decay_None,
Decay_Linear, Decay_Linear,
Decay_Quadratic, Decay_Quadratic,
@ -347,7 +344,7 @@ public:
Model(uint64_t id, const Element& element, const Document& doc, const std::string& name); Model(uint64_t id, const Element& element, const Document& doc, const std::string& name);
virtual ~Model(); virtual ~Model() = default;
fbx_simple_property(QuaternionInterpolate, int, 0) fbx_simple_property(QuaternionInterpolate, int, 0)
@ -578,31 +575,27 @@ public:
BlendMode_BlendModeCount BlendMode_BlendModeCount
}; };
const Texture* getTexture(int index=0) const const Texture* getTexture(int index=0) const {
{
return textures[index]; return textures[index];
} }
int textureCount() const { int textureCount() const {
return static_cast<int>(textures.size()); return static_cast<int>(textures.size());
} }
BlendMode GetBlendMode() const BlendMode GetBlendMode() const {
{
return blendMode; return blendMode;
} }
float Alpha() float Alpha() {
{
return alpha; return alpha;
} }
private: private:
std::vector<const Texture*> textures; std::vector<const Texture*> textures;
BlendMode blendMode; BlendMode blendMode;
float alpha; float alpha;
}; };
typedef std::fbx_unordered_map<std::string, const Texture*> TextureMap; using TextureMap = std::fbx_unordered_map<std::string, const Texture*>;
typedef std::fbx_unordered_map<std::string, const LayeredTexture*> LayeredTextureMap; using LayeredTextureMap = std::fbx_unordered_map<std::string, const LayeredTexture*>;
/** DOM class for generic FBX videos */ /** DOM class for generic FBX videos */
class Video : public Object { class Video : public Object {
@ -690,8 +683,8 @@ private:
LayeredTextureMap layeredTextures; LayeredTextureMap layeredTextures;
}; };
typedef std::vector<int64_t> KeyTimeList; using KeyTimeList = std::vector<int64_t>;
typedef std::vector<float> KeyValueList; using KeyValueList = std::vector<float>;
/** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefore) */ /** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefore) */
class AnimationCurve : public Object { class AnimationCurve : public Object {
@ -727,7 +720,7 @@ private:
}; };
// property-name -> animation curve // property-name -> animation curve
typedef std::map<std::string, const AnimationCurve*> AnimationCurveMap; using AnimationCurveMap = std::map<std::string, const AnimationCurve*>;
/** Represents a FBX animation curve (i.e. a mapping from single animation curves to nodes) */ /** Represents a FBX animation curve (i.e. a mapping from single animation curves to nodes) */
class AnimationCurveNode : public Object { class AnimationCurveNode : public Object {
@ -777,7 +770,7 @@ private:
const Document& doc; const Document& doc;
}; };
typedef std::vector<const AnimationCurveNode*> AnimationCurveNodeList; using AnimationCurveNodeList = std::vector<const AnimationCurveNode*>;
/** Represents a FBX animation layer (i.e. a list of node animations) */ /** Represents a FBX animation layer (i.e. a list of node animations) */
class AnimationLayer : public Object { class AnimationLayer : public Object {
@ -800,7 +793,7 @@ private:
const Document& doc; const Document& doc;
}; };
typedef std::vector<const AnimationLayer*> AnimationLayerList; using AnimationLayerList = std::vector<const AnimationLayer*>;
/** Represents a FBX animation stack (i.e. a list of animation layers) */ /** Represents a FBX animation stack (i.e. a list of animation layers) */
class AnimationStack : public Object { class AnimationStack : public Object {
@ -843,8 +836,8 @@ private:
std::shared_ptr<const PropertyTable> props; std::shared_ptr<const PropertyTable> props;
}; };
typedef std::vector<float> WeightArray; using WeightArray = std::vector<float>;
typedef std::vector<unsigned int> WeightIndexArray; using WeightIndexArray = std::vector<unsigned int>;
/** DOM class for BlendShapeChannel deformers */ /** DOM class for BlendShapeChannel deformers */
@ -956,7 +949,7 @@ class Connection {
public: public:
Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc); Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc);
~Connection(); ~Connection() = default;
// note: a connection ensures that the source and dest objects exist, but // note: a connection ensures that the source and dest objects exist, but
// not that they have DOM representations, so the return value of one of // not that they have DOM representations, so the return value of one of
@ -1011,10 +1004,9 @@ public:
// during their entire lifetime (Document). FBX files have // during their entire lifetime (Document). FBX files have
// up to many thousands of objects (most of which we never use), // up to many thousands of objects (most of which we never use),
// so the memory overhead for them should be kept at a minimum. // so the memory overhead for them should be kept at a minimum.
typedef std::fbx_unordered_map<uint64_t, LazyObject*> ObjectMap; using ObjectMap = std::fbx_unordered_map<uint64_t, LazyObject*> ;
typedef std::fbx_unordered_map<std::string, std::shared_ptr<const PropertyTable> > PropertyTemplateMap; using PropertyTemplateMap = std::fbx_unordered_map<std::string, std::shared_ptr<const PropertyTable> > ;
using ConnectionMap = std::fbx_unordered_multimap<uint64_t, const Connection*>;
typedef std::fbx_unordered_multimap<uint64_t, const Connection*> ConnectionMap;
/** DOM class for global document settings, a single instance per document can /** DOM class for global document settings, a single instance per document can
* be accessed via Document.Globals(). */ * be accessed via Document.Globals(). */
@ -1022,7 +1014,7 @@ class FileGlobalSettings {
public: public:
FileGlobalSettings(const Document& doc, std::shared_ptr<const PropertyTable> props); FileGlobalSettings(const Document& doc, std::shared_ptr<const PropertyTable> props);
~FileGlobalSettings(); ~FileGlobalSettings() = default;
const PropertyTable& Props() const { const PropertyTable& Props() const {
ai_assert(props.get()); ai_assert(props.get());

View File

@ -140,11 +140,32 @@ Material::~Material() {
// empty // empty
} }
aiVector2D uvTrans;
aiVector2D uvScaling;
ai_real uvRotation;
std::string type;
std::string relativeFileName;
std::string fileName;
std::string alphaSource;
std::shared_ptr<const PropertyTable> props;
unsigned int crop[4]{};
const Video* media;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name) : Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name) :
Object(id,element,name), Object(id,element,name),
uvTrans(0.0f, 0.0f),
uvScaling(1.0f,1.0f), uvScaling(1.0f,1.0f),
media(0) { uvRotation(0.0f),
type(),
relativeFileName(),
fileName(),
alphaSource(),
props(),
media(nullptr) {
const Scope& sc = GetRequiredScope(element); const Scope& sc = GetRequiredScope(element);
const Element* const Type = sc["Type"]; const Element* const Type = sc["Type"];

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2022, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -76,10 +75,6 @@ Model::Model(uint64_t id, const Element &element, const Document &doc, const std
ResolveLinks(element, doc); ResolveLinks(element, doc);
} }
// ------------------------------------------------------------------------------------------------
Model::~Model() {
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Model::ResolveLinks(const Element&, const Document &doc) { void Model::ResolveLinks(const Element&, const Document &doc) {
const char *const arr[] = { "Geometry", "Material", "NodeAttribute" }; const char *const arr[] = { "Geometry", "Material", "NodeAttribute" };