コード例 #1
0
void SolidConstrcutFromSurface(Solid * * solid, txTriSurfaceData *surf)
{
	Solid * s;
	s = SolidNew();

	VertexListConstrcutFromSurface(&s, surf);
	VertexListIndexConstruct(&s);
	FaceListConstructFromSurface(&s,surf);
	EdgeListConstruct(&s);

	*solid = s;
}
コード例 #2
0
ファイル: obj_read.cpp プロジェクト: shanfl/openglframework
Solid *ConstructHalfEdge_ModelFromOBJ_WStatus( char *FileName )
{
	struct _Model *m;
	FILE *file;
	Solid *s;
	int i;

	/* open the file */
	file = fopen(FileName, "r");
	if (!file) return NULL;

	/* load the OBJ, unitize it, compute facet normals, etc */
	m = (struct _Model *) malloc( sizeof( struct _Model ) );
	memset( m, 0, sizeof( struct _Model ) );
	m->file = strdup( FileName );
	ReadOBJFirstPass( m, file );
	rewind(file);
	ReadOBJSecondPass( m, file );
	Unitize_Model( m );
	ComputeFacetNormals( m );
	ComputeVertexNormals( m );
	fclose( file );
    
    s = SolidNew( );
	for (i=0; i< m->numVertices; i++)
		VertexConstructN( &s, m->vertexPos[3*i+0], m->vertexPos[3*i+1], m->vertexPos[3*i+2],
							  m->normList[3*i+0],  m->normList[3*i+1],  m->normList[3*i+2] );

	printf("    (-) Constructing faces (%8.4f%% done)...", 0.0f ); fflush( stdout );
	for (i=0; i< m->numTriangles; i++)
	{
		 Vertex *va = VertexListIndex( s, m->triVertexIndex[3*i+0] );
		 Vertex *vb = VertexListIndex( s, m->triVertexIndex[3*i+1] );
		 Vertex *vc = VertexListIndex( s, m->triVertexIndex[3*i+2] );
		 FaceConstruct( &s, va, vb, vc);
		 if (i%1000 == 0)
		 {
			printf("\r    (-) Constructing faces (%8.4f%% done)...", 100.0f*((float)i/m->numTriangles) ); 
			fflush( stdout );
		 }
	}
	printf("\r    (-) Constructing faces (%8.4f%% done)...\n", 100.0f ); fflush( stdout );

    EdgeListConstructVerbose(&s, m->numTriangles);

    return s;
}
コード例 #3
0
ファイル: obj_read.cpp プロジェクト: shanfl/openglframework
Solid *ConstructHalfEdge_ModelFromOBJ( char *FileName )
{
	struct _Model *m;
	FILE *file;
	Solid *s;
	int i;

	/* open the file */
	file = fopen(FileName, "r");
	if (!file) return NULL;

	/* load the OBJ, unitize it, compute facet normals, etc */
	m = (struct _Model *) malloc( sizeof( struct _Model ) );
	memset( m, 0, sizeof( struct _Model ) );
	m->file = strdup( FileName );
	ReadOBJFirstPass( m, file );
	rewind(file);
	ReadOBJSecondPass( m, file );
	Unitize_Model( m );
	ComputeFacetNormals( m );
	ComputeVertexNormals( m );
	fclose( file );
    
    s = SolidNew( );
	for (i=0; i< m->numVertices; i++)
		VertexConstructN( &s, m->vertexPos[3*i+0], m->vertexPos[3*i+1], m->vertexPos[3*i+2],
							  m->normList[3*i+0],  m->normList[3*i+1],  m->normList[3*i+2] );

	for (i=0; i< m->numTriangles; i++)
	{
		 Vertex *va = VertexListIndex( s, m->triVertexIndex[3*i+0] );
		 Vertex *vb = VertexListIndex( s, m->triVertexIndex[3*i+1] );
		 Vertex *vc = VertexListIndex( s, m->triVertexIndex[3*i+2] );
		 FaceConstruct( &s, va, vb, vc);
	}

    EdgeListConstruct(&s);

    return s;
}
コード例 #4
0
ファイル: input_hem.cpp プロジェクト: shanfl/openglframework
Solid *LoadHalfEdgeModel( char *FileName )
{
	FILE *file;
	Solid *s;
	char buf[512];
	unsigned int vertCount=0, triCount=0, edgeCount=0;
	unsigned int verts=0, tris=0, edges=0;
	Vertex *vertMem=0;
	Edge *edgeMem=0;
	Face *faceMem=0;

	/* open the file */
	file = fopen(FileName, "r");
	if (!file) return NULL;

	// Get our edge, triangle, and vertex counts!
	while ( !vertCount || !triCount || !edgeCount )
	{
		if ( fgets(buf, 512, file) == NULL ) break;
		if (buf[0] == '#' || buf[0] == ' ') continue;
		if (buf[0] == 'v')
			sscanf( buf, "verts %d", &vertCount );
		if (buf[0] == 't')
			sscanf( buf, "tris  %d", &triCount );
		if (buf[0] == 'e')
			sscanf( buf, "edges %d", &edgeCount );
	}

	//printf("Count: %d %d %d\n", vertCount, triCount, edgeCount );
	
	// If we got to the end of the file, print an error, return NULL
	if (feof(file))
	{
		fclose( file );
		printf("**** Error: Reached EOF before encountering vert/tri/edge count!\n");
		return 0;
	}

	vertMem = (Vertex *) malloc( sizeof( Vertex ) * vertCount );
	faceMem = (Face *) malloc( sizeof( Face ) * triCount );
	edgeMem = (Edge *) malloc( sizeof( Edge ) * edgeCount );

	s = SolidNew( );
	s->sedges = edgeMem;
	s->sfaces = faceMem;
	s->sverts = vertMem;

//#define DEBUG
#ifdef DEBUG
	printf("# edge faces = %d\n",edgeCount);
#endif

	// Read in the geometry
	while ( !feof( file ) )
	{
		if ( fgets(buf, 512, file) == NULL ) break;
		if (buf[0] == '#' || buf[0] == ' ') continue;

		if (buf[0] == 'v')
		{
			unsigned int ID;
			float pos[3], norm[3];
			sscanf( buf, "v %d %f %f %f %f %f %f", &ID,
					&pos[0], &pos[1], &pos[2], &norm[0], &norm[1], &norm[2] );
			VertexAddExisting( &vertMem[ID], &(s->sverts) );
			vertMem[ID].vertexno = ID;
			vertMem[ID].vcoord[0] = pos[0];
			vertMem[ID].vcoord[1] = pos[1];
			vertMem[ID].vcoord[2] = pos[2];
			vertMem[ID].ncoord[0] = norm[0];
			vertMem[ID].ncoord[1] = norm[1];
			vertMem[ID].ncoord[2] = norm[2];
		}
		else if (buf[0] == 't')
		{
			HalfEdge *he;
			Face *ptr;
			unsigned int ID;
			unsigned int vertID[3], edgeID[3];
			sscanf( buf, "t %d %d %d %d %d %d %d", &ID,
					&vertID[0], &vertID[1], &vertID[2], &edgeID[0], &edgeID[1], &edgeID[2] );
			FaceAddExisting( &faceMem[ID], &(s->sfaces) );
			faceMem[ID].fsolid = s;
			faceMem[ID].faceno = ID;
			ptr = &faceMem[ID];
			LoopConstruct( &ptr, &vertMem[vertID[0]], &vertMem[vertID[1]], &vertMem[vertID[2]] );
			he = faceMem[ID].floop->ledges;
			he->hedge = &edgeMem[edgeID[0]];
			if (edgeMem[edgeID[0]].he1)
				edgeMem[edgeID[0]].he2 = he;
			else
				edgeMem[edgeID[0]].he1 = he;
			he = he->next;
			he->hedge = &edgeMem[edgeID[1]];
			if (edgeMem[edgeID[1]].he1)
				edgeMem[edgeID[1]].he2 = he;
			else
				edgeMem[edgeID[1]].he1 = he;
			he = he->next;
			he->hedge = &edgeMem[edgeID[2]];
			if (edgeMem[edgeID[2]].he1)
				edgeMem[edgeID[2]].he2 = he;
			else
				edgeMem[edgeID[2]].he1 = he;
		}
		else if (buf[0] == 'e')
		{
			unsigned int ID;
			unsigned int vertID1, vertID2;
			sscanf( buf, "e %d %d %d", &ID, &vertID1, &vertID2 );
		//	printf(" Read e %d %d %d\n",ID, vertID1, vertID2 ); 
			EdgeAddExisting( &edgeMem[ID], &(s->sedges) );
			edgeMem[ID].edgeno = ID;
			edgeMem[ID].esolid = s;
			edgeMem[ID].he1 = 0;
			edgeMem[ID].he2 = 0;
		}
	}

	fclose( file );
    
	// Now we have to update the edge list to make sure we point to the half edges.
    //EdgeListConstruct(&s);

    return s;
}