Merge pull request #4432 from assimp/kimkulling/init_fbx_texture_members_issue4429

Fix missing members and do some small refactorings.
pull/4431/head
Kim Kulling 2022-03-09 11:35:01 +01:00 committed by GitHub
commit 1bf5dd2731
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
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -68,23 +67,13 @@ namespace FBX {
using namespace Util;
// ------------------------------------------------------------------------------------------------
LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc)
: doc(doc)
, element(element)
, id(id)
, flags() {
LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc) :
doc(doc), element(element), id(id), flags() {
// empty
}
// ------------------------------------------------------------------------------------------------
LazyObject::~LazyObject()
{
// empty
}
// ------------------------------------------------------------------------------------------------
const Object* LazyObject::Get(bool dieOnError)
{
const Object* LazyObject::Get(bool dieOnError) {
if(IsBeingConstructed() || FailedToConstruct()) {
return nullptr;
}
@ -234,17 +223,8 @@ const Object* LazyObject::Get(bool dieOnError)
}
// ------------------------------------------------------------------------------------------------
Object::Object(uint64_t id, const Element& element, const std::string& name)
: element(element)
, name(name)
, id(id)
{
// empty
}
// ------------------------------------------------------------------------------------------------
Object::~Object()
{
Object::Object(uint64_t id, const Element& element, const std::string& name) :
element(element), name(name), id(id) {
// empty
}
@ -255,16 +235,8 @@ FileGlobalSettings::FileGlobalSettings(const Document &doc, std::shared_ptr<cons
}
// ------------------------------------------------------------------------------------------------
FileGlobalSettings::~FileGlobalSettings()
{
// empty
}
// ------------------------------------------------------------------------------------------------
Document::Document(const Parser& parser, const ImportSettings& settings)
: settings(settings)
, parser(parser)
{
Document::Document(const Parser& parser, const ImportSettings& settings) :
settings(settings), parser(parser) {
ASSIMP_LOG_DEBUG("Creating FBX Document");
// 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) {
delete v.second;
}
@ -348,8 +319,7 @@ void Document::ReadHeader() {
}
// ------------------------------------------------------------------------------------------------
void Document::ReadGlobalSettings()
{
void Document::ReadGlobalSettings() {
const Scope& sc = parser.GetRootScope();
const Element* const ehead = sc["GlobalSettings"];
if ( nullptr == ehead || !ehead->Compound() ) {
@ -370,8 +340,7 @@ void Document::ReadGlobalSettings()
}
// ------------------------------------------------------------------------------------------------
void Document::ReadObjects()
{
void Document::ReadObjects() {
// read ID objects from "Objects" section
const Scope& sc = parser.GetRootScope();
const Element* const eobjects = sc["Objects"];
@ -418,8 +387,7 @@ void Document::ReadObjects()
}
// ------------------------------------------------------------------------------------------------
void Document::ReadPropertyTemplates()
{
void Document::ReadPropertyTemplates() {
const Scope& sc = parser.GetRootScope();
// read property templates from "Definitions" section
const Element* const edefs = sc["Definitions"];
@ -476,8 +444,7 @@ void Document::ReadPropertyTemplates()
}
// ------------------------------------------------------------------------------------------------
void Document::ReadConnections()
{
void Document::ReadConnections() {
const Scope& sc = parser.GetRootScope();
// read property templates from "Definitions" section
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()) {
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);
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;
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
@ -575,9 +539,7 @@ std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, co
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src,
const ConnectionMap& conns,
const char* const* classnames,
size_t count) const
{
size_t count) const {
ai_assert(classnames);
ai_assert( count != 0 );
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());
}
// ------------------------------------------------------------------------------------------------
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};
return GetConnectionsBySourceSequenced(src, arr,1);
}
// ------------------------------------------------------------------------------------------------
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);
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
const char* classname) const
{
const char* classname) const {
const char* arr[] = {classname};
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());
}
// ------------------------------------------------------------------------------------------------
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);
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop,
const Document& doc)
: insertionOrder(insertionOrder)
, prop(prop)
, src(src)
, dest(dest)
, doc(doc)
{
const Document& doc) :
insertionOrder(insertionOrder), prop(prop), src(src), dest(dest), doc(doc) {
ai_assert(doc.Objects().find(src) != doc.Objects().end());
// dest may be 0 (root node)
ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end());
}
// ------------------------------------------------------------------------------------------------
Connection::~Connection()
{
// empty
}
// ------------------------------------------------------------------------------------------------
LazyObject& Connection::LazySourceObject() const
{
LazyObject& Connection::LazySourceObject() const {
LazyObject* const lazy = doc.GetObject(src);
ai_assert(lazy);
return *lazy;
}
// ------------------------------------------------------------------------------------------------
LazyObject& Connection::LazyDestinationObject() const
{
LazyObject& Connection::LazyDestinationObject() const {
LazyObject* const lazy = doc.GetObject(dest);
ai_assert(lazy);
return *lazy;
}
// ------------------------------------------------------------------------------------------------
const Object* Connection::SourceObject() const
{
const Object* Connection::SourceObject() const {
LazyObject* const lazy = doc.GetObject(src);
ai_assert(lazy);
return lazy->Get();
}
// ------------------------------------------------------------------------------------------------
const Object* Connection::DestinationObject() const
{
const Object* Connection::DestinationObject() const {
LazyObject* const lazy = doc.GetObject(dest);
ai_assert(lazy);
return lazy->Get();
@ -719,4 +658,4 @@ const Object* Connection::DestinationObject() const
} // !FBX
} // !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
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -89,7 +88,7 @@ class LazyObject {
public:
LazyObject(uint64_t id, const Element& element, const Document& doc);
~LazyObject();
~LazyObject() = default;
const Object* Get(bool dieOnError = false);
@ -139,7 +138,7 @@ class Object {
public:
Object(uint64_t id, const Element& element, const std::string& name);
virtual ~Object();
virtual ~Object() = default;
const Element& SourceElement() const {
return element;
@ -267,8 +266,7 @@ public:
Light(uint64_t id, const Element& element, const Document& doc, const std::string& name);
virtual ~Light();
enum Type
{
enum Type {
Type_Point,
Type_Directional,
Type_Spot,
@ -278,8 +276,7 @@ public:
Type_MAX // end-of-enum sentinel
};
enum Decay
{
enum Decay {
Decay_None,
Decay_Linear,
Decay_Quadratic,
@ -347,7 +344,7 @@ public:
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)
@ -578,31 +575,27 @@ public:
BlendMode_BlendModeCount
};
const Texture* getTexture(int index=0) const
{
const Texture* getTexture(int index=0) const {
return textures[index];
}
int textureCount() const {
return static_cast<int>(textures.size());
}
BlendMode GetBlendMode() const
{
BlendMode GetBlendMode() const {
return blendMode;
}
float Alpha()
{
float Alpha() {
return alpha;
}
private:
std::vector<const Texture*> textures;
BlendMode blendMode;
float alpha;
};
typedef std::fbx_unordered_map<std::string, const Texture*> TextureMap;
typedef std::fbx_unordered_map<std::string, const LayeredTexture*> LayeredTextureMap;
using TextureMap = std::fbx_unordered_map<std::string, const Texture*>;
using LayeredTextureMap = std::fbx_unordered_map<std::string, const LayeredTexture*>;
/** DOM class for generic FBX videos */
class Video : public Object {
@ -690,8 +683,8 @@ private:
LayeredTextureMap layeredTextures;
};
typedef std::vector<int64_t> KeyTimeList;
typedef std::vector<float> KeyValueList;
using KeyTimeList = std::vector<int64_t>;
using KeyValueList = std::vector<float>;
/** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefore) */
class AnimationCurve : public Object {
@ -727,7 +720,7 @@ private:
};
// 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) */
class AnimationCurveNode : public Object {
@ -777,7 +770,7 @@ private:
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) */
class AnimationLayer : public Object {
@ -800,7 +793,7 @@ private:
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) */
class AnimationStack : public Object {
@ -843,8 +836,8 @@ private:
std::shared_ptr<const PropertyTable> props;
};
typedef std::vector<float> WeightArray;
typedef std::vector<unsigned int> WeightIndexArray;
using WeightArray = std::vector<float>;
using WeightIndexArray = std::vector<unsigned int>;
/** DOM class for BlendShapeChannel deformers */
@ -956,7 +949,7 @@ class Connection {
public:
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
// 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
// up to many thousands of objects (most of which we never use),
// so the memory overhead for them should be kept at a minimum.
typedef std::fbx_unordered_map<uint64_t, LazyObject*> ObjectMap;
typedef std::fbx_unordered_map<std::string, std::shared_ptr<const PropertyTable> > PropertyTemplateMap;
typedef std::fbx_unordered_multimap<uint64_t, const Connection*> ConnectionMap;
using ObjectMap = std::fbx_unordered_map<uint64_t, LazyObject*> ;
using PropertyTemplateMap = std::fbx_unordered_map<std::string, std::shared_ptr<const PropertyTable> > ;
using ConnectionMap = std::fbx_unordered_multimap<uint64_t, const Connection*>;
/** DOM class for global document settings, a single instance per document can
* be accessed via Document.Globals(). */
@ -1022,7 +1014,7 @@ class FileGlobalSettings {
public:
FileGlobalSettings(const Document& doc, std::shared_ptr<const PropertyTable> props);
~FileGlobalSettings();
~FileGlobalSettings() = default;
const PropertyTable& Props() const {
ai_assert(props.get());

View File

@ -140,11 +140,32 @@ Material::~Material() {
// 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) :
Object(id,element,name),
uvTrans(0.0f, 0.0f),
uvScaling(1.0f,1.0f),
media(0) {
uvRotation(0.0f),
type(),
relativeFileName(),
fileName(),
alphaSource(),
props(),
media(nullptr) {
const Scope& sc = GetRequiredScope(element);
const Element* const Type = sc["Type"];

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2022, assimp team
All rights reserved.
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);
}
// ------------------------------------------------------------------------------------------------
Model::~Model() {
}
// ------------------------------------------------------------------------------------------------
void Model::ResolveLinks(const Element&, const Document &doc) {
const char *const arr[] = { "Geometry", "Material", "NodeAttribute" };