2012-06-26 16:31:19 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2012, assimp team
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
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.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
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
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file FBXDocument.cpp
|
|
|
|
* @brief Implementation of the FBX DOM classes
|
|
|
|
*/
|
|
|
|
#include "AssimpPCH.h"
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
|
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
#include "FBXParser.h"
|
|
|
|
#include "FBXDocument.h"
|
|
|
|
#include "FBXUtil.h"
|
2012-06-26 19:35:16 +00:00
|
|
|
#include "FBXImporter.h"
|
2012-06-28 17:16:14 +00:00
|
|
|
#include "FBXImportSettings.h"
|
2012-07-01 12:38:14 +00:00
|
|
|
#include "FBXDocumentUtil.h"
|
2012-07-02 14:51:19 +00:00
|
|
|
#include "FBXProperties.h"
|
2012-06-26 16:31:19 +00:00
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace FBX {
|
2012-07-01 12:38:14 +00:00
|
|
|
namespace Util {
|
2012-06-27 19:55:28 +00:00
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// signal DOM construction error, this is always unrecoverable. Throws DeadlyImportError.
|
|
|
|
void DOMError(const std::string& message, const Token& token)
|
|
|
|
{
|
|
|
|
throw DeadlyImportError(Util::AddTokenText("FBX-DOM",message,&token));
|
|
|
|
}
|
2012-06-27 19:55:28 +00:00
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-01 12:38:14 +00:00
|
|
|
void DOMError(const std::string& message, const Element* element /*= NULL*/)
|
2012-06-27 22:35:40 +00:00
|
|
|
{
|
|
|
|
if(element) {
|
|
|
|
DOMError(message,element->KeyToken());
|
2012-06-27 19:55:28 +00:00
|
|
|
}
|
2012-06-27 22:35:40 +00:00
|
|
|
throw DeadlyImportError("FBX-DOM " + message);
|
|
|
|
}
|
2012-06-27 19:55:28 +00:00
|
|
|
|
|
|
|
|
2012-07-02 13:57:51 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// print warning, do return
|
|
|
|
void DOMWarning(const std::string& message, const Token& token)
|
|
|
|
{
|
|
|
|
if(DefaultLogger::get()) {
|
|
|
|
DefaultLogger::get()->warn(Util::AddTokenText("FBX-DOM",message,&token));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void DOMWarning(const std::string& message, const Element* element /*= NULL*/)
|
|
|
|
{
|
|
|
|
if(element) {
|
|
|
|
DOMWarning(message,element->KeyToken());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(DefaultLogger::get()) {
|
|
|
|
DefaultLogger::get()->warn("FBX-DOM: " + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// extract required compound scope
|
|
|
|
const Scope& GetRequiredScope(const Element& el)
|
|
|
|
{
|
|
|
|
const Scope* const s = el.Compound();
|
|
|
|
if(!s) {
|
|
|
|
DOMError("expected compound scope",&el);
|
2012-06-26 18:05:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
return *s;
|
|
|
|
}
|
2012-06-26 18:05:24 +00:00
|
|
|
|
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// get token at a particular index
|
|
|
|
const Token& GetRequiredToken(const Element& el, unsigned int index)
|
|
|
|
{
|
|
|
|
const TokenList& t = el.Tokens();
|
2012-06-27 23:49:52 +00:00
|
|
|
if(index >= t.size()) {
|
2012-06-27 22:35:40 +00:00
|
|
|
DOMError(Formatter::format( "missing token at index " ) << index,&el);
|
2012-06-26 18:05:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
return *t[index];
|
2012-06-26 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-27 19:55:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// wrapper around ParseTokenAsID() with DOMError handling
|
2012-06-27 21:02:00 +00:00
|
|
|
uint64_t ParseTokenAsID(const Token& t)
|
2012-06-27 19:55:28 +00:00
|
|
|
{
|
|
|
|
const char* err;
|
|
|
|
const uint64_t i = ParseTokenAsID(t,err);
|
|
|
|
if(err) {
|
2012-06-27 21:02:00 +00:00
|
|
|
DOMError(err,t);
|
2012-06-27 19:55:28 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// wrapper around ParseTokenAsDim() with DOMError handling
|
2012-06-27 21:02:00 +00:00
|
|
|
size_t ParseTokenAsDim(const Token& t)
|
2012-06-27 19:55:28 +00:00
|
|
|
{
|
|
|
|
const char* err;
|
|
|
|
const size_t i = ParseTokenAsDim(t,err);
|
|
|
|
if(err) {
|
2012-06-27 21:02:00 +00:00
|
|
|
DOMError(err,t);
|
2012-06-27 19:55:28 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// wrapper around ParseTokenAsFloat() with DOMError handling
|
2012-06-27 21:02:00 +00:00
|
|
|
float ParseTokenAsFloat(const Token& t)
|
2012-06-27 19:55:28 +00:00
|
|
|
{
|
|
|
|
const char* err;
|
|
|
|
const float i = ParseTokenAsFloat(t,err);
|
|
|
|
if(err) {
|
2012-06-27 21:02:00 +00:00
|
|
|
DOMError(err,t);
|
2012-06-27 19:55:28 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// wrapper around ParseTokenAsInt() with DOMError handling
|
2012-06-27 21:02:00 +00:00
|
|
|
int ParseTokenAsInt(const Token& t)
|
2012-06-27 19:55:28 +00:00
|
|
|
{
|
|
|
|
const char* err;
|
|
|
|
const int i = ParseTokenAsInt(t,err);
|
|
|
|
if(err) {
|
2012-06-27 21:02:00 +00:00
|
|
|
DOMError(err,t);
|
2012-06-27 19:55:28 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// wrapper around ParseTokenAsString() with DOMError handling
|
2012-06-27 21:02:00 +00:00
|
|
|
std::string ParseTokenAsString(const Token& t)
|
2012-06-27 19:55:28 +00:00
|
|
|
{
|
|
|
|
const char* err;
|
|
|
|
const std::string& i = ParseTokenAsString(t,err);
|
|
|
|
if(err) {
|
2012-06-27 21:02:00 +00:00
|
|
|
DOMError(err,t);
|
2012-06-27 19:55:28 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// extract a required element from a scope, abort if the element cannot be found
|
2012-07-01 12:38:14 +00:00
|
|
|
const Element& GetRequiredElement(const Scope& sc, const std::string& index, const Element* element /*= NULL*/)
|
2012-06-27 22:35:40 +00:00
|
|
|
{
|
|
|
|
const Element* el = sc[index];
|
|
|
|
if(!el) {
|
|
|
|
DOMError("did not find required element \"" + index + "\"",element);
|
|
|
|
}
|
|
|
|
return *el;
|
|
|
|
}
|
|
|
|
|
2012-07-21 19:28:02 +00:00
|
|
|
// XXX: tacke code duplication in the various ReadVectorDataArray() overloads below.
|
|
|
|
// could use a type traits based solution.
|
2012-06-27 22:35:40 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of float3 tuples
|
|
|
|
void ReadVectorDataArray(std::vector<aiVector3D>& out, const Element& el)
|
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// may throw bad_alloc if the input is rubbish, but this need
|
|
|
|
// not to be prevented - importing would fail but we wouldn't
|
|
|
|
// crash since assimp handles this case properly.
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
if (a.Tokens().size() % 3 != 0) {
|
|
|
|
DOMError("number of floats is not a multiple of three (3)",&el);
|
|
|
|
}
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
aiVector3D v;
|
|
|
|
v.x = ParseTokenAsFloat(**it++);
|
|
|
|
v.y = ParseTokenAsFloat(**it++);
|
|
|
|
v.z = ParseTokenAsFloat(**it++);
|
|
|
|
|
|
|
|
out.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-28 14:51:55 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of color4 tuples
|
|
|
|
void ReadVectorDataArray(std::vector<aiColor4D>& out, const Element& el)
|
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// see notes in ReadVectorDataArray() above
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
if (a.Tokens().size() % 4 != 0) {
|
|
|
|
DOMError("number of floats is not a multiple of four (4)",&el);
|
|
|
|
}
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
aiColor4D v;
|
|
|
|
v.r = ParseTokenAsFloat(**it++);
|
|
|
|
v.g = ParseTokenAsFloat(**it++);
|
|
|
|
v.b = ParseTokenAsFloat(**it++);
|
|
|
|
v.a = ParseTokenAsFloat(**it++);
|
|
|
|
|
|
|
|
out.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-27 22:35:40 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of float2 tuples
|
|
|
|
void ReadVectorDataArray(std::vector<aiVector2D>& out, const Element& el)
|
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// see notes in ReadVectorDataArray() above
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
if (a.Tokens().size() % 2 != 0) {
|
|
|
|
DOMError("number of floats is not a multiple of two (2)",&el);
|
|
|
|
}
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
aiVector2D v;
|
|
|
|
v.x = ParseTokenAsFloat(**it++);
|
|
|
|
v.y = ParseTokenAsFloat(**it++);
|
|
|
|
|
|
|
|
out.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of ints
|
2012-06-28 15:13:13 +00:00
|
|
|
void ReadVectorDataArray(std::vector<int>& out, const Element& el)
|
2012-06-27 22:35:40 +00:00
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// see notes in ReadVectorDataArray()
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
const int ival = ParseTokenAsInt(**it++);
|
|
|
|
out.push_back(ival);
|
|
|
|
}
|
|
|
|
}
|
2012-06-28 15:13:13 +00:00
|
|
|
|
|
|
|
|
2012-07-20 22:45:37 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of floats
|
|
|
|
void ReadVectorDataArray(std::vector<float>& out, const Element& el)
|
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// see notes in ReadVectorDataArray()
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
const float ival = ParseTokenAsFloat(**it++);
|
|
|
|
out.push_back(ival);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-28 15:13:13 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of uints
|
|
|
|
void ReadVectorDataArray(std::vector<unsigned int>& out, const Element& el)
|
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// see notes in ReadVectorDataArray()
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
const int ival = ParseTokenAsInt(**it++);
|
|
|
|
if(ival < 0) {
|
|
|
|
DOMError("encountered negative integer index");
|
|
|
|
}
|
|
|
|
out.push_back(static_cast<unsigned int>(ival));
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 12:40:45 +00:00
|
|
|
|
|
|
|
|
2012-07-21 19:28:02 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// read an array of uint64_ts
|
|
|
|
void ReadVectorDataArray(std::vector<uint64_t>& out, const Element& el)
|
|
|
|
{
|
|
|
|
out.clear();
|
|
|
|
const TokenList& tok = el.Tokens();
|
|
|
|
const size_t dim = ParseTokenAsDim(*tok[0]);
|
|
|
|
|
|
|
|
// see notes in ReadVectorDataArray()
|
|
|
|
out.reserve(dim);
|
|
|
|
|
|
|
|
const Scope& scope = GetRequiredScope(el);
|
|
|
|
const Element& a = GetRequiredElement(scope,"a",&el);
|
|
|
|
|
|
|
|
for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end; ) {
|
|
|
|
const uint64_t ival = ParseTokenAsID(**it++);
|
|
|
|
|
|
|
|
out.push_back(ival);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 12:40:45 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// fetch a property table and the corresponding property template
|
|
|
|
boost::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
|
|
|
|
const std::string& templateName,
|
|
|
|
const Element &element,
|
|
|
|
const Scope& sc)
|
|
|
|
{
|
|
|
|
const Element* const Properties70 = sc["Properties70"];
|
2012-07-04 15:06:55 +00:00
|
|
|
boost::shared_ptr<const PropertyTable> templateProps = boost::shared_ptr<const PropertyTable>(
|
|
|
|
static_cast<const PropertyTable*>(NULL));
|
|
|
|
|
2012-07-03 12:40:45 +00:00
|
|
|
if(templateName.length()) {
|
|
|
|
PropertyTemplateMap::const_iterator it = doc.Templates().find(templateName);
|
|
|
|
if(it != doc.Templates().end()) {
|
|
|
|
templateProps = (*it).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!Properties70) {
|
|
|
|
DOMWarning("material property table (Properties70) not found",&element);
|
|
|
|
if(templateProps) {
|
|
|
|
return templateProps;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return boost::make_shared<const PropertyTable>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return boost::make_shared<const PropertyTable>(*Properties70,templateProps);
|
|
|
|
}
|
2012-07-01 12:38:14 +00:00
|
|
|
} // !Util
|
2012-06-27 22:35:40 +00:00
|
|
|
|
2012-07-01 12:38:14 +00:00
|
|
|
using namespace Util;
|
2012-06-27 22:35:40 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-03 17:36:38 +00:00
|
|
|
LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc)
|
2012-07-02 15:37:00 +00:00
|
|
|
: doc(doc)
|
2012-06-28 17:16:14 +00:00
|
|
|
, element(element)
|
2012-07-03 17:36:38 +00:00
|
|
|
, id(id)
|
2012-07-21 18:02:00 +00:00
|
|
|
, flags()
|
2012-06-26 16:31:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
LazyObject::~LazyObject()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-21 18:02:00 +00:00
|
|
|
const Object* LazyObject::Get(bool dieOnError)
|
2012-06-26 16:31:19 +00:00
|
|
|
{
|
2012-07-21 18:02:00 +00:00
|
|
|
if(IsBeingConstructed() || FailedToConstruct()) {
|
2012-07-21 15:13:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
if (object.get()) {
|
|
|
|
return object.get();
|
|
|
|
}
|
|
|
|
|
2012-06-26 17:19:13 +00:00
|
|
|
const Token& key = element.KeyToken();
|
|
|
|
const TokenList& tokens = element.Tokens();
|
|
|
|
|
|
|
|
if(tokens.size() < 3) {
|
|
|
|
DOMError("expected at least 3 tokens: id, name and class tag",&element);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* err;
|
|
|
|
const std::string name = ParseTokenAsString(*tokens[1],err);
|
|
|
|
if (err) {
|
|
|
|
DOMError(err,&element);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string classtag = ParseTokenAsString(*tokens[2],err);
|
|
|
|
if (err) {
|
|
|
|
DOMError(err,&element);
|
|
|
|
}
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
// prevent recursive calls
|
2012-07-21 18:02:00 +00:00
|
|
|
flags |= BEING_CONSTRUCTED;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// this needs to be relatively fast since it happens a lot,
|
|
|
|
// so avoid constructing strings all the time.
|
|
|
|
const char* obtype = key.begin();
|
|
|
|
const size_t length = static_cast<size_t>(key.end()-key.begin());
|
|
|
|
if (!strncmp(obtype,"Geometry",length)) {
|
|
|
|
if (!strcmp(classtag.c_str(),"Mesh")) {
|
|
|
|
object.reset(new MeshGeometry(id,element,name,doc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strncmp(obtype,"Model",length)) {
|
|
|
|
object.reset(new Model(id,element,doc,name));
|
|
|
|
}
|
|
|
|
else if (!strncmp(obtype,"Material",length)) {
|
|
|
|
object.reset(new Material(id,element,doc,name));
|
|
|
|
}
|
|
|
|
else if (!strncmp(obtype,"Texture",length)) {
|
|
|
|
object.reset(new Texture(id,element,doc,name));
|
|
|
|
}
|
|
|
|
else if (!strncmp(obtype,"AnimationStack",length)) {
|
|
|
|
object.reset(new AnimationStack(id,element,name,doc));
|
|
|
|
}
|
|
|
|
else if (!strncmp(obtype,"AnimationLayer",length)) {
|
|
|
|
object.reset(new AnimationLayer(id,element,name,doc));
|
|
|
|
}
|
|
|
|
// note: order matters for these two
|
|
|
|
else if (!strncmp(obtype,"AnimationCurve",length)) {
|
|
|
|
object.reset(new AnimationCurve(id,element,name,doc));
|
2012-06-26 17:19:13 +00:00
|
|
|
}
|
2012-07-21 19:28:02 +00:00
|
|
|
else if (!strncmp(obtype,"AnimationCurveNode",length)) {
|
|
|
|
object.reset(new AnimationCurveNode(id,element,name,doc));
|
|
|
|
}
|
2012-06-26 17:19:13 +00:00
|
|
|
}
|
2012-07-21 18:02:00 +00:00
|
|
|
catch(std::exception& ex) {
|
|
|
|
flags &= ~BEING_CONSTRUCTED;
|
|
|
|
flags |= FAILED_TO_CONSTRUCT;
|
|
|
|
|
|
|
|
//if(dieOnError) {
|
|
|
|
throw;
|
|
|
|
//}
|
|
|
|
|
|
|
|
// note: the error message is already formatted, so raw logging is ok
|
|
|
|
if(!DefaultLogger::isNullLogger()) {
|
|
|
|
DefaultLogger::get()->error(ex.what());
|
|
|
|
}
|
|
|
|
return NULL;
|
2012-07-20 22:45:37 +00:00
|
|
|
}
|
2012-06-26 17:19:13 +00:00
|
|
|
|
|
|
|
if (!object.get()) {
|
2012-06-27 23:49:52 +00:00
|
|
|
//DOMError("failed to convert element to DOM object, class: " + classtag + ", name: " + name,&element);
|
2012-06-26 17:19:13 +00:00
|
|
|
}
|
|
|
|
|
2012-07-21 18:02:00 +00:00
|
|
|
flags &= ~BEING_CONSTRUCTED;
|
2012-06-26 17:19:13 +00:00
|
|
|
return object.get();
|
2012-06-26 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-03 17:36:38 +00:00
|
|
|
Object::Object(uint64_t id, const Element& element, const std::string& name)
|
2012-06-26 16:31:19 +00:00
|
|
|
: element(element)
|
2012-06-26 17:19:13 +00:00
|
|
|
, name(name)
|
2012-07-03 17:36:38 +00:00
|
|
|
, id(id)
|
2012-06-26 16:31:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object::~Object()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-03 17:36:38 +00:00
|
|
|
Geometry::Geometry(uint64_t id, const Element& element, const std::string& name)
|
|
|
|
: Object(id, element,name)
|
2012-06-26 16:31:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Geometry::~Geometry()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-28 00:06:24 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-06-28 17:16:14 +00:00
|
|
|
Document::Document(const Parser& parser, const ImportSettings& settings)
|
2012-07-08 01:28:14 +00:00
|
|
|
: settings(settings)
|
|
|
|
, parser(parser)
|
2012-06-26 16:31:19 +00:00
|
|
|
{
|
2012-07-06 20:46:19 +00:00
|
|
|
// cannot use array default initialization syntax because vc8 fails on it
|
|
|
|
for (unsigned int i = 0; i < 7; ++i) {
|
|
|
|
creationTimeStamp[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadHeader();
|
2012-07-02 14:51:19 +00:00
|
|
|
ReadPropertyTemplates();
|
2012-07-03 23:45:15 +00:00
|
|
|
|
|
|
|
// 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.
|
2012-07-02 14:51:19 +00:00
|
|
|
ReadObjects();
|
2012-07-03 14:50:58 +00:00
|
|
|
ReadConnections();
|
2012-07-02 14:51:19 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Document::~Document()
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(ObjectMap::value_type& v, objects) {
|
|
|
|
delete v.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-07-06 20:46:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Document::ReadHeader()
|
|
|
|
{
|
|
|
|
// read ID objects from "Objects" section
|
|
|
|
const Scope& sc = parser.GetRootScope();
|
|
|
|
const Element* const ehead = sc["FBXHeaderExtension"];
|
|
|
|
if(!ehead || !ehead->Compound()) {
|
|
|
|
DOMError("no FBXHeaderExtension dictionary found");
|
|
|
|
}
|
|
|
|
|
|
|
|
const Scope& shead = *ehead->Compound();
|
|
|
|
fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
|
|
|
|
|
|
|
|
const Element* const ecreator = shead["Creator"];
|
|
|
|
if(ecreator) {
|
|
|
|
creator = ParseTokenAsString(GetRequiredToken(*ecreator,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
const Element* const etimestamp = shead["CreationTimeStamp"];
|
|
|
|
if(etimestamp && etimestamp->Compound()) {
|
|
|
|
const Scope& stimestamp = *etimestamp->Compound();
|
|
|
|
creationTimeStamp[0] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Year"),0));
|
|
|
|
creationTimeStamp[1] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Month"),0));
|
|
|
|
creationTimeStamp[2] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Day"),0));
|
|
|
|
creationTimeStamp[3] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Hour"),0));
|
|
|
|
creationTimeStamp[4] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Minute"),0));
|
|
|
|
creationTimeStamp[5] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Second"),0));
|
|
|
|
creationTimeStamp[6] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Millisecond"),0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Document::ReadObjects()
|
|
|
|
{
|
|
|
|
// read ID objects from "Objects" section
|
2012-06-26 16:31:19 +00:00
|
|
|
const Scope& sc = parser.GetRootScope();
|
|
|
|
const Element* const eobjects = sc["Objects"];
|
|
|
|
if(!eobjects || !eobjects->Compound()) {
|
|
|
|
DOMError("no Objects dictionary found");
|
|
|
|
}
|
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
const Scope& sobjects = *eobjects->Compound();
|
|
|
|
BOOST_FOREACH(const ElementMap::value_type& el, sobjects.Elements()) {
|
2012-06-26 16:31:19 +00:00
|
|
|
|
|
|
|
// extract ID
|
|
|
|
const TokenList& tok = el.second->Tokens();
|
|
|
|
|
|
|
|
if (tok.empty()) {
|
|
|
|
DOMError("expected ID after object key",el.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* err;
|
|
|
|
|
|
|
|
const uint64_t id = ParseTokenAsID(*tok[0], err);
|
|
|
|
if(err) {
|
|
|
|
DOMError(err,el.second);
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
objects[id] = new LazyObject(id, *el.second, *this);
|
2012-07-20 22:45:37 +00:00
|
|
|
|
|
|
|
// grab all animation stacks upfront since there is no listing of them
|
|
|
|
if(el.first == "AnimationStack") {
|
|
|
|
animationStacks.push_back(id);
|
|
|
|
}
|
2012-06-26 16:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-02 14:51:19 +00:00
|
|
|
void Document::ReadPropertyTemplates()
|
2012-06-26 16:31:19 +00:00
|
|
|
{
|
2012-07-02 14:51:19 +00:00
|
|
|
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) {
|
2012-07-02 15:37:00 +00:00
|
|
|
boost::shared_ptr<const PropertyTable> props = boost::make_shared<const PropertyTable>(
|
2012-07-04 15:06:55 +00:00
|
|
|
*Properties70,boost::shared_ptr<const PropertyTable>(static_cast<const PropertyTable*>(NULL))
|
2012-07-02 15:37:00 +00:00
|
|
|
);
|
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
templates[oname+"."+pname] = props;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Document::ReadConnections()
|
|
|
|
{
|
|
|
|
const Scope& sc = parser.GetRootScope();
|
|
|
|
// read property templates from "Definitions" section
|
|
|
|
const Element* const econns = sc["Connections"];
|
|
|
|
if(!econns || !econns->Compound()) {
|
|
|
|
DOMError("no Connections dictionary found");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t insertionOrder = 0l;
|
|
|
|
|
|
|
|
const Scope& sconns = *econns->Compound();
|
|
|
|
const ElementCollection conns = sconns.GetCollection("C");
|
|
|
|
for(ElementMap::const_iterator it = conns.first; it != conns.second; ++it) {
|
|
|
|
const Element& el = *(*it).second;
|
|
|
|
const std::string& type = ParseTokenAsString(GetRequiredToken(el,0));
|
|
|
|
const uint64_t src = ParseTokenAsID(GetRequiredToken(el,1));
|
|
|
|
const uint64_t dest = ParseTokenAsID(GetRequiredToken(el,2));
|
|
|
|
|
|
|
|
// OO = object-object connection
|
|
|
|
// OP = object-property connection, in which case the destination property follows the object ID
|
|
|
|
const std::string& prop = (type == "OP" ? ParseTokenAsString(GetRequiredToken(el,3)) : "");
|
|
|
|
|
|
|
|
if(objects.find(src) == objects.end()) {
|
|
|
|
DOMWarning("source object for connection does not exist",&el);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-04 14:33:21 +00:00
|
|
|
// dest may be 0 (root node)
|
|
|
|
if(dest && objects.find(dest) == objects.end()) {
|
2012-07-03 14:50:58 +00:00
|
|
|
DOMWarning("destination object for connection does not exist",&el);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add new connection
|
|
|
|
const Connection* const c = new Connection(insertionOrder++,src,dest,prop,*this);
|
|
|
|
src_connections.insert(ConnectionMap::value_type(src,c));
|
|
|
|
dest_connections.insert(ConnectionMap::value_type(dest,c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
|
2012-07-20 22:45:37 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const std::vector<const AnimationStack*>& Document::AnimationStacks() const
|
|
|
|
{
|
2012-07-21 02:15:10 +00:00
|
|
|
if (!animationStacksResolved.empty() || !animationStacks.size()) {
|
2012-07-20 22:45:37 +00:00
|
|
|
return animationStacksResolved;
|
|
|
|
}
|
|
|
|
|
|
|
|
animationStacksResolved.reserve(animationStacks.size());
|
|
|
|
BOOST_FOREACH(uint64_t id, animationStacks) {
|
|
|
|
LazyObject* const lazy = GetObject(id);
|
|
|
|
const AnimationStack* stack;
|
|
|
|
if(!lazy || !(stack = lazy->Get<AnimationStack>())) {
|
|
|
|
DOMWarning("failed to read AnimationStack object");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
animationStacksResolved.push_back(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return animationStacksResolved;
|
|
|
|
}
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
LazyObject* Document::GetObject(uint64_t id) const
|
|
|
|
{
|
|
|
|
ObjectMap::const_iterator it = objects.find(id);
|
|
|
|
return it == objects.end() ? NULL : (*it).second;
|
|
|
|
}
|
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
#define MAX_CLASSNAMES 6
|
2012-07-21 15:12:04 +00:00
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-21 16:02:10 +00:00
|
|
|
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns) const
|
2012-07-03 15:57:21 +00:00
|
|
|
{
|
|
|
|
std::vector<const Connection*> temp;
|
|
|
|
|
|
|
|
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
|
2012-07-21 16:02:10 +00:00
|
|
|
conns.equal_range(id);
|
2012-07-03 15:57:21 +00:00
|
|
|
|
|
|
|
temp.reserve(std::distance(range.first,range.second));
|
|
|
|
for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
|
|
|
|
temp.push_back((*it).second);
|
|
|
|
}
|
|
|
|
|
2012-07-05 15:18:54 +00:00
|
|
|
std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
|
2012-07-03 15:57:21 +00:00
|
|
|
|
|
|
|
return temp; // NRVO should handle this
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-07-21 18:02:00 +00:00
|
|
|
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src, const ConnectionMap& conns, const char* const* classnames, size_t count) const
|
2012-07-03 15:57:21 +00:00
|
|
|
{
|
2012-07-21 16:02:10 +00:00
|
|
|
ai_assert(classnames);
|
|
|
|
ai_assert(count != 0 && count <= MAX_CLASSNAMES);
|
|
|
|
|
|
|
|
size_t lenghts[MAX_CLASSNAMES];
|
|
|
|
|
|
|
|
const size_t c = count;
|
|
|
|
for (size_t i = 0; i < c; ++i) {
|
|
|
|
lenghts[i] = strlen(classnames[i]);
|
|
|
|
}
|
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
std::vector<const Connection*> temp;
|
|
|
|
|
|
|
|
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
|
2012-07-21 16:02:10 +00:00
|
|
|
conns.equal_range(id);
|
2012-07-03 15:57:21 +00:00
|
|
|
|
|
|
|
temp.reserve(std::distance(range.first,range.second));
|
|
|
|
for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
|
2012-07-21 18:02:00 +00:00
|
|
|
const Token& key = (is_src
|
|
|
|
? (*it).second->LazyDestinationObject()
|
|
|
|
: (*it).second->LazySourceObject()
|
|
|
|
).GetElement().KeyToken();
|
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
const char* obtype = key.begin();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < c; ++i) {
|
|
|
|
ai_assert(classnames[i]);
|
2012-07-21 19:28:02 +00:00
|
|
|
if(std::distance(key.begin(),key.end()) == lenghts[i] && !strncmp(classnames[i],obtype,lenghts[i])) {
|
2012-07-21 16:02:10 +00:00
|
|
|
obtype = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(obtype) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
temp.push_back((*it).second);
|
|
|
|
}
|
|
|
|
|
2012-07-05 15:18:54 +00:00
|
|
|
std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
|
2012-07-03 15:57:21 +00:00
|
|
|
return temp; // NRVO should handle this
|
|
|
|
}
|
2012-07-03 14:50:58 +00:00
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const
|
|
|
|
{
|
|
|
|
return GetConnectionsSequenced(source, ConnectionsBySource());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-21 18:02:00 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t dest, const char* classname) const
|
|
|
|
{
|
|
|
|
const char* arr[] = {classname};
|
|
|
|
return GetConnectionsBySourceSequenced(dest, arr,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source, const char* const* classnames, size_t count) const
|
|
|
|
{
|
2012-07-21 18:02:00 +00:00
|
|
|
return GetConnectionsSequenced(source, true, ConnectionsBySource(),classnames, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest, const char* classname) const
|
|
|
|
{
|
|
|
|
const char* arr[] = {classname};
|
|
|
|
return GetConnectionsByDestinationSequenced(dest, arr,1);
|
2012-07-21 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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
|
|
|
|
{
|
2012-07-21 18:02:00 +00:00
|
|
|
return GetConnectionsSequenced(dest, false, ConnectionsByDestination(),classnames, count);
|
2012-07-21 16:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc)
|
|
|
|
: insertionOrder(insertionOrder)
|
2012-07-08 01:28:14 +00:00
|
|
|
, prop(prop)
|
2012-07-03 14:50:58 +00:00
|
|
|
, src(src)
|
|
|
|
, dest(dest)
|
|
|
|
, doc(doc)
|
|
|
|
{
|
|
|
|
ai_assert(doc.Objects().find(src) != doc.Objects().end());
|
2012-07-04 14:33:21 +00:00
|
|
|
// dest may be 0 (root node)
|
|
|
|
ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end());
|
2012-07-03 14:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Connection::~Connection()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
LazyObject& Connection::LazySourceObject() const
|
|
|
|
{
|
|
|
|
LazyObject* const lazy = doc.GetObject(src);
|
|
|
|
ai_assert(lazy);
|
|
|
|
return *lazy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
LazyObject& Connection::LazyDestinationObject() const
|
|
|
|
{
|
|
|
|
LazyObject* const lazy = doc.GetObject(dest);
|
|
|
|
ai_assert(lazy);
|
|
|
|
return *lazy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Object* Connection::SourceObject() const
|
|
|
|
{
|
|
|
|
LazyObject* const lazy = doc.GetObject(src);
|
|
|
|
ai_assert(lazy);
|
|
|
|
return lazy->Get();
|
|
|
|
}
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Object* Connection::DestinationObject() const
|
|
|
|
{
|
|
|
|
LazyObject* const lazy = doc.GetObject(dest);
|
|
|
|
ai_assert(lazy);
|
|
|
|
return lazy->Get();
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
} // !FBX
|
|
|
|
} // !Assimp
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|