-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh.hpp
78 lines (59 loc) · 2.23 KB
/
mesh.hpp
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
#pragma once
#include <memory>
#include "dataTypes.hpp"
#include "geometry.hpp"
#include "material.hpp"
/*
A class representing an instance of a Geometry with an applied Material and spatial transformation
*/
class Mesh {
public:
// Reference to an externally managed complete Geometry.
std::shared_ptr<Geometry> geometry;
// Reference to an externally managed Material.
std::shared_ptr<Material> material;
vec3 translation{0};
vec3 rotation{0};
float scale{1};
// Translation, rotation, scale
mat4 modelMatrix = identity<mat4>();
// Inverse of the model matrix to transform rays
mat4 invModelMatrix = identity<mat4>();
mat4 normalMatrix = transpose(invModelMatrix);
// Transformed limits for constructing TLAS
vec3 aabbMin{FLT_MAX};
vec3 aabbMax{-FLT_MAX};
vec3 centroid{0};
Mesh() = default;
Mesh(std::shared_ptr<Geometry> geometry, std::shared_ptr<Material> material);
~Mesh() = default;
void setPosition(vec3 translation);
void setRotationX(float angle);
void setRotationY(float angle);
void setRotationZ(float angle);
void setScale(float scale);
void update();
vec3 getMin() const;
vec3 getMax() const;
// Find the distance to the closest intersection, the index of the primitive and the number of BVH tests.
// Store distance in ray.t (FLT_MAX if no intersection) and geometry data in hitRecord
void intersect(Ray& ray, HitRecord& hitRecord, uint& count) const;
// Center geometry at the origin
void centerGeometry();
};
class GPUMesh {
public:
// Inverse of the model matrix to transform rays
mat4 invModelMatrix = identity<mat4>();
// Device pointer to an externally managed complete GPUGeometry.
GPUGeometry* geometry = nullptr;
// Device pointer to an externally managed GPUMaterial.
GPUMaterial* material = nullptr;
mat4 normalMatrix = transpose(invModelMatrix);
GPUMesh() = delete;
GPUMesh(const Mesh& mesh, GPUGeometry* geometry, GPUMaterial* material);
~GPUMesh() = default;
// Find the distance to the closest intersection, the index of the primitive and the number of BVH tests.
// Store distance in ray.t (FLT_MAX if no intersection) and geometry data in hitRecord
__device__ void intersect(Ray& ray, HitRecord& hitRecord, uint& count) const;
};