Skip to content
Snippets Groups Projects
Commit b03bfcdc authored by Shon Ferguson's avatar Shon Ferguson
Browse files

Automated NiSkinInstance Skeleton Root attribute and AController Target Node...

Automated NiSkinInstance Skeleton Root attribute and AController Target Node attribute.  All back references should now be automatic.
parent 7fe90af9
No related branches found
No related tags found
No related merge requests found
...@@ -114,8 +114,8 @@ void ABlock::AddAttr( string type, string name ) { ...@@ -114,8 +114,8 @@ void ABlock::AddAttr( string type, string name ) {
attr = new MipMapFormatAttr( name, this ); attr = new MipMapFormatAttr( name, this );
} else if ( type == "alphaformat" ) { } else if ( type == "alphaformat" ) {
attr = new AlphaFormatAttr( name, this ); attr = new AlphaFormatAttr( name, this );
} else if ( type == "parent" ) { } else if ( type == "nodeancestor" ) {
attr = new ParentAttr( name, this ); attr = new NodeAncestorAttr( name, this );
} else if ( type == "root" ) { } else if ( type == "root" ) {
attr = new RootAttr( name, this ); attr = new RootAttr( name, this );
} else { } else {
......
...@@ -200,7 +200,7 @@ public: ...@@ -200,7 +200,7 @@ public:
AddAttr( "float", "Phase" ); AddAttr( "float", "Phase" );
AddAttr( "float", "Start Time" ); AddAttr( "float", "Start Time" );
AddAttr( "float", "Stop Time" ); AddAttr( "float", "Stop Time" );
AddAttr( "int", "Target Node" ); AddAttr( "nodeancestor", "Target Node" );
} }
~AController() {} ~AController() {}
}; };
...@@ -976,7 +976,7 @@ class NiSkinInstance : public ABlock, public ISkinInstInternal { ...@@ -976,7 +976,7 @@ class NiSkinInstance : public ABlock, public ISkinInstInternal {
NiSkinInstance(){ NiSkinInstance(){
AddAttr( "index", "Data" ); AddAttr( "index", "Data" );
AddAttr( "int", "Skeleton Root" ); AddAttr( "root", "Skeleton Root" );
AddAttr( "bones", "Bones" ); AddAttr( "bones", "Bones" );
} }
~NiSkinInstance(){} ~NiSkinInstance(){}
......
...@@ -1195,29 +1195,48 @@ private: ...@@ -1195,29 +1195,48 @@ private:
int data; int data;
}; };
class ParentAttr : public AAttr { class NodeAncestorAttr : public AAttr {
public: public:
ParentAttr( string name, IBlock * owner ) : AAttr(name, owner) {} NodeAncestorAttr( string name, IBlock * owner ) : AAttr(name, owner) {}
~ParentAttr() {} ~NodeAncestorAttr() {}
string GetType() const { return "parent"; } string GetType() const { return "nodeancestor"; }
void Read( ifstream& in ) { void Read( ifstream& in ) {
ReadUInt(in); //Read data but do nothing with it ReadUInt(in);
//_owner->SetParent( blk_ref(ReadUInt(in)) );
} }
void Write( ofstream& out ) { void Write( ofstream& out ) {
WriteUInt( _owner->GetParent()->GetBlockNum(), out ); WriteUInt( _owner->GetParent()->GetBlockNum(), out );
} }
blk_ref FindNodeAncestor() const {
//Find first ancestor that is a node
blk_ref block(_owner);
blk_ref par;
while ( true ) {
//Get parent
par = block->GetParent();
//If parent is null, we're done - there are no node ancestors so return a null reference
if (par.is_null() == true)
return blk_ref(-1);
//If parent is a node, return it
if ( QueryNode(par) != NULL ) {
return par;
}
//We didn't find a node this time, set block to par and try again
block = par;
}
}
string asString() const { string asString() const {
stringstream out; stringstream out;
out.setf(ios::fixed, ios::floatfield); out.setf(ios::fixed, ios::floatfield);
out << setprecision(1); out << setprecision(1);
out << _owner->GetParent(); out << FindNodeAncestor();
return out.str(); return out.str();
} }
private: blk_ref asLink() const { return FindNodeAncestor(); }
IBlock * _owner;
}; };
class RootAttr : public AAttr { class RootAttr : public AAttr {
...@@ -1232,11 +1251,30 @@ public: ...@@ -1232,11 +1251,30 @@ public:
WriteUInt( FindRoot().get_index(), out ); WriteUInt( FindRoot().get_index(), out );
} }
blk_ref FindRoot() const { blk_ref FindRoot() const {
blk_ref itr = _owner; //Find Skeleton Root - first node in ancestry that has 'not a skin influence' flag set
while ( itr.is_null() == false ) { blk_ref block(_owner);
itr = itr->GetParent(); blk_ref par;
int flags;
while ( true ) {
//Get parent
par = block->GetParent();
//If parent is null, we're done - every node is an influence or there are no nodes
//Probably shouldn't happen
if (par.is_null() == true)
return block;
//If parent is a node and its 'not a skin influence' flag is set, it is the root for this skeleton
if ( QueryNode(par) != NULL ) {
flags = par->GetAttr("Flags")->asInt();
if ( (flags & 8) == 1 )
return par;
}
//We didn't find the root this time, set block to par and try again
block = par;
} }
return itr;
} }
string asString() const { string asString() const {
stringstream out; stringstream out;
...@@ -1249,8 +1287,7 @@ public: ...@@ -1249,8 +1287,7 @@ public:
return out.str(); return out.str();
} }
private: blk_ref asLink() const { return FindRoot(); }
IBlock * _owner;
}; };
#endif #endif
\ No newline at end of file
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