| 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 |
#pragma once |
| 32 |
|
| 33 |
#include "jolt_object_3d.h" |
| 34 |
|
| 35 |
#include "core/templates/self_list.h" |
| 36 |
|
| 37 |
#include "Jolt/Jolt.h" |
| 38 |
|
| 39 |
#include "Jolt/Physics/Body/Body.h" |
| 40 |
#include "Jolt/Physics/Body/BodyCreationSettings.h" |
| 41 |
|
| 42 |
class JoltShapedObject3D : public JoltObject3D { |
| 43 |
friend class JoltShape3D; |
| 44 |
|
| 45 |
protected: |
| 46 |
SelfList<JoltShapedObject3D> shapes_changed_element; |
| 47 |
SelfList<JoltShapedObject3D> needs_optimization_element; |
| 48 |
|
| 49 |
Vector3 scale = Vector3(1, 1, 1); |
| 50 |
|
| 51 |
JPH::ShapeRefC jolt_shape; |
| 52 |
JPH::ShapeRefC previous_jolt_shape; |
| 53 |
|
| 54 |
JPH::BodyCreationSettings *jolt_settings = new JPH::BodyCreationSettings(); |
| 55 |
|
| 56 |
virtual JPH::EMotionType _get_motion_type() const = 0; |
| 57 |
|
| 58 |
bool _is_big() const; |
| 59 |
|
| 60 |
JPH::ShapeRefC _try_build_shape(bool p_optimize_compound); |
| 61 |
JPH::ShapeRefC _try_build_single_shape(); |
| 62 |
JPH::ShapeRefC _try_build_compound_shape(bool p_optimize); |
| 63 |
|
| 64 |
void _enqueue_shapes_changed(); |
| 65 |
void _dequeue_shapes_changed(); |
| 66 |
|
| 67 |
void _enqueue_needs_optimization(); |
| 68 |
void _dequeue_needs_optimization(); |
| 69 |
|
| 70 |
virtual void _shapes_changed(); |
| 71 |
virtual void _shapes_committed(); |
| 72 |
virtual void _space_changing() override; |
| 73 |
|
| 74 |
public: |
| 75 |
explicit JoltShapedObject3D(ObjectType p_object_type); |
| 76 |
virtual ~JoltShapedObject3D() override; |
| 77 |
|
| 78 |
Transform3D get_transform_unscaled() const; |
| 79 |
Transform3D get_transform_scaled() const; |
| 80 |
|
| 81 |
Vector3 get_scale() const { return scale; } |
| 82 |
Basis get_basis() const; |
| 83 |
Vector3 get_position() const; |
| 84 |
|
| 85 |
Vector3 get_center_of_mass() const; |
| 86 |
Vector3 get_center_of_mass_relative() const; |
| 87 |
Vector3 get_center_of_mass_local() const; |
| 88 |
|
| 89 |
Vector3 get_linear_velocity() const; |
| 90 |
Vector3 get_angular_velocity() const; |
| 91 |
|
| 92 |
AABB get_aabb() const; |
| 93 |
|
| 94 |
virtual bool has_custom_center_of_mass() const = 0; |
| 95 |
virtual Vector3 get_center_of_mass_custom() const = 0; |
| 96 |
|
| 97 |
JPH::ShapeRefC build_shapes(bool p_optimize_compound); |
| 98 |
|
| 99 |
void commit_shapes(bool p_optimize_compound); |
| 100 |
|
| 101 |
const JPH::Shape *get_jolt_shape() const { return jolt_shape; } |
| 102 |
const JPH::Shape *get_previous_jolt_shape() const { return previous_jolt_shape; } |
| 103 |
|
| 104 |
void add_shape(JoltShape3D *p_shape, Transform3D p_transform, bool p_disabled); |
| 105 |
void remove_shape(const JoltShape3D *p_shape); |
| 106 |
void remove_shape(int p_index); |
| 107 |
|
| 108 |
JoltShape3D *get_shape(int p_index) const; |
| 109 |
void set_shape(int p_index, JoltShape3D *p_shape); |
| 110 |
|
| 111 |
void clear_shapes(); |
| 112 |
void clear_previous_shape(); |
| 113 |
|
| 114 |
int get_shape_count() const { return shapes.size(); } |
| 115 |
|
| 116 |
int find_shape_index(uint32_t p_shape_instance_id) const; |
| 117 |
int find_shape_index(const JPH::SubShapeID &p_sub_shape_id) const; |
| 118 |
|
| 119 |
JoltShape3D *find_shape(uint32_t p_shape_instance_id) const; |
| 120 |
JoltShape3D *find_shape(const JPH::SubShapeID &p_sub_shape_id) const; |
| 121 |
|
| 122 |
Transform3D get_shape_transform_unscaled(int p_index) const; |
| 123 |
Transform3D get_shape_transform_scaled(int p_index) const; |
| 124 |
void set_shape_transform(int p_index, Transform3D p_transform); |
| 125 |
|
| 126 |
Vector3 get_shape_scale(int p_index) const; |
| 127 |
|
| 128 |
bool is_shape_disabled(int p_index) const; |
| 129 |
void set_shape_disabled(int p_index, bool p_disabled); |
| 130 |
}; |