void dRigidbodyNodeInfo::Serialize (TiXmlElement* const rootNode) const
{
    SerialiseBase(dNodeInfo, rootNode);

    char tmp[1024];

    TiXmlElement* dataNode = new TiXmlElement ("transform");
    rootNode->LinkEndChild(dataNode);

    dataNode = new TiXmlElement ("centerOfMass");
    rootNode->LinkEndChild(dataNode);
    dFloatArrayToString (&m_centerOfMass[0], 4, tmp, sizeof (tmp));
    dataNode->SetAttribute("float4", tmp);

    dataNode = new TiXmlElement ("massMatrix");
    rootNode->LinkEndChild(dataNode);
    dFloatArrayToString (&m_massMatrix[0], 4, tmp, sizeof (tmp));
    dataNode->SetAttribute("float4", tmp);

    dataNode = new TiXmlElement ("velocity");
    rootNode->LinkEndChild(dataNode);
    dFloatArrayToString (&m_velocity[0], 4, tmp, sizeof (tmp));
    dataNode->SetAttribute("float4", tmp);

    dataNode = new TiXmlElement ("omega");
    rootNode->LinkEndChild(dataNode);
    dFloatArrayToString (&m_omega[0], 4, tmp, sizeof (tmp));
    dataNode->SetAttribute("float4", tmp);

    dataNode = new TiXmlElement ("internalDamp");
    rootNode->LinkEndChild(dataNode);
    dFloatArrayToString (&m_internalDamp[0], 4, tmp, sizeof (tmp));
    dataNode->SetAttribute("float4", tmp);
}
Esempio n. 2
0
void dLineNodeInfo::Serialize (TiXmlElement* const rootNode) const
{
	SerialiseBase(dGeometryNodeInfo, rootNode);

	TiXmlElement* const bezierCurve = new TiXmlElement ("dBezierSpline");
	rootNode->LinkEndChild (bezierCurve);

	bezierCurve->SetAttribute("degree", m_curve.GetDegree());

	int pointCount = m_curve.GetControlPointCount();
	const dBigVector* const controlPoints = m_curve.GetControlPointArray();
	int bufferSizeInBytes = pointCount * sizeof (dVector) * 3;
	char* const buffer = new char[bufferSizeInBytes];
	dFloatArrayToString (&controlPoints[0][0], pointCount * sizeof (dBigVector) / sizeof (dFloat), buffer, bufferSizeInBytes);

	TiXmlElement* const ctrlPoints = new TiXmlElement ("controlPoints");
	bezierCurve->LinkEndChild (ctrlPoints);
	ctrlPoints->SetAttribute("float4", pointCount);
	ctrlPoints->SetAttribute("floats", buffer);

	int knotCount = m_curve.GetKnotCount();
	const dFloat64* const knotPoints = m_curve.GetKnotArray();
	int buffer1SizeInBytes = knotCount * sizeof (dFloat) * 3;
	char* const buffer1 = new char[buffer1SizeInBytes];
	dFloatArrayToString (knotPoints, knotCount, buffer1, buffer1SizeInBytes);

	TiXmlElement* const knotVector = new TiXmlElement ("knotVector");
	bezierCurve->LinkEndChild (knotVector);
	knotVector->SetAttribute("float", knotCount);
	knotVector->SetAttribute("floats", buffer1);

	delete[] buffer;
	delete[] buffer1;
}
void dMaterialNodeInfo::Serialize (TiXmlElement* const rootNode) 
{
	SerialiseBase(dNodeInfo, rootNode);

	char buffer[4096];

//	itoa64____ (m_id, id, 10);
//	rootNode->SetAttribute("id", id);
	rootNode->SetAttribute("id", m_id);

//	char id[256];
	TiXmlElement* const ambient = new TiXmlElement ("ambient");
	rootNode->LinkEndChild(ambient);
	dFloatArrayToString(&m_ambientColor[0], 4, buffer, sizeof (buffer));

	//itoa64____ (m_ambientTexId, id, 10);
	dString id (m_ambientTexId);
	ambient->SetAttribute("textureId", id.GetStr());
	ambient->SetAttribute("color", buffer);

	TiXmlElement* const diffuse = new TiXmlElement ("diffuse");
	rootNode->LinkEndChild(diffuse);
	dFloatArrayToString(&m_diffuseColor[0], 4, buffer, sizeof (buffer));

	//itoa64____ (m_diffuseTexId, id, 10);
	id = dString (m_diffuseTexId);
	diffuse->SetAttribute("textureId", id.GetStr());
	diffuse->SetAttribute("color", buffer);

	TiXmlElement* const specular = new TiXmlElement ("specular");
	rootNode->LinkEndChild(specular);
	dFloatArrayToString(&m_specularColor[0], 4, buffer, sizeof (buffer));

	//itoa64____ (m_specularTexId, id, 10);
	id =  dString (m_specularTexId);
	specular->SetAttribute("textureId", id.GetStr());
	specular->SetAttribute("color", buffer);

	TiXmlElement* const emissive = new TiXmlElement ("emissive");
	rootNode->LinkEndChild(emissive);
	dFloatArrayToString(&m_emissiveColor[0], 4, buffer, sizeof (buffer));

	//itoa64____ (m_emissiveTexId, id, 10);
	id =  dString (m_emissiveTexId);
	emissive->SetAttribute("textureId", id.GetStr());
	emissive->SetAttribute("color", buffer);

	TiXmlElement* const shininess = new TiXmlElement ("shininess");
	rootNode->LinkEndChild(shininess);
	shininess->SetDoubleAttribute ("float", m_shininess);

	TiXmlElement* const opacity = new TiXmlElement ("opacity");
	rootNode->LinkEndChild(opacity);
	opacity->SetDoubleAttribute ("float", m_opacity);
}
Esempio n. 4
0
void dCollisionBoxNodeInfo::Serialize (TiXmlElement* rootNode) const
{
	SerialiseBase(dCollisionNodeInfo, rootNode);

	char tmp[1024];
	TiXmlElement* dataNode = new TiXmlElement ("size");
	rootNode->LinkEndChild(dataNode);
	dFloatArrayToString (&m_size[0], 4, tmp, sizeof (tmp));
	dataNode->SetAttribute("float4", tmp);
}
void dGeometryNodeInfo::Serialize (TiXmlElement* const rootNode) const 
{
	SerialiseBase(dNodeInfo, rootNode);

	char matrixText[32 * 16];

	TiXmlElement* matrix = new TiXmlElement ("pivotMatrix");
	rootNode->LinkEndChild(matrix);
	dFloatArrayToString (&m_matrix[0][0], 16, matrixText, sizeof (matrixText));
	matrix->SetAttribute("float16", matrixText);
}
Esempio n. 6
0
void dMeshNodeInfo::Serialize (TiXmlElement* rootNode) const
{

 	SerialiseBase(dGeometryNodeInfo, rootNode);

	TiXmlElement* pointElement = new TiXmlElement ("points");
	rootNode->LinkEndChild(pointElement);

	int bufferCount = max (NewtonMeshGetVertexCount(m_mesh), NewtonMeshGetPointCount(m_mesh));
	char* buffer = new char[bufferCount * sizeof (dFloat) * 4 * 12];
	dFloat* packVertex = new dFloat [4 * bufferCount];

	int vertexCount = NewtonMeshGetVertexCount (m_mesh); 
	int vertexStride = NewtonMeshGetVertexStrideInByte(m_mesh) / sizeof (dFloat);
	const dFloat* const vertex = NewtonMeshGetVertexArray(m_mesh); 

	// pack the vertex Array
	int* vertexIndexList = new int [vertexCount];
	for (int i = 0; i < vertexCount; i ++) {
		packVertex[i * 4 + 0] = vertex[i * vertexStride + 0];
		packVertex[i * 4 + 1] = vertex[i * vertexStride + 1];
		packVertex[i * 4 + 2] = vertex[i * vertexStride + 2];
		packVertex[i * 4 + 3] = vertex[i * vertexStride + 3];
		vertexIndexList[i] = i;
	}
	dFloatArrayToString (packVertex, vertexCount * 4, buffer, vertexCount * sizeof (dFloat) * 4 * 12);
	
	TiXmlElement* position = new TiXmlElement ("position");
	pointElement->LinkEndChild(position);
	position->SetAttribute("float4", vertexCount);
	position->SetAttribute("floats", buffer);

	// pack the normal array
	int pointCount = NewtonMeshGetPointCount (m_mesh); 
	int pointStride = NewtonMeshGetPointStrideInByte(m_mesh) / sizeof (dFloat);
	const dFloat* const normals = NewtonMeshGetNormalArray(m_mesh); 
	int* normalIndexList = new int [pointCount];
	for (int i = 0; i < pointCount; i ++) {
		packVertex[i * 3 + 0] = normals[i * pointStride + 0];
		packVertex[i * 3 + 1] = normals[i * pointStride + 1];
		packVertex[i * 3 + 2] = normals[i * pointStride + 2];
	}
	int count = dPackVertexArray (packVertex, 3, 3 * sizeof (dFloat), pointCount, normalIndexList);
	dFloatArrayToString (packVertex, count * 3, buffer, pointCount * sizeof (dFloat) * 3 * 12);

	TiXmlElement* normal = new TiXmlElement ("normal");
	pointElement->LinkEndChild(normal);
	normal->SetAttribute("float3", count);
	normal->SetAttribute("floats", buffer);

	// pack the uv0 array
	int* uv0IndexList = new int [pointCount];
	const dFloat* const uv0s = NewtonMeshGetUV0Array(m_mesh); 
	for (int i = 0; i < pointCount; i ++) {
		packVertex[i * 3 + 0] = uv0s[i * pointStride + 0];
		packVertex[i * 3 + 1] = uv0s[i * pointStride + 1];
		packVertex[i * 3 + 2] = 0.0f;
	}
	count = dPackVertexArray (packVertex, 3, 3 * sizeof (dFloat), pointCount, uv0IndexList);
	for (int i = 0; i < pointCount; i ++) {
		packVertex[i * 2 + 0] = packVertex[i * 3 + 0];
		packVertex[i * 2 + 1] = packVertex[i * 3 + 1];
	}
	dFloatArrayToString (packVertex, count * 2, buffer, pointCount * sizeof (dFloat) * 3 * 12);

	TiXmlElement* uv0 = new TiXmlElement ("uv0");
	pointElement->LinkEndChild(uv0);
	uv0->SetAttribute("float2", count);
	uv0->SetAttribute("floats", buffer);

	// pack the uv1 array
	int* uv1IndexList = new int [pointCount];
	const dFloat* const uv1s = NewtonMeshGetUV1Array(m_mesh); 
	for (int i = 0; i < pointCount; i ++) {
		packVertex[i * 3 + 0] = uv1s[i * pointStride + 0];
		packVertex[i * 3 + 1] = uv1s[i * pointStride + 1];
		packVertex[i * 3 + 2] = 0.0f;
	}
	count = dPackVertexArray (packVertex, 3, 3 * sizeof (dFloat), pointCount, uv1IndexList);
	for (int i = 0; i < pointCount; i ++) {
		packVertex[i * 2 + 0] = packVertex[i * 3 + 0];
		packVertex[i * 2 + 1] = packVertex[i * 3 + 1];
	}
	dFloatArrayToString (packVertex, count * 2, buffer, pointCount * sizeof (dFloat) * 3 * 12);

	TiXmlElement* uv1 = new TiXmlElement ("uv1");
	pointElement->LinkEndChild(uv1);
	uv1->SetAttribute("float2", count);
	uv1->SetAttribute("floats", buffer);

	// save the polygon array
	int faceCount = NewtonMeshGetTotalFaceCount (m_mesh); 
	int indexCount = NewtonMeshGetTotalIndexCount (m_mesh); 

	int* faceArray = new int [faceCount];
	void** indexArray = new void* [indexCount];
	int* materialIndexArray = new int [faceCount];
	int* remapedIndexArray = new int [indexCount];

	NewtonMeshGetFaces (m_mesh, faceArray, materialIndexArray, indexArray); 

	// save the faces vertex Count
	dIntArrayToString (faceArray, faceCount, buffer, pointCount * sizeof (dFloat) * 3 * 12);
	TiXmlElement* polygons = new TiXmlElement ("polygons");
	rootNode->LinkEndChild(polygons);
	polygons->SetAttribute("count", faceCount);
	polygons->SetAttribute("faceIndexCount", buffer);

	dIntArrayToString (materialIndexArray, faceCount, buffer, pointCount * sizeof (dFloat) * 3 * 12);
	TiXmlElement* faceMaterial = new TiXmlElement ("faceMaterial");
	polygons->LinkEndChild(faceMaterial);
	faceMaterial->SetAttribute("index", buffer);

	for (int i = 0; i < indexCount; i ++) {
//		void* face = indexArray[i];
		int index = NewtonMeshGetVertexIndex (m_mesh, indexArray[i]);
		remapedIndexArray[i] = vertexIndexList[index];
	}
	dIntArrayToString (remapedIndexArray, indexCount, buffer, pointCount * sizeof (dFloat) * 3 * 12);
	TiXmlElement* positionIndex = new TiXmlElement ("position");
	polygons->LinkEndChild(positionIndex);
	positionIndex->SetAttribute("index", buffer);


	for (int i = 0; i < indexCount; i ++) {
//		int index = indexArray[i];
		int index = NewtonMeshGetPointIndex(m_mesh, indexArray[i]);
		remapedIndexArray[i] = normalIndexList[index];
	}
	dIntArrayToString (remapedIndexArray, indexCount, buffer, pointCount * sizeof (dFloat) * 3 * 12);
	TiXmlElement* normalIndex = new TiXmlElement ("normal");
	polygons->LinkEndChild(normalIndex);
	normalIndex->SetAttribute("index", buffer);


	for (int i = 0; i < indexCount; i ++) {
//		int index = indexArray[i];
		int index = NewtonMeshGetPointIndex(m_mesh, indexArray[i]);
		remapedIndexArray[i] = uv0IndexList[index];
	}
	dIntArrayToString (remapedIndexArray, indexCount, buffer, pointCount * sizeof (dFloat) * 3 * 12);
	TiXmlElement* uv0Index = new TiXmlElement ("uv0");
	polygons->LinkEndChild(uv0Index);
	uv0Index->SetAttribute("index", buffer);


	for (int i = 0; i < indexCount; i ++) {
//		int index = indexArray[i];
		int index = NewtonMeshGetPointIndex(m_mesh, indexArray[i]);
		remapedIndexArray[i] = uv1IndexList[index];
	}
	dIntArrayToString (remapedIndexArray, indexCount, buffer, pointCount * sizeof (dFloat) * 3 * 12);
	TiXmlElement* uv1Index = new TiXmlElement ("uv1");
	polygons->LinkEndChild(uv1Index);
	uv1Index->SetAttribute("index", buffer);

	delete[] remapedIndexArray;
	delete[] faceArray;
	delete[] indexArray;
	delete[] materialIndexArray;
	delete[] uv1IndexList;
	delete[] uv0IndexList;
	delete[] normalIndexList;
	delete[] vertexIndexList;
	delete[] packVertex;
	delete[] buffer;
}