Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FBXDocument.cpp 22 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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,"LayeredTexture",length)) {
  153. object.reset(new LayeredTexture(id,element,doc,name));
  154. }
  155. else if (!strncmp(obtype,"AnimationStack",length)) {
  156. object.reset(new AnimationStack(id,element,name,doc));
  157. }
  158. else if (!strncmp(obtype,"AnimationLayer",length)) {
  159. object.reset(new AnimationLayer(id,element,name,doc));
  160. }
  161. // note: order matters for these two
  162. else if (!strncmp(obtype,"AnimationCurve",length)) {
  163. object.reset(new AnimationCurve(id,element,name,doc));
  164. }
  165. else if (!strncmp(obtype,"AnimationCurveNode",length)) {
  166. object.reset(new AnimationCurveNode(id,element,name,doc));
  167. }
  168. }
  169. catch(std::exception& ex) {
  170. flags &= ~BEING_CONSTRUCTED;
  171. flags |= FAILED_TO_CONSTRUCT;
  172. if(dieOnError || doc.Settings().strictMode) {
  173. throw;
  174. }
  175. // note: the error message is already formatted, so raw logging is ok
  176. if(!DefaultLogger::isNullLogger()) {
  177. DefaultLogger::get()->error(ex.what());
  178. }
  179. return NULL;
  180. }
  181. if (!object.get()) {
  182. //DOMError("failed to convert element to DOM object, class: " + classtag + ", name: " + name,&element);
  183. }
  184. flags &= ~BEING_CONSTRUCTED;
  185. return object.get();
  186. }
  187. // ------------------------------------------------------------------------------------------------
  188. Object::Object(uint64_t id, const Element& element, const std::string& name)
  189. : element(element)
  190. , name(name)
  191. , id(id)
  192. {
  193. }
  194. // ------------------------------------------------------------------------------------------------
  195. Object::~Object()
  196. {
  197. }
  198. // ------------------------------------------------------------------------------------------------
  199. FileGlobalSettings::FileGlobalSettings(const Document& doc, boost::shared_ptr<const PropertyTable> props)
  200. : props(props)
  201. , doc(doc)
  202. {
  203. }
  204. // ------------------------------------------------------------------------------------------------
  205. FileGlobalSettings::~FileGlobalSettings()
  206. {
  207. }
  208. // ------------------------------------------------------------------------------------------------
  209. Document::Document(const Parser& parser, const ImportSettings& settings)
  210. : settings(settings)
  211. , parser(parser)
  212. {
  213. // cannot use array default initialization syntax because vc8 fails on it
  214. for (unsigned int i = 0; i < 7; ++i) {
  215. creationTimeStamp[i] = 0;
  216. }
  217. ReadHeader();
  218. ReadPropertyTemplates();
  219. ReadGlobalSettings();
  220. // this order is important, connections need parsed objects to check
  221. // whether connections are ok or not. Objects may not be evaluated yet,
  222. // though, since this may require valid connections.
  223. ReadObjects();
  224. ReadConnections();
  225. }
  226. // ------------------------------------------------------------------------------------------------
  227. Document::~Document()
  228. {
  229. BOOST_FOREACH(ObjectMap::value_type& v, objects) {
  230. delete v.second;
  231. }
  232. }
  233. // ------------------------------------------------------------------------------------------------
  234. void Document::ReadHeader()
  235. {
  236. // read ID objects from "Objects" section
  237. const Scope& sc = parser.GetRootScope();
  238. const Element* const ehead = sc["FBXHeaderExtension"];
  239. if(!ehead || !ehead->Compound()) {
  240. DOMError("no FBXHeaderExtension dictionary found");
  241. }
  242. const Scope& shead = *ehead->Compound();
  243. fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
  244. // while we maye have some success with newer files, we don't support
  245. // the older 6.n fbx format
  246. if(fbxVersion < 7100) {
  247. DOMError("unsupported, old format version, supported are only FBX 2011, FBX 2012 and FBX 2013");
  248. }
  249. if(fbxVersion > 7300) {
  250. if(Settings().strictMode) {
  251. DOMError("unsupported, newer format version, supported are only FBX 2011, FBX 2012 and FBX 2013"
  252. " (turn off strict mode to try anyhow) ");
  253. }
  254. else {
  255. DOMWarning("unsupported, newer format version, supported are only FBX 2011, FBX 2012 and FBX 2013,"
  256. " trying to read it nevertheless");
  257. }
  258. }
  259. const Element* const ecreator = shead["Creator"];
  260. if(ecreator) {
  261. creator = ParseTokenAsString(GetRequiredToken(*ecreator,0));
  262. }
  263. const Element* const etimestamp = shead["CreationTimeStamp"];
  264. if(etimestamp && etimestamp->Compound()) {
  265. const Scope& stimestamp = *etimestamp->Compound();
  266. creationTimeStamp[0] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Year"),0));
  267. creationTimeStamp[1] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Month"),0));
  268. creationTimeStamp[2] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Day"),0));
  269. creationTimeStamp[3] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Hour"),0));
  270. creationTimeStamp[4] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Minute"),0));
  271. creationTimeStamp[5] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Second"),0));
  272. creationTimeStamp[6] = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(stimestamp,"Millisecond"),0));
  273. }
  274. }
  275. // ------------------------------------------------------------------------------------------------
  276. void Document::ReadGlobalSettings()
  277. {
  278. const Scope& sc = parser.GetRootScope();
  279. const Element* const ehead = sc["GlobalSettings"];
  280. if(!ehead || !ehead->Compound()) {
  281. DOMWarning("no GlobalSettings dictionary found");
  282. globals.reset(new FileGlobalSettings(*this, boost::make_shared<const PropertyTable>()));
  283. return;
  284. }
  285. boost::shared_ptr<const PropertyTable> props = GetPropertyTable(*this, "", *ehead, *ehead->Compound(), true);
  286. if(!props) {
  287. DOMError("GlobalSettings dictionary contains no property table");
  288. }
  289. globals.reset(new FileGlobalSettings(*this, props));
  290. }
  291. // ------------------------------------------------------------------------------------------------
  292. void Document::ReadObjects()
  293. {
  294. // read ID objects from "Objects" section
  295. const Scope& sc = parser.GetRootScope();
  296. const Element* const eobjects = sc["Objects"];
  297. if(!eobjects || !eobjects->Compound()) {
  298. DOMError("no Objects dictionary found");
  299. }
  300. // add a dummy entry to represent the Model::RootNode object (id 0),
  301. // which is only indirectly defined in the input file
  302. objects[0] = new LazyObject(0L, *eobjects, *this);
  303. const Scope& sobjects = *eobjects->Compound();
  304. BOOST_FOREACH(const ElementMap::value_type& el, sobjects.Elements()) {
  305. // extract ID
  306. const TokenList& tok = el.second->Tokens();
  307. if (tok.empty()) {
  308. DOMError("expected ID after object key",el.second);
  309. }
  310. const char* err;
  311. const uint64_t id = ParseTokenAsID(*tok[0], err);
  312. if(err) {
  313. DOMError(err,el.second);
  314. }
  315. // id=0 is normally implicit
  316. if(id == 0L) {
  317. DOMError("encountered object with implicitly defined id 0",el.second);
  318. }
  319. if(objects.find(id) != objects.end()) {
  320. DOMWarning("encountered duplicate object id, ignoring first occurrence",el.second);
  321. }
  322. objects[id] = new LazyObject(id, *el.second, *this);
  323. // grab all animation stacks upfront since there is no listing of them
  324. if(!strcmp(el.first.c_str(),"AnimationStack")) {
  325. animationStacks.push_back(id);
  326. }
  327. }
  328. }
  329. // ------------------------------------------------------------------------------------------------
  330. void Document::ReadPropertyTemplates()
  331. {
  332. const Scope& sc = parser.GetRootScope();
  333. // read property templates from "Definitions" section
  334. const Element* const edefs = sc["Definitions"];
  335. if(!edefs || !edefs->Compound()) {
  336. DOMWarning("no Definitions dictionary found");
  337. return;
  338. }
  339. const Scope& sdefs = *edefs->Compound();
  340. const ElementCollection otypes = sdefs.GetCollection("ObjectType");
  341. for(ElementMap::const_iterator it = otypes.first; it != otypes.second; ++it) {
  342. const Element& el = *(*it).second;
  343. const Scope* sc = el.Compound();
  344. if(!sc) {
  345. DOMWarning("expected nested scope in ObjectType, ignoring",&el);
  346. continue;
  347. }
  348. const TokenList& tok = el.Tokens();
  349. if(tok.empty()) {
  350. DOMWarning("expected name for ObjectType element, ignoring",&el);
  351. continue;
  352. }
  353. const std::string& oname = ParseTokenAsString(*tok[0]);
  354. const ElementCollection templs = sc->GetCollection("PropertyTemplate");
  355. for(ElementMap::const_iterator it = templs.first; it != templs.second; ++it) {
  356. const Element& el = *(*it).second;
  357. const Scope* sc = el.Compound();
  358. if(!sc) {
  359. DOMWarning("expected nested scope in PropertyTemplate, ignoring",&el);
  360. continue;
  361. }
  362. const TokenList& tok = el.Tokens();
  363. if(tok.empty()) {
  364. DOMWarning("expected name for PropertyTemplate element, ignoring",&el);
  365. continue;
  366. }
  367. const std::string& pname = ParseTokenAsString(*tok[0]);
  368. const Element* Properties70 = (*sc)["Properties70"];
  369. if(Properties70) {
  370. boost::shared_ptr<const PropertyTable> props = boost::make_shared<const PropertyTable>(
  371. *Properties70,boost::shared_ptr<const PropertyTable>(static_cast<const PropertyTable*>(NULL))
  372. );
  373. templates[oname+"."+pname] = props;
  374. }
  375. }
  376. }
  377. }
  378. // ------------------------------------------------------------------------------------------------
  379. void Document::ReadConnections()
  380. {
  381. const Scope& sc = parser.GetRootScope();
  382. // read property templates from "Definitions" section
  383. const Element* const econns = sc["Connections"];
  384. if(!econns || !econns->Compound()) {
  385. DOMError("no Connections dictionary found");
  386. }
  387. uint64_t insertionOrder = 0l;
  388. const Scope& sconns = *econns->Compound();
  389. const ElementCollection conns = sconns.GetCollection("C");
  390. for(ElementMap::const_iterator it = conns.first; it != conns.second; ++it) {
  391. const Element& el = *(*it).second;
  392. const std::string& type = ParseTokenAsString(GetRequiredToken(el,0));
  393. const uint64_t src = ParseTokenAsID(GetRequiredToken(el,1));
  394. const uint64_t dest = ParseTokenAsID(GetRequiredToken(el,2));
  395. // OO = object-object connection
  396. // OP = object-property connection, in which case the destination property follows the object ID
  397. const std::string& prop = (type == "OP" ? ParseTokenAsString(GetRequiredToken(el,3)) : "");
  398. if(objects.find(src) == objects.end()) {
  399. DOMWarning("source object for connection does not exist",&el);
  400. continue;
  401. }
  402. // dest may be 0 (root node) but we added a dummy object before
  403. if(objects.find(dest) == objects.end()) {
  404. DOMWarning("destination object for connection does not exist",&el);
  405. continue;
  406. }
  407. // add new connection
  408. const Connection* const c = new Connection(insertionOrder++,src,dest,prop,*this);
  409. src_connections.insert(ConnectionMap::value_type(src,c));
  410. dest_connections.insert(ConnectionMap::value_type(dest,c));
  411. }
  412. }
  413. // ------------------------------------------------------------------------------------------------
  414. const std::vector<const AnimationStack*>& Document::AnimationStacks() const
  415. {
  416. if (!animationStacksResolved.empty() || !animationStacks.size()) {
  417. return animationStacksResolved;
  418. }
  419. animationStacksResolved.reserve(animationStacks.size());
  420. BOOST_FOREACH(uint64_t id, animationStacks) {
  421. LazyObject* const lazy = GetObject(id);
  422. const AnimationStack* stack;
  423. if(!lazy || !(stack = lazy->Get<AnimationStack>())) {
  424. DOMWarning("failed to read AnimationStack object");
  425. continue;
  426. }
  427. animationStacksResolved.push_back(stack);
  428. }
  429. return animationStacksResolved;
  430. }
  431. // ------------------------------------------------------------------------------------------------
  432. LazyObject* Document::GetObject(uint64_t id) const
  433. {
  434. ObjectMap::const_iterator it = objects.find(id);
  435. return it == objects.end() ? NULL : (*it).second;
  436. }
  437. #define MAX_CLASSNAMES 6
  438. // ------------------------------------------------------------------------------------------------
  439. std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id,
  440. const ConnectionMap& conns) const
  441. {
  442. std::vector<const Connection*> temp;
  443. const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
  444. conns.equal_range(id);
  445. temp.reserve(std::distance(range.first,range.second));
  446. for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
  447. temp.push_back((*it).second);
  448. }
  449. std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
  450. return temp; // NRVO should handle this
  451. }
  452. // ------------------------------------------------------------------------------------------------
  453. std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, bool is_src,
  454. const ConnectionMap& conns,
  455. const char* const* classnames,
  456. size_t count) const
  457. {
  458. ai_assert(classnames);
  459. ai_assert(count != 0 && count <= MAX_CLASSNAMES);
  460. size_t lenghts[MAX_CLASSNAMES];
  461. const size_t c = count;
  462. for (size_t i = 0; i < c; ++i) {
  463. lenghts[i] = strlen(classnames[i]);
  464. }
  465. std::vector<const Connection*> temp;
  466. const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
  467. conns.equal_range(id);
  468. temp.reserve(std::distance(range.first,range.second));
  469. for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
  470. const Token& key = (is_src
  471. ? (*it).second->LazyDestinationObject()
  472. : (*it).second->LazySourceObject()
  473. ).GetElement().KeyToken();
  474. const char* obtype = key.begin();
  475. for (size_t i = 0; i < c; ++i) {
  476. ai_assert(classnames[i]);
  477. if(static_cast<size_t>(std::distance(key.begin(),key.end())) == lenghts[i] && !strncmp(classnames[i],obtype,lenghts[i])) {
  478. obtype = NULL;
  479. break;
  480. }
  481. }
  482. if(obtype) {
  483. continue;
  484. }
  485. temp.push_back((*it).second);
  486. }
  487. std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
  488. return temp; // NRVO should handle this
  489. }
  490. // ------------------------------------------------------------------------------------------------
  491. std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const
  492. {
  493. return GetConnectionsSequenced(source, ConnectionsBySource());
  494. }
  495. // ------------------------------------------------------------------------------------------------
  496. std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t dest,
  497. const char* classname) const
  498. {
  499. const char* arr[] = {classname};
  500. return GetConnectionsBySourceSequenced(dest, arr,1);
  501. }
  502. // ------------------------------------------------------------------------------------------------
  503. std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source,
  504. const char* const* classnames, size_t count) const
  505. {
  506. return GetConnectionsSequenced(source, true, ConnectionsBySource(),classnames, count);
  507. }
  508. // ------------------------------------------------------------------------------------------------
  509. std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
  510. const char* classname) const
  511. {
  512. const char* arr[] = {classname};
  513. return GetConnectionsByDestinationSequenced(dest, arr,1);
  514. }
  515. // ------------------------------------------------------------------------------------------------
  516. std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const
  517. {
  518. return GetConnectionsSequenced(dest, ConnectionsByDestination());
  519. }
  520. // ------------------------------------------------------------------------------------------------
  521. std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest,
  522. const char* const* classnames, size_t count) const
  523. {
  524. return GetConnectionsSequenced(dest, false, ConnectionsByDestination(),classnames, count);
  525. }
  526. // ------------------------------------------------------------------------------------------------
  527. Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop,
  528. const Document& doc)
  529. : insertionOrder(insertionOrder)
  530. , prop(prop)
  531. , src(src)
  532. , dest(dest)
  533. , doc(doc)
  534. {
  535. ai_assert(doc.Objects().find(src) != doc.Objects().end());
  536. // dest may be 0 (root node)
  537. ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end());
  538. }
  539. // ------------------------------------------------------------------------------------------------
  540. Connection::~Connection()
  541. {
  542. }
  543. // ------------------------------------------------------------------------------------------------
  544. LazyObject& Connection::LazySourceObject() const
  545. {
  546. LazyObject* const lazy = doc.GetObject(src);
  547. ai_assert(lazy);
  548. return *lazy;
  549. }
  550. // ------------------------------------------------------------------------------------------------
  551. LazyObject& Connection::LazyDestinationObject() const
  552. {
  553. LazyObject* const lazy = doc.GetObject(dest);
  554. ai_assert(lazy);
  555. return *lazy;
  556. }
  557. // ------------------------------------------------------------------------------------------------
  558. const Object* Connection::SourceObject() const
  559. {
  560. LazyObject* const lazy = doc.GetObject(src);
  561. ai_assert(lazy);
  562. return lazy->Get();
  563. }
  564. // ------------------------------------------------------------------------------------------------
  565. const Object* Connection::DestinationObject() const
  566. {
  567. LazyObject* const lazy = doc.GetObject(dest);
  568. ai_assert(lazy);
  569. return lazy->Get();
  570. }
  571. } // !FBX
  572. } // !Assimp
  573. #endif