示例#1
0
int objLoad(char* filePath) {
   FILE* file = fopen(filePath, "r");
   char* line = (char*)calloc(LINE_SIZE, sizeof(char));
   char* token = NULL, * delim = " \n\t";

   int vertexCount = 0, textureCount = 0, normalCount = 0, faceCount = 0;
   while(fgets(line, LINE_SIZE, file) != NULL) {
      if(prefix("vt", line)) ++textureCount;
      else if(prefix("vn", line)) ++normalCount;
      else if(prefix("v", line))  ++vertexCount;
      else if(prefix("f", line))  ++faceCount;
   }
   rewind(file);

   obj* object = (obj*)calloc(1, sizeof(obj));
   object->faceCount = faceCount;
   object->vertexCount = vertexCount;
   object->vertices = (vec3*)calloc(vertexCount, sizeof(vec3));
   object->shared = (int*)calloc(vertexCount, sizeof(int));
   object->normals = (vec3*)calloc(normalCount, sizeof(vec3));
   object->tangents = (vec3*)calloc(vertexCount, sizeof(vec3));
   object->bitangents = (vec3*)calloc(vertexCount, sizeof(vec3));
   object->textures = (vec2*)calloc(textureCount, sizeof(vec2));
   object->faces = (face*)calloc(faceCount, sizeof(face));

   int vertexTally = 0, normalTally = 0, textureTally = 0, faceTally = 0;

   while(fgets(line, LINE_SIZE, file) != NULL) {
      if(prefix("vt", line)) {
         parseVec2(line, &object->textures[textureTally]);
         object->textures[textureTally].y = 1.0 - object->textures[textureTally].y;
         ++textureTally;
      }
      else if(prefix("vn", line)) parseVec3(line, &object->normals[normalTally++]);
      else if(prefix("v", line)) parseVec3(line, &object->vertices[vertexTally++]);
      else if(prefix("f", line)) parseFace(line, object->faces[faceTally++]);
   }
   uniqueMap(object);

   free(line);
   fclose(file);

   int index = nextIndex();
   objects[index] = object;
   return index;
}
示例#2
0
文件: MapEpetra.cpp 项目: lifev/lifev
void MapEpetra::createMap (Int  numGlobalElements,
                           Int  numMyElements,
                           Int* myGlobalElements,
                           const comm_Type& comm)
{
    if ( numMyElements != 0 && myGlobalElements == 0 ) // linearMap
        M_repeatedMapEpetra.reset ( new Epetra_Map ( numGlobalElements,
                                                     numMyElements,
                                                     0,
                                                     comm ) );
    else // classic LifeV map
        M_repeatedMapEpetra.reset ( new Epetra_Map ( numGlobalElements,
                                                     numMyElements,
                                                     myGlobalElements,
                                                     0,
                                                     comm ) );

    uniqueMap();
}
示例#3
0
文件: MapEpetra.cpp 项目: lifev/lifev
MapEpetra::MapEpetra ( const map_Type map ) :
    M_repeatedMapEpetra ( new map_Type ( map ) ),
    M_commPtr(map.Comm().Clone())
{
    uniqueMap ();
}