I made some code to try to replace the Export Node or SaveXML parsing through a scene. So far the output is as follows.
Any help is appreciated? I should be able to loadXML with the output since Editor.as is written in Angelscript directly linking the Save XML(Differiental) will not happen soon unless a c/c++ editor becomes available.
Source code in github.com/vivienneanthony/Exis … enceClient as manager.cpp and manager.cpp
[code]/// Main Save scene
int Manager::SaveScene(int mode)
{
/// Check if scene exist
if(scene_==NULL)
{
return 1;
}
String savesceneexport;
ResourceCache * cache = GetSubsystem<ResourceCache>();
FileSystem * filesystem = GetSubsystem<FileSystem>();
savesceneexport.Append(filesystem->GetProgramDir().CString());
savesceneexport.Append("CoreData/");
savesceneexport.Append("testing.xml");
File saveFile(context_, savesceneexport.CString(), FILE_WRITE);
/// Check if the account file information exist
if(!filesystem->FileExists(savesceneexport.CString()))
{
//cout << "\r\nAccount file ("<< savesceneexport.CString() << ") does not exist.";
}
XMLFile * savesceneexportxml= new XMLFile(context_);
XMLElement configElem = savesceneexportxml-> CreateRoot("node");
/// point
unsigned int childrencount=scene_->GetNumChildren();
cout << childrencount << endl;
children_ = scene_->GetChildren();
/// loop each child
for (Vector<SharedPtr<Node> >::Iterator i = children_.Begin(); i != children_.End(); ++i)
{
/// Create a new child instance
Node* childnode = *i;
/// Get node infomration, check for children, and check components
if((childnode->GetName().Find("Generated",0,false)==String::NPOS)
&&(childnode->GetName().Find("Character",0,false)==String::NPOS)
&&(childnode->GetName().Find("Camera",0,false)==String::NPOS))
{
XMLElement NodeElement = configElem. CreateChild ("node");
// set virtual const
const Vector<AttributeInfo>* attributes = childnode->GetAttributes();
/// loop through attributes
for (Vector<AttributeInfo>::ConstIterator i = attributes->Begin(); i != attributes->End(); ++i)
{
XMLElement AttributeElement = NodeElement. CreateChild ("attribute");
AttributeElement.SetAttribute ("name", i -> name_);
AttributeElement.SetAttribute ("value", i -> defaultValue_.ToString());
}
if(childnode->GetNumChildren())
{
SaveSceneNode(childnode);
}
else
{
SaveSceneNodeComponents(childnode);
}
}
}
savesceneexportxml->Save(saveFile);
}
/// Recursive
int Manager::SaveSceneNode(Node * node)
{
/// Define a temporary pointer
Vector<SharedPtr > subchildren_;
/// Get children node
subchildren_ = node->GetChildren();
for (Vector<SharedPtr<Node> >::Iterator i = subchildren_.Begin(); i != subchildren_.End(); ++i)
{
/// Create a new child instance
Node* childnode = *i;
/// Get node infomration, check for children, and check components
if(childnode->GetName().Find("Generated",0,false)==String::NPOS)
{
///cout << "SubNode :" << childnode->GetName().CString() <<endl;
XMLElement NodeElement = configElem. CreateChild ("node");
if(childnode->GetNumChildren())
{
SaveSceneNode(childnode);
}
else
{
SaveSceneNodeComponents(childnode);
}
}
}
}
int Manager::SaveSceneNodeComponents(Node *node)
{
/// Define temporary pointer for components
Vector< SharedPtr< Component > > subcomponents_;
/// If node has no components
if(node-> GetNumComponents ()==0)
{
cout << " Node has no components" << endl;
return 1;
}
/// Get children node
subcomponents_ = node->GetComponents();
/// Loop through components
for (Vector<SharedPtr<Component> >::Iterator i = subcomponents_.Begin(); i != subcomponents_.End(); ++i)
{
Component * subcomponent = *i;
XMLElement componentElement = configElem.CreateChild ("component");
componentElement.SetAttribute("Type", subcomponent->GetTypeName());
/// READ EACH COMPONENT AND GET ATTRIBUTES
if(subcomponent->GetNumAttributes ())
{
/// set virtual const
const Vector<AttributeInfo>* attributes = subcomponent->GetAttributes();
/// loop through attributes
for (Vector<AttributeInfo>::ConstIterator i = attributes->Begin(); i != attributes->End(); ++i)
{
/// output info
///cout << i -> name_.CString() << " type " << i -> defaultValue_. GetTypeName ().CString() <<" value " << i -> defaultValue_.ToString().CString()<< endl;
XMLElement AttributeElement = configElem. CreateChild ("attribute");
AttributeElement.SetAttribute ("name", i -> name_);
AttributeElement.SetAttribute ("value", i -> defaultValue_.ToString());
}
}
}
return 1;
}[/code]
The output is
<?xml version="1.0"?>
<node>
<node>
<attribute name="Is Enabled" value="true" />
<attribute name="Name" value="" />
<attribute name="Position" value="0 0 0" />
<attribute name="Rotation" value="1 0 0 0" />
<attribute name="Scale" value="1 1 1" />
<attribute name="Variables" value="" />
<attribute name="Network Position" value="0 0 0" />
<attribute name="Network Rotation" value="" />
<attribute name="Network Parent Node" value="" />
</node>
<node>
<attribute name="Is Enabled" value="true" />
<attribute name="Name" value="" />
<attribute name="Position" value="0 0 0" />
<attribute name="Rotation" value="1 0 0 0" />
<attribute name="Scale" value="1 1 1" />
<attribute name="Variables" value="" />
<attribute name="Network Position" value="0 0 0" />
<attribute name="Network Rotation" value="" />
<attribute name="Network Parent Node" value="" />
</node>
</node>
I’m trying to get output similiar to
<?xml version="1.0"?>
<node id="16777249">
<attribute name="Is Enabled" value="true" />
<attribute name="Name" value="" />
<attribute name="Position" value="-0.012422 0.460372 0.00271687" />
<attribute name="Rotation" value="1 1.30976e-06 0.000361086 6.60281e-07" />
<attribute name="Scale" value="1 1 1" />
<attribute name="Variables" />
<component type="RigidBody" id="16777277">
<attribute name="Physics Rotation" value="1 1.30991e-06 0.000361086 6.34012e-07" />
<attribute name="Physics Position" value="-0.012422 0.460372 0.00271687" />
</component>
<component type="CollisionShape" id="16777278">
<attribute name="Size" value="1.1 1.3 3.95" />
<attribute name="Offset Position" value="0 0.13 0.3" />
</component>
<node id="16777236">
<attribute name="Is Enabled" value="true" />
<attribute name="Name" value="" />
<attribute name="Position" value="0 0 0" />
<attribute name="Rotation" value="1 0 0 0" />
<attribute name="Scale" value="1 1 1" />
<attribute name="Variables" />
<component type="StaticModel" id="16777257">
<attribute name="Model" value="Model;Models/airbikefoils.mdl" />
<attribute name="Material" value="Material;Materials/airbike.colorbase.xml" />
<attribute name="Cast Shadows" value="true" />
</component>
</node>
</node>