- fbx: read property templates. Fix some memory leaks.
parent
00f249b8dd
commit
21713841d3
|
@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "FBXImporter.h"
|
||||
#include "FBXImportSettings.h"
|
||||
#include "FBXDocumentUtil.h"
|
||||
#include "FBXProperties.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
|
@ -419,15 +420,34 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
|
|||
: parser(parser)
|
||||
, settings(settings)
|
||||
{
|
||||
ReadPropertyTemplates();
|
||||
ReadObjects();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Document::~Document()
|
||||
{
|
||||
BOOST_FOREACH(ObjectMap::value_type& v, objects) {
|
||||
delete v.second;
|
||||
}
|
||||
|
||||
BOOST_FOREACH(PropertyTemplateMap::value_type& v, templates) {
|
||||
delete v.second;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Document::ReadObjects()
|
||||
{
|
||||
// read ID objects from "Objects" section
|
||||
const Scope& sc = parser.GetRootScope();
|
||||
const Element* const eobjects = sc["Objects"];
|
||||
if(!eobjects || !eobjects->Compound()) {
|
||||
DOMError("no Objects dictionary found");
|
||||
}
|
||||
|
||||
const Scope* const sobjects = eobjects->Compound();
|
||||
BOOST_FOREACH(const ElementMap::value_type& el, sobjects->Elements()) {
|
||||
const Scope& sobjects = *eobjects->Compound();
|
||||
BOOST_FOREACH(const ElementMap::value_type& el, sobjects.Elements()) {
|
||||
|
||||
// extract ID
|
||||
const TokenList& tok = el.second->Tokens();
|
||||
|
@ -450,9 +470,58 @@ Document::Document(const Parser& parser, const ImportSettings& settings)
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Document::~Document()
|
||||
void Document::ReadPropertyTemplates()
|
||||
{
|
||||
|
||||
const Scope& sc = parser.GetRootScope();
|
||||
// read property templates from "Definitions" section
|
||||
const Element* const edefs = sc["Definitions"];
|
||||
if(!edefs || !edefs->Compound()) {
|
||||
DOMWarning("no Definitions dictionary found");
|
||||
return;
|
||||
}
|
||||
|
||||
const Scope& sdefs = *edefs->Compound();
|
||||
const ElementCollection otypes = sdefs.GetCollection("ObjectType");
|
||||
for(ElementMap::const_iterator it = otypes.first; it != otypes.second; ++it) {
|
||||
const Element& el = *(*it).second;
|
||||
const Scope* sc = el.Compound();
|
||||
if(!sc) {
|
||||
DOMWarning("expected nested scope in ObjectType, ignoring",&el);
|
||||
continue;
|
||||
}
|
||||
|
||||
const TokenList& tok = el.Tokens();
|
||||
if(tok.empty()) {
|
||||
DOMWarning("expected name for ObjectType element, ignoring",&el);
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string& oname = ParseTokenAsString(*tok[0]);
|
||||
|
||||
const ElementCollection templs = sc->GetCollection("PropertyTemplate");
|
||||
for(ElementMap::const_iterator it = templs.first; it != templs.second; ++it) {
|
||||
const Element& el = *(*it).second;
|
||||
const Scope* sc = el.Compound();
|
||||
if(!sc) {
|
||||
DOMWarning("expected nested scope in PropertyTemplate, ignoring",&el);
|
||||
continue;
|
||||
}
|
||||
|
||||
const TokenList& tok = el.Tokens();
|
||||
if(tok.empty()) {
|
||||
DOMWarning("expected name for PropertyTemplate element, ignoring",&el);
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string& pname = ParseTokenAsString(*tok[0]);
|
||||
|
||||
const Element* Properties70 = (*sc)["Properties70"];
|
||||
if(Properties70) {
|
||||
PropertyTable* const props = new PropertyTable(*Properties70,NULL);
|
||||
templates[oname+"."+pname] = props;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // !FBX
|
||||
|
|
|
@ -55,6 +55,8 @@ namespace FBX {
|
|||
class Object;
|
||||
struct ImportSettings;
|
||||
|
||||
class PropertyTable;
|
||||
|
||||
|
||||
/** Represents a delay-parsed FBX objects. Many objects in the scene
|
||||
* are not needed by assimp, so it makes no sense to parse them
|
||||
|
@ -227,7 +229,7 @@ private:
|
|||
// 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::map<uint64_t, LazyObject*> ObjectMap;
|
||||
|
||||
typedef std::fbx_unordered_map<std::string, PropertyTable*> PropertyTemplateMap;
|
||||
|
||||
/** DOM root for a FBX file */
|
||||
class Document
|
||||
|
@ -239,6 +241,10 @@ public:
|
|||
|
||||
public:
|
||||
|
||||
const PropertyTemplateMap& Templates() const {
|
||||
return templates;
|
||||
}
|
||||
|
||||
const ObjectMap& Objects() const {
|
||||
return objects;
|
||||
}
|
||||
|
@ -247,12 +253,19 @@ public:
|
|||
return settings;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void ReadObjects();
|
||||
void ReadPropertyTemplates();
|
||||
|
||||
private:
|
||||
|
||||
const ImportSettings& settings;
|
||||
|
||||
ObjectMap objects;
|
||||
const Parser& parser;
|
||||
|
||||
PropertyTemplateMap templates;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -144,6 +144,9 @@ PropertyTable::PropertyTable(const Element& element, PropertyTable* templateProp
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
PropertyTable::~PropertyTable()
|
||||
{
|
||||
BOOST_FOREACH(PropertyMap::value_type& v, props) {
|
||||
delete v.second;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue