Пример #1
0
	INT32 TriangleClipperBase::clipByPlane(const Plane& plane)
	{
		int state = processVertices(plane);

		if (state == 1)
			return +1; // Nothing is clipped
		else if (state == -1)
			return -1; // Everything is clipped

		processEdges();
		processFaces();

		return 0;
	}
Пример #2
0
ClipMesh::Result ClipMesh::clip( const Plane& clipPlane ) {
	const Result result = processVertices(clipPlane);

	// no more processing required if the mesh isn't clipped
	if( result != Result::Dissected ) {
		return result;
	}

	processEdges();
	if( !processFaces(clipPlane) ) {
		//printf("Error: Failed to process faces.\n");
		return Result::Visible;
	}

	return Result::Dissected;
}
Пример #3
0
/**
 * Processes all <Mesh> elements from the XML file.
 *
 * @param n:       <Mesh> element
 * @param outfile: Binary file, opened as "wb", for output.
 *
 * @return: TRUE if successful, FALSE otherwise.
 */
int processMesh(xmlNode *n, FILE *outfile)
{
	xmlChar name[]           = "name";
	xmlChar frameCount[]     = "frameCount";
	xmlChar vertexCount[]    = "vertexCount";
	xmlChar indexCount[]     = "indexCount";
	xmlChar specularPower[]  = "specularPower";
	xmlChar opacity[]        = "opacity";
	xmlChar twoSided[]       = "twoSided";
	xmlChar customColor[]    = "customColor";
	xmlChar diffuseTexture[] = "diffuseTexture";

	float32 color[3];
	
	struct MeshHeader mh;
	uint8 texname[NAMESIZE+1];

	int foundFlag = FALSE;
	xmlNode *texn = NULL;
	xmlNode *curNode = NULL;
	
	/* make sure we're dealing with a <Mesh> element */
	assert(strcmp((char*)n->name, "Mesh") == 0);

	/* populate the MeshHeader structure appropriately */
	memset(&mh, 0, sizeof(struct MeshHeader));
	strncpy((char*)mh.name, (char*)xmlGetProp(n, name), NAMESIZE-1);
	mh.frameCount    = (uint32)atoi((char*)xmlGetProp(n, frameCount));
	mh.vertexCount   = (uint32)atoi((char*)xmlGetProp(n, vertexCount));
	mh.indexCount    = (uint32)atoi((char*)xmlGetProp(n, indexCount));
	if (readColorChild(n, "Diffuse", color) == FALSE)
		return FALSE;
	mh.diffuseColor[0] = color[0];
	mh.diffuseColor[1] = color[1];
	mh.diffuseColor[2] = color[2];
	if (readColorChild(n, "Specular", color) == FALSE)
		return FALSE;
	mh.specularColor[0] = color[0];
	mh.specularColor[1] = color[1];
	mh.specularColor[2] = color[2];
	mh.specularPower = (float32)atof((char*)xmlGetProp(n, specularPower));
	mh.opacity       = (float32)atof((char*)xmlGetProp(n, opacity));
	mh.properties    = 0;
	if (strcmp((char*)xmlGetProp(n, twoSided), "true") == 0)
		mh.properties += (0x1 << mpfTwoSided);
	if (strcmp((char*)xmlGetProp(n, customColor), "true") == 0)
		mh.properties += (0x1 << mpfCustomColor);
	mh.textures      = 0;
	if (strcmp((char*)xmlGetProp(n, diffuseTexture), "true") == 0)
		mh.textures = 1;

	/* write the MeshHeader */
	fwrite(&mh, sizeof(struct MeshHeader), 1, outfile);

	/* if we have a texture, then also write its name */
	foundFlag = FALSE;
	if (mh.textures)
	{
		for (texn=n->children; texn; texn = texn->next)
		{
			if (texn->type == XML_ELEMENT_NODE)
			{
				if (strcmp((char*)texn->name, "Texture") == 0)
				{
					foundFlag = TRUE;
					break;
				}
			}
		}
		if (foundFlag == FALSE)
		{
			printf("Could not find <Texture> element!\n");
			return FALSE;
		}
		memset(texname, 0, NAMESIZE+1);
		strncpy((char*)texname, 
			(char*)xmlGetProp(texn, (xmlChar*)"name"), NAMESIZE);
		fwrite(texname, NAMESIZE, 1, outfile);
	}

	/* write out vertices */
	foundFlag = FALSE;
	for (curNode=n->children; curNode; curNode = curNode->next)
	{
		if (curNode->type == XML_ELEMENT_NODE)
		{
			if (strcmp((char*)curNode->name, "Vertices") == 0)
			{
				foundFlag = TRUE;
				if (processVertices(curNode, outfile,
					mh.vertexCount) == FALSE)
				{
					return FALSE;
				}
			}
		}
	}
	if (foundFlag == FALSE)
	{
		printf("No <Vertices> found!\n");
		return FALSE;
	}
	
	/* write out normals */
	foundFlag = FALSE;
	for (curNode=n->children; curNode; curNode = curNode->next)
	{
		if (curNode->type == XML_ELEMENT_NODE)
		{
			if (strcmp((char*)curNode->name, "Normals") == 0)
			{
				foundFlag = TRUE;
				if (processNormals(curNode, outfile,
					mh.vertexCount) == FALSE)
				{
					return FALSE;
				}
			}
		}
	}
	if (foundFlag == FALSE)
	{
		printf("No <Normals> found!\n");
		return FALSE;
	}
	
	/* write out texture coordinates */
	if (mh.textures)
	{
		foundFlag = FALSE;
		for (curNode=n->children; curNode; curNode = curNode->next)
		{
			if (curNode->type == XML_ELEMENT_NODE)
			{
				if (strcmp((char*)curNode->name, "TexCoords")
					== 0)
				{
					foundFlag = TRUE;
					if (processTexcoords(curNode,
						outfile, mh.vertexCount) == 
						FALSE)
					{
						return FALSE;
					}
				}
			}
		}
		if (foundFlag == FALSE)
		{
			printf("No <TexCoords> found!\n");
			return FALSE;
		}
	}
	
	/* write out indices */
	foundFlag = FALSE;
	for (curNode=n->children; curNode; curNode = curNode->next)
	{
		if (curNode->type == XML_ELEMENT_NODE)
		{
			if (strcmp((char*)curNode->name, "Indices") == 0)
			{
				foundFlag = TRUE;
				if (processIndices(curNode, outfile,
					mh.indexCount) == FALSE)
				{
					return FALSE;
				}
			}
		}
	}
	if (foundFlag == FALSE)
	{
		printf("No <Indices> found!\n");
	}

	return TRUE;
}