cgv
Loading...
Searching...
No Matches
obj_loader.h
1#pragma once
2
3#include "obj_reader.h"
4#include <map>
5#include <set>
6#include <cgv/math/fvec.h>
7
8#include <cgv/media/lib_begin.h>
9
10namespace cgv {
11 namespace media {
12 namespace mesh {
13
15struct CGV_API face_info
16{
18 unsigned degree;
30 face_info(unsigned _nr = 0, unsigned _vi0 = 0, int _ti0 = -1, int _ni0 = -1, unsigned gi=-1, unsigned mi=-1);
31};
32
34struct CGV_API line_info
35{
37 unsigned length;
47 line_info(unsigned _nr = 0, unsigned _vi0 = 0, int _ti0 = -1, int _ni0 = -1, unsigned gi = -1);
48};
49
50
53{
55 std::string name;
57 std::string parameters;
58};
59
63template <typename T>
64class CGV_API obj_loader_generic : public obj_reader_generic<T>
65{
66public:
67 // We need to repeat the typenames here, because gcc will not inherit them in templates
70 typedef obj_reader_base::color_type color_type;
71
72 std::vector<vec3_type> vertices;
73 std::vector<vec3_type> normals;
74 std::vector<vec2_type> texcoords;
75 std::vector<color_type> colors;
76
77 std::vector<unsigned> vertex_indices;
78 std::vector<unsigned> normal_indices;
79 std::vector<unsigned> texcoord_indices;
80
81 std::vector<line_info> lines;
82 std::vector<face_info> faces;
83 std::vector<group_info> groups;
84 std::vector<cgv::media::illum::obj_material> materials;
85protected:
89 void process_vertex(const vec3_type& p);
91 void process_texcoord(const vec2_type& t);
93 void process_normal(const vec3_type& n);
95 void process_color(const color_type& c);
97 void process_line(unsigned vcount, int* vertices, int* texcoords = 0, int* normals = 0);
99 void process_face(unsigned vcount, int* vertices, int* texcoords = 0, int* normals = 0);
101 void process_group(const std::string& name, const std::string& parameters);
103 void process_material(const cgv::media::illum::obj_material& mtl, unsigned idx);
105public:
107 bool read_obj(const std::string& file_name);
109 bool read_obj_bin(const std::string& file_name);
111 bool write_obj_bin(const std::string& file_name) const;
113 void show_stats() const;
115 void clear();
116};
117
118
122
123 }
124 }
125}
126
127#include <cgv/config/lib_end.h>
>extension of a phong material with support for texture mapped color channels
implements the virtual interface of the obj_reader and stores all read information.
Definition obj_loader.h:65
illum::obj_material::color_type color_type
type used for rgba colors
Definition obj_reader.h:22
implements the pure reading of an obj file and calls virtual callback functions to allow a derived cl...
Definition obj_reader.h:98
the cgv namespace
Definition print.h:11
simple structure to describe a face
Definition obj_loader.h:16
unsigned first_vertex_index
index into vertex index array
Definition obj_loader.h:20
int first_normal_index
index into normal index array or -1 if not specified
Definition obj_loader.h:24
int first_texcoord_index
index into texcoord index array or -1 if not specified
Definition obj_loader.h:22
int group_index
index of group to which the face belongs
Definition obj_loader.h:26
int material_index
material index to which the face belongs
Definition obj_loader.h:28
unsigned degree
degree of face
Definition obj_loader.h:18
simple structure to describe a group
Definition obj_loader.h:53
std::string parameters
parameters string
Definition obj_loader.h:57
std::string name
name of the group
Definition obj_loader.h:55
simple structure to describe a line
Definition obj_loader.h:35
int first_normal_index
index into normal index array or -1 if not specified
Definition obj_loader.h:43
int group_index
index of group to which the face belongs
Definition obj_loader.h:45
int first_texcoord_index
index into texcoord index array or -1 if not specified
Definition obj_loader.h:41
unsigned first_vertex_index
index into vertex index array
Definition obj_loader.h:39
unsigned length
length of line strip
Definition obj_loader.h:37