Path: blob/master/modules/jolt_physics/objects/jolt_soft_body_3d.h
21409 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_3d/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 {44HashSet<int> pinned_vertices;45LocalVector<RID> exceptions;46LocalVector<Vector3> normals;4748RID mesh;49LocalVector<int> mesh_to_physics;5051JPH::SoftBodyCreationSettings *jolt_settings = new JPH::SoftBodyCreationSettings();5253float mass = 0.0f;54float pressure = 0.0f;55float linear_damping = 0.01f;56float stiffness_coefficient = 0.5f;57float shrinking_factor = 0.0f;5859int simulation_precision = 5;6061virtual JPH::BroadPhaseLayer _get_broad_phase_layer() const override;62virtual JPH::ObjectLayer _get_object_layer() const override;6364virtual void _space_changing() override;65virtual void _space_changed() override;6667virtual void _add_to_space() override;6869JPH::SoftBodySharedSettings *_create_shared_settings();7071void _update_mass();72void _update_pressure();73void _update_damping();74void _update_simulation_precision();75void _update_group_filter();7677void _try_rebuild();7879void _mesh_changed();80void _simulation_precision_changed();81void _mass_changed();82void _pressure_changed();83void _damping_changed();84void _pins_changed();85void _vertices_changed();86void _exceptions_changed();87void _motion_changed();8889public:90JoltSoftBody3D();91virtual ~JoltSoftBody3D() override;9293void add_collision_exception(const RID &p_excepted_body);94void remove_collision_exception(const RID &p_excepted_body);95bool has_collision_exception(const RID &p_excepted_body) const;9697const LocalVector<RID> &get_collision_exceptions() const { return exceptions; }9899virtual bool can_interact_with(const JoltBody3D &p_other) const override;100virtual bool can_interact_with(const JoltSoftBody3D &p_other) const override;101virtual bool can_interact_with(const JoltArea3D &p_other) const override;102103virtual bool reports_contacts() const override { return false; }104105virtual Vector3 get_velocity_at_position(const Vector3 &p_position) const override;106107void set_mesh(const RID &p_mesh);108109bool is_pickable() const { return pickable; }110void set_pickable(bool p_enabled) { pickable = p_enabled; }111112bool is_sleeping() const;113void set_is_sleeping(bool p_enabled);114115bool is_sleep_allowed() const;116void set_is_sleep_allowed(bool p_enabled);117118void put_to_sleep() { set_is_sleeping(true); }119void wake_up() { set_is_sleeping(false); }120121int get_simulation_precision() const { return simulation_precision; }122void set_simulation_precision(int p_precision);123124float get_mass() const { return mass; }125void set_mass(float p_mass);126127float get_stiffness_coefficient() const;128void set_stiffness_coefficient(float p_coefficient);129130float get_shrinking_factor() const;131void set_shrinking_factor(float p_shrinking_factor);132133float get_pressure() const { return pressure; }134void set_pressure(float p_pressure);135136float get_linear_damping() const { return linear_damping; }137void set_linear_damping(float p_damping);138139float get_drag() const;140void set_drag(float p_drag);141142Variant get_state(PhysicsServer3D::BodyState p_state) const;143void set_state(PhysicsServer3D::BodyState p_state, const Variant &p_value);144145Transform3D get_transform() const;146void set_transform(const Transform3D &p_transform);147148AABB get_bounds() const;149150void update_rendering_server(PhysicsServer3DRenderingServerHandler *p_rendering_server_handler);151152Vector3 get_vertex_position(int p_index);153void set_vertex_position(int p_index, const Vector3 &p_position);154155void pin_vertex(int p_index);156void unpin_vertex(int p_index);157158void unpin_all_vertices();159160bool is_vertex_pinned(int p_index) const;161162void apply_vertex_impulse(int p_index, const Vector3 &p_impulse);163void apply_vertex_force(int p_index, const Vector3 &p_force);164void apply_central_impulse(const Vector3 &p_impulse);165void apply_central_force(const Vector3 &p_force);166};167168169