Пример #1
0
int     get_files_list(char *pathname, t_option_struct *option_struct)
{
  char          *new_pathname;
  t_file_info   **file_info_array;
  int           i;

  file_info_array = make_info_array(pathname);
  if (file_info_array == NULL)
    return (0);
  if (option_struct->t == 1)
    file_info_array = sort_time_info_array(file_info_array);
  else
    file_info_array = sort_name_info_array(file_info_array);
  if (option_struct->r == 1)
    read_reverse(file_info_array, option_struct);
  else
    read_normal(file_info_array, option_struct);
  i = 0;
  while (file_info_array[i] != NULL)
    free(file_info_array[i++]);
  free(file_info_array);
  return (0);
}
Пример #2
0
Model_error_code OBJ_load (const char* filename, char clockwise, char left_handed, Model* model)
{
    vec3* norms     = 0;
    vec3* verts     = 0;
    texCoord* texcs = 0;
    triangle* tris  = 0;
    
    FILE* file = fopen (filename, "r");
    if (file == NULL) return Model_File_Not_Found;
    
    vec3 vert;
    vec3 normal;
    texCoord texc;
    
    vector vertices;
    vector normals;
    vector texCoords;
    vector triangles;
    
    int result = vector_new (&vertices,  sizeof(vec3),     0)
               | vector_new (&normals,   sizeof(vec3),     0)
               | vector_new (&texCoords, sizeof(texCoord), 0)
               | vector_new (&triangles, sizeof(triangle), 0);
    
    if (result != 0)
    {
        safe_free (vertices.data);
        safe_free (normals.data);
        safe_free (texCoords.data);
        safe_free (triangles.data);
        return Model_Memory_Allocation_Error;
    }
    
    while (!feof(file))
    {
        switch (fgetc(file))
        {
        case 'v':
            switch (fgetc(file))
            {
            case 't':
                read_tex_coord (file, &texc);
                vector_append (&texCoords, &texc);
                break;
                
            case 'n':
                read_normal (file, &normal);
                vector_append (&normals, &normal);
                break;
                
            default:
                read_vertex (file, &vert);
                vector_append (&vertices, &vert);
                break;
            }
            break;
            
        case 'f':
            // Initialise the normals vector if it is empty.
            if (vector_size(&normals) == 0)
            {
                vec3 zero;
                zero.x = 0.0f; zero.y = 0.0f; zero.z = 0.0f;
                vector_new (&normals, sizeof(vec3), vector_size(&vertices));
                vector_initialise (&normals, &zero);
            }
            read_face (file, clockwise, &vertices, &normals, &triangles);
            break;
        
        case '#':
        {
            int x = 17;
            while (x != '\n' && x != EOF) x = fgetc(file);
            break;
        }
            
        default: break;
        }
    }
    
    fclose (file);
    
    unsigned numVertices = vector_size (&vertices);
    
    // Normalise normals.
    unsigned i;
    for (i = 0; i < numVertices; ++i)
    {
        normalise (vector_ith (&normals, i));
    }
    
    model->vertices      = (vec3*) vertices.data;
    model->normals       = (vec3*) normals.data;
    model->texCoords     = (texCoord*) texCoords.data;
    model->triangles     = (triangle*) triangles.data;
    model->skins         = 0;
    model->animations    = 0;
    model->numFrames     = 1;
    model->numVertices   = numVertices;
    model->numTriangles  = vector_size (&triangles);
    model->numTexCoords  = vector_size (&texCoords);
    model->numSkins      = 0;
    model->numAnimations = 0;
    
    return Model_Success;
}