This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtypes.h
181 lines (152 loc) · 5.17 KB
/
types.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#pragma once
#include <NvFlex.h>
#include <NvFlexExt.h>
#include <NvFlexDevice.h>
#include <vector>
#include "GarrysMod/Lua/Interface.h"
#include <string>
#include <map>
//Float4 structure, holds 4 floats, X, Y, Z, and W
struct float4 {
float x, y, z, w;
float4(float x1, float y1, float z1, float w1) : x(x1), y(y1), z(z1), w(w1) {};
float4() : x(0), y(0), z(0), w(0) {};
float4(float l) : x(l), y(l), z(l), w(l) {};
float4(Vector l, float w1) : x(l.x), y(l.y), z(l.z), w(w1) {};
float4 operator+(float4 other) {
x = other.x;
y = other.y;
z = other.z;
w = other.w;
}
};
//Float3 structure, holds 3 floats, X, Y, and Z
struct float3 {
float x, y, z;
float3(float x1, float y1, float z1) : x(x1), y(y1), z(z1) {};
float3() : x(0), y(0), z(0) {};
float3(float l) : x(l), y(l), z(l) {};
float3(Vector l) : x(l.x), y(l.y), z(l.z) {};
float3(float4 l) : x(l.x), y(l.y), z(l.z) {};
float3 operator+(float3 e) {
return { x + e.x, y + e.y, z + e.z };
}
float3 operator*(float3 e) {
return { x * e.x, y * e.y, z * e.z };
}
float3 operator-(float3 e) {
return { x - e.x, y - e.y, z - e.z };
}
float3 operator/(float e) {
return { x / e, y / e, z / e };
}
bool operator==(float3 e) {
return (x == e.x && y == e.y && z == e.z);
}
bool operator!=(float3 e) {
return (x != e.x || y != e.y || z != e.z);
}
};
struct Particle {
float4 pos;
float3 vel;
};
struct Prop {
NvFlexBuffer* verts;
NvFlexBuffer* indices;
int meshID;
float4 pos;
float4 lastPos;
float4 ang;
float4 lastAng;
};
struct SimBuffers {
float4* particles;
float3* velocities;
int* phases;
int* activeIndices;
NvFlexCollisionGeometry* geometry;
float4* positions;
float4* rotations;
float4* prevPositions;
float4* prevRotations;
int* flags;
int* indices;
float* lengths;
float* coefficients;
};
struct ForceFieldData {
NvFlexExtForceFieldCallback* forceFieldCallback;
NvFlexExtForceField* forceFieldBuffer;
int forceFieldCount;
};
class FLEX_API {
NvFlexLibrary* flexLibrary;
NvFlexSolver* flexSolver;
SimBuffers* simBuffers;
NvFlexBuffer* particleBuffer;
NvFlexBuffer* velocityBuffer;
NvFlexBuffer* phaseBuffer;
NvFlexBuffer* activeBuffer;
NvFlexBuffer* geometryBuffer;
NvFlexBuffer* geoFlagsBuffer;
NvFlexBuffer* geoPosBuffer;
NvFlexBuffer* geoQuatBuffer;
NvFlexBuffer* geoPrevPosBuffer;
NvFlexBuffer* geoPrevQuatBuffer;
NvFlexBuffer* indicesBuffer;
NvFlexBuffer* lengthsBuffer;
NvFlexBuffer* coefficientsBuffer;
NvFlexBuffer* diffusePosBuffer;
NvFlexBuffer* diffuseSingleBuffer;
ForceFieldData* forceFieldData;
std::vector<Prop> props;
std::vector<Particle> particleQueue;
int springCount = 0;
int rigidSpringCount = 0;
int rigidCoeffCount = 0;
public:
std::map<std::string, float*> flexMap;
NvFlexParams* flexParams;
NvFlexSolverDesc flexSolverDesc;
std::vector<std::vector<int>> triangles;
std::vector<Vector> particleColors;
float radius;
void addParticle(Vector pos, Vector vel, Vector color);
void addMeshConcave(GarrysMod::Lua::ILuaBase* LUA);
void addMeshConvex(GarrysMod::Lua::ILuaBase* LUA);
void addMeshCapsule(GarrysMod::Lua::ILuaBase* LUA);
void addCloth(float3 pos, int width, float radius, float stiffness, float mass);
void addRigidbody(float3 lower, int dimx, int dimy, int dimz, float radius, float3 velocity, float mass, bool constraints);
void updateMeshPos(Vector pos, QAngle ang, int id);
void freeProp(int ID);
void updateParam(std::string, float n);
void initParams();
void initParamsRadius(float r);
void flexSolveThread();
void removeAllParticles();
void removeAllProps();
int removeInRadius(float3 pos, float radius);
void removeAllCloth();
void SetParticleLimit(int limit);
void cullParticles();
void cleanLostParticles();
int cleanLoneParticles();
void applyForce(float3 pos, float3 vel, float radius, bool linear);
void applyForceRange(float3 pos, float3 vel, float radius, bool linear, std::vector<int> range);
void applyForceOutwards(float3 pos, float strength, float radius, bool linear);
void applyForceOutwardsRange(float3 pos, float strength, float radius, bool linear, std::vector<int> range);
// springs (flex provided functions)
void CreateSpringGrid(float3 lower, int dx, int dy, float radius, int phase, float stretchStiffness, float mass);
void CreateParticleGrid(float3 lower, int dimx, int dimy, int dimz, float radius, float3 velocity, float mass, int phase, bool constraints);
void CreateSpring(int i, int j, float stiffness, float give = 0.0f);
void addForceField(Vector pos, float radius, float strength, bool linear, int type);
void deleteForceField(int ID);
void setForceFieldPos(int ID, Vector pos);
void editForceField(int ID, float radius, float strength, bool linear, int type);
float editParticle(int ID, float3 pos, float3 vel, float mass);
void mapBuffers();
void unmapBuffers();
FLEX_API();
~FLEX_API();
};