载入中...
搜索中...
未找到
Shape3D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6
7#include <memory>
9
10#include <string>
11#include <vector>
12
13#include <cstdint>
14
15namespace eve::physics {
16namespace jolt {
17class WorldBackend;
18}
19namespace box3d {
20class WorldBackend;
21}
22
23namespace box3d {
24struct Access;
25}
26class Body3D;
27class World3D;
28struct WorldSnapshotAccess;
29
35public:
38
40 Shape3D(World3D *world, Body3D *body, std::unique_ptr<IShapeBackend3D> backend, PhysicsShapeHandle runtimeHandle,
42 ~Shape3D();
43
44 Shape3D(const Shape3D &) = delete;
45 Shape3D &operator=(const Shape3D &) = delete;
46
48 int getId() const { return id_; }
50 [[nodiscard]] PhysicsShapeHandle runtimeHandle() const noexcept { return runtimeHandle_; }
52 void setTag(int tag);
54 int getTag() const { return tag_; }
55
57 void setHitEventsEnabled(bool enabled);
59 bool areHitEventsEnabled() const;
60
62 std::string getKind() const;
64 void setBoxSize(float width, float height, float depth);
66 void setSphereRadius(float radius);
73 void setCapsuleSize(float height, float radius);
80 void setConvexHullVertices(const std::vector<float> &vertices, int maxVertices = 64);
83 return geometry_.kind == Kind::ConvexHull ? static_cast<int>(geometry_.hullVertices.size() / 3) : 0;
84 }
86 int getConvexHullMaxVertices() const { return geometry_.kind == Kind::ConvexHull ? geometry_.hullMaxVertices : 0; }
91 void setTriangleMeshData(const std::vector<float> &vertices,
92 const std::vector<int32_t> &indices, bool weldVertices = true,
93 float weldTolerance = 0.001f, bool identifyEdges = true,
94 bool useMedianSplit = false);
97 return geometry_.kind == Kind::TriangleMesh ? static_cast<int>(geometry_.meshVertices.size() / 3) : 0;
98 }
101 return geometry_.kind == Kind::TriangleMesh ? static_cast<int>(geometry_.meshIndices.size() / 3) : 0;
102 }
104 void setTriangleMeshMaterialIndices(const std::vector<int32_t> &materialIndices);
106 int getTriangleMeshMaterialIndex(int triangleIndex) const;
108 int getTriangleMeshMaterialCount() const;
122 void setTriangleMeshMaterial(int slot, float friction, float restitution,
123 float rollingResistance, float tangentX, float tangentY,
124 float tangentZ, int materialId,
125 const std::string &frictionMode,
126 const std::string &restitutionMode);
128 float getTriangleMeshMaterialFriction(int slot) const;
130 float getTriangleMeshMaterialRestitution(int slot) const;
132 float getTriangleMeshMaterialRollingResistance(int slot) const;
134 int getTriangleMeshMaterialId(int slot) const;
136 void setHeightFieldHeights(const std::vector<float> &heights);
138 void setHeightFieldRegion(int x, int z, int width, int depth,
139 const std::vector<float> &heights);
141 float getHeightFieldHeight(int x, int z) const;
143 int getHeightFieldCountX() const { return geometry_.kind == Kind::HeightField ? geometry_.heightCountX : 0; }
145 int getHeightFieldCountZ() const { return geometry_.kind == Kind::HeightField ? geometry_.heightCountZ : 0; }
148 return geometry_.kind == Kind::HeightField ? geometry_.heightCellSizeX : 0.f;
149 }
152 return geometry_.kind == Kind::HeightField ? geometry_.heightCellSizeZ : 0.f;
153 }
156 return geometry_.kind == Kind::HeightField ? geometry_.heightGlobalMin : 0.f;
157 }
160 return geometry_.kind == Kind::HeightField ? geometry_.heightGlobalMax : 0.f;
161 }
163 float getBoxWidth() const { return geometry_.kind == Kind::Box ? 2.f * geometry_.a : 0.f; }
165 float getBoxHeight() const { return geometry_.kind == Kind::Box ? 2.f * geometry_.b : 0.f; }
167 float getBoxDepth() const { return geometry_.kind == Kind::Box ? 2.f * geometry_.c : 0.f; }
169 float getRadius() const {
170 return geometry_.kind == Kind::Sphere ? geometry_.a : (geometry_.kind == Kind::Capsule ? geometry_.b : 0.f);
171 }
173 float getCapsuleHeight() const { return geometry_.kind == Kind::Capsule ? 2.f * geometry_.a : 0.f; }
174
184 void setOneWay(float nx, float ny, float nz, float planeOffset, float margin,
185 float minNormalDot);
187 void disableOneWay();
189 bool isOneWay() const { return oneWayEnabled_; }
190
201 void setLocalTransform(float px, float py, float pz, float qx, float qy, float qz, float qw);
203 void setLocalPosition(float x, float y, float z);
205 void setLocalRotation(float qx, float qy, float qz, float qw);
207 float getLocalX() const { return geometry_.localX; }
209 float getLocalY() const { return geometry_.localY; }
211 float getLocalZ() const { return geometry_.localZ; }
213 float getLocalRotX() const { return geometry_.localQx; }
215 float getLocalRotY() const { return geometry_.localQy; }
217 float getLocalRotZ() const { return geometry_.localQz; }
219 float getLocalRotW() const { return geometry_.localQw; }
220
222 void setSensor(bool sensor);
223 bool isSensor() const;
224
226 void setFriction(float friction);
227 float getFriction() const;
228
229 void setRestitution(float restitution);
230 float getRestitution() const;
231
233 void setRollingResistance(float resistance);
235 float getRollingResistance() const;
237 void setTangentVelocity(float x, float y, float z);
239 float getTangentVelocityX() const;
241 float getTangentVelocityY() const;
243 float getTangentVelocityZ() const;
245 void setMaterialId(int id);
247 int getMaterialId() const;
249 void setExplosionScale(float scale);
251 float getExplosionScale() const { return explosionScale_; }
253 void setFrictionCombineMode(const std::string &mode);
255 std::string getFrictionCombineMode() const;
257 void setRestitutionCombineMode(const std::string &mode);
259 std::string getRestitutionCombineMode() const;
260
261 void setDensity(float density);
262 float getDensity() const;
263
266 void setFilterBits(uint64_t categoryBits, uint64_t maskBits);
267 uint64_t getCategoryBits() const;
269 void setCategoryBits(uint64_t bits);
271 void setMaskBits(uint64_t bits);
273 uint64_t getMaskBits() const;
275 void setGroupIndex(int index);
276 int getGroupIndex() const;
277
286 Body3D *getBody() { return body_; }
295 const Body3D *getBody() const { return body_; }
296
298 bool testPoint(float x, float y, float z) const;
299
301 void destroy();
302
304 bool isValid() const;
305
307 void invalidate();
308
309private:
311 friend class jolt::WorldBackend;
312 friend struct box3d::Access;
313 friend class World3D;
314 friend class Body3D;
315 friend struct WorldSnapshotAccess;
317
318 void recreate(bool sensor);
319 void rebuildGeometry(const ShapeGeometry3D &geometry, bool sensor);
320 void applyGeometry(ShapeGeometry3D geometry, bool sensor);
321 void enableContactOverrideFiltering();
322 void refreshOneWayWorldData();
323 bool allowsOneWayContact(double pointX, double pointY, double pointZ, float normalX,
324 float normalY, float normalZ) const;
325
326 World3D *world_ = nullptr;
327 Body3D *body_ = nullptr;
328 std::unique_ptr<IShapeBackend3D> backend_;
329 PhysicsShapeHandle runtimeHandle_ = PhysicsShapeHandle::invalid();
330 ShapeGeometry3D geometry_;
331 std::vector<SurfaceMaterial3D> meshMaterials_;
332 bool meshMaterialsDirty_ = false;
333 bool contactOverrideFiltering_ = false;
334 float explosionScale_ = 1.f;
335 int id_ = 0;
336 int tag_ = 0;
337 bool hitEventsEnabled_ = false;
338 bool oneWayEnabled_ = false;
339 float oneWayLocalNormalX_ = 0.f, oneWayLocalNormalY_ = 1.f,
340 oneWayLocalNormalZ_ = 0.f;
341 float oneWayPlaneOffset_ = 0.f;
342 float oneWayMargin_ = 0.05f;
343 float oneWayMinNormalDot_ = 0.1f;
344 double oneWayWorldPointX_ = 0.0, oneWayWorldPointY_ = 0.0, oneWayWorldPointZ_ = 0.0;
345 float oneWayWorldNormalX_ = 0.f, oneWayWorldNormalY_ = 1.f,
346 oneWayWorldNormalZ_ = 0.f;
347};
348
349} // namespace eve::physics
double z
double y
double x
#define EVENGINE_API_WORLD
Definition Export.h:109
float rollingResistance
float friction
float density
std::vector< std::uint32_t > indices
std::vector< Colorf > px
std::uint32_t height
std::uint32_t width
void(* destroy)(void *)
std::array< float, 3 > scale
double radius
Definition MeleeHit.cpp:42
const std::string * tag
OceanRenderBackend backend
glm::dvec3 tangentZ
glm::dvec3 tangentX
Process-local, generation-qualified handles owned by the physics domain.
std::string body
std::string slot
std::string geometry
double restitution
std::array< double, 2 > vertices[3]
int margin
std::uint32_t depth
uint32_t index
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:34
const Body3D * getBody() const
Returns the owning body for read-only link construction.
Definition Shape3D.h:295
int getId() const
Stable world-local id, preserved when sensor state recreates the backend shape.
Definition Shape3D.h:48
float getHeightFieldCellSizeZ() const
Height-field cell spacing along local Z, or zero.
Definition Shape3D.h:151
PhysicsShapeHandle runtimeHandle() const noexcept
Process-local generation-qualified handle owned by World3D.
Definition Shape3D.h:50
int getHeightFieldCountZ() const
Height-field sample count along local Z, or zero.
Definition Shape3D.h:145
float getLocalZ() const
Local translation Z in meters.
Definition Shape3D.h:211
int getTriangleMeshVertexCount() const
Source vertex count for a triangle mesh, or zero.
Definition Shape3D.h:96
float getLocalRotX() const
Normalized local quaternion X.
Definition Shape3D.h:213
int getTag() const
User-defined integer tag, zero by default.
Definition Shape3D.h:54
float getLocalY() const
Local translation Y in meters.
Definition Shape3D.h:209
float getBoxHeight() const
Full box height, or zero for another geometry kind.
Definition Shape3D.h:165
float getLocalX() const
Local translation X in meters.
Definition Shape3D.h:207
bool isOneWay() const
Whether one-way pre-solve filtering is requested.
Definition Shape3D.h:189
Shape3D & operator=(const Shape3D &)=delete
float getBoxWidth() const
Full box width, or zero for another geometry kind.
Definition Shape3D.h:163
float getHeightFieldGlobalMin() const
Height-field shared quantization minimum, or zero.
Definition Shape3D.h:155
float getLocalRotW() const
Normalized local quaternion scalar component.
Definition Shape3D.h:219
Shape3D(const Shape3D &)=delete
float getExplosionScale() const
Current explosion impulse multiplier; zero opts this shape out.
Definition Shape3D.h:251
float getCapsuleHeight() const
Capsule hemisphere-center distance, or zero for another kind.
Definition Shape3D.h:173
float getBoxDepth() const
Full box depth, or zero for another geometry kind.
Definition Shape3D.h:167
int getHeightFieldCountX() const
Height-field sample count along local X, or zero.
Definition Shape3D.h:143
float getHeightFieldCellSizeX() const
Height-field cell spacing along local X, or zero.
Definition Shape3D.h:147
float getLocalRotZ() const
Normalized local quaternion Z.
Definition Shape3D.h:217
float getHeightFieldGlobalMax() const
Height-field shared quantization maximum, or zero.
Definition Shape3D.h:159
int getTriangleMeshTriangleCount() const
Source triangle count for a triangle mesh, or zero.
Definition Shape3D.h:100
Body3D * getBody()
Returns the owning body, or null after invalidation.
Definition Shape3D.h:286
int getConvexHullPointCount() const
Source point count for a convex hull, or zero for another kind.
Definition Shape3D.h:82
float getLocalRotY() const
Normalized local quaternion Y.
Definition Shape3D.h:215
float getRadius() const
Sphere/capsule radius, or zero for a box.
Definition Shape3D.h:169
int getConvexHullMaxVertices() const
Current convex-hull simplification budget, or zero for another kind.
Definition Shape3D.h:86
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
ShapeKind3D
Geometry kinds supported by the rigid shape contract.
bool enabled
Owning, backend-independent shape source; metres, local quaternion XYZW.
Private bridge used exclusively by Box3D composition and native query code.
Definition Box3DBody.h:15