collect map links to shared models map Object with the same model to first object in tree with that model, first object maps to oneself numberSharedFileInSharedFolder - unique number for all Objects with the same shared model to avoid name collision > <ObjectWithSharedModel1, <ObjectWithSharedModelFirst, numbe
| 58 | // <ObjectWithSharedModelN, <ObjectWithSharedModelFirst, numberSharedFileInSharedFolder>> |
| 59 | // return shared models count |
| 60 | int collectLinks( const Object& rootObject, Obj2FirstSharedObj& links ) |
| 61 | { |
| 62 | links.clear(); |
| 63 | |
| 64 | HashSet<KeyObjectModel, KeyObjectModelHasher> uniqueObjectsModels; |
| 65 | |
| 66 | std::stack<const Object*> sceneGraphVisitedList; |
| 67 | sceneGraphVisitedList.push( &rootObject ); |
| 68 | |
| 69 | int countSharedFiles = 0; |
| 70 | while ( !sceneGraphVisitedList.empty() ) |
| 71 | { |
| 72 | auto node = sceneGraphVisitedList.top(); |
| 73 | sceneGraphVisitedList.pop(); |
| 74 | |
| 75 | if ( node->isAncillary() ) |
| 76 | continue; // consider ancillary_ objects as temporary, not requiring saving |
| 77 | |
| 78 | auto [it, inserted] = uniqueObjectsModels.insert( { node } ); |
| 79 | if ( !inserted ) // object with the same model exists |
| 80 | { |
| 81 | // insert first met object |
| 82 | int numFile = countSharedFiles + 1; |
| 83 | auto [itFirst, insertedFirst] = links.insert( { it->object, { it->object, numFile } } ); |
| 84 | if ( insertedFirst ) |
| 85 | ++countSharedFiles; |
| 86 | else |
| 87 | numFile = itFirst->second.second; |
| 88 | |
| 89 | // map current object to first met object |
| 90 | links.insert( { node, { it->object, numFile } } ); |
| 91 | } |
| 92 | auto children = node->children(); |
| 93 | for ( int i = int( children.size() ) - 1; i >= 0; --i ) |
| 94 | { |
| 95 | sceneGraphVisitedList.push( children[i].get() ); |
| 96 | } |
| 97 | } |
| 98 | return countSharedFiles; |
| 99 | } |
| 100 | |
| 101 | } // anonymous namespace |
| 102 |