2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2021-10-18 21:24:30 +02:00
|
|
|
/* godot_shape_3d.h */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
#ifndef GODOT_SHAPE_3D_H
|
|
|
|
#define GODOT_SHAPE_3D_H
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
#include "core/math/geometry_3d.h"
|
2021-05-12 03:40:34 +02:00
|
|
|
#include "core/templates/local_vector.h"
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "servers/physics_server_3d.h"
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotShape3D;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotShapeOwner3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void _shape_changed() = 0;
|
2021-10-18 21:24:30 +02:00
|
|
|
virtual void remove_shape(GodotShape3D *p_shape) = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
virtual ~GodotShapeOwner3D() {}
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotShape3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
RID self;
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2021-09-14 11:01:49 +02:00
|
|
|
bool configured = false;
|
|
|
|
real_t custom_bias = 0.0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Map<GodotShapeOwner3D *, int> owners;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
protected:
|
2017-11-17 03:09:00 +01:00
|
|
|
void configure(const AABB &p_aabb);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
public:
|
2021-02-09 19:25:29 +01:00
|
|
|
enum FeatureType {
|
|
|
|
FEATURE_POINT,
|
|
|
|
FEATURE_EDGE,
|
|
|
|
FEATURE_FACE,
|
|
|
|
FEATURE_CIRCLE,
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual real_t get_area() const { return aabb.get_area(); }
|
2016-12-31 15:39:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; }
|
|
|
|
_FORCE_INLINE_ RID get_self() const { return self; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-03-25 02:49:04 +01:00
|
|
|
_FORCE_INLINE_ const AABB &get_aabb() const { return aabb; }
|
2014-09-03 04:13:40 +02:00
|
|
|
_FORCE_INLINE_ bool is_configured() const { return configured; }
|
|
|
|
|
|
|
|
virtual bool is_concave() const { return false; }
|
|
|
|
|
2020-10-17 07:08:21 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
2021-02-09 19:25:29 +01:00
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const = 0;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const = 0;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data) = 0;
|
|
|
|
virtual Variant get_data() const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_custom_bias(real_t p_bias) { custom_bias = p_bias; }
|
2014-09-03 04:13:40 +02:00
|
|
|
_FORCE_INLINE_ real_t get_custom_bias() const { return custom_bias; }
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
void add_owner(GodotShapeOwner3D *p_owner);
|
|
|
|
void remove_owner(GodotShapeOwner3D *p_owner);
|
|
|
|
bool is_owner(GodotShapeOwner3D *p_owner) const;
|
|
|
|
const Map<GodotShapeOwner3D *, int> &get_owners() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotShape3D() {}
|
|
|
|
virtual ~GodotShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotConcaveShape3D : public GodotShape3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
public:
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual bool is_concave() const override { return true; }
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-05-08 04:16:04 +02:00
|
|
|
// Returns true to stop the query.
|
2021-10-18 21:24:30 +02:00
|
|
|
typedef bool (*QueryCallback)(void *p_userdata, GodotShape3D *p_convex);
|
2021-05-08 04:16:04 +02:00
|
|
|
|
|
|
|
virtual void cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata) const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotConcaveShape3D() {}
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotWorldBoundaryShape3D : public GodotShape3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
Plane plane;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(const Plane &p_plane);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-09-03 04:13:40 +02:00
|
|
|
Plane get_plane() const;
|
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual real_t get_area() const override { return INFINITY; }
|
2021-09-14 19:52:35 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_WORLD_BOUNDARY; }
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotWorldBoundaryShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotSeparationRayShape3D : public GodotShape3D {
|
2021-09-14 11:01:49 +02:00
|
|
|
real_t length = 1.0;
|
|
|
|
bool slide_on_slope = false;
|
2021-08-17 19:15:11 +02:00
|
|
|
|
2021-08-19 20:02:40 +02:00
|
|
|
void _setup(real_t p_length, bool p_slide_on_slope);
|
2021-08-17 19:15:11 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
real_t get_length() const;
|
2021-08-19 20:02:40 +02:00
|
|
|
bool get_slide_on_slope() const;
|
2021-08-17 19:15:11 +02:00
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual real_t get_area() const override { return 0.0; }
|
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SEPARATION_RAY; }
|
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
2021-08-17 19:15:11 +02:00
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2021-08-17 19:15:11 +02:00
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2021-08-17 19:15:11 +02:00
|
|
|
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2021-08-17 19:15:11 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotSeparationRayShape3D();
|
2021-08-17 19:15:11 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotSphereShape3D : public GodotShape3D {
|
2021-09-14 11:01:49 +02:00
|
|
|
real_t radius = 0.0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
void _setup(real_t p_radius);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-09-03 04:13:40 +02:00
|
|
|
real_t get_radius() const;
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual real_t get_area() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius; }
|
2016-12-31 15:39:25 +01:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SPHERE; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotSphereShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotBoxShape3D : public GodotShape3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 half_extents;
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(const Vector3 &p_half_extents);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-09-03 04:13:40 +02:00
|
|
|
_FORCE_INLINE_ Vector3 get_half_extents() const { return half_extents; }
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual real_t get_area() const override { return 8 * half_extents.x * half_extents.y * half_extents.z; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_BOX; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotBoxShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotCapsuleShape3D : public GodotShape3D {
|
2021-09-14 11:01:49 +02:00
|
|
|
real_t height = 0.0;
|
|
|
|
real_t radius = 0.0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(real_t p_height, real_t p_radius);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
_FORCE_INLINE_ real_t get_height() const { return height; }
|
|
|
|
_FORCE_INLINE_ real_t get_radius() const { return radius; }
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual real_t get_area() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius + (height - radius * 2.0) * Math_PI * radius * radius; }
|
2016-12-31 15:39:25 +01:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CAPSULE; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotCapsuleShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
class GodotCylinderShape3D : public GodotShape3D {
|
2021-09-14 11:01:49 +02:00
|
|
|
real_t height = 0.0;
|
|
|
|
real_t radius = 0.0;
|
2021-02-09 19:25:29 +01:00
|
|
|
|
|
|
|
void _setup(real_t p_height, real_t p_radius);
|
|
|
|
|
|
|
|
public:
|
|
|
|
_FORCE_INLINE_ real_t get_height() const { return height; }
|
|
|
|
_FORCE_INLINE_ real_t get_radius() const { return radius; }
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual real_t get_area() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius + height * Math_PI * radius * radius; }
|
2021-02-09 19:25:29 +01:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CYLINDER; }
|
2021-02-09 19:25:29 +01:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2021-02-09 19:25:29 +01:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2021-02-09 19:25:29 +01:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2021-02-09 19:25:29 +01:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotCylinderShape3D();
|
2021-02-09 19:25:29 +01:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
struct GodotConvexPolygonShape3D : public GodotShape3D {
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::MeshData mesh;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(const Vector<Vector3> &p_vertices);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-05-25 19:20:45 +02:00
|
|
|
const Geometry3D::MeshData &get_mesh() const { return mesh; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotConvexPolygonShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
struct _Volume_BVH;
|
|
|
|
struct GodotFaceShape3D;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
struct GodotConcavePolygonShape3D : public GodotConcaveShape3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
// always a trimesh
|
|
|
|
|
|
|
|
struct Face {
|
|
|
|
Vector3 normal;
|
2021-09-14 11:01:49 +02:00
|
|
|
int indices[3] = {};
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Face> faces;
|
|
|
|
Vector<Vector3> vertices;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
struct BVH {
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2021-09-14 11:01:49 +02:00
|
|
|
int left = 0;
|
|
|
|
int right = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-09-14 11:01:49 +02:00
|
|
|
int face_index = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<BVH> bvh;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
struct _CullParams {
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2021-05-08 04:16:04 +02:00
|
|
|
QueryCallback callback = nullptr;
|
2021-03-12 02:15:31 +01:00
|
|
|
void *userdata = nullptr;
|
|
|
|
const Face *faces = nullptr;
|
|
|
|
const Vector3 *vertices = nullptr;
|
|
|
|
const BVH *bvh = nullptr;
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotFaceShape3D *face = nullptr;
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _SegmentCullParams {
|
|
|
|
Vector3 from;
|
|
|
|
Vector3 to;
|
|
|
|
Vector3 dir;
|
2021-03-12 02:15:31 +01:00
|
|
|
const Face *faces = nullptr;
|
|
|
|
const Vector3 *vertices = nullptr;
|
|
|
|
const BVH *bvh = nullptr;
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotFaceShape3D *face = nullptr;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
Vector3 result;
|
|
|
|
Vector3 normal;
|
2021-03-12 02:15:31 +01:00
|
|
|
real_t min_d = 1e20;
|
|
|
|
int collisions = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-03-12 02:15:31 +01:00
|
|
|
bool backface_collision = false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _cull_segment(int p_idx, _SegmentCullParams *p_params) const;
|
2021-05-08 04:16:04 +02:00
|
|
|
bool _cull(int p_idx, _CullParams *p_params) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
void _fill_bvh(_Volume_BVH *p_bvh_tree, BVH *p_bvh_array, int &p_idx);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-03-12 02:15:31 +01:00
|
|
|
void _setup(const Vector<Vector3> &p_faces, bool p_backface_collision);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector3> get_faces() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-05-08 04:16:04 +02:00
|
|
|
virtual void cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotConcavePolygonShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
struct GodotHeightMapShape3D : public GodotConcaveShape3D {
|
2021-08-10 00:15:17 +02:00
|
|
|
Vector<real_t> heights;
|
2021-03-25 02:49:04 +01:00
|
|
|
int width = 0;
|
|
|
|
int depth = 0;
|
|
|
|
Vector3 local_origin;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-05-12 03:40:34 +02:00
|
|
|
// Accelerator.
|
|
|
|
struct Range {
|
|
|
|
real_t min = 0.0;
|
|
|
|
real_t max = 0.0;
|
|
|
|
};
|
|
|
|
LocalVector<Range> bounds_grid;
|
|
|
|
int bounds_grid_width = 0;
|
|
|
|
int bounds_grid_depth = 0;
|
|
|
|
|
|
|
|
static const int BOUNDS_CHUNK_SIZE = 16;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ const Range &_get_bounds_chunk(int p_x, int p_z) const {
|
|
|
|
return bounds_grid[(p_z * bounds_grid_width) + p_x];
|
|
|
|
}
|
|
|
|
|
2021-08-10 00:15:17 +02:00
|
|
|
_FORCE_INLINE_ real_t _get_height(int p_x, int p_z) const {
|
2021-03-25 02:49:04 +01:00
|
|
|
return heights[(p_z * width) + p_x];
|
|
|
|
}
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-03-25 02:49:04 +01:00
|
|
|
_FORCE_INLINE_ void _get_point(int p_x, int p_z, Vector3 &r_point) const {
|
|
|
|
r_point.x = p_x - 0.5 * (width - 1.0);
|
|
|
|
r_point.y = _get_height(p_x, p_z);
|
|
|
|
r_point.z = p_z - 0.5 * (depth - 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _get_cell(const Vector3 &p_point, int &r_x, int &r_y, int &r_z) const;
|
|
|
|
|
2021-05-12 03:40:34 +02:00
|
|
|
void _build_accelerator();
|
|
|
|
|
|
|
|
template <typename ProcessFunction>
|
|
|
|
bool _intersect_grid_segment(ProcessFunction &p_process, const Vector3 &p_begin, const Vector3 &p_end, int p_width, int p_depth, const Vector3 &offset, Vector3 &r_point, Vector3 &r_normal) const;
|
|
|
|
|
2021-08-10 00:15:17 +02:00
|
|
|
void _setup(const Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2021-08-10 00:15:17 +02:00
|
|
|
Vector<real_t> get_heights() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
int get_width() const;
|
|
|
|
int get_depth() const;
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_HEIGHTMAP; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2021-05-08 04:16:04 +02:00
|
|
|
virtual void cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override;
|
|
|
|
virtual Variant get_data() const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotHeightMapShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//used internally
|
2021-10-18 21:24:30 +02:00
|
|
|
struct GodotFaceShape3D : public GodotShape3D {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 normal; //cache
|
|
|
|
Vector3 vertex[3];
|
2021-03-12 02:15:31 +01:00
|
|
|
bool backface_collision = false;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector3 &get_vertex(int p_idx) const { return vertex[p_idx]; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override;
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override {}
|
|
|
|
virtual Variant get_data() const override { return Variant(); }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotFaceShape3D();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
struct GodotMotionShape3D : public GodotShape3D {
|
|
|
|
GodotShape3D *shape = nullptr;
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 motion;
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 cast = p_transform.basis.xform(motion);
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t mina, maxa;
|
|
|
|
real_t minb, maxb;
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D ofsb = p_transform;
|
2017-03-05 16:44:50 +01:00
|
|
|
ofsb.origin += cast;
|
|
|
|
shape->project_range(p_normal, p_transform, mina, maxa);
|
|
|
|
shape->project_range(p_normal, ofsb, minb, maxb);
|
|
|
|
r_min = MIN(mina, minb);
|
|
|
|
r_max = MAX(maxa, maxb);
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const override {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 support = shape->get_support(p_normal);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_normal.dot(motion) > 0) {
|
|
|
|
support += motion;
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
|
|
|
return support;
|
|
|
|
}
|
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const override { return false; }
|
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const override { return false; }
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override { return p_point; }
|
|
|
|
|
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const override { return Vector3(); }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-08-20 01:19:49 +02:00
|
|
|
virtual void set_data(const Variant &p_data) override {}
|
|
|
|
virtual Variant get_data() const override { return Variant(); }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
GodotMotionShape3D() { configure(AABB()); }
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
#endif // GODOT_SHAPE_3D_H
|