Esempio n. 1
0
/**
 * Creates XML objects for all the bones in a skeleton.
 **/
void IO::saveBones(TiXmlElement *parent, vector<Bone *> *bones,
	vector<Joint *> *joints, vector<Vertex *> *vertices)
{
	TiXmlElement *bonesXML = new TiXmlElement("bones");
	parent->LinkEndChild(bonesXML);

	vector<Bone *>::iterator i = bones->begin();
	for (; i < bones->end(); i++)
	{
		Bone *b = *i;
		TiXmlElement *boneXML = new TiXmlElement("bone");
		const char *name = b->getName();
		if (name[0] != 0) // save name only for named bones
			boneXML->SetAttribute("name", name);
		// find vertex indices in mesh and set attributes
		boneXML->SetAttribute("j0",
			index(joints->begin(), joints->end(), b->j0));
		boneXML->SetAttribute("j1",
			index(joints->begin(), joints->end(), b->j1));
		boneXML->SetDoubleAttribute("stiffness", b->damp);
		boneXML->SetDoubleAttribute("lm", b->getLengthMult());
		boneXML->SetDoubleAttribute("lmmin", b->getLengthMultMin());
		boneXML->SetDoubleAttribute("lmmax", b->getLengthMultMax());
		boneXML->SetDoubleAttribute("tempo", b->getTempo());
		boneXML->SetDoubleAttribute("time", b->getTime());
		boneXML->SetDoubleAttribute("size", b->getOrigSize());
		boneXML->SetAttribute("selected", b->selected);
		boneXML->SetDoubleAttribute("radius", b->getRadiusMult());

		bonesXML->LinkEndChild(boneXML);

		// save attached vertices
		float *dsts, *weights, *ca, *sa;
		vector<Vertex *> *attachedVertices =
			b->getAttachedVertices(&dsts, &weights, &ca, &sa);
		int count = attachedVertices->size();
		if (!count) // no vertices attached
			continue;
		TiXmlElement *attachedXML = new TiXmlElement("attached");
		boneXML->LinkEndChild(attachedXML);
		for (int j = 0; j < count; j++)
		{
			Vertex *v = (*attachedVertices)[j];
			TiXmlElement *vertexXML = new TiXmlElement("vertex");
			// find and set vertex index
			vertexXML->SetAttribute("id",
			 index(vertices->begin(), vertices->end(), v));
			vertexXML->SetDoubleAttribute("d", dsts[j]);	// distance
			vertexXML->SetDoubleAttribute("w", weights[j]); // weight
			vertexXML->SetDoubleAttribute("ca", ca[j]); // cosinus
			vertexXML->SetDoubleAttribute("sa", sa[j]); // sinus
			attachedXML->LinkEndChild(vertexXML);
		}
	}
}