-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClothModel.h
More file actions
116 lines (91 loc) · 3.51 KB
/
Copy pathClothModel.h
File metadata and controls
116 lines (91 loc) · 3.51 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
#pragma once
#include "Falcor.h"
#include "Utils.h"
#include "External/HalfEdge/trimesh.h"
using namespace Falcor;
struct SelectionQuery;
class ClothSample;
struct SelectableObject
{
virtual ~SelectableObject() {}
virtual void testSelection(SelectionQuery&) = 0;
virtual void makeSelection(ClothSample*, SelectionQuery&) = 0;
virtual void loseSelection(ClothSample*) = 0;
virtual bool loseSelectionOnMouseUp() { return true; }
virtual bool onMouseEvent(ClothSample*, SampleCallbacks*, const MouseEvent&) = 0;
};
struct SelectionQuery
{
Ray ray;
float closestHit = std::numeric_limits<float>::infinity();
SelectableObject *closestObject = nullptr;
uint8 cache[256]; // owned by current closest object
};
struct ClothModel : NonCopyable, public SelectableObject, public std::enable_shared_from_this<ClothModel>
{
using SharedPtr = std::shared_ptr<ClothModel>;
using SharedConstPtr = std::shared_ptr<const ClothModel>;
enum EType
{
FiniteElementsMethod,
ParticleSpringModel
};
static const char *ClothVS;
static const char *ClothPS;
static GraphicsProgram::SharedPtr spClothProgram;
static GraphicsVars::SharedPtr spClothVars;
static VertexLayout::SharedPtr spVertexLayout;
struct TTextureSet
{
std::string Name;
Texture::SharedPtr BaseColorMap;
Texture::SharedPtr RoughnessMap;
Texture::SharedPtr NormalMap;
};
static std::vector<TTextureSet> sTextureSets;
std::string mName;
std::vector<trimesh::triangle_t> mTriangles;
trimesh::trimesh_t mMesh;
Buffer::SharedPtr mpVBPositions;
Buffer::SharedPtr mpVBNormals;
Buffer::SharedPtr mpVBColors;
Buffer::SharedPtr mpIndexBuffer;
Buffer::SharedPtr mpVBTexCoords;
Vao::SharedPtr mpVao;
GraphicsState::SharedPtr mpClothState;
RasterizerState::SharedPtr mpRasterizeNormal;
RasterizerState::SharedPtr mpRasterizeWireframe;
virtual EType getType() const = 0;
virtual vec3 getVertexPosition(int32 index) const = 0;
virtual vec3 getVertexNormal(int32 index) const;
void getTriangleVertices(const trimesh::triangle_t &triangle, vec3 vertices[3]) const;
vec3 computeVertexNormal(int32 index) const;
virtual void init(const vec2 &size, const ivec2 &tessellation) = 0;
virtual void init(const Model *model) = 0;
virtual void simulate(ClothSample*, float deltaTime) = 0;
virtual void render(ClothSample*, SampleCallbacks*);
virtual void onGuiRender(ClothSample*, SampleCallbacks*);
virtual void testSelection(SelectionQuery&) override {};
virtual void makeSelection(ClothSample*, SelectionQuery&) override {};
virtual void loseSelection(ClothSample*) override {};
virtual bool onMouseEvent(ClothSample*, SampleCallbacks*, const MouseEvent&) { return false; }
static void init();
static int32 createRectMesh(const vec2 &size, const ivec2 &tessellation, std::vector<float3> &position, std::vector<float2> &texCoords, std::vector<trimesh::triangle_t> &triangles, trimesh::trimesh_t &mesh);
static SharedPtr createClothModel(EType type, const ClothModel *parent);
protected:
void sharedInit(const std::vector<float2> &texCoords);
struct
{
float windDragCoefficient = 0.1f;
float windLiftCoefficient = 0.1f;
bool bShowWindEffect = false;
bool bShowNormals = false;
bool bShowParticles = false;
bool bShowWireframe = false;
bool bShowSelfCollisions = false;
int32 textureSet = 0;
vec3 baseColor = vec3(0.0f, 255.0f / 255.0f, 84.0f / 255.0f);
} mUserParams;
template <EType type>
static SharedPtr createClothModel(const ClothModel *parent);
};