DHART
Loading...
Searching...
No Matches
objloader.h
Go to the documentation of this file.
1#pragma once
8
9#ifndef OBJLOADER_H
10#define OBJLOADER_H
11
12#include <vector>
13#include <string>
14#include "meshinfo.h"
15
30namespace Eigen {}
31
32
33
34// [nanoRT]
35namespace HF::nanoGeom {
36 bool LoadObj(Mesh& mesh, const char* filename);
37}
38// end [nanoRT]
39
40
41
58namespace HF::Geometry{
69 };
70
71 template <typename T>
72 struct tinyobj_attr {
73 std::vector<T> vertices;
74 };
75
76
77 template <typename T>
79 std::string name;
80 std::vector<int> indices;
81 std::vector<int> mat_ids;
82 };
83
85 std::string name;
86 };
87
88 template <typename T>
90 std::vector<tinyobj_shape<T>> shapes;
92 std::vector<tinyobj_material> materials;
93 };
94
96
97 template <typename T>
99
100 // Load the mesh from tinyobj
102
103 // Count total indexes
104 int index_count = 0;
105 for (const auto & shape : geom.shapes)
106 index_count +=shape.indices.size();
107
108
109 // Copy all indices into one big array
110 int last_index = 0;
111 std::vector<int> complete_indices(index_count);
112 for (const auto& shape : geom.shapes) {
113 std::copy(shape.indices.begin(), shape.indices.end(), complete_indices.begin() + last_index);
114 last_index += shape.indices.size();
115 }
116
117 //std::vector<T> converted_vertices = ConvertVertices<T, double>(geom.attributes.vertices);
118
119 //Convert vertices to T
120 std::vector<T> out_vertices(geom.attributes.vertices.size());
121 for (int i = 0; i < geom.attributes.vertices.size(); i++)
122 out_vertices[i] = static_cast<T>(geom.attributes.vertices[i]);
123
124 return HF::Geometry::MeshInfo<T>(out_vertices, complete_indices, 1, std::string("DoubleMesh"));
125 }
126
127
134
163 std::vector<MeshInfo<float>> LoadMeshObjects(
164 std::string path,
166 bool change_coords = false,
167 int scale = 1
168 );
169
176
208 std::vector<MeshInfo<float>> LoadMeshObjects(
209 std::vector<std::string>& path,
211 bool change_coords = false,
212 int scale = 1
213 );
214
248 std::vector<std::array<float, 3>> LoadRawVertices(std::string path);
249
250
261 std::string GetTestOBJPath(std::string key);
262}
263
264#endif
Contains definitions for the MeshInfo class.
Manipulate and load geometry from disk.
Definition: meshinfo.cpp:21
vector< MeshInfo< float > > LoadMeshObjects(std::string path, GROUP_METHOD gm, bool change_coords, int scale)
Create MeshInfo instances from the OBJ at path.
Definition: objloader.cpp:195
std::vector< int > mat_ids
Definition: objloader.h:81
std::vector< tinyobj_material > materials
Definition: objloader.h:92
tinyobj_attr< T > attributes
Definition: objloader.h:91
std::vector< tinyobj_shape< T > > shapes
Definition: objloader.h:90
HF::Geometry::MeshInfo< T > LoadTMPMeshObjects(const std::string &path)
Definition: objloader.h:98
tinyobj_geometry< double > LoadMeshesFromTinyOBJ(std::string path)
Definition: objloader.cpp:177
std::vector< T > vertices
Definition: objloader.h:73
GROUP_METHOD
Method of grouping submeshes in OBJ files.
Definition: objloader.h:64
@ ONLY_FILE
Treat all the geometry in the file as a single mesh.
Definition: objloader.h:65
@ MATERIAL_AND_FILE
UNIMPLEMENTED.
Definition: objloader.h:68
@ BY_MATERIAL
Create a new MeshInfo instance for every different material in the file.
Definition: objloader.h:67
@ BY_GROUP
Create a new MeshInfo instance for every OBJ group in the file.
Definition: objloader.h:66
std::vector< int > indices
Definition: objloader.h:80
std::string GetTestOBJPath(std::string key)
Get the path to the OBJ with the given key.
Definition: objloader.cpp:407
vector< array< float, 3 > > LoadRawVertices(std::string path)
Load a list of vertices directly from an OBJ file.
Definition: objloader.cpp:371
bool LoadObj(Mesh &mesh, const char *filename)
Definition: objloader.cpp:29
Eigen a C++ template library for linear algebra: matrices, vectors, numerical solvers,...
Definition: objloader.h:30
A collection of vertices and indices representing geometry.
Definition: meshinfo.h:124