Exemplo n.º 1
0
/*
===============
AddEdge

===============
*/
static void
AddEdge(vec3_t p1, vec3_t p2)
{
    wedge_t *w;
    vec_t t1, t2;

    w = FindEdge(p1, p2, &t1, &t2);
    AddVert(w, t1);
    AddVert(w, t2);
}
Exemplo n.º 2
0
void MY_UI_Too::Renderer::DrawText_NoClip(const MY_UI_Too::Interfaces::ITexture* pTexture, const MY_UI_Too::Interfaces::IFont* font, const std::string text, const MY_UI_Too::Utilities::Point startinpos, const unsigned int fontsize, const MY_UI_Too::Utilities::Color color_tl,const  MY_UI_Too::Utilities::Color color_tr, const MY_UI_Too::Utilities::Color color_bl, const MY_UI_Too::Utilities::Color color_br, bool drawnow){
	if(!SetTexture(pTexture, drawnow)) return;
	int startleft= startinpos.x;
	float skinwidth = (float)pTexture->Get_Dimensions().left;
	float skinheight = (float)pTexture->Get_Dimensions().top;
	float fontsizef = (float)fontsize;
	float fontscale = fontsizef/(float)FONT_CREATE_SIZE;

	Utilities::UVs spaceuvs = font->Get_Char('a');
	unsigned int spacewidth=(int)(skinwidth*(spaceuvs.u2 - spaceuvs.u1)*fontscale);
	spaceuvs = font->Get_Char(')');
	unsigned int vertheight =(int)(NEXTLINEPERCENT*skinheight*(spaceuvs.v2 - spaceuvs.v1) + skinheight*(spaceuvs.v2 - spaceuvs.v1));
	MY_UI_Too::Utilities::Point startin_pos=startinpos;

	//goto http://www.asciitable.com/ for ascii info
	for(auto beg = text.begin(); beg!= text.end(); beg++){

		char c = *beg;
		if(c == 0)continue;
		else if(c==9) startin_pos.left+=(spacewidth*8);// a tab is 8 spaces
		else if(c==32) startin_pos.left+=spacewidth;
		else if(c==13){
			if(beg+1 != text.end()){
				if(*(beg+1) == 10) {
					beg++;//advance a character.. some people still think \r\n is appropriate for a newline instead of just \n
				}
			}
			startin_pos.top+=vertheight;
			startin_pos.left = startleft;
		} else if(c==10) {
			startin_pos.top+=vertheight;
			startin_pos.left = startleft;
		}
		else {
			if( (c<START_CHAR) | (c> END_CHAR)) {
				OUTPUT_DEBUG_MSG("Measure string encountered a non keyboard character. The character is(dec): "<<(int)c<<"  This character is being ignored");
				continue;
			}
			Utilities::UVs uvs = font->Get_Char(c);
			float width = skinwidth*(uvs.u2 - uvs.u1)*fontscale;

			float left= static_cast<float>(startin_pos.x);
			float top = static_cast<float>(startin_pos.y);
			float right = width + left;
			float height = fontsizef;
			float bottom = height + top;

			AddVert( left, top,					uvs.u1, uvs.v1, color_tl );
			AddVert( right, top,				uvs.u2, uvs.v1, color_tr );
			AddVert( left, bottom,				uvs.u1, uvs.v2, color_bl );
			AddVert( right, bottom,				uvs.u2, uvs.v2, color_br );
			startin_pos.x+=(int)width+1;// add at least one pixel
		}
	}
}
Exemplo n.º 3
0
void MY_UI_Too::Renderer::DrawTexturedRect_NoClip(const MY_UI_Too::Interfaces::ITexture* pTexture, const MY_UI_Too::Utilities::UVs& uvs, const MY_UI_Too::Utilities::Rect rect, const MY_UI_Too::Utilities::Color color_tl, const MY_UI_Too::Utilities::Color color_tr, const MY_UI_Too::Utilities::Color color_bl, const MY_UI_Too::Utilities::Color color_br, bool drawnow){
	if(!SetTexture(pTexture, drawnow)) return;

	float left= static_cast<float>(rect.left);
	float top = static_cast<float>(rect.top);
	float width = static_cast<float>(rect.width);
	float right = width + left;
	float height = static_cast<float>(rect.height);
	float bottom = height + top;
	if(Draw_States[ Draw_State_Index ].Verts.size() <= 4 + Draw_States[ Draw_State_Index ].NumVerts ) Draw_States[ Draw_State_Index ].Verts.resize(Draw_States[ Draw_State_Index ].Verts.size() + 200);
	AddVert( left, top,					uvs.u1, uvs.v1, color_tl );
	AddVert( right, top,				uvs.u2, uvs.v1, color_tr );
	AddVert( left, bottom,				uvs.u1, uvs.v2, color_bl );
	AddVert( right, bottom,				uvs.u2, uvs.v2, color_br );
}
Exemplo n.º 4
0
/**
 Copy all the vertices and triangle of another TIN to this one.
 This is a simple join.  No attempt is made to share vertices or any other integration.
 It is further assumed that the two TINs have compatible coordinate systems.
 */
void vtTin::AppendFrom(const vtTin *pTin)
{
	const size_t verts = pTin->NumVerts();
	const size_t tris = pTin->NumTris();

	// Preallocate (for efficiency)
	m_vert.SetMaxSize(m_vert.GetSize() + verts + 1);
	m_z.reserve(m_vert.GetSize() + verts + 1);
	m_tri.reserve(m_tri.size() + (tris*3) + 1);

	// Remember the starting point for vertex indices
	const int base = NumVerts();

	// Simple, naive copy of vertices and triangles
	DPoint2 p;
	float z;
	for (size_t i = 0; i < verts; i++)
	{
		pTin->GetVert(i, p, z);
		AddVert(p, z);
	}
	for (size_t i = 0; i < tris; i++)
	{
		const int *tri = pTin->GetAtTri(i);
		AddTri(base+tri[0], base+tri[1], base+tri[2]);
	}
	ComputeExtents();
}
Exemplo n.º 5
0
		void AddFace(Face* f, std::vector<Vertex>& verts) 
		{       
			ASSERT(!f->m_drawn);
			f->m_drawn = true;
			for(int i = 0; i < 3; ++i) {
				int vertIdx = f->m_indices[i];
				AddVert(verts, vertIdx, i);
			}

			int srcIdx = 0;
			int destIdx = 3;
			while( srcIdx < m_maxCacheSize && destIdx < m_maxCacheSize)
			{
				// A vert has been moved if it was added when already in the cache, so skip over those.
				if(m_cache[srcIdx] >= 0) {
					m_cacheOther[destIdx] = m_cache[srcIdx];
					verts[m_cacheOther[destIdx]].m_cacheIndex = destIdx;
					++destIdx;
				}
				++srcIdx;
			}

			// Let the verts that have been pushed out of the cache know that they're no longer there.
			for(int j = srcIdx; j < m_maxCacheSize; ++j) {
				if(m_cache[j] >= 0) {
					verts[m_cache[j]].m_cacheIndex = -1;
				}
			}

			m_cache.swap(m_cacheOther);
		}
Exemplo n.º 6
0
void Gwen::Renderer::SFML2::DrawPixel( int x, int y )
{
	EnsurePrimitiveType( sf::Points );
	EnsureTexture( NULL );
	Translate( x, y );
	AddVert( x, y+1 );
}
Exemplo n.º 7
0
bool vtTin::_ReadTinBody(FILE *fp, bool progress_callback(int))
{
	fseek(fp, m_file_data_start, SEEK_SET);

	// pre-allocate for efficiency
	m_vert.SetMaxSize(m_file_verts);
	m_tri.reserve(m_file_tris * 3);

	// read verts
	DPoint2 p;
	float z;
	for (int i = 0; i < m_file_verts; i++)
	{
		if (progress_callback != NULL && (i % 1024) == 0)
			progress_callback(i * 49 / m_file_verts);

		fread(&p.x, 8, 2, fp);	// 2 doubles
		fread(&z, 4, 1, fp);	// 1 float
		AddVert(p, z);
	}
	// read tris
	int tribuf[3];
	for (int i = 0; i < m_file_tris; i++)
	{
		if (progress_callback != NULL && (i % 1024) == 0)
			progress_callback(50 + i * 49 / m_file_tris);

		fread(tribuf, 4, 3, fp);	// 3 ints
		AddTri(tribuf[0], tribuf[1], tribuf[2]);
	}
	return true;
}
Exemplo n.º 8
0
		void DirectX9::DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect rect, float u1, float v1, float u2, float v2 )
		{
			IDirect3DTexture9* pImage = ( IDirect3DTexture9* ) pTexture->data;

			// Missing image, not loaded properly?
			if ( !pImage )
			{
				return DrawMissingImage( rect );
			}

			Translate( rect );

			if ( m_pCurrentTexture != pImage )
			{
				Flush();
				m_pDevice->SetTexture( 0, pImage );
				m_pCurrentTexture = pImage;
			}

			AddVert( rect.x, rect.y,			u1, v1 );
			AddVert( rect.x + rect.w, rect.y,		u2, v1 );
			AddVert( rect.x, rect.y + rect.h,	u1, v2 );
			AddVert( rect.x + rect.w, rect.y,		u2, v1 );
			AddVert( rect.x + rect.w, rect.y + rect.h, u2, v2 );
			AddVert( rect.x, rect.y + rect.h, u1, v2 );
		}
Exemplo n.º 9
0
		void OpenGL_DebugFont::DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect rect, float u1, float v1, float u2, float v2 )
		{
			GLuint* tex = (GLuint*)pTexture->data;

			// Missing image, not loaded properly?
			if ( !tex )
			{
				return DrawMissingImage( rect );
			}

			Translate( rect );
			GLuint boundtex;

			GLboolean texturesOn;
			glGetBooleanv(GL_TEXTURE_2D, &texturesOn);
			glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint *)&boundtex);
			if ( !texturesOn || *tex != boundtex )
			{
				Flush();
				glBindTexture( GL_TEXTURE_2D, *tex );
				glEnable(GL_TEXTURE_2D);
			}		

			AddVert( rect.x, rect.y,			u1, v1 );
			AddVert( rect.x+rect.w, rect.y,		u2, v1 );
			AddVert( rect.x, rect.y + rect.h,	u1, v2 );

			AddVert( rect.x+rect.w, rect.y,		u2, v1 );
			AddVert( rect.x+rect.w, rect.y+rect.h, u2, v2 );
			AddVert( rect.x, rect.y + rect.h, u1, v2 );			
		}
Exemplo n.º 10
0
/**
 * Attempt to read TIN data from a DXF file.
 */
bool vtTin::ReadDXF(const char *fname, bool progress_callback(int))
{
	VTLOG("vtTin::ReadDXF():\n");

	std::vector<DxfEntity> entities;
	std::vector<DxfLayer> layers;

	DxfParser parser(fname, entities, layers);
	bool bSuccess = parser.RetrieveEntities(progress_callback);
	if (!bSuccess)
	{
		VTLOG(parser.GetLastError());
		return false;
	}

	int vtx = 0;
	int found = 0;
	for (uint i = 0; i < entities.size(); i++)
	{
		const DxfEntity &ent = entities[i];
		if (ent.m_iType == DET_3DFace || ent.m_iType == DET_Polygon)
		{
			int NumVerts = ent.m_points.size();
			if (NumVerts == 3)
			{
				for (int j = 0; j < 3; j++)
				{
					DPoint2 p(ent.m_points[j].x, ent.m_points[j].y);
					float z = (float) ent.m_points[j].z;

					AddVert(p, z);
				}
				AddTri(vtx, vtx+1, vtx+2);
				vtx += 3;
				found ++;
			}
		}
	}
	VTLOG(" Found %d triangle entities, of type 3DFace or Polygon.\n", found);

	// If we didn't find any surfaces, we haven't got a TIN
	if (found == 0)
		return false;

	// Test each triangle for clockwisdom, fix if needed
	CleanupClockwisdom();

	ComputeExtents();
	return true;
}
Exemplo n.º 11
0
void Patch::GeneratePlane()
{
	// Allocate vertices for the plane
	int vertNum = 0;
	GLfloat numVertsf = (GLfloat)NUM_VERTS;
	for (GLfloat i = 0.0f; i < numVertsf; i += 1.0f)
	{
		for (GLfloat j = 0.0f; j < numVertsf; j += 1.0f)
		{
			AddVert(0.0f, 0.0f, 0.0f, i / (numVertsf - 1.0f), j / (numVertsf - 1.0f), vertNum++);
		}
	}

	int cp = 0;
	float zOffset = 1.0f / 3.0f;
	float xOffset = 1.0f / 3.0f;
	glm::vec3 baseVec = glm::vec3(-0.5f, 0.0f, -0.5f);
	for (int row = 0; row < 4; ++row)
	{
		_controlPoints[cp++] = glm::vec3(baseVec.x, baseVec.y, baseVec.z + zOffset * row);
		_controlPoints[cp++] = glm::vec3(baseVec.x + xOffset, baseVec.y, baseVec.z + zOffset * row);
		_controlPoints[cp++] = glm::vec3(baseVec.x + xOffset * 2, baseVec.y, baseVec.z + zOffset * row);
		_controlPoints[cp++] = glm::vec3(baseVec.x + xOffset * 3, baseVec.y, baseVec.z + zOffset * row);
	}

	// Add elements for faces
	int faceNum = 0;
	int quadsPerRow = NUM_VERTS * (NUM_VERTS - 1);
	for (int i = 0; i < quadsPerRow; i += NUM_VERTS)
	{
		for (int j = 0; j < NUM_VERTS - 1; ++j)
		{
			AddFace(i + j, i + j + 1, i + NUM_VERTS + j, faceNum++);
			AddFace(i + j + 1, i + NUM_VERTS + j + 1, i + NUM_VERTS + j, faceNum++);
		}
	}
	glBindBuffer(GL_VERTEX_ARRAY, _vao);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_elements), (void*)&_elements, GL_DYNAMIC_DRAW);

	UpdateSurface();
}
Exemplo n.º 12
0
void Gwen::Renderer::SFML2::DrawFilledRect( Gwen::Rect rect )
{
	EnsurePrimitiveType( sf::Triangles );
	EnsureTexture( NULL );

	Translate( rect );

	AddVert( rect.x, rect.y );
	AddVert( rect.x+rect.w, rect.y );
	AddVert( rect.x, rect.y + rect.h );

	AddVert( rect.x+rect.w, rect.y );
	AddVert( rect.x+rect.w, rect.y+rect.h );
	AddVert( rect.x, rect.y + rect.h );
}
Exemplo n.º 13
0
bool vtTin::_ReadTinOld(FILE *fp)
{
	int i, num;
	FPoint3 f;
	DPoint2 p;

	fread(&num, 1, sizeof(int), fp);
	m_vert.SetMaxSize(num);
	for (i = 0; i < num; i++)
	{
		fread(&f.x, 3, sizeof(float), fp);

		p.Set(f.x, f.y);
		AddVert(p, f.z);
	}
	for (i = 0; i < num/3; i++)
	{
		AddTri(i*3, i*3+1, i*3+2);
	}
	return true;
}
Exemplo n.º 14
0
void Gwen::Renderer::SFML2::DrawLinedRect( Gwen::Rect rect )
{
	EnsurePrimitiveType( sf::Lines );
	EnsureTexture( NULL );

	Translate ( rect );

	//   (x,y) ---------- (x+w, y)
	//         |        |
	// (x,y+h) ---------- (x+w,y+h)

	AddVert( rect.x, rect.y);
	AddVert( rect.x+rect.w, rect.y	);

	AddVert( rect.x+rect.w, rect.y	);
	AddVert( rect.x+rect.w, rect.y+rect.h );

	AddVert( rect.x+rect.w, rect.y+rect.h );
	AddVert( rect.x, rect.y + rect.h );

	AddVert( rect.x, rect.y + rect.h );
	AddVert( rect.x, rect.y );
}
Exemplo n.º 15
0
		void DirectX9::DrawFilledRect( Gwen::Rect rect )
		{
			if ( m_pCurrentTexture != NULL )
			{
				Flush();
				m_pDevice->SetTexture( 0, NULL );
				m_pCurrentTexture = NULL;
			}

			Translate( rect );
			AddVert( rect.x, rect.y );
			AddVert( rect.x + rect.w, rect.y );
			AddVert( rect.x, rect.y + rect.h );
			AddVert( rect.x + rect.w, rect.y );
			AddVert( rect.x + rect.w, rect.y + rect.h );
			AddVert( rect.x, rect.y + rect.h );
		}
Exemplo n.º 16
0
AdjacencyList::AdjacencyList(const char* fname){
  FILE* graphdata=fopen(fname,"r");


  int numvert;
  Vector pos;
  int numedge;
  int v1,v2;
  float speed;
  char speedchar;  //the character read in from the file,
                   //A is fast, B is medium, C is slows
                   //actual speeds stored as global constants in general.h
                   //you can modify general.h to change the actual speeds
                   //to show your results better
//  debug=fopen("aldebug.txt","w");

  fscanf(graphdata,"%d\n",&numvert);
  cap_=numvert;
  vertexlist_=new VInfo*[cap_];
  size_=0;
  for(int i=0;i<numvert;i++){
    fscanf(graphdata,"%f %f %f\n",&(pos.x),&(pos.y),&(pos.z));
    AddVert(pos);
  }
  fscanf(graphdata,"%d\n",&numedge);
  for(int i=0;i<numedge;i++){
    fscanf(graphdata,"%d %d %c\n",&v1,&v2,&speedchar);
    switch(speedchar){
      case 'A': speed=FAST; break;
      case 'B': speed=MEDIUM; break;
      case 'C': speed=SLOW; break;
    }
    AddEdge(v1,v2,speed);
  }
  numedges_=numedge;
  fclose(graphdata);
}
Exemplo n.º 17
0
		void OpenGL::DrawFilledRect( Gwen::Rect rect )
		{
			GLboolean texturesOn;
			glGetBooleanv( GL_TEXTURE_2D, &texturesOn );

			if ( texturesOn )
			{
				Flush();
				glDisable( GL_TEXTURE_2D );
			}

			Translate( rect );
			AddVert( rect.x, rect.y );
			AddVert( rect.x + rect.w, rect.y );
			AddVert( rect.x, rect.y + rect.h );
			AddVert( rect.x + rect.w, rect.y );
			AddVert( rect.x + rect.w, rect.y + rect.h );
			AddVert( rect.x, rect.y + rect.h );
		}
Exemplo n.º 18
0
void Gwen::Renderer::SFML2::DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect rect, float u1, float v1, float u2, float v2 )
{
	TextureData* data = reinterpret_cast<TextureData*>( pTexture->data );

	// Missing image, not loaded properly?
	if ( !data )
		return DrawMissingImage( rect );

	const sf::Texture* tex = data->texture;

	EnsurePrimitiveType( sf::Triangles );
	EnsureTexture( tex );

	Translate( rect );

	AddVert( rect.x, rect.y, u1, v1 );
	AddVert( rect.x+rect.w, rect.y,	u2, v1 );
	AddVert( rect.x, rect.y + rect.h,	u1, v2 );

	AddVert( rect.x+rect.w, rect.y, u2, v1 );
	AddVert( rect.x+rect.w, rect.y+rect.h, u2, v2 );
	AddVert( rect.x, rect.y + rect.h, u1, v2 );
}
Exemplo n.º 19
0
//-----------------------------------------------------------------------------
BOOL CExporter::Capture()
{
	VERIFY				(m_Style!=eExportUndef);
	Modifier*			pPhysique;
	IPhysiqueExport*	pExport;
	IPhyContextExport*	pContext;
	Object*				pObject;

	Matrix3				matMesh;
	Matrix3				matZero;

	if (!m_MeshNode){
		ERR("Select mesh and try again.");
		m_bHasError=TRUE; 
		return FALSE;
	}

	
	pObject				= m_MeshNode->GetObjectRef();
	if (!IsExportableMesh(m_MeshNode,pObject)){
		ERR("Can't receive node references.");
		m_bHasError=TRUE; 
		return FALSE;
	}

	// Get export interface
	pPhysique			= FindPhysiqueModifier(m_MeshNode);
	if (!pPhysique){
		ERR("Can't find Physique modifier.");
		m_bHasError=TRUE; 
		return FALSE;
	}
	pExport		= (IPhysiqueExport *)pPhysique->GetInterface(I_PHYINTERFACE);
	if (!pExport){
		ERR("Can't find Physique interface.");
		m_bHasError=TRUE; 
		return FALSE;
	}

	// Get mesh initial transform (used to mult by the bone matrices)
	int rval = CGINTM(m_MeshNode,pExport->GetInitNodeTM(m_MeshNode, matMesh));
	matZero.Zero();
	if (rval || matMesh.Equals(matZero, 0.0)){
		ERR("Old CS version. Can't export mesh");
		matMesh.IdentityMatrix();
	}

	// Add hierrarhy parts that has no effect on vertices, 
	// but required for hierrarhy stability

	if (eExportMotion==m_Style){
		if (m_AllBones.empty()){
			ERR("Invalid skin object. Bone not found.");
			return FALSE;
		}

		EConsole.ProgressStart((float)m_AllBones.size(),"..Capturing bones");
		for (DWORD i=0; i<m_AllBones.size(); i++){
			AddBone(m_AllBones[i], matMesh, pExport);
			EConsole.ProgressInc();
		}
		EConsole.ProgressEnd();
	}

	bool bRes = TRUE;
	if (eExportSkin==m_Style){
		// For a given Object's INode get a
		// ModContext Interface from the Physique Export Interface:
		pContext = (IPhyContextExport *)pExport->GetContextInterface(m_MeshNode);
		if (!pContext){
			ERR("Can't find Physique context interface.");
			return FALSE;
		}

		// convert to rigid with blending
		pContext->ConvertToRigid(TRUE);
		pContext->AllowBlending	(TRUE);

		// process vertices
		int	numVertices = pContext->GetNumberVertices();
		EConsole.ProgressStart(float(numVertices),"..Capturing vertices");
		for (int iVertex = 0; iVertex < numVertices; iVertex++ ){
			IPhyVertexExport *pVertexExport = (IPhyVertexExport *)pContext->GetVertexInterface(iVertex);
			R_ASSERT(pVertexExport);

			// What kind of vertices are these?
			int iVertexType = pVertexExport->GetVertexType();

			IPhyRigidVertex* pRigidVertex=(IPhyRigidVertex*)pContext->GetVertexInterface(iVertex);
			R_ASSERT					(pRigidVertex);
			switch (iVertexType){
			case RIGID_TYPE:{			
				INode* node				= pRigidVertex->GetNode(); 
				R_ASSERT				(node);
				LPCSTR nm				= node->GetName();
				// get bone and create vertex
				CVertexDef* pVertex		= AddVertex();
				int boneId				= AddBone(node,matMesh,pExport);
				if(BONE_NONE==boneId){
					ERR					("Invalid bone: ",node->GetName());
					bRes				= FALSE;
				}else pVertex->Append	(boneId,1.f);
							}break;
			case RIGID_BLENDED_TYPE:{
				IPhyBlendedRigidVertex*	pBlendedRigidVertex=(IPhyBlendedRigidVertex*)pRigidVertex;
				int cnt					= pBlendedRigidVertex->GetNumberNodes();
				CVertexDef* pVertex		= AddVertex();
				for (int i=0; i<cnt; i++){
					INode* node			= pBlendedRigidVertex->GetNode(i); 
					R_ASSERT			(node);
					LPCSTR nm			= node->GetName();
					// get bone and create vertex
					int boneId			= AddBone(node,matMesh,pExport);
					if(BONE_NONE==boneId){
						ERR				("Invalid bone: ",node->GetName());
						bRes			= FALSE;
					}else pVertex->Append(boneId,pBlendedRigidVertex->GetWeight(i));
				}
									}break;
			}

			// release vertex
			pContext->ReleaseVertexInterface( pRigidVertex );

			EConsole.ProgressInc();

			if (!bRes) break;
		}
		EConsole.ProgressEnd();

		if (!bRes) return FALSE;

		static int remap[3];
		if (U.m_SkinFlipFaces){
			remap[0] = 0;
			remap[1] = 1;
			remap[2] = 2;
		}else{
			remap[0] = 0;
			remap[1] = 2;
			remap[2] = 1;
		}

		// Process mesh
		// Get object from node. Abort if no object.
		Log("..Transforming mesh");
		BOOL		bDeleteTriObject;
		R_ASSERT	(pObject);
		TriObject *	pTriObject	= GetTriObjectFromObjRef(pObject, &bDeleteTriObject);
		if (!pTriObject){
			ERR("Can't create tri object.");
			return FALSE;
		}
		Mesh&		M = pTriObject->mesh;

		// Vertices
		{
			// check match with
			int iNumVert = M.getNumVerts();
			if (!(iNumVert==numVertices && iNumVert==m_Vertices.size()))
			{
				ERR("Non attached vertices found.");
				if (bDeleteTriObject)	delete(pTriObject);
				return FALSE;
			}

			// transform vertices
			for (int i=0; i<iNumVert; i++){
				Point3 P = M.getVert(i);
				Point3 T = matMesh.PointTransform(P);
				T *= m_fGlobalScale;
				m_Vertices[i]->SetPosition(T);
			}
		}

		Log("..Parsing materials");
		// Parse Materials
		m_MtlMain = m_MeshNode->GetMtl();
		R_ASSERT(m_MtlMain);

		DWORD cSubMaterials=m_MtlMain->NumSubMtls();
		if (cSubMaterials < 1) {
			// Count the material itself as a submaterial.
			cSubMaterials = 1;
		}

		// build normals
		M.buildRenderNormals();

		Log("..Converting vertices");
		// our Faces and Vertices
		{
			for (int i=0; i<M.getNumFaces(); i++){
				Face*	gF	= M.faces  + i;
				TVFace*	tF	= M.tvFace + i;

				int m_id = gF->getMatID();
				if (cSubMaterials == 1){
					m_id = 0;
				}else{
					// SDK recommends mod'ing the material ID by the valid # of materials, 
					// as sometimes a material number that's too high is returned.
					m_id %= cSubMaterials;
				}

				st_FACE* nF		= xr_new<st_FACE>();
				nF->m_id		= m_id;
				nF->sm_group	= gF->getSmGroup();
				for (int VVV=0; VVV<3; VVV++){
					int vert_id = gF->v[remap[VVV]];

					CVertexDef	&D	= *(m_Vertices[vert_id]);
					Point3		&UV	= M.tVerts[tF->t[remap[VVV]]];

					st_VERT		v;
					v.Set		(D);
					v.P.set		(D.P); 
					v.SetUV		(UV.x,1-UV.y);
//					v.sm_group	= U.m_SkinSuppressSmoothGroup?0:gF->getSmGroup(); // smooth group
					nF->v[VVV]	= AddVert(v);
				}
				m_ExpFaces.push_back(nF);
			}
		}
		if (bDeleteTriObject)	delete(pTriObject);
	}
	UpdateParenting();

	return bRes;
};
Exemplo n.º 20
0
bool vtTin::ReadADF(const char *fname, bool progress_callback(int))
{
	const vtString tnxy_name = fname;
	if (tnxy_name.Right(6) != "xy.adf")
		return false;

	vtString base = tnxy_name.Left(tnxy_name.GetLength()-6);
	vtString tnz_name = base + "z.adf";
	vtString tnod_name = base + "od.adf";

	FILE *fp1 = vtFileOpen(tnxy_name, "rb");
	FILE *fp2 = vtFileOpen(tnz_name, "rb");
	FILE *fp3 = vtFileOpen(tnod_name, "rb");
	if (!fp1 || !fp2 || !fp3)
		return false;

	fseek(fp1, 0, SEEK_END);
	const int length_xy = ftell(fp1);
	rewind(fp1);	// go back again
	uint num_points = length_xy / 16;	// X and Y, each 8 byte doubles

	fseek(fp2, 0, SEEK_END);
	const int length_z = ftell(fp2);
	rewind(fp2);	// go back again
	uint num_heights = length_z / 4;		// Z is a 4 byte float

	DPoint2 p;
	float z;
	for (uint i = 0; i < num_points; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(i * 40 / num_points);

		FRead(&p.x, DT_DOUBLE, 2, fp1, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		FRead(&z, DT_FLOAT, 1, fp2, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		AddVert(p, z);
	}

	fseek(fp3, 0, SEEK_END);
	const int length_od = ftell(fp3);
	rewind(fp3);	// go back again
	const uint num_faces = length_od / 12;		// A B C as 4-byte ints

	int v[3];
	for (uint i = 0; i < num_faces; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(40 + i * 40 / num_faces);

		FRead(v, DT_INT, 3, fp3, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		AddTri(v[0]-1, v[1]-1, v[2]-1);
	}

	fclose(fp1);
	fclose(fp2);
	fclose(fp3);

	// Cleanup: the ESRI TIN contains four "boundary" point far outside the
	//  extents (directly North, South, East, and West).  We should ignore
	//  those four points and the triangles connected to them.
	// It seems we can assume the four 'extra' vertices are the first four.
	m_vert.RemoveAt(0, 4);
	m_z.erase(m_z.begin(), m_z.begin() + 4);
	m_vert_normal.RemoveAt(0, 4);

	// Re-index the triangles
	uint total = m_tri.size()/3;
	for (uint i = 0; i < total; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(80 + i * 20 / total);

		// Remove any triangles which referenced this vertex
		if (m_tri[i*3 + 0] < 4 ||
			m_tri[i*3 + 1] < 4 ||
			m_tri[i*3 + 2] < 4)
		{
			m_tri.erase(m_tri.begin() + i*3, m_tri.begin() + i*3 + 3);
			i--;
			total--;
			continue;
		}
	}
	// For all other triangles, adjust the indices to reflect the removal
	for (uint i = 0; i < m_tri.size(); i++)
		m_tri[i] = m_tri[i] - 4;

	// Test each triangle for clockwisdom, fix if needed
	CleanupClockwisdom();

	ComputeExtents();

	return true;
}
Exemplo n.º 21
0
/**
 * Write the TIN to the Aquaveo GMS format.
 */
bool vtTin::ReadGMS(const char *fname, bool progress_callback(int))
{
	FILE *fp = vtFileOpen(fname, "rb");
	if (!fp)
		return false;

	char buf[256];
	vtString tin_name;
	int material_id;
	int num_points;

	// first line is file identifier
	if (fgets(buf, 256, fp) == NULL)
		return false;

	if (strncmp(buf, "TIN", 3) != 0)
		return false;

	while (1)
	{
		if (fgets(buf, 256, fp) == NULL)
			break;

		// trim trailing EOL characters
		vtString vstr = buf;
		vstr.Remove('\r');
		vstr.Remove('\n');
		const char *str = (const char *)vstr;

		if (!strncmp(str, "BEGT", 4))	// beginning of TIN block
			continue;

		if (!strncmp(str, "ID", 2))	// material ID
		{
			sscanf(str, "ID %d", &material_id);
		}
		else if (!strncmp(str, "MAT", 3))	// material ID
		{
			sscanf(str, "MAT %d", &material_id);
		}
		else if (!strncmp(str, "TCOL", 4))	// material ID
		{
			sscanf(str, "TCOL %d", &material_id);
		}
		else if (!strncmp(str, "TNAM", 4))	// TIN name
		{
			tin_name = str + 5;
		}
		else if (!strncmp(str, "VERT", 4))	// Beginning of vertices
		{
			sscanf(buf, "VERT %d\n", &num_points);
			DPoint2 p;
			float z;
			int optional;
			for (int i = 0; i < num_points; i++)
			{
				if (fgets(buf, 256, fp) == NULL)
					break;

				// First three are X, Y, Z.  Optional fourth is "ID" or "locked".
				sscanf(buf, "%lf %lf %f %d", &p.x, &p.y, &z, &optional);
#if 0
				// Some files have Y/-Z flipped (but they are non-standard)
				double temp = p.y; p.y = -z; z = temp;
#endif

				AddVert(p, z);

				if ((i%200) == 0 && progress_callback != NULL)
				{
					if (progress_callback(i * 49 / num_points))
					{
						fclose(fp);
						return false;	// user cancelled
					}
				}
			}
		}
		else if (!strncmp(str, "TRI", 3))	// Beginning of triangles
		{
			int num_faces;
			sscanf(str, "TRI %d\n", &num_faces);
			int v[3];
			for (int i = 0; i < num_faces; i++)
			{
				fscanf(fp, "%d %d %d\n", v, v+2, v+1);
				// the indices in the file are 1-based, so subtract 1
				AddTri(v[0]-1, v[1]-1, v[2]-1);

				if ((i%200) == 0 && progress_callback != NULL)
				{
					if (progress_callback(49 + i * 50 / num_faces))
					{
						fclose(fp);
						return false;	// user cancelled
					}
				}
			}
		}
	}
	fclose(fp);
	ComputeExtents();
	return true;
}
Exemplo n.º 22
0
bool vtTin::ReadPLY(const char *fname, bool progress_callback(int))
{
	FILE *fp = vtFileOpen(fname, "rb");
	if (!fp)
		return false;

	VTLOG("ReadPLY '%s'\n", fname);

	char buf[256];
	int material_id;
	int num_points;
	int num_faces;

	// first line is file identifier
	if (fgets(buf, 256, fp) == NULL)
		return false;

	if (strncmp(buf, "ply", 3) != 0)
		return false;

	while (fgets(buf, 256, fp) != NULL)
	{
		// trim trailing EOL characters
		vtString vstr = buf;
		vstr.Remove('\r');
		vstr.Remove('\n');
		const char *str = (const char *)vstr;

		if (!strncmp(str, "format", 6))	// beginning of TIN block
			continue;

		if (!strncmp(str, "ID", 2))	// material ID
		{
			sscanf(str, "ID %d", &material_id);
		}
		else if (!strncmp(str, "MAT", 3))	// material ID
		{
			sscanf(str, "MAT %d", &material_id);
		}
		else if (!strncmp(str, "TCOL", 4))	// material ID
		{
			sscanf(str, "TCOL %d", &material_id);
		}
 		else if (!strncmp(str, "element vertex", 14))	// Number of vertices
		{
			sscanf(buf, "element vertex %d\n", &num_points);
		}
 		else if (!strncmp(str, "element face", 12))	// Number of triangles
		{
			sscanf(buf, "element face %d\n", &num_faces);
		}
		else if (!strncmp(str, "end_header", 10))
		{
			DPoint2 p;
			float z;
			int optional;

			VTLOG("ReadPLY num_points %d\n", num_points);

			for (int i = 0; i < num_points; i++)
			{
				if (fgets(buf, 256, fp) == NULL)
					break;

				// First three are X, Y, Z.  Optional fourth is "ID" or "locked".
				sscanf(buf, "%lf %lf %f %d", &p.x, &p.y, &z, &optional);
#if 0
				// Some files have Y/-Z flipped (but they are non-standard)
				double temp = p.y; p.y = -z; z = temp;
#endif
				AddVert(p, z);

				if ((i%200) == 0 && progress_callback != NULL)
				{
					if (progress_callback(i * 49 / num_points))
					{
						fclose(fp);
						return false;	// user cancelled
					}
				}
			}

			// Then read the triangles
			VTLOG("ReadPLY num_faces %d\n", num_faces);

			int inu, a, b, c;
			for (int i = 0; i < num_faces; i++)
			{
				if (fgets(buf, 256, fp) == NULL)
					break;

				sscanf(buf, "%d %d %d %d\n", &inu, &a, &b, &c);
				AddTri(a, b, c);

				if ((i%200) == 0 && progress_callback != NULL)
				{
					if (progress_callback(49 + i * 50 / num_faces))
					{
						fclose(fp);
						return false;	// user cancelled
					}
				}
			}
		}
	}
	fclose(fp);
	ComputeExtents();
	return true;
}
Exemplo n.º 23
0
/**
 * Inspect \a name, and return the information about the parameters.
 * @param name Name to inspect.
 * @param pos Position to report in case of a found error.
 * @return The found parameter ranges.
 */
HorVert ParameterizedName::DecodeName(const char *name, const Position &pos)
{
	const char *p = name;

	delete[] this->name;
	this->name = nullptr;
	delete[] this->variant;
	this->variant = nullptr;

	this->result = HV_NONE;
	while (*p) {
		if (*p != '{') {
			p++;
			continue;
		}

		/* Check which type of parameter is used in the name. */
		ParameterizedNameRange *range;
		const char *range_type;
		if (strncmp(p, "{hor(", 5) == 0) {
			this->result = AddHor(this->result);
			range = &this->hor_range;
			range->offset = p - name;
			p += 5;
			range_type = "hor";
		} else {
			assert(strncmp(p, "{vert(", 6) == 0);
			this->result = AddVert(this->result);
			range = &this->vert_range;
			range->offset = p - name;
			p += 6;
			range_type = "vert";
		}

		/* Process range. */
		if (range->used) {
			fprintf(stderr, "Error at line %d: A \"%s\" range is used more than one time in name \"%s\".", pos.line, range_type, name);
			exit(1);
		}

		range->min_value = ReadNumber(&p);
		assert(p[0] == '.' && p[1] == '.');
		p += 2;
		range->max_value = ReadNumber(&p);
		assert(p[0] == ')' && p[1] == '}');
		p += 2;
		if (range->min_value > range->max_value) {
			fprintf(stderr, "Error at line %d: A \"%s\" range runs from %d to %d in name \"%s\", which is an empty range.", pos.line, range_type, range->min_value, range->max_value, name);
			exit(1);
		}
		range->used = true;
		range->length = (p - name) - range->offset;
		continue;
	}
	/* Copy name. */
	this->name = new char[(p - name) + 1];
	this->variant = new char[(p - name) + 1];
	memcpy(this->name, name, (p - name) + 1);

	return this->result;
}
Exemplo n.º 24
0
void MY_UI_Too::Renderer::DrawTexturedRect_Clip(const MY_UI_Too::Interfaces::ITexture* pTexture,const  MY_UI_Too::Utilities::UVs& uvs, const MY_UI_Too::Utilities::Rect rect,  const MY_UI_Too::Utilities::Color color_tl, const MY_UI_Too::Utilities::Color color_tr, const MY_UI_Too::Utilities::Color color_bl, const MY_UI_Too::Utilities::Color color_br, bool drawnow){
	if(!SetTexture(pTexture, drawnow)) return;
	assert(!ClipRects.empty());
	Utilities::Point tl(rect.left, rect.top);
	Utilities::Point tr(rect.left + rect.width, rect.top);
	Utilities::Point bl(rect.left, rect.top + rect.height);
	Utilities::Point br(rect.left + rect.width, rect.top + rect.height);
	// if all the points are not within the cliprect, dont draw it
	bool brin = ClipRects.back().Intersect(br);
	bool trin = ClipRects.back().Intersect(tr);

	bool blin = ClipRects.back().Intersect(bl);
	bool tlin = ClipRects.back().Intersect(tl);

	if( (!brin) & (!trin) & (!blin) & (!tlin)) return;// all points are outside the cliprect


	float left= static_cast<float>(rect.left);
	float top = static_cast<float>(rect.top);
	float width = static_cast<float>(rect.width);
	float right = width + left;
	float height = static_cast<float>(rect.height);
	float bottom = height + top;
	// resize the buffer if needed
	if(Draw_States[ Draw_State_Index ].Verts.size() <= 4 + Draw_States[ Draw_State_Index ].NumVerts ) Draw_States[ Draw_State_Index ].Verts.resize(Draw_States[ Draw_State_Index ].Verts.size() + 200);
	if( (brin) & (trin) & (blin) & (tlin)){// all points are fully contained inside the cliprect

		AddVert( left, top,					uvs.u1, uvs.v1, color_tl );
		AddVert( right, top,				uvs.u2, uvs.v1, color_tr );
		AddVert( left, bottom,				uvs.u1, uvs.v2, color_bl );
		AddVert( right, bottom,				uvs.u2, uvs.v2, color_br );


	} else {// this means the rect is partially in the clip region. Use the cpu to clip it

		Utilities::Rect& r = ClipRects.back();
		float newleft= static_cast<float>(Utilities::Clamp<int>(rect.left, r.left, r.left + r.width));
		float newtop = static_cast<float>(Utilities::Clamp<int>(rect.top, r.top, r.top + r.height));
		float newright = static_cast<float>(Utilities::Clamp<int>(rect.width + rect.left, r.left, r.left + r.width));
		float newbottom = static_cast<float>(Utilities::Clamp<int>(rect.height + rect.top, r.top, r.top + r.height));

		float difleft = newleft - left;
		float diftop = newtop - top;
		float difright = newright - right;
		float difbottom = newbottom - bottom;

		difleft /= width;
		diftop /= height;
		difright /= width;
		difbottom /= height;

		float u1 = uvs.u1;
		float v1 = uvs.v1;
		float u2 = uvs.u2;
		float v2 = uvs.v2;

		float uwidth = u2 - u1;
		float vheight = v2 - v1;

		u1 = u1 + (uwidth*difleft);
		u2 = u2 + (uwidth*difright);
		v1 = v1 + (vheight*diftop);
		v2 = v2 + (vheight*difbottom);

		AddVert( newleft, newtop,					u1, v1, color_tl );
		AddVert( newright, newtop,					u2, v1, color_tr );
		AddVert( newleft, newbottom,				u1, v2, color_bl );
		AddVert( newright, newbottom,				u2, v2, color_br );

	}
}