gKit3
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
MeshIOData Struct Reference

Public Member Functions

int find_object (const char *name)
 
std::vector< MeshIOGroupsort_by_material ()
 
std::vector< MeshIOGroupsort_by_object ()
 
std::vector< MeshIOGroupgroups (const std::vector< int > &properties)
 

Public Attributes

std::vector< Pointpositions
 
std::vector< Pointtexcoords
 
std::vector< Vectornormals
 
std::vector< unsigned > indices
 
Materials materials
 
std::vector< int > material_indices
 
std::vector< std::string > object_names
 
std::vector< int > object_indices
 

Detailed Description

Definition at line 167 of file mesh_io.h.

Member Function Documentation

◆ find_object()

int MeshIOData::find_object ( const char *  name)

Definition at line 427 of file mesh_io.cpp.

428{
429 for(unsigned i= 0; i < object_names.size(); i++)
430 if(object_names[i] == name)
431 return i;
432
433 return -1;
434}

◆ sort_by_material()

std::vector< MeshIOGroup > MeshIOData::sort_by_material ( )
inline

Definition at line 181 of file mesh_io.h.

181{ return groups(material_indices); }

◆ sort_by_object()

std::vector< MeshIOGroup > MeshIOData::sort_by_object ( )
inline

Definition at line 182 of file mesh_io.h.

182{ return groups(object_indices); }

◆ groups()

std::vector< MeshIOGroup > MeshIOData::groups ( const std::vector< int > &  properties)

Definition at line 436 of file mesh_io.cpp.

437{
438 std::vector<int> remap( properties.size() );
439 for(unsigned i= 0; i < remap.size(); i++)
440 remap[i]= i;
441
442 std::stable_sort(remap.begin(), remap.end(),
443 [&]( const int a, const int b)
444 {
445 return properties[a] < properties[b];
446 });
447
448 // re-organise l'index buffer
449 std::vector<unsigned> tmp;
450 tmp.reserve(indices.size());
451 for(unsigned i= 0; i < remap.size(); i++)
452 {
453 int id= remap[i];
454 tmp.push_back( indices[3*id] );
455 tmp.push_back( indices[3*id+1] );
456 tmp.push_back( indices[3*id+2] );
457 }
458
459 std::swap(indices, tmp);
460
461 // construit les groupes de triangles
462 std::vector<MeshIOGroup> groups;
463
464 // first group
465 int id= properties[remap[0]];
466 unsigned first= 0;
467 unsigned count= 1;
468 for(unsigned i= 1; i < remap.size(); i++)
469 {
470 if(properties[remap[i]] != id)
471 {
472 groups.push_back({ id, first, count });
473 // restart
474 id= properties[remap[i]];
475 first= i;
476 count= 0;
477 }
478
479 count++;
480 }
481
482 // last group
483 groups.push_back({ id, first, count });
484
485 {
486 // re-organise aussi les indices de matieres
487 std::vector<int> tmp;
488 tmp.reserve(remap.size());
489 for(unsigned i= 0; i < remap.size(); i++)
490 tmp.push_back( material_indices[remap[i]] );
491
492 std::swap(material_indices, tmp);
493
494 // re-organise aussi les indices d'objets
495 tmp.clear();
496 for(unsigned i= 0; i < remap.size(); i++)
497 tmp.push_back( object_indices[remap[i]] );
498
499 std::swap(object_indices, tmp);
500 }
501
502 return groups;
503}

Member Data Documentation

◆ positions

std::vector<Point> MeshIOData::positions

Definition at line 169 of file mesh_io.h.

◆ texcoords

std::vector<Point> MeshIOData::texcoords

Definition at line 170 of file mesh_io.h.

◆ normals

std::vector<Vector> MeshIOData::normals

Definition at line 171 of file mesh_io.h.

◆ indices

std::vector<unsigned> MeshIOData::indices

Definition at line 172 of file mesh_io.h.

◆ materials

Materials MeshIOData::materials

Definition at line 174 of file mesh_io.h.

◆ material_indices

std::vector<int> MeshIOData::material_indices

Definition at line 175 of file mesh_io.h.

◆ object_names

std::vector<std::string> MeshIOData::object_names

Definition at line 177 of file mesh_io.h.

◆ object_indices

std::vector<int> MeshIOData::object_indices

Definition at line 178 of file mesh_io.h.


The documentation for this struct was generated from the following files: