CGVIS Utils
Loading...
Searching...
No Matches
OBJFile.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <array>
5#include <string>
6#include <sstream>
7
8#include "Vec3.h"
9
27class OBJFile {
28public:
37 OBJFile(const std::string& filename, bool normalize=false);
38
43 typedef std::array<size_t, 3> IndexType;
44
46 std::vector<IndexType> indices;
48 std::vector<Vec3> vertices;
54 std::vector<Vec3> normals;
55
56private:
58 void ltrim(std::string &s);
60 void rtrim(std::string &s);
62 void trim(std::string &s);
69 std::vector<std::string> tokenize(const std::string& str, size_t startpos);
70
77 template <typename T> T fromStr(const std::string& str) {
78 T t;
79 std::istringstream iss{str};
80 iss >> std::dec >> t;
81 return t;
82 }
83
84
85};
3D vector template with arithmetic, geometry helpers, and RNG utilities.
std::vector< Vec3 > normals
Per-vertex normals.
Definition OBJFile.h:54
std::vector< Vec3 > vertices
Vertex positions parsed from "v" records (x,y,z).
Definition OBJFile.h:48
std::vector< IndexType > indices
Triangle index buffer (each element is one face as three indices).
Definition OBJFile.h:46
std::array< size_t, 3 > IndexType
Index triple forming one triangle (zero-based vertex indices).
Definition OBJFile.h:43
OBJFile(const std::string &filename, bool normalize=false)
Load an OBJ file.
Definition OBJFile.cpp:6