예제 #1
0
/*************************************
	BucketIndexSet File Layout
	{
	PVRTBoundingBox2D boundingbox;
	CHECKPOINT
	unsigned int  bucketindex;
	CHECKPOINT
	IndexSet      indexset;
	CHECKPOINT
	};
*************************************/
void writeBucketIndexSet(std::ofstream &file, const PVRTBucketIndexSet &indexset)
{	
	file.write((const char*)&indexset.bucketindex, sizeof(indexset.bucketindex));
	writeSecurityCheckpoint(file);
	writeBoundingBox(file, indexset.boundingbox);
	writeSecurityCheckpoint(file);
	writeRenderIndexSet(file, indexset.indexset);
	writeSecurityCheckpoint(file);
}
//! writes a mesh
bool CIrrMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags)
{
	if (!file)
		return false;

	Writer = FileSystem->createXMLWriter(file);

	if (!Writer)
	{
		os::Printer::log("Could not write file", file->getFileName());
		return false;
	}

	os::Printer::log("Writing mesh", file->getFileName());

	// write IRR MESH header

	Writer->writeXMLHeader();

	Writer->writeElement(L"mesh", false,
		L"xmlns", L"http://irrlicht.sourceforge.net/IRRMESH_09_2007",
		L"version", L"1.0");
	Writer->writeLineBreak();

	// add some informational comment. Add a space after and before the comment
	// tags so that some braindead xml parsers (AS anyone?) are able to parse this too.

	core::stringw infoComment = L" This file contains a static mesh in the Irrlicht Engine format with ";
	infoComment += core::stringw(mesh->getMeshBufferCount());
	infoComment += L" materials.";

	Writer->writeComment(infoComment.c_str());
	Writer->writeLineBreak();

	// write mesh bounding box

	writeBoundingBox(mesh->getBoundingBox());
	Writer->writeLineBreak();

	// write mesh buffers

	for (int i=0; i<(int)mesh->getMeshBufferCount(); ++i)
	{
		scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i);
		if (buffer)
		{
			writeMeshBuffer(buffer);
			Writer->writeLineBreak();
		}
	}

	Writer->writeClosingTag(L"mesh");

	Writer->drop();
	return true;
}
예제 #3
0
/*************************************
    MapLayer File layout
	{
	VERSION
	PVRTBoundingBox2D      boundingbox;
	CHECKPOINT
	PVRTCoordinateVector   coordinates;	
	CHECKPOINT
	PVRTIndexSet           indexset
	CHECKPOINT
	};
*************************************/
bool writeMapLayer(const char *pszFilename, const PVRTMapLayer &layer)
{
	ofstream file(pszFilename, ios::binary);
	if (!file.is_open())
		return false;
	
	writeVersion(file);
	writeBoundingBox(file, layer.boundingbox);
	writeSecurityCheckpoint(file);
	writeVector<PVRTVertex>(file, layer.coordinates);
	writeSecurityCheckpoint(file);
	writeIndexSet(file, layer.indexset);	
	writeSecurityCheckpoint(file);
	
	file.close();
	return true;
}
예제 #4
0
/*************************************
	BucketMapLayer File layout
	{
	VERSION
	PVRTBoundingBox2D          boundingbox;
	CHECKPOINT
	PVRTCoordinateBucketVector coordinatebuckets;
	CHECKPOINT	
	PVRTBucketIndexSetVector   bucketindexsets;
	CHECKPOINT
	};
*************************************/
bool writeBucketMapLayer(const char *pszFilename, const PVRTBucketMapLayer &layer)
{
	ofstream file(pszFilename, ios::binary);
	if (!file.is_open())
		return false;
	
	writeVersion(file);
	writeBoundingBox(file, layer.boundingbox);
	writeSecurityCheckpoint(file);
	
	if (!writeCoordinateBucketVector(file, layer.coordinatebuckets)) return false;
	writeSecurityCheckpoint(file);
	writeBucketIndexSetVector(file, layer.bucketindexsets);
	writeSecurityCheckpoint(file);
		
	file.close();
	return true;
}
예제 #5
0
bool writeCoordinateBucket(std::ofstream &file, const PVRTCoordinateBucket &bucket)
{	
	writeBoundingBox(file, bucket.boundingbox);
	writeSecurityCheckpoint(file);
	
	if ((bucket.coordinates.size() > 0) && (bucket.pivotquads.size() > 0))
	{
		// Only one should contain data
		return false;
	}
	else if (bucket.coordinates.size() > 0)
	{
		// TODO test 2d coordinates
		vector<PVRTVertex2> coords2d;
		coords2d.resize(bucket.coordinates.size());

		for (unsigned int i=0; i < bucket.coordinates.size(); i++)
		{
			coords2d[i].position.x = bucket.coordinates[i].position.x;
			coords2d[i].position.y = bucket.coordinates[i].position.y;
			
			//coords2d[i].u = (PVRTint16)(bucket.coordinates[i].texcoord.x * 32768.0f);
			//coords2d[i].v = (PVRTint16)(bucket.coordinates[i].texcoord.y * 32768.0f);
			coords2d[i].u = bucket.coordinates[i].texcoord.x;
			coords2d[i].v = bucket.coordinates[i].texcoord.y;
		}

		//writeRawVector<PVRTVertex>(file, bucket.coordinates);
		writeRawVector<PVRTVertex2>(file, coords2d);
		writeSecurityCheckpoint(file);
	}
	else if (bucket.pivotquads.size() > 0)
	{
		writeRawVector<PVRTPivotQuadVertex>(file, bucket.pivotquads);
		writeSecurityCheckpoint(file);
	}
	else
	{
		// at least one should contain data
		return false;
	}

	return true;
}
void CIrrMeshWriter::writeMeshBuffer(const scene::IMeshBuffer* buffer)
{
	Writer->writeElement(L"buffer", false);
	Writer->writeLineBreak();

	// write bounding box

	writeBoundingBox(buffer->getBoundingBox());
	Writer->writeLineBreak();

	// write material

	writeMaterial(buffer->getMaterial());

	// write vertices

	const core::stringw vertexTypeStr = video::sBuiltInVertexTypeNames[buffer->getVertexType()];

	Writer->writeElement(L"vertices", false,
		L"type", vertexTypeStr.c_str(),
		L"vertexCount", core::stringw(buffer->getVertexCount()).c_str());

	Writer->writeLineBreak();

	u32 vertexCount = buffer->getVertexCount();

	switch(buffer->getVertexType())
	{
	case video::EVT_STANDARD:
		{
			video::S3DVertex* vtx = (video::S3DVertex*)buffer->getVertices();
			for (u32 j=0; j<vertexCount; ++j)
			{
				core::stringw str = getVectorAsStringLine(vtx[j].Pos);
				str += L" ";
				str += getVectorAsStringLine(vtx[j].Normal);

				char tmp[12];
				sprintf(tmp, " %02x%02x%02x%02x ", vtx[j].Color.getAlpha(), vtx[j].Color.getRed(), vtx[j].Color.getGreen(), vtx[j].Color.getBlue());
				str += tmp;

				str += getVectorAsStringLine(vtx[j].TCoords);

				Writer->writeText(str.c_str());
				Writer->writeLineBreak();
			}
		}
		break;
	case video::EVT_2TCOORDS:
		{
			video::S3DVertex2TCoords* vtx = (video::S3DVertex2TCoords*)buffer->getVertices();
			for (u32 j=0; j<vertexCount; ++j)
			{
				core::stringw str = getVectorAsStringLine(vtx[j].Pos);
				str += L" ";
				str += getVectorAsStringLine(vtx[j].Normal);

				char tmp[12];
				sprintf(tmp, " %02x%02x%02x%02x ", vtx[j].Color.getAlpha(), vtx[j].Color.getRed(), vtx[j].Color.getGreen(), vtx[j].Color.getBlue());
				str += tmp;

				str += getVectorAsStringLine(vtx[j].TCoords);
				str += L" ";
				str += getVectorAsStringLine(vtx[j].TCoords2);

				Writer->writeText(str.c_str());
				Writer->writeLineBreak();
			}
		}
		break;
	case video::EVT_TANGENTS:
		{
			video::S3DVertexTangents* vtx = (video::S3DVertexTangents*)buffer->getVertices();
			for (u32 j=0; j<vertexCount; ++j)
			{
				core::stringw str = getVectorAsStringLine(vtx[j].Pos);
				str += L" ";
				str += getVectorAsStringLine(vtx[j].Normal);

				char tmp[12];
				sprintf(tmp, " %02x%02x%02x%02x ", vtx[j].Color.getAlpha(), vtx[j].Color.getRed(), vtx[j].Color.getGreen(), vtx[j].Color.getBlue());
				str += tmp;

				str += getVectorAsStringLine(vtx[j].TCoords);
				str += L" ";
				str += getVectorAsStringLine(vtx[j].Tangent);
				str += L" ";
				str += getVectorAsStringLine(vtx[j].Binormal);

				Writer->writeText(str.c_str());
				Writer->writeLineBreak();
			}
		}
		break;
	}

	Writer->writeClosingTag(L"vertices");
	Writer->writeLineBreak();

	// write indices

	Writer->writeElement(L"indices", false,
		L"indexCount", core::stringw(buffer->getIndexCount()).c_str());

	Writer->writeLineBreak();

	int indexCount = (int)buffer->getIndexCount();

	video::E_INDEX_TYPE iType = buffer->getIndexType();

	const u16* idx16 = buffer->getIndices();
	const u32* idx32 = (u32*) buffer->getIndices();
	const int maxIndicesPerLine = 25;

	for (int i=0; i<indexCount; ++i)
	{
		if(iType == video::EIT_16BIT)
		{
			core::stringw str((int)idx16[i]);
			Writer->writeText(str.c_str());
		}
		else
		{
			core::stringw str((int)idx32[i]);
			Writer->writeText(str.c_str());
		}

		if (i % maxIndicesPerLine != maxIndicesPerLine)
		{
			if (i % maxIndicesPerLine == maxIndicesPerLine-1)
				Writer->writeLineBreak();
			else
				Writer->writeText(L" ");
		}
	}

	if ((indexCount-1) % maxIndicesPerLine != maxIndicesPerLine-1)
		Writer->writeLineBreak();

	Writer->writeClosingTag(L"indices");
	Writer->writeLineBreak();

	// close buffer tag

	Writer->writeClosingTag(L"buffer");
}