6#include <cgv/math/fvec.h>
7#include <cgv/math/fmat.h>
8#include <cgv/utils/file.h>
9#include <cgv/media/illum/textured_surface_material.h>
10#include <cgv/media/axis_aligned_box.h>
11#include <cgv/media/colored_model.h>
13#include "../lib_begin.h"
41 begin=0, position=0, texcoords=1, normal=2, tangent=3,
color=4, end=5
51 static std::string get_attribute_name(attribute_type attr);
52 static AttributeFlags get_attribute_flag(attribute_type attr);
53 virtual bool has_attribute(attribute_type attr)
const = 0;
54 virtual const uint8_t* get_attribute_ptr(attribute_type attr, idx_type ai = 0)
const = 0;
55 virtual size_t get_attribute_size(attribute_type attr)
const = 0;
56 virtual size_t get_attribute_offset(attribute_type attr)
const = 0;
58 std::vector<idx_type> position_indices;
59 std::vector<idx_type> tex_coord_indices;
60 std::vector<idx_type> normal_indices;
61 std::vector<idx_type> tangent_indices;
62 std::vector<idx_type> faces;
63 std::vector<idx_type> group_indices;
64 std::vector<std::string> group_names;
65 std::vector<idx_type> material_indices;
66 std::vector<mat_type> materials;
102 bool has_normal_indices()
const {
return normal_indices.size() > 0 && normal_indices.size() == position_indices.size(); }
106 bool has_tex_coord_indices()
const {
return tex_coord_indices.size() > 0 && tex_coord_indices.size() == position_indices.size(); }
142 const std::string&
group_name(
size_t i)
const {
return group_names[i]; }
152 void revert_face_orientation();
162 void sort_faces(std::vector<idx_type>& perm,
bool by_group =
true,
bool by_material =
true)
const;
185 void merge_indices(std::vector<idx_type>& vertex_indices, std::vector<idx4_type>& unique_tuples,
186 bool* include_tex_coords_ptr = 0,
bool* include_normals_ptr = 0,
bool* include_tangents_ptr = 0)
const;
198 void extract_triangle_element_buffer(
const std::vector<idx_type>& vertex_indices,
199 std::vector<idx_type>& triangle_element_buffer,
200 const std::vector<idx_type>* face_permutation_ptr = 0,
201 std::vector<idx3_type>* material_group_start_ptr = 0)
const;
210 void extract_wireframe_element_buffer(
const std::vector<idx_type>& vertex_indices,
211 std::vector<idx_type>& edge_element_buffer)
const;
213 idx_type extract_vertex_attribute_buffer_base(
const std::vector<idx4_type>& unique_quadruples, AttributeFlags& flags, std::vector<uint8_t>& attrib_buffer)
const;
230 idx_type compute_inv(
231 std::vector<idx_type>& inv,
232 bool link_non_manifold_edges =
false,
233 std::vector<idx_type>* p2c_ptr = 0,
234 std::vector<idx_type>* next_ptr = 0,
235 std::vector<idx_type>* prev_ptr = 0,
236 std::vector<idx_type>* unmatched = 0,
237 std::vector<idx_type>* non_manifold = 0,
238 std::vector<idx_type>* unmatched_elements = 0,
239 std::vector<idx_type>* non_manifold_elements = 0)
const;
241 idx_type compute_c2e(
const std::vector<idx_type>& inv, std::vector<idx_type>& c2e, std::vector<idx_type>* e2c_ptr = 0)
const;
243 void compute_c2f(std::vector<idx_type>& c2f)
const;
247template <
typename T =
float>
251 using numeric_type = T;
265 std::vector<vec3_type> positions;
266 std::vector<vec3_type> normals;
267 std::vector<vec3_type> tangents;
268 std::vector<vec2_type> tex_coords;
271 case attribute_type::position:
return true;
272 case attribute_type::texcoords:
return has_tex_coords() && has_tex_coord_indices();
273 case attribute_type::normal:
return has_normals() && has_normal_indices();
274 case attribute_type::tangent:
return has_tangents();
275 case attribute_type::color:
return has_colors();
280 const uint8_t* get_attribute_ptr(attribute_type attr, idx_type ai = 0)
const {
282 case attribute_type::position:
return reinterpret_cast<const uint8_t*
>( &positions[ai]);
283 case attribute_type::texcoords:
return reinterpret_cast<const uint8_t*
>(&tex_coords[ai]);
284 case attribute_type::normal:
return reinterpret_cast<const uint8_t*
>( &normals[ai]);
285 case attribute_type::tangent:
return reinterpret_cast<const uint8_t*
>( &tangents[ai]);
286 case attribute_type::color:
return reinterpret_cast<const uint8_t*
>(get_color_data_ptr()) + ai * get_color_size();
291 size_t get_attribute_size(attribute_type attr)
const {
293 case attribute_type::position:
return sizeof(vec3_type);
294 case attribute_type::texcoords:
return sizeof(vec2_type);
295 case attribute_type::normal:
return sizeof(vec3_type);
296 case attribute_type::tangent:
return sizeof(vec3_type);
297 case attribute_type::color:
return get_color_size();
302 size_t get_attribute_offset(attribute_type attr)
const
304 size_t s = get_attribute_size(attr);
309 vec3_type compute_normal(
const vec3_type& p0,
const vec3_type& p1,
const vec3_type& p2);
312 simple_mesh(
const simple_mesh<T>& sm);
314 simple_mesh(simple_mesh<T>&& sm);
316 simple_mesh(
const std::string& conway_notation =
"");
318 simple_mesh<T>& operator= (
const simple_mesh<T>& sm);
320 simple_mesh<T>& operator= (simple_mesh<T>&& sm);
330 vec3_type& position(idx_type pi) {
return positions[pi]; }
331 const vec3_type& position(idx_type pi)
const {
return positions[pi]; }
332 const std::vector<vec3_type>& get_positions()
const {
return positions; }
333 std::vector<vec3_type>& ref_positions() {
return positions; }
339 idx_type get_nr_normals()
const {
return idx_type(normals.size()); }
340 vec3_type& normal(idx_type ni) {
return normals[ni]; }
341 const vec3_type& normal(idx_type ni)
const {
return normals[ni]; }
342 const std::vector<vec3_type>& get_normals()
const {
return normals; }
348 idx_type get_nr_tangents()
const {
return idx_type(tangents.size()); }
349 vec3_type& tangent(idx_type ti) {
return tangents[ti]; }
350 const vec3_type& tangent(idx_type ti)
const {
return tangents[ti]; }
356 idx_type get_nr_tex_coords()
const {
return idx_type(tex_coords.size()); }
357 vec2_type& tex_coord(idx_type ti) {
return tex_coords[ti]; }
358 const vec2_type& tex_coord(idx_type ti)
const {
return tex_coords[ti]; }
361 bool compute_face_normal(idx_type fi, vec3_type& nml,
bool normalize =
true)
const;
363 vec3_type compute_face_center(idx_type fi)
const;
365 void compute_face_normals(
bool construct_normal_indices =
true);
367 void compute_face_tangents(
bool construct_tangent_indices =
true);
371 void truncate(T lambda = 0.33333f);
373 void snub(T lambda = 0.33333f);
377 void gyro(T lambda = 0.3333f);
383 void construct_conway_polyhedron(
const std::string& conway_notation);
386 box_type compute_box()
const;
388 void compute_vertex_normals(
bool use_parallel_implementation =
true);
390 void construct(
const obj_loader_generic<T>& loader,
bool copy_grp_info,
bool copy_material_info);
392 bool read(
const std::string& file_name);
394 bool write(
const std::string& file_name)
const;
407 unsigned extract_vertex_attribute_buffer(
const std::vector<idx4_type>& unique_quadruples,
bool include_tex_coords,
408 bool include_normals,
bool include_tangents, std::vector<T>& attrib_buffer,
409 bool* include_colors_ptr = 0,
int* num_floats_in_vertex =
nullptr)
const;
411 void transform(
const mat3_type& linear_transformation,
const vec3_type& translation);
413 void transform(
const mat3_type& linear_transform,
const vec3_type& translation,
const mat3_type& inverse_linear_transform);
420#include <cgv/config/lib_end.h>
matrix of fixed size dimensions
A vector with zero based index.
simple class to hold the material properties of a phong material
unsigned int uint32_type
this type provides an 32 bit unsigned integer type