Path: blob/master/modules/jolt_physics/objects/jolt_soft_body_3d.h
10278 views
/**************************************************************************/1/* jolt_soft_body_3d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "jolt_object_3d.h"3334#include "servers/physics_server_3d.h"3536#include "Jolt/Jolt.h"3738#include "Jolt/Physics/SoftBody/SoftBodyCreationSettings.h"39#include "Jolt/Physics/SoftBody/SoftBodySharedSettings.h"4041class JoltSpace3D;4243class JoltSoftBody3D final : public JoltObject3D {44struct Shared {45LocalVector<int> mesh_to_physics;46JPH::Ref<JPH::SoftBodySharedSettings> settings = new JPH::SoftBodySharedSettings();47int ref_count = 1;48};4950inline static HashMap<RID, Shared> mesh_to_shared;5152HashSet<int> pinned_vertices;53LocalVector<RID> exceptions;54LocalVector<Vector3> normals;5556const Shared *shared = nullptr;5758RID mesh;5960JPH::SoftBodyCreationSettings *jolt_settings = new JPH::SoftBodyCreationSettings();6162float mass = 0.0f;63float pressure = 0.0f;64float linear_damping = 0.01f;65float stiffness_coefficient = 0.5f;66float shrinking_factor = 0.0f;6768int simulation_precision = 5;6970virtual JPH::BroadPhaseLayer _get_broad_phase_layer() const override;71virtual JPH::ObjectLayer _get_object_layer() const override;7273virtual void _space_changing() override;74virtual void _space_changed() override;7576virtual void _add_to_space() override;7778bool _ref_shared_data();79void _deref_shared_data();8081void _update_mass();82void _update_pressure();83void _update_damping();84void _update_simulation_precision();85void _update_group_filter();8687void _try_rebuild();8889void _mesh_changed();90void _simulation_precision_changed();91void _mass_changed();92void _pressure_changed();93void _damping_changed();94void _pins_changed();95void _vertices_changed();96void _exceptions_changed();97void _motion_changed();9899public:100JoltSoftBody3D();101virtual ~JoltSoftBody3D() override;102103bool in_space() const;104105void add_collision_exception(const RID &p_excepted_body);106void remove_collision_exception(const RID &p_excepted_body);107bool has_collision_exception(const RID &p_excepted_body) const;108109const LocalVector<RID> &get_collision_exceptions() const { return exceptions; }110111virtual bool can_interact_with(const JoltBody3D &p_other) const override;112virtual bool can_interact_with(const JoltSoftBody3D &p_other) const override;113virtual bool can_interact_with(const JoltArea3D &p_other) const override;114115virtual bool reports_contacts() const override { return false; }116117virtual Vector3 get_velocity_at_position(const Vector3 &p_position) const override;118119void set_mesh(const RID &p_mesh);120121bool is_pickable() const { return pickable; }122void set_pickable(bool p_enabled) { pickable = p_enabled; }123124bool is_sleeping() const;125void set_is_sleeping(bool p_enabled);126127bool is_sleep_allowed() const;128void set_is_sleep_allowed(bool p_enabled);129130void put_to_sleep() { set_is_sleeping(true); }131void wake_up() { set_is_sleeping(false); }132133int get_simulation_precision() const { return simulation_precision; }134void set_simulation_precision(int p_precision);135136float get_mass() const { return mass; }137void set_mass(float p_mass);138139float get_stiffness_coefficient() const;140void set_stiffness_coefficient(float p_coefficient);141142float get_shrinking_factor() const;143void set_shrinking_factor(float p_shrinking_factor);144145float get_pressure() const { return pressure; }146void set_pressure(float p_pressure);147148float get_linear_damping() const { return linear_damping; }149void set_linear_damping(float p_damping);150151float get_drag() const;152void set_drag(float p_drag);153154Variant get_state(PhysicsServer3D::BodyState p_state) const;155void set_state(PhysicsServer3D::BodyState p_state, const Variant &p_value);156157Transform3D get_transform() const;158void set_transform(const Transform3D &p_transform);159160AABB get_bounds() const;161162void update_rendering_server(PhysicsServer3DRenderingServerHandler *p_rendering_server_handler);163164Vector3 get_vertex_position(int p_index);165void set_vertex_position(int p_index, const Vector3 &p_position);166167void pin_vertex(int p_index);168void unpin_vertex(int p_index);169170void unpin_all_vertices();171172bool is_vertex_pinned(int p_index) const;173174void apply_vertex_impulse(int p_index, const Vector3 &p_impulse);175void apply_vertex_force(int p_index, const Vector3 &p_force);176void apply_central_impulse(const Vector3 &p_impulse);177void apply_central_force(const Vector3 &p_force);178};179180181