Skip to content
Snippets Groups Projects
Commit 727bc11e authored by Amorilia's avatar Amorilia
Browse files

* added GetParents() to get all parents of a block

* fixed skeleton root calculation
parent 49f18e13
No related branches found
No related tags found
No related merge requests found
...@@ -172,6 +172,13 @@ blk_ref ABlock::GetParent() const { ...@@ -172,6 +172,13 @@ blk_ref ABlock::GetParent() const {
return blk_ref(-1); return blk_ref(-1);
} }
list<blk_ref> ABlock::GetParents() const {
list<blk_ref> parents;
for (vector<IBlock *>::const_iterator it = _parents.begin(); it != _parents.end(); it++ )
parents.push_back(blk_ref(*it));
return parents;
}
void ABlock::Read( istream& in, unsigned int version ) { void ABlock::Read( istream& in, unsigned int version ) {
//Read Attributes //Read Attributes
......
...@@ -104,6 +104,7 @@ public: ...@@ -104,6 +104,7 @@ public:
//Links //Links
blk_ref GetParent() const; blk_ref GetParent() const;
list<blk_ref> GetParents() const;
list<blk_ref> GetLinks() const; list<blk_ref> GetLinks() const;
//Reference Counting //Reference Counting
......
...@@ -1218,21 +1218,45 @@ public: ...@@ -1218,21 +1218,45 @@ public:
// We want to get the closest common ancestor between the _owner and the bones // We want to get the closest common ancestor between the _owner and the bones
// So start with a list of ancestors of the first bone (this is just a random choice) // So start with a list of ancestors of the first bone (this is just a random choice)
blk_ref block = bones[0]; blk_ref block = bones[0];
blk_ref par = block->GetParent(); list<blk_ref> pars = block->GetParents();
blk_ref nodepar = blk_ref();
for ( list<blk_ref>::const_iterator it = pars.begin(); it != pars.end(); it++ )
if ( (*it)->GetBlockType() == "NiNode" ) {
nodepar = *it;
break;
};
list<blk_ref> bone_pars; list<blk_ref> bone_pars;
while ( par.is_null() == false ) { while ( nodepar.is_null() == false ) {
bone_pars.push_front(par); bone_pars.push_front(nodepar);
par = par->GetParent(); pars = nodepar->GetParents();
nodepar = blk_ref();
for ( list<blk_ref>::const_iterator it = pars.begin(); it != pars.end(); it++ )
if ( (*it)->GetBlockType() == "NiNode" ) {
nodepar = *it;
break;
};
}; };
// Now do the same with the owner. // Now do the same with the owner.
block = _owner; block = _owner->GetParent(); // TriShape
par = block->GetParent(); pars = block->GetParents();
nodepar = blk_ref();
for ( list<blk_ref>::const_iterator it = pars.begin(); it != pars.end(); it++ )
if ( (*it)->GetBlockType() == "NiNode" ) {
nodepar = *it;
break;
};
list<blk_ref> owner_pars; list<blk_ref> owner_pars;
while ( par.is_null() == false ) { while ( nodepar.is_null() == false ) {
owner_pars.push_front(par); owner_pars.push_front(nodepar);
par = par->GetParent(); pars = nodepar->GetParents();
nodepar = blk_ref();
for ( list<blk_ref>::const_iterator it = pars.begin(); it != pars.end(); it++ )
if ( (*it)->GetBlockType() == "NiNode" ) {
nodepar = *it;
break;
};
}; };
// Now find closest common ancestor. // Now find closest common NiNode ancestor.
if ( owner_pars.empty() || bone_pars.empty() ) if ( owner_pars.empty() || bone_pars.empty() )
throw runtime_error("Skinning instance has no common parent with the bones it refers to (invalid NIF file?). Cannot set skeleton root."); throw runtime_error("Skinning instance has no common parent with the bones it refers to (invalid NIF file?). Cannot set skeleton root.");
blk_ref skelroot; blk_ref skelroot;
......
...@@ -1310,6 +1310,26 @@ public: ...@@ -1310,6 +1310,26 @@ public:
*/ */
virtual blk_ref GetParent() const = 0; virtual blk_ref GetParent() const = 0;
/*!
* Used to retrieve all parents that are linked to this block.
* \return A list of block references to the parents that are linked to this block.
*
* <b>Example:</b>
* \code
* blk_ref my_block = ReadNifTree("test_in.nif");
* list<blk_ref> parents = my_block->GetParents();
* \endcode
*
* <b>In Python:</b>
* \code
* my_block = ReadNifTree("test_in.nif")
* parents = block.GetParents()
* \endcode
*
* \sa IAttr::Set(blk_ref const &), IAttr::AddLink, IAttr::AddLinks, IAttr::RemoveLinks, IAttr::ClearLinks
*/
virtual list<blk_ref> GetParents() const = 0;
/*! /*!
* Summarizes the information contained in this block in English. * Summarizes the information contained in this block in English.
* \return A string containing a summary of the information within the block in English. This is the function that Niflyze calls to generate its analysis, so the output is the same. * \return A string containing a summary of the information within the block in English. This is the function that Niflyze calls to generate its analysis, so the output is the same.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment