- fbx: add support for reading GlobalSettings.

pull/14/head
Alexander Gessler 2012-08-25 16:15:13 +02:00
parent 5ea9de5d3e
commit d881bb9cdc
2 changed files with 135 additions and 7 deletions

View File

@ -215,6 +215,22 @@ Object::~Object()
}
// ------------------------------------------------------------------------------------------------
FileGlobalSettings::FileGlobalSettings(const Document& doc, boost::shared_ptr<const PropertyTable> props)
: doc(doc)
, props(props)
{
}
// ------------------------------------------------------------------------------------------------
FileGlobalSettings::~FileGlobalSettings()
{
}
// ------------------------------------------------------------------------------------------------
Document::Document(const Parser& parser, const ImportSettings& settings)
: settings(settings)
@ -228,6 +244,8 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
ReadHeader();
ReadPropertyTemplates();
ReadGlobalSettings();
// this order is important, connections need parsed objects to check
// whether connections are ok or not. Objects may not be evaluated yet,
// though, since this may require valid connections.
@ -283,6 +301,25 @@ void Document::ReadHeader()
}
}
// ------------------------------------------------------------------------------------------------
void Document::ReadGlobalSettings()
{
const Scope& sc = parser.GetRootScope();
const Element* const ehead = sc["GlobalSettings"];
if(!ehead || !ehead->Compound()) {
DOMError("no GlobalSettings dictionary found");
}
const Element* Properties70 = (*ehead->Compound())["Properties70"];
if(!Properties70) {
DOMError("GlobalSettings dictionary contains no property table");
}
globals.reset(new FileGlobalSettings(*this, boost::make_shared<const PropertyTable>(
*Properties70,boost::shared_ptr<const PropertyTable>(static_cast<const PropertyTable*>(NULL))
)));
}
// ------------------------------------------------------------------------------------------------
void Document::ReadObjects()
@ -456,7 +493,8 @@ LazyObject* Document::GetObject(uint64_t id) const
#define 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;
@ -475,7 +513,11 @@ 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
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src,
const ConnectionMap& conns,
const char* const* classnames,
size_t count) const
{
ai_assert(classnames);
ai_assert(count != 0 && count <= MAX_CLASSNAMES);
@ -530,7 +572,8 @@ std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t dest, const char* classname) const
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t dest,
const char* classname) const
{
const char* arr[] = {classname};
return GetConnectionsBySourceSequenced(dest, arr,1);
@ -539,14 +582,16 @@ std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source, const char* const* classnames, size_t count) const
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source,
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
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
const char* classname) const
{
const char* arr[] = {classname};
return GetConnectionsByDestinationSequenced(dest, arr,1);
@ -561,14 +606,18 @@ std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(ui
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest, const char* const* classnames, size_t count) const
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
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)
Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop,
const Document& doc)
: insertionOrder(insertionOrder)
, prop(prop)
, src(src)

View File

@ -1099,6 +1099,77 @@ public:
typedef std::multimap<uint64_t, const Connection*> ConnectionMap;
/** DOM class for global document settings, a single instance per document can
* be accessed via Document.Globals(). */
class FileGlobalSettings
{
public:
FileGlobalSettings(const Document& doc, boost::shared_ptr<const PropertyTable> props);
~FileGlobalSettings();
public:
const PropertyTable& Props() const {
ai_assert(props.get());
return *props.get();
}
const Document& GetDocument() const {
return doc;
}
fbx_simple_property(UpAxis, int, 1);
fbx_simple_property(UpAxisSign, int, 1);
fbx_simple_property(FrontAxis, int, 2);
fbx_simple_property(FrontAxisSign, int, 1);
fbx_simple_property(CoordAxis, int, 0);
fbx_simple_property(CoordAxisSign, int, 1);
fbx_simple_property(OriginalUpAxis, int, 0);
fbx_simple_property(OriginalUpAxisSign, int, 1);
fbx_simple_property(UnitScaleFactor, double, 1);
fbx_simple_property(OriginalUnitScaleFactor, double, 1);
fbx_simple_property(AmbientColor, aiVector3D, aiVector3D(0,0,0));
fbx_simple_property(DefaultCamera, std::string, "");
enum FrameRate {
FrameRate_DEFAULT = 0,
FrameRate_120 = 1,
FrameRate_100 = 2,
FrameRate_60 = 3,
FrameRate_50 = 4,
FrameRate_48 = 5,
FrameRate_30 = 6,
FrameRate_30_DROP = 7,
FrameRate_NTSC_DROP_FRAME = 8,
FrameRate_NTSC_FULL_FRAME = 9,
FrameRate_PAL = 10,
FrameRate_CINEMA = 11,
FrameRate_1000 = 12,
FrameRate_CINEMA_ND = 13,
FrameRate_CUSTOM = 14,
FrameRate_TIME_MODE_COUNT = 15,
FrameRate_MAX// end-of-enum sentinel
};
fbx_simple_enum_property(TimeMode, FrameRate, FrameRate_DEFAULT);
fbx_simple_property(TimeSpanStart, uint64_t, 0L);
fbx_simple_property(TimeSpanStop, uint64_t, 0L);
fbx_simple_property(CustomFrameRate, float, -1.0f);
private:
boost::shared_ptr<const PropertyTable> props;
const Document& doc;
};
/** DOM root for a FBX file */
class Document
{
@ -1128,6 +1199,11 @@ public:
return creationTimeStamp;
}
const FileGlobalSettings& GlobalSettings() const {
ai_assert(globals.get());
return *globals.get();
}
const PropertyTemplateMap& Templates() const {
return templates;
}
@ -1182,6 +1258,7 @@ private:
void ReadObjects();
void ReadPropertyTemplates();
void ReadConnections();
void ReadGlobalSettings();
private:
@ -1200,6 +1277,8 @@ private:
std::vector<uint64_t> animationStacks;
mutable std::vector<const AnimationStack*> animationStacksResolved;
boost::scoped_ptr<FileGlobalSettings> globals;
};
}