Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
SpringBone.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
19#pragma once
20
21#include "../../core/Types.hpp"
23#include "../../math/Math.hpp"
24
25#include <vector>
26
27namespace esengine::ecs {
28
30ES_ENUM()
31enum class SpringBoneShape : i32 {
32 Sphere = 0,
34};
35
37struct SpringBone {
39 ES_PROPERTY(tooltip="Off leaves the chain exactly as the animation poses it.")
40 bool enabled{true};
41
43 ES_PROPERTY(category=Motion, min=0, max=1, step=0.01, slider, tooltip="How hard each bone is pulled back toward its animated pose. 0 hangs free, 1 follows the animation exactly.")
45
47 ES_PROPERTY(category=Motion, min=0, max=1, step=0.01, slider, tooltip="How much of its speed a bone loses each frame. Higher settles sooner.")
48 f32 drag{0.5f};
49
51 ES_PROPERTY(category=Motion, tooltip="Gravity on the chain, in world units a second squared (world y is up).")
52 glm::vec3 gravity{0.0f, -980.0f, 0.0f};
53
55 ES_PROPERTY(category=Wind, tooltip="A steady wind on the chain, in world units a second squared. Zero is still air.")
56 glm::vec3 wind{0.0f, 0.0f, 0.0f};
57
59 ES_PROPERTY(category=Wind, min=0, max=1, step=0.01, slider, tooltip="How far gusts swing the wind's strength. 0 is a steady wind, 1 takes it from calm to twice its strength.")
61
63 ES_PROPERTY(category=Wind, min=0, step=0.05, tooltip="Gusts a second.")
65
67 ES_PROPERTY(category=Chain, min=0, step=0.1, tooltip="Length of the tip past each end bone, in world units. 0 leaves the end bones unsimulated.")
69
71 ES_PROPERTY(category=Chain, min=0, step=0.1, tooltip="Thickness of the strand, in world units, kept clear of the colliders.")
72 f32 radius{0.0f};
73
75 ES_PROPERTY(category=Chain, min=0, max=1, step=0.01, slider, tooltip="How much of the simulation is used. 0 is the animation alone.")
76 f32 weight{1.0f};
77
79 ES_PROPERTY(category=Collision, entity_ref, tooltip="Entities with a SpringBoneCollider that this chain is kept out of (the head, the shoulders).")
81
82 SpringBone() = default;
83
85 bool operator==(const SpringBone&) const = default;
86};
87
93 ES_PROPERTY(category=Shape, enum=SpringBoneShape, tooltip="Sphere, or a capsule along the entity's own Y axis.")
95
97 ES_PROPERTY(category=Shape, min=0, step=0.1, tooltip="Radius in world units, before the entity's scale.")
98 f32 radius{10.0f};
99
101 ES_PROPERTY(category=Shape, min=0, step=0.1, shown_when=shape:Capsule, tooltip="A capsule's length between the centres of its end spheres, in world units before scale.")
102 f32 height{20.0f};
103
105 ES_PROPERTY(category=Shape, tooltip="Where the centre of the shape is, in the entity's own space.")
106 glm::vec3 offset{0.0f, 0.0f, 0.0f};
107
109};
110
111} // namespace esengine::ecs
Math utilities and GLM configuration for ESEngine.
Reflection and metadata system for automatic binding generation.
#define ES_COMPONENT(...)
Mark a struct/class as a component that should be exposed to scripts.
#define ES_ENUM(...)
Mark an enum that should be exposed to scripts.
#define ES_PROPERTY(...)
Mark a field as a property that should be exposed to scripts.
Core type definitions and utilities for ESEngine.
SpringBoneShape
What a SpringBoneCollider is shaped like.
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
float f32
32-bit floating point
Definition Types.hpp:59
Entity identifier with packed index + generation.
Definition Types.hpp:135
f32 height
A capsule's length between its two end spheres' centres, in world units before scale.
glm::vec3 offset
Where the shape's centre is, in the entity's own space.
f32 radius
Radius, in world units before the entity's scale.
f32 drag
How much of its velocity a bone loses each frame, 0 to 1.
glm::vec3 wind
A steady wind on the chain, in world units a second squared.
f32 weight
How much of the simulated pose is used, 0 to 1: 0 is the animation alone.
f32 windGust
How far gusts swing the wind's strength, 0 to 1.
f32 radius
The thickness of the strand, in world units, kept clear of every collider.
bool enabled
Simulated this frame. Off leaves the chain exactly as the animation poses it.
std::vector< Entity > colliders
Entities with a SpringBoneCollider this chain keeps out of.
f32 windFrequency
Gusts a second.
glm::vec3 gravity
Gravity on the chain, in world units a second squared.
f32 endLength
How far the last bones of a chain reach past themselves, in world units: a leaf has no child to aim a...
f32 stiffness
How hard each bone is pulled back toward the pose the animation gives it, 0 to 1.