FBXDocument.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file FBXDocument.cpp
  34. * @brief Implementation of the FBX DOM classes
  35. */
  36. #include "AssimpPCH.h"
  37. #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
  38. #include <functional>
  39. #include "FBXParser.h"
  40. #include "FBXDocument.h"
  41. #include "FBXUtil.h"
  42. #include "FBXImporter.h"
  43. #include "FBXImportSettings.h"
  44. #include "FBXDocumentUtil.h"
  45. #include "FBXProperties.h"
  46. namespace Assimp {
  47. namespace FBX {
  48. using namespace Util;
  49. // ------------------------------------------------------------------------------------------------
  50. LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc)
  51. : doc(doc)
  52. , element(element)
  53. , id(id)
  54. , flags()
  55. {
  56. }
  57. // ------------------------------------------------------------------------------------------------
  58. LazyObject::~LazyObject()
  59. {
  60. }
  61. // ------------------------------------------------------------------------------------------------
  62. const Object* LazyObject::Get(bool dieOnError)
  63. {
  64. if(IsBeingConstructed() || FailedToConstruct()) {
  65. return NULL;
  66. }
  67. if (object.get()) {
  68. return object.get();
  69. }
  70. // if this is the root object, we return a dummy since there
  71. // is no root object int he fbx file - it is just referenced
  72. // with id 0.
  73. if(id == 0L) {
  74. object.reset(new Object(id, element, "Model::RootNode"));
  75. return object.get();
  76. }
  77. const Token& key = element.KeyToken();
  78. const TokenList& tokens = element.Tokens();
  79. if(tokens.size() < 3) {
  80. DOMError("expected at least 3 tokens: id, name and class tag",&element);
  81. }
  82. const char* err;
  83. std::string name = ParseTokenAsString(*tokens[1],err);
  84. if (err) {
  85. DOMError(err,&element);
  86. }
  87. // small fix for binary reading: binary fbx files don't use
  88. // prefixes such as Model:: in front of their names. The
  89. // loading code expects this at many places, though!
  90. // so convert the binary representation (a 0x0001) to the
  91. // double colon notation.
  92. if(tokens[1]->IsBinary()) {
  93. for (size_t i = 0; i < name.length(); ++i) {
  94. if (name[i] == 0x0 && name[i+1] == 0x1) {
  95. name = name.substr(i+2) + "::" + name.substr(0,i);
  96. }
  97. }
  98. }
  99. const std::string classtag = ParseTokenAsString(*tokens[2],err);
  100. if (err) {
  101. DOMError(err,&element);
  102. }
  103. // prevent recursive calls
  104. flags |= BEING_CONSTRUCTED;
  105. try {
  106. // this needs to be relatively fast since it happens a lot,
  107. // so avoid constructing strings all the time.
  108. const char* obtype = key.begin();
  109. const size_t length = static_cast<size_t>(key.end()-key.begin());
  110. if (!strncmp(obtype,"Geometry",length)) {
  111. if (!strcmp(classtag.c_str(),"Mesh")) {
  112. object.reset(new MeshGeometry(id,element,name,doc));
  113. }
  114. }
  115. else if (!strncmp(obtype,"NodeAttribute",length)) {
  116. if (!strcmp(classtag.c_str(),"Camera")) {
  117. object.reset(new Camera(id,element,doc,name));
  118. }
  119. else if (!strcmp(classtag.c_str(),"CameraSwitcher")) {
  120. object.reset(new CameraSwitcher(id,element,doc,name));
  121. }
  122. else if (!strcmp(classtag.c_str(),"Light")) {
  123. object.reset(new Light(id,element,doc,name));
  124. }
  125. else if (!strcmp(classtag.c_str(),"Null")) {
  126. object.reset(new Null(id,element,doc,name));
  127. }
  128. else if (!strcmp(classtag.c_str(),"LimbNode")) {
  129. object.reset(new LimbNode(id,element,doc,name));
  130. }
  131. }
  132. else if (!strncmp(obtype,"Deformer",length)) {
  133. if (!strcmp(classtag.c_str(),"Cluster")) {
  134. object.reset(new Cluster(id,element,doc,name));
  135. }
  136. else if (!strcmp(classtag.c_str(),"Skin")) {
  137. object.reset(new Skin(id,element,doc,name));
  138. }
  139. }
  140. else if (!strncmp(obtype,"Model",length)) {
  141. // FK and IK effectors are not supported
  142. if (strcmp(classtag.c_str(),"IKEffector") && strcmp(classtag.c_str(),"FKEffector")) {
  143. object.reset(new Model(id,element,doc,name));
  144. }
  145. }
  146. else if (!strncmp(obtype,"Material",length)) {
  147. object.reset(new Material(id,element,doc,name));
  148. }
  149. else if (!strncmp(obtype,"Texture",length)) {
  150. object.reset(new Texture(id,element,doc,name));
  151. }
  152. else if (!strncmp(obtype,"AnimationStack",length)) {
  153. object.reset(new AnimationStack(id,element,name,doc));
  154. }
  155. else if (!strncmp(obtype,"AnimationLayer",length)) {
  156. object.reset(new AnimationLayer(id,element,name,doc));
  157. }
  158. // note: order matters for these two
  159. else if (!strncmp(obtype,"AnimationCurve",length)) {
  160. object.reset(new AnimationCurve(id,element,name,doc));
  161. }
  162. else if (!strncmp(obtype,"AnimationCurveNode",length)) {
  163. object.reset(new AnimationCurveNode(id,element,name,doc));
  164. }
  165. }
  166. catch(std::exception& ex) {
  167. flags &= ~BEING_CONSTRUCTED;
  168. flags |= FAILED_TO_CONSTRUCT;
  169. if(dieOnError || doc.Settings().strictMode) {
  170. throw;
  171. }
  172. // note: the error message is already formatted, so raw logging is ok
  173. if(!DefaultLogger::isNullLogger()) {
  174. DefaultLogger::get()->error(ex.what());
  175. }
  176. return NULL;
  177. }
  178. if (!object.get()) {
  179. //DOMError("failed to convert element to DOM object, class: " + classtag + ", name: " + name,&element);
  180. }
  181. flags &= ~BEING_CONSTRUCTED;
  182. return object.get();
  183. }
  184. // ------------------------------------------------------------------------------------------------
  185. Object::Object(uint64_t id, const Element& element, const std::string& name)
  186. : element(element)
  187. , name(name)
  188. , id(id)
  189. {
  190. }
  191. // ------------------------------------------------------------------------------------------------
  192. Object::~Object()
  193. {
  194. }
  195. // ------------------------------------------------------------------------------------------------
  196. FileGlobalSettings::FileGlobalSettings(const Document& doc, boost::shared_ptr<const PropertyTable> props)
  197. : doc(doc)
  198. , props(props)
  199. {
  200. }
  201. // ------------------------------------------------------------------------------------------------
  202. FileGlobalSettings::~FileGlobalSettings()
  203. {
  204. }
  205. // ------------------------------------------------------------------------------------------------
  206. Document::Document(const Parser& parser, const ImportSettings& settings)
  207. : settings(settings)
  208. , parser(parser)
  209. {
  210. // cannot use array default initialization syntax because vc8 fails on it
  211. for (unsigned int i = 0; i < 7; ++i) {
  212. creationTimeStamp[i] = 0;
  213. }
  214. ReadHeader();
  215. ReadPropertyTemplates();
  216. ReadGlobalSettings();
  217. // this order is important, connections need parsed objects to check
  218. // whether connections are ok or not. Objects may not be evaluated yet,
  219. // though, since this may require valid connections.
  220. ReadObjects();
  221. ReadConnections();
  222. }
  223. // ------------------------------------------------------------------------------------------------
  224. Document::~Document()
  225. {
  226. BOOST_FOREACH(ObjectMap::value_type& v, objects) {
  227. delete v.second;
  228. }
  229. }
  230. // ------------------------------------------------------------------------------------------------
  231. void Document::ReadHeader()
  232. {
  233. // read ID objects from "Objects" section
  234. const Scope& sc = parser.GetRootScope();
  235. const Element* const ehead = sc["FBXHeaderExtension"];
  236. if(!ehead || !ehead->Compound()) {
  237. DOMError("no FBXHeaderExtension dictionary found");
  238. }
  239. const Scope& shead = *ehead->Compound();
  240. fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
  241. if(fbxVersion < 7200 || fbxVersion > 7300) {
  242. if(Settings().strictMode) {
  243. DOMError("unsupported format version, supported are only FBX 2012 and FBX 2013"\
  244. " in ASCII format (turn off strict mode to try anyhow) ");
  245. }
  246. else {
  247. DOMWarning("unsupported format version, supported are only FBX 2012 and FBX 2013, trying to read it nevertheless");
  248. }
  249. }
  250. const Element* const ecreator = shead["Creator"];
  251. if(ecreator) {
  252. creator = ParseTokenAsString(GetRequiredToken(*ecreator,0));
  253. }
  254. const Element* const etimestamp = shead["CreationTimeStamp"];
  255. if(etimestamp && etimestamp->Compound()) {
  256. const Scope& stimestamp = *etimestamp->Compound();
  257. creationTimeStamp[0] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Year"),0));
  258. creationTimeStamp[1] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Month"),0));
  259. creationTimeStamp[2] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Day"),0));
  260. creationTimeStamp[3] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Hour"),0));
  261. creationTimeStamp[4] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Minute"),0));
  262. creationTimeStamp[5] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Second"),0));
  263. creationTimeStamp[6] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Millisecond"),0));
  264. }
  265. }
  266. // ------------------------------------------------------------------------------------------------
  267. void Document::ReadGlobalSettings()
  268. {
  269. const Scope& sc = parser.GetRootScope();
  270. const Element* const ehead = sc["GlobalSettings"];
  271. if(!ehead || !ehead->Compound()) {
  272. DOMWarning("no GlobalSettings dictionary found");
  273. globals.reset(new FileGlobalSettings(*this, boost::make_shared<const PropertyTable>()));
  274. return;
  275. }
  276. boost::shared_ptr<const PropertyTable> props = GetPropertyTable(*this, "", *ehead, *ehead->Compound(), true);
  277. if(!props) {
  278. DOMError("GlobalSettings dictionary contains no property table");
  279. }
  280. globals.reset(new FileGlobalSettings(*this, props));
  281. }
  282. // ------------------------------------------------------------------------------------------------
  283. void Document::ReadObjects()
  284. {
  285. // read ID objects from "Objects" section
  286. const Scope& sc = parser.GetRootScope();
  287. const Element* const eobjects = sc["Objects"];
  288. if(!eobjects || !eobjects->Compound()) {
  289. DOMError("no Objects dictionary found");
  290. }
  291. // add a dummy entry to represent the Model::RootNode object (id 0),
  292. // which is only indirectly defined in the input file
  293. objects[0] = new LazyObject(0L, *eobjects, *this);
  294. const Scope& sobjects = *eobjects->Compound();
  295. BOOST_FOREACH(const ElementMap::value_type& el, sobjects.Elements()) {
  296. // extract ID
  297. const TokenList& tok = el.second->Tokens();
  298. if (tok.empty()) {
  299. DOMError("expected ID after object key",el.second);
  300. }
  301. const char* err;
  302. const uint64_t id = ParseTokenAsID(*tok[0], err);
  303. if(err) {
  304. DOMError(err,el.second);
  305. }
  306. // id=0 is normally implicit
  307. if(id == 0L) {
  308. DOMError("encountered object with implicitly defined id 0",el.second);
  309. }
  310. if(objects.find(id) != objects.end()) {
  311. DOMWarning("encountered duplicate object id, ignoring first occurrence",el.second);
  312. }
  313. objects[id] = new LazyObject(id, *el.second, *this);
  314. // grab all animation stacks upfront since there is no listing of them
  315. if(!strcmp(el.first.c_str(),"AnimationStack")) {
  316. animationStacks.push_back(id);
  317. }
  318. }
  319. }
  320. // ------------------------------------------------------------------------------------------------
  321. void Document::ReadPropertyTemplates()
  322. {
  323. const Scope& sc = parser.GetRootScope();
  324. // read property templates from "Definitions" section
  325. const Element* const edefs = sc["Definitions"];
  326. if(!edefs || !edefs->Compound()) {
  327. DOMWarning("no Definitions dictionary found");
  328. return;
  329. }
  330. const Scope& sdefs = *edefs->Compound();
  331. const ElementCollection otypes = sdefs.GetCollection("ObjectType");
  332. for(ElementMap::const_iterator it = otypes.first; it != otypes.second; ++it) {
  333. const Element& el = *(*it).second;
  334. const Scope* sc = el.Compound();
  335. if(!sc) {
  336. DOMWarning("expected nested scope in ObjectType, ignoring",&el);
  337. continue;
  338. }
  339. const TokenList& tok = el.Tokens();
  340. if(tok.empty()) {
  341. DOMWarning("expected name for ObjectType element, ignoring",&el);
  342. continue;
  343. }
  344. const std::string& oname = ParseTokenAsString(*tok[0]);
  345. const ElementCollection templs = sc->GetCollection("PropertyTemplate");
  346. for(ElementMap::const_iterator it = templs.first; it != templs.second; ++it) {
  347. const Element& el = *(*it).second;
  348. const Scope* sc = el.Compound();
  349. if(!sc) {
  350. DOMWarning("expected nested scope in PropertyTemplate, ignoring",&el);
  351. continue;
  352. }
  353. const TokenList& tok = el.Tokens();
  354. if(tok.empty()) {
  355. DOMWarning("expected name for PropertyTemplate element, ignoring",&el);
  356. continue;
  357. }
  358. const std::string& pname = ParseTokenAsString(*tok[0]);
  359. const Element* Properties70 = (*sc)["Properties70"];
  360. if(Properties70) {
  361. boost::shared_ptr<const PropertyTable> props = boost::make_shared<const PropertyTable>(
  362. *Properties70,boost::shared_ptr<const PropertyTable>(static_cast<const PropertyTable*>(NULL))
  363. );
  364. templates[oname+"."+pname] = props;
  365. }
  366. }
  367. }
  368. }
  369. // ------------------------------------------------------------------------------------------------
  370. void Document::ReadConnections()
  371. {
  372. const Scope& sc = parser.GetRootScope();
  373. // read property templates from "Definitions" section
  374. const Element* const econns = sc["Connections"];
  375. if(!econns || !econns->Compound()) {
  376. DOMError("no Connections dictionary found");
  377. }
  378. uint64_t insertionOrder = 0l;
  379. const Scope& sconns = *econns->Compound();
  380. const ElementCollection conns = sconns.GetCollection("C");
  381. for(ElementMap::const_iterator it = conns.first; it != conns.second; ++it) {
  382. const Element& el = *(*it).second;
  383. const std::string& type = ParseTokenAsString(GetRequiredToken(el,0));
  384. const uint64_t src = ParseTokenAsID(GetRequiredToken(el,1));
  385. const uint64_t dest = ParseTokenAsID(GetRequiredToken(el,2));
  386. // OO = object-object connection
  387. // OP = object-property connection, in which case the destination property follows the object ID
  388. const std::string& prop = (type == "OP" ? ParseTokenAsString(GetRequiredToken(el,3)) : "");
  389. if(objects.find(src) == objects.end()) {
  390. DOMWarning("source object for connection does not exist",&el);
  391. continue;
  392. }
  393. // dest may be 0 (root node) but we added a dummy object before
  394. if(objects.find(dest) == objects.end()) {
  395. DOMWarning("destination object for connection does not exist",&el);
  396. continue;
  397. }
  398. // add new connection
  399. const Connection* const c = new Connection(insertionOrder++,src,dest,prop,*this);
  400. src_connections.insert(ConnectionMap::value_type(src,c));
  401. dest_connections.insert(ConnectionMap::value_type(dest,c));
  402. }
  403. }
  404. // ------------------------------------------------------------------------------------------------
  405. const std::vector<const AnimationStack*>& Document::AnimationStacks() const
  406. {
  407. if (!animationStacksResolved.empty() || !animationStacks.size()) {
  408. return animationStacksResolved;
  409. }
  410. animationStacksResolved.reserve(animationStacks.size());
  411. BOOST_FOREACH(uint64_t id, animationStacks) {
  412. LazyObject* const lazy = GetObject(id);
  413. const AnimationStack* stack;
  414. if(!lazy || !(stack = lazy->Get<AnimationStack>())) {
  415. DOMWarning("failed to read AnimationStack object");
  416. continue;
  417. }
  418. animationStacksResolved.push_back(stack);
  419. }
  420. return animationStacksResolved;
  421. }
  422. // ------------------------------------------------------------------------------------------------
  423. LazyObject* Document::GetObject(uint64_t id) const
  424. {
  425. ObjectMap::const_iterator it = objects.find(id);
  426. return it == objects.end() ? NULL : (*it).second;
  427. }
  428. #define MAX_CLASSNAMES 6
  429. // ------------------------------------------------------------------------------------------------
  430. std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id,
  431. const ConnectionMap& conns) const
  432. {
  433. std::vector<const Connection*> temp;
  434. const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
  435. conns.equal_range(id);
  436. temp.reserve(std::distance(range.first,range.second));
  437. for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
  438. temp.push_back((*it).second);
  439. }
  440. std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
  441. return temp; // NRVO should handle this
  442. }
  443. // ------------------------------------------------------------------------------------------------
  444. std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src,
  445. const ConnectionMap& conns,
  446. const char* const* classnames,
  447. size_t count) const
  448. {
  449. ai_assert(classnames);
  450. ai_assert(count != 0 && count <= MAX_CLASSNAMES);
  451. size_t lenghts[MAX_CLASSNAMES];
  452. const size_t c = count;
  453. for (size_t i = 0; i < c; ++i) {
  454. lenghts[i] = strlen(classnames[i]);
  455. }
  456. std::vector<const Connection*> temp;
  457. const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
  458. conns.equal_range(id);
  459. temp.reserve(std::distance(range.first,range.second));
  460. for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
  461. const Token& key = (is_src
  462. ? (*it).second->LazyDestinationObject()
  463. : (*it).second->LazySourceObject()
  464. ).GetElement().KeyToken();
  465. const char* obtype = key.begin();
  466. for (size_t i = 0; i < c; ++i) {
  467. ai_assert(classnames[i]);
  468. if(std::distance(key.begin(),key.end()) == lenghts[i] && !strncmp(classnames[i],obtype,lenghts[i])) {
  469. obtype = NULL;
  470. break;
  471. }
  472. }
  473. if(obtype) {
  474. continue;
  475. }
  476. temp.push_back((*it).second);
  477. }
  478. std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
  479. return temp; // NRVO should handle this
  480. }
  481. // ------------------------------------------------------------------------------------------------
  482. std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const
  483. {
  484. return GetConnectionsSequenced(source, ConnectionsBySource());
  485. }
  486. // ------------------------------------------------------------------------------------------------
  487. std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t dest,
  488. const char* classname) const
  489. {
  490. const char* arr[] = {classname};
  491. return GetConnectionsBySourceSequenced(dest, arr,1);
  492. }
  493. // ------------------------------------------------------------------------------------------------
  494. std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source,
  495. const char* const* classnames, size_t count) const
  496. {
  497. return GetConnectionsSequenced(source, true, ConnectionsBySource(),classnames, count);
  498. }
  499. // ------------------------------------------------------------------------------------------------
  500. std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
  501. const char* classname) const
  502. {
  503. const char* arr[] = {classname};
  504. return GetConnectionsByDestinationSequenced(dest, arr,1);
  505. }
  506. // ------------------------------------------------------------------------------------------------
  507. std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const
  508. {
  509. return GetConnectionsSequenced(dest, ConnectionsByDestination());
  510. }
  511. // ------------------------------------------------------------------------------------------------
  512. std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
  513. const char* const* classnames, size_t count) const
  514. {
  515. return GetConnectionsSequenced(dest, false, ConnectionsByDestination(),classnames, count);
  516. }
  517. // ------------------------------------------------------------------------------------------------
  518. Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop,
  519. const Document& doc)
  520. : insertionOrder(insertionOrder)
  521. , prop(prop)
  522. , src(src)
  523. , dest(dest)
  524. , doc(doc)
  525. {
  526. ai_assert(doc.Objects().find(src) != doc.Objects().end());
  527. // dest may be 0 (root node)
  528. ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end());
  529. }
  530. // ------------------------------------------------------------------------------------------------
  531. Connection::~Connection()
  532. {
  533. }
  534. // ------------------------------------------------------------------------------------------------
  535. LazyObject& Connection::LazySourceObject() const
  536. {
  537. LazyObject* const lazy = doc.GetObject(src);
  538. ai_assert(lazy);
  539. return *lazy;
  540. }
  541. // ------------------------------------------------------------------------------------------------
  542. LazyObject& Connection::LazyDestinationObject() const
  543. {
  544. LazyObject* const lazy = doc.GetObject(dest);
  545. ai_assert(lazy);
  546. return *lazy;
  547. }
  548. // ------------------------------------------------------------------------------------------------
  549. const Object* Connection::SourceObject() const
  550. {
  551. LazyObject* const lazy = doc.GetObject(src);
  552. ai_assert(lazy);
  553. return lazy->Get();
  554. }
  555. // ------------------------------------------------------------------------------------------------
  556. const Object* Connection::DestinationObject() const
  557. {
  558. LazyObject* const lazy = doc.GetObject(dest);
  559. ai_assert(lazy);
  560. return lazy->Get();
  561. }
  562. } // !FBX
  563. } // !Assimp
  564. #endif