-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.h
More file actions
156 lines (138 loc) · 3.77 KB
/
Object.h
File metadata and controls
156 lines (138 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#pragma once
#include "Screen.h"
#include "stdafx.h"
class V {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Vector3R v;
V(Real x, Real y, Real z, Real w = 1) {
v = Vector3R(x, y, z);
}
};
class VN {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Vector3R v;
VN(Real x, Real y, Real z, Real w = 1) {
v = Vector3R(x, y, z);
}
VN(const Vector3R& v) { this->v = v; }
};
class VT {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Vector3R v;
VT(Real x, Real y, Real z, Real w = 1) {
v = Vector3R(x, y, z);
}
};
class Material;
class F {
public:
std::vector<int> v;
std::vector<int> vt;
std::vector<int> vn;
Material *materialPtr;
F(std::string, std::string, std::string);
};
class Sphere {
public:
Vector3R center;
Real r;
Material *materialPtr;
Sphere(Real x, Real y, Real z, Real _r, Material *_m) : center(Vector3R(x, y, z)), r(_r), materialPtr(_m) {}
};
class Ray {
public:
Vector3R source;
Vector3R direction;
Ray(){}
Ray(const Vector3R& s_, const Vector3R& d_) {
source = s_;
direction = d_;
}
static Ray fromPoints(const Vector3R& s_, const Vector3R& p_) {
Ray ray;
ray.source = s_;
ray.direction = (p_ - s_).normalized();
return ray;
}
};
class Texture {
public:
Texture() {}
std::vector<std::vector<Real>> bump;
std::vector<std::vector<std::vector<Real>>> texture;
void loadBump(const char*);
void loadTexture(const char*);
int H, W;
};
class Material
{
public:
Material(){};
~Material(){};
Material(const Material&);
//std::string name;
vector<Real> Kd, Ks, Td, Ts;
int Ns = -1;
Real n = 1; // relative refraction rate
int Nst = -1;
Texture *texturePtr;
unsigned short flag = 0; // 1 rd | 2 rs | 4 tr | 8 td | 16 ts | 32 texture | 64 brdf | channel: 128 bump | 256 Kd | Ks | Td | Ts | islightsource | fresnel
inline void setRd() { flag |= 1; }
inline void setRs() { flag |= (1 << 1); }
inline void setTr() { flag |= 1 << 2; }
inline void setTd() { flag |= 1 << 3; }
inline void setTs() { flag |= 1 << 4; }
inline void setTexture() { flag |= 1 << 5; }
inline void setBRDF() { flag |= 1 << 6; }
inline void setBump() { flag |= 1 << 7; }
inline void setTextureKd() { flag |= 256; }
inline void setTextureKs() { flag |= 512; }
inline void setTextureTd() { flag |= (1 << 10); }
inline void setTextureTs() { flag |= 2048; }
inline void setLightsource() { flag |= 4096; }
inline void setFresnel() { flag |= 8192; }
inline void setScatter() { flag |= (1 << 14); }
bool isRd() { return flag & 1; }
bool isRs() { return flag & 2; }
bool isTr() { return flag & 4; }
bool isTd() { return flag & 8; }
bool isTs() { return flag & 16; }
bool isTextured() { return flag & 32; }
bool isBRDF() { return flag & 64; }
bool isBumped() { return flag & 128; }
bool isTextureKd() { return flag & 256; }
bool isTextureKs() { return flag & 512; }
bool isTextureTd() { return flag & 1024; }
bool isTextureTs() { return flag & 2048; }
bool isLightSource() { return flag & 4096; }
bool isFresnel() { return flag & 8192; }
bool isScatter() { return flag & (1 << 14); }
};
typedef Material *MaterialPtr;
class Object
{
public:
Object(){};
~Object(){};
// io:
void load(const char* filename);
void loadMtl(const char* filename);
void printInfo();
// geometry transformations:
void translate(const Vector3R& v);
void rotate(int axis, Real angle);
void relocate(Real minx, Real minY, Real minz);
void computeNormals(bool interpolation);
void meshSimplify(int, bool);
void scale(Real ratio);
// material information:
std::vector<V, Eigen::aligned_allocator<Vector3R>> vertices;
std::vector<VN, Eigen::aligned_allocator<Vector3R>> normals;
std::vector<VT, Eigen::aligned_allocator<Vector3R>> textures;
std::vector<F, Eigen::aligned_allocator<Vector3R>> faces;
std::vector<Sphere, Eigen::aligned_allocator<Vector3R>> spheres;
std::map<std::string, MaterialPtr> materials;
};