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;
225 void extract_triangle_indices(std::vector<idx3_type>& position_indices, std::vector<idx3_type>* tex_coord_indices =
nullptr, std::vector<idx3_type>* normal_indices =
nullptr, std::vector<idx3_type>* tangent_indices =
nullptr)
const;
242 idx_type compute_inv(
243 std::vector<idx_type>& inv,
244 bool link_non_manifold_edges =
false,
245 std::vector<idx_type>* p2c_ptr = 0,
246 std::vector<idx_type>* next_ptr = 0,
247 std::vector<idx_type>* prev_ptr = 0,
248 std::vector<idx_type>* unmatched = 0,
249 std::vector<idx_type>* non_manifold = 0,
250 std::vector<idx_type>* unmatched_elements = 0,
251 std::vector<idx_type>* non_manifold_elements = 0)
const;
253 idx_type compute_c2e(
const std::vector<idx_type>& inv, std::vector<idx_type>& c2e, std::vector<idx_type>* e2c_ptr = 0)
const;
255 void compute_c2f(std::vector<idx_type>& c2f)
const;
259template <
typename T =
float>
263 using numeric_type = T;
277 std::vector<vec3_type> positions;
278 std::vector<vec3_type> normals;
279 std::vector<vec3_type> tangents;
280 std::vector<vec2_type> tex_coords;
283 case attribute_type::position:
return true;
284 case attribute_type::texcoords:
return has_tex_coords() && has_tex_coord_indices();
285 case attribute_type::normal:
return has_normals() && has_normal_indices();
286 case attribute_type::tangent:
return has_tangents();
287 case attribute_type::color:
return has_colors();
292 const uint8_t* get_attribute_ptr(attribute_type attr, idx_type ai = 0)
const {
294 case attribute_type::position:
return reinterpret_cast<const uint8_t*
>( &positions[ai]);
295 case attribute_type::texcoords:
return reinterpret_cast<const uint8_t*
>(&tex_coords[ai]);
296 case attribute_type::normal:
return reinterpret_cast<const uint8_t*
>( &normals[ai]);
297 case attribute_type::tangent:
return reinterpret_cast<const uint8_t*
>( &tangents[ai]);
298 case attribute_type::color:
return reinterpret_cast<const uint8_t*
>(get_color_data_ptr()) + ai * get_color_size();
303 size_t get_attribute_size(attribute_type attr)
const {
305 case attribute_type::position:
return sizeof(vec3_type);
306 case attribute_type::texcoords:
return sizeof(vec2_type);
307 case attribute_type::normal:
return sizeof(vec3_type);
308 case attribute_type::tangent:
return sizeof(vec3_type);
309 case attribute_type::color:
return get_color_size();
314 size_t get_attribute_offset(attribute_type attr)
const
316 size_t s = get_attribute_size(attr);
321 vec3_type compute_normal(
const vec3_type& p0,
const vec3_type& p1,
const vec3_type& p2);
324 simple_mesh(
const simple_mesh<T>& sm);
326 simple_mesh(simple_mesh<T>&& sm);
328 simple_mesh(
const std::string& conway_notation =
"");
330 simple_mesh<T>& operator= (
const simple_mesh<T>& sm);
332 simple_mesh<T>& operator= (simple_mesh<T>&& sm);
342 vec3_type& position(idx_type pi) {
return positions[pi]; }
343 const vec3_type& position(idx_type pi)
const {
return positions[pi]; }
344 const std::vector<vec3_type>& get_positions()
const {
return positions; }
345 std::vector<vec3_type>& ref_positions() {
return positions; }
351 idx_type get_nr_normals()
const {
return idx_type(normals.size()); }
352 vec3_type& normal(idx_type ni) {
return normals[ni]; }
353 const vec3_type& normal(idx_type ni)
const {
return normals[ni]; }
354 const std::vector<vec3_type>& get_normals()
const {
return normals; }
360 idx_type get_nr_tangents()
const {
return idx_type(tangents.size()); }
361 vec3_type& tangent(idx_type ti) {
return tangents[ti]; }
362 const vec3_type& tangent(idx_type ti)
const {
return tangents[ti]; }
368 idx_type get_nr_tex_coords()
const {
return idx_type(tex_coords.size()); }
369 vec2_type& tex_coord(idx_type ti) {
return tex_coords[ti]; }
370 const vec2_type& tex_coord(idx_type ti)
const {
return tex_coords[ti]; }
373 bool compute_face_normal(idx_type fi, vec3_type& nml,
bool normalize =
true)
const;
375 vec3_type compute_face_center(idx_type fi)
const;
377 void compute_face_normals(
bool construct_normal_indices =
true);
379 void compute_face_tangents(
bool construct_tangent_indices =
true);
383 void truncate(T lambda = 0.33333f);
385 void snub(T lambda = 0.33333f);
389 void gyro(T lambda = 0.3333f);
395 void construct_conway_polyhedron(
const std::string& conway_notation);
398 box_type compute_box()
const;
400 void compute_vertex_normals(
bool use_parallel_implementation =
true);
402 void construct(
const obj_loader_generic<T>& loader,
bool copy_grp_info,
bool copy_material_info);
404 bool read(
const std::string& file_name);
406 bool write(
const std::string& file_name)
const;
419 unsigned extract_vertex_attribute_buffer(
const std::vector<idx4_type>& unique_quadruples,
bool include_tex_coords,
420 bool include_normals,
bool include_tangents, std::vector<T>& attrib_buffer,
421 bool* include_colors_ptr = 0,
int* num_floats_in_vertex =
nullptr)
const;
423 void transform(
const mat3_type& linear_transformation,
const vec3_type& translation);
425 void transform(
const mat3_type& linear_transform,
const vec3_type& translation,
const mat3_type& inverse_linear_transform);
432#include <cgv/config/lib_end.h>
matrix of fixed size dimensions
A vector with zero based index.
Stores properties of a surface material with support for texturing.
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
this header is dependency free