Beispiel #1
0
void ISoftBody::updateSoftBody()
{
    // Update the node position
    getWorldTransform();
    node->setPosition(worldTransform.getTranslation());
    node->setRotation(worldTransform.getRotationDegrees());

    // Update the vertices
    u32 cMeshBuffer;
    IMeshBuffer *mb;
    IMesh* collMesh = node->getMesh();
    s32 count = -1;

    for(cMeshBuffer=0; cMeshBuffer < 1; cMeshBuffer++)
    {
        mb = collMesh->getMeshBuffer(cMeshBuffer);

        updateMeshBuffer(mb, count);
        mb->recalculateBoundingBox();
    }
    // Update the normals so they're not messed up by the soft body calculations
    node->getSceneManager()->getMeshManipulator()->recalculateNormals(collMesh, false, false);
}
//! reads a mesh sections and creates a mesh buffer from it
IMeshBuffer* CIrrMeshFileLoader::readMeshBuffer(io::IXMLReader* reader)
{
	IMeshBuffer* buffer = 0;
	SMeshBuffer* sbuffer1 = 0;
	SMeshBufferLightMap* sbuffer2 = 0;
	SMeshBufferTangents* sbuffer3 = 0;

	core::stringc verticesSectionName = "vertices";
	core::stringc bbSectionName = "boundingBox";
	core::stringc materialSectionName = "material";
	core::stringc indicesSectionName = "indices";
	core::stringc bufferSectionName = "buffer";

	bool insideVertexSection = false;
	bool insideIndexSection = false;

	int vertexCount = 0;
	int indexCount = 0;

	video::SMaterial material;

	if (!reader->isEmptyElement())
	while(reader->read())
	{
		if (reader->getNodeType() == io::EXN_ELEMENT)
		{
			const wchar_t* nodeName = reader->getNodeName();
			if (bbSectionName == nodeName)
			{
				// inside a bounding box, ignore it for now because
				// we are calculating this anyway ourselves later.
			}
			else
			if (materialSectionName == nodeName)
			{
				//we've got a material

				io::IAttributes* attributes = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver());
				attributes->read(reader, true, L"material");

				SceneManager->getVideoDriver()->fillMaterialStructureFromAttributes(material, attributes);
				attributes->drop();
			}
			else
			if (verticesSectionName == nodeName)
			{
				// vertices section

				core::stringc vertexTypeName1 = "standard";
				core::stringc vertexTypeName2 = "2tcoords";
				core::stringc vertexTypeName3 = "tangents";

				const wchar_t* vertexType = reader->getAttributeValue(L"type");
				vertexCount = reader->getAttributeValueAsInt(L"vertexCount");

				insideVertexSection = true;

				if (vertexTypeName1 == vertexType)
				{
					sbuffer1 = new SMeshBuffer();
					sbuffer1->Vertices.reallocate(vertexCount);
					sbuffer1->Material = material;
					buffer = sbuffer1;
				}
				else
				if (vertexTypeName2 == vertexType)
				{
					sbuffer2 = new SMeshBufferLightMap();
					sbuffer2->Vertices.reallocate(vertexCount);
					sbuffer2->Material = material;
					buffer = sbuffer2;
				}
				else
				if (vertexTypeName3 == vertexType)
				{
					sbuffer3 = new SMeshBufferTangents();
					sbuffer3->Vertices.reallocate(vertexCount);
					sbuffer3->Material = material;
					buffer = sbuffer3;
				}
			}
			else
			if (indicesSectionName == nodeName)
			{
				// indices section

				indexCount = reader->getAttributeValueAsInt(L"indexCount");
				insideIndexSection = true;
			}

		} // end if node type is element
		else
		if (reader->getNodeType() == io::EXN_TEXT)
		{
			// read vertex data
			if (insideVertexSection)
			{
				if (sbuffer1)
					readMeshBuffer(reader, vertexCount, sbuffer1);
				else
				if (sbuffer2)
					readMeshBuffer(reader, vertexCount, sbuffer2);
				else
				if (sbuffer3)
					readMeshBuffer(reader, vertexCount, sbuffer3);

				insideVertexSection = false;

			} // end reading vertex array
			else
			if (insideIndexSection)
			{
				if (sbuffer1)
					readIndices(reader, indexCount, sbuffer1->Indices);
				else
				if (sbuffer2)
					readIndices(reader, indexCount, sbuffer2->Indices);
				else
				if (sbuffer3)
					readIndices(reader, indexCount, sbuffer3->Indices);

				insideIndexSection = false;
			}

		} // end if node type is text
		else
		if (reader->getNodeType() == io::EXN_ELEMENT_END)
		{
			if (bufferSectionName == reader->getNodeName())
			{
				// end of buffer section reached, cancel out
				break;
			}
		}
	} // end while reader->read();

	if (buffer)
		buffer->recalculateBoundingBox();

	return buffer;
}