コード例 #1
0
ファイル: xmlparse.cpp プロジェクト: 0bsidian/GtkRadiant
void Entity_XMLParse( entity_t *pEntity, xmlNodePtr entity ){
	brush_t *pBrush;

	for ( xmlNodePtr current = entity->children; current != NULL; current = current->next )
	{
		if ( current->type != XML_ELEMENT_NODE ) {
			continue;
		}
		if ( !strcmp( (char *)current->name, "epair" ) ) {
			char *key = (char *)xmlGetProp( current, (xmlChar *)"key" );
			char *value = (char *)xmlGetProp( current, (xmlChar *)"value" );
			SetKeyValue( pEntity, key, value );
			xmlFree( key );
			xmlFree( value );
		}
		else if ( strcmp( (char *)current->name, "brush" ) == 0 ) {
			pBrush = Brush_Alloc();
			Brush_XMLParse( pBrush, current );
			( (CPtrArray*)pEntity->pData )->Add( pBrush );
		}
		else if ( strcmp( (char *)current->name, "patch" ) == 0 ) {
			pBrush = Brush_Alloc();
			pBrush->patchBrush = true;
			pBrush->pPatch = Patch_Alloc();
			pBrush->pPatch->pSymbiot = pBrush;
			Patch_XMLParse( pBrush->pPatch, current );
			( (CPtrArray*)pEntity->pData )->Add( pBrush );
		}
	}
}
コード例 #2
0
LPVOID CPlugInManager::CreateBrushHandle()
{
	brush_t *pb = Brush_Alloc();
	pb->numberId = g_nBrushId++;
  m_BrushHandles.Add(pb);
  return (LPVOID)pb;
}
コード例 #3
0
brush_t *BrushFromMapBrush(idMapBrush *mapbrush, idVec3 origin) {
	brush_t *b = NULL;
	if (mapbrush) {
		b = Brush_Alloc();
		int count = mapbrush->GetNumSides();
		for (int i = 0; i < count; i++) {
			idMapBrushSide *side = mapbrush->GetSide(i);
			face_t *f = Face_Alloc();
			f->next = NULL;
			if (!b->brush_faces) {
				b->brush_faces = f;
			}
			else {
				face_t	*scan;
				for (scan = b->brush_faces; scan->next; scan = scan->next) {
					;
				}
				scan->next = f;
			}
			f->plane = side->GetPlane();
			f->originalPlane = f->plane;
			f->dirty = false;

// ---> sikk - Old Brush Format
/*			idWinding w;
			w.BaseForPlane(f->plane);

			for (int j = 0; j < 3; j++) {
				f->planepts[j].x = w[j].x + origin.x;
				f->planepts[j].y = w[j].y + origin.y;
				f->planepts[j].z = w[j].z + origin.z;
			}*/
			
			side->GetPlanePoints( f->planepts[0], f->planepts[1], f->planepts[2] );
			for ( int j = 0; j < 3; j++ ) {
				f->planepts[j] += origin;
			}
// <--- sikk - Old Brush Format



			idVec3 mat[2];
			side->GetTextureMatrix(mat[0], mat[1]);
			f->brushprimit_texdef.coords[0][0] = mat[0][0];
			f->brushprimit_texdef.coords[0][1] = mat[0][1];
			f->brushprimit_texdef.coords[0][2] = mat[0][2];
			f->brushprimit_texdef.coords[1][0] = mat[1][0];
			f->brushprimit_texdef.coords[1][1] = mat[1][1];
			f->brushprimit_texdef.coords[1][2] = mat[1][2];

			f->texdef.SetName(side->GetMaterial());
		}
	}
	return b;
}
コード例 #4
0
ファイル: parse.cpp プロジェクト: 0bsidian/GtkRadiant
void Entity_Parse( entity_t *pEntity ){
	brush_t *pBrush;
//  CPtrArray *brushes = NULL;
	char temptoken[1024];

	char *token = Token();

	while ( 1 )
	{
		GetToken( true ); // { or } or epair
		if ( !strcmp( token, "}" ) ) {
			break;
		}
		else if ( !strcmp( token, "{" ) ) {

			pBrush = Brush_Alloc();
			if ( Primitive_Parse( pBrush ) ) {
				( (CPtrArray*)pEntity->pData )->Add( pBrush );
			}
			else {
				Brush_Free( pBrush, true );
			}

		}
		else {

			strcpy( temptoken, token );
			GetToken( false );

			SetKeyValue( pEntity, temptoken, token );

			if ( g_MapVersion == MAPVERSION_HL ) {
				// if we've not god a "wads" key/pair already, then break it into a list.
				if ( !g_WadList && ( stricmp( temptoken,"wad" ) == 0 ) ) {
					BuildWadList( token );
				}
			}

		}
	}
}
コード例 #5
0
/*
=============
Brush_MergeList

 Tries to merge all brushes in the list into one new brush.
 The input brush list stays intact.
 Returns NULL if no merged brush can be created.
 To create a new brush the brushes in the list may not overlap and
 the outer faces of the brushes together should make a new convex brush.

 if onlyshape is true then the merge is allowed based on the shape only
 otherwise the texture references of faces in the same plane have to
 be the same as well.
=============
*/
brush_t *Brush_MergeList(brush_t *brushlist, int onlyshape)
{
	brush_t *brush1, *brush2, *brush3, *newbrush;
	face_t *face1, *face2, *face3, *newface, *f;

	if (!brushlist) return NULL;
	for (brush1 = brushlist; brush1; brush1 = brush1->next)
	{
		// check if the new brush would be convex... flipped planes make a brush concave
		for (face1 = brush1->brush_faces; face1; face1 = face1->next)
		{
			// don't check face1 if it touches another brush
			for (brush2 = brushlist; brush2; brush2 = brush2->next)
			{
				if (brush2 == brush1) continue;
				for (face2 = brush2->brush_faces; face2; face2 = face2->next)
				{
					if (Plane_Equal(&face1->plane, &face2->plane, true))
					{
						break;
					}
				}
				if (face2) break;
			}
			// if face1 touches another brush
			if (brush2) continue;
			//
			for (brush2 = brush1->next; brush2; brush2 = brush2->next)
			{
				// don't check the faces of brush 2 touching another brush
				for (face2 = brush2->brush_faces; face2; face2 = face2->next)
				{
					for (brush3 = brushlist; brush3; brush3 = brush3->next)
					{
						if (brush3 == brush2) continue;
						for (face3 = brush3->brush_faces; face3; face3 = face3->next)
						{
							if (Plane_Equal(&face2->plane, &face3->plane, true)) break;
						}
						if (face3) break;
					}
					// if face2 touches another brush
					if (brush3) continue;
					//
					if (Plane_Equal(&face1->plane, &face2->plane, false))
					{
						//if the texture references should be the same but are not
						if (!onlyshape && stricmp(face1->texdef.name, face2->texdef.name) != 0) return NULL;
						continue;
					}
					//
					if (Winding_PlanesConcave(face1->face_winding, face2->face_winding,
											face1->plane.normal, face2->plane.normal,
											face1->plane.dist, face2->plane.dist))
					{
						return NULL;
					}
				}
			}
		}
	}
	//
	newbrush = Brush_Alloc();
	//
	for (brush1 = brushlist; brush1; brush1 = brush1->next)
	{
		for (face1 = brush1->brush_faces; face1; face1 = face1->next)
		{
			// don't add face1 to the new brush if it touches another brush
			for (brush2 = brushlist; brush2; brush2 = brush2->next)
			{
				if (brush2 == brush1) continue;
				for (face2 = brush2->brush_faces; face2; face2 = face2->next)
				{
					if (Plane_Equal(&face1->plane, &face2->plane, true))
					{
						break;
					}
				}
				if (face2) break;
			}
			if (brush2) continue;
			// don't add faces with the same plane twice
			for (f = newbrush->brush_faces; f; f = f->next)
			{
				if (Plane_Equal(&face1->plane, &f->plane, false))
					break;
				if (Plane_Equal(&face1->plane, &f->plane, true))
					break;
			}
			if (f)
				continue;
			//
			newface = Face_Alloc();
			newface->texdef = face1->texdef;
			VectorCopy(face1->planepts[0], newface->planepts[0]);
			VectorCopy(face1->planepts[1], newface->planepts[1]);
			VectorCopy(face1->planepts[2], newface->planepts[2]);
			newface->plane = face1->plane;
			newface->next = newbrush->brush_faces;
			newbrush->brush_faces = newface;
		}
	}
	// link the new brush to an entity
	Entity_LinkBrush (brushlist->owner, newbrush);
	// build windings for the faces
	Brush_BuildWindings( newbrush);
	return newbrush;
}
コード例 #6
0
/*
=============
Brush_Merge

 Returns a new brush that is created by merging brush1 and brush2.
 May return NULL if brush1 and brush2 do not create a convex brush when merged.
 The input brushes brush1 and brush2 stay intact.

 if onlyshape is true then the merge is allowed based on the shape only
 otherwise the texture references of faces in the same plane have to
 be the same as well.
=============
*/
brush_t *Brush_Merge(brush_t *brush1, brush_t *brush2, int onlyshape)
{
	int i, shared;
	brush_t *newbrush;
	face_t *face1, *face2, *newface, *f;

	// check for bounding box overlapp
	for (i = 0; i < 3; i++)
	{
		if (brush1->mins[i] > brush2->maxs[i] + ON_EPSILON
				|| brush1->maxs[i] < brush2->mins[i] - ON_EPSILON)
		{
			// never merge if the brushes overlap
			return NULL;
		}
	}
	//
	shared = 0;
	// check if the new brush would be convex... flipped planes make a brush non-convex
	for (face1 = brush1->brush_faces; face1; face1 = face1->next)
	{
		// don't check the faces of brush 1 and 2 touching each other
		for (face2 = brush2->brush_faces; face2; face2 = face2->next)
		{
			if (Plane_Equal(&face1->plane, &face2->plane, true))
			{
				shared++;
				// there may only be ONE shared side
				if (shared > 1)
					return NULL;
				break;
			}
		}
		// if this face plane is shared
		if (face2) continue;
		//
		for (face2 = brush2->brush_faces; face2; face2 = face2->next)
		{
			// don't check the faces of brush 1 and 2 touching each other
			for (f = brush1->brush_faces; f; f = f->next)
			{
				if (Plane_Equal(&face2->plane, &f->plane, true)) break;
			}
			if (f)
				continue;
			//
			if (Plane_Equal(&face1->plane, &face2->plane, false))
			{
				//if the texture references should be the same but are not
				if (!onlyshape && stricmp(face1->texdef.name, face2->texdef.name) != 0) return NULL;
				continue;
			}
			//
			if (Winding_PlanesConcave(face1->face_winding, face2->face_winding,
									face1->plane.normal, face2->plane.normal,
									face1->plane.dist, face2->plane.dist))
			{
				return NULL;
			} //end if
		} //end for
	} //end for
	//
	newbrush = Brush_Alloc();
	//
	for (face1 = brush1->brush_faces; face1; face1 = face1->next)
	{
		// don't add the faces of brush 1 and 2 touching each other
		for (face2 = brush2->brush_faces; face2; face2 = face2->next)
		{
			if (Plane_Equal(&face1->plane, &face2->plane, true))
				break;
		}
		if (face2)
			continue;
		// don't add faces with the same plane twice
		for (f = newbrush->brush_faces; f; f = f->next)
		{
			if (Plane_Equal(&face1->plane, &f->plane, false))
				break;
			if (Plane_Equal(&face1->plane, &f->plane, true))
				break;
		}
		if (f)
			continue;
		//
		newface = Face_Alloc();
		newface->texdef = face1->texdef;
		VectorCopy(face1->planepts[0], newface->planepts[0]);
		VectorCopy(face1->planepts[1], newface->planepts[1]);
		VectorCopy(face1->planepts[2], newface->planepts[2]);
		newface->plane = face1->plane;
		newface->next = newbrush->brush_faces;
		newbrush->brush_faces = newface;
	}
	//
	for (face2 = brush2->brush_faces; face2; face2 = face2->next)
	{
		// don't add the faces of brush 1 and 2 touching each other
		for (face1 = brush1->brush_faces; face1; face1 = face1->next)
		{
			if (Plane_Equal(&face2->plane, &face1->plane, true))
				break;
		}
		if (face1)
			continue;
		// don't add faces with the same plane twice
		for (f = newbrush->brush_faces; f; f = f->next)
		{
			if (Plane_Equal(&face2->plane, &f->plane, false))
				break;
			if (Plane_Equal(&face2->plane, &f->plane, true))
				break;
		}
		if (f)
			continue;
		//
		newface = Face_Alloc();
		newface->texdef = face2->texdef;
		VectorCopy(face2->planepts[0], newface->planepts[0]);
		VectorCopy(face2->planepts[1], newface->planepts[1]);
		VectorCopy(face2->planepts[2], newface->planepts[2]);
		newface->plane = face2->plane;
		newface->next = newbrush->brush_faces;
		newbrush->brush_faces = newface;
	}
	// link the new brush to an entity
	Entity_LinkBrush (brush1->owner, newbrush);
	// build windings for the faces
	Brush_BuildWindings(newbrush);
	return newbrush;
}