Commit de22a938 authored by frankie's avatar frankie 💬

stickiness feature in dots + better force management

parent 887d004a
......@@ -883,10 +883,18 @@ bool Softskin::_set(const StringName &p_path, const Variant &p_value) {
default:
break;
}
} else if (what == PROP_GROUP_DOT_DAMPING) {
} else if (what == PROP_GROUP_DOT_STICKINESS) {
switch (sg->get_type()) {
case sf_DOT:
((SoftskinGroupDot*) sg)->set_damping(p_value);
((SoftskinGroupDot*) sg)->set_stickiness(p_value);
break;
default:
break;
}
} else if (what == PROP_GROUP_DOT_REACTIVITY) {
switch (sg->get_type()) {
case sf_DOT:
((SoftskinGroupDot*) sg)->set_reactivity(p_value);
break;
default:
break;
......@@ -1023,13 +1031,22 @@ bool Softskin::_get(const StringName &p_path, Variant &r_ret) const {
r_ret = ssk_DEFAULT_MUSCLE_FREQUENCY;
break;
}
} else if (what == PROP_GROUP_DOT_DAMPING) {
} else if (what == PROP_GROUP_DOT_STICKINESS) {
switch (sg->get_type()) {
case sf_DOT:
r_ret = ((SoftskinGroupDot*) sg)->get_stickiness();
break;
default:
r_ret = ssk_DEFAULT_DOT_STICKINESS;
break;
}
} else if (what == PROP_GROUP_DOT_REACTIVITY) {
switch (sg->get_type()) {
case sf_DOT:
r_ret = ((SoftskinGroupDot*) sg)->get_damping();
r_ret = ((SoftskinGroupDot*) sg)->get_reactivity();
break;
default:
r_ret = ssk_DEFAULT_DOT_DAMPING;
r_ret = ssk_DEFAULT_DOT_REACTIVITY;
break;
}
} else if (what == PROP_GROUP_DOT_PRESSURE) {
......@@ -1085,7 +1102,8 @@ void Softskin::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::REAL, prep + PROP_GROUP_MUSCLE_FREQUENCY, PROPERTY_HINT_RANGE, "0.0,1.0,0.00001,or_greater"));
break;
case sf_DOT:
p_list->push_back(PropertyInfo(Variant::REAL, prep + PROP_GROUP_DOT_DAMPING, PROPERTY_HINT_RANGE, "0.0,1.0,0.00001,or_greater"));
p_list->push_back(PropertyInfo(Variant::REAL, prep + PROP_GROUP_DOT_STICKINESS, PROPERTY_HINT_RANGE, "-1.0,1.0,0.00001,or_greater,or_lesser"));
p_list->push_back(PropertyInfo(Variant::REAL, prep + PROP_GROUP_DOT_REACTIVITY, PROPERTY_HINT_RANGE, "-1.0,1.0,0.00001,or_greater,or_lesser"));
p_list->push_back(PropertyInfo(Variant::REAL, prep + PROP_GROUP_DOT_PRESSURE, PROPERTY_HINT_RANGE, "-1.0,1.0,0.00001,or_greater,or_lesser"));
break;
default:
......
......@@ -92,7 +92,8 @@
#define ssk_DEFAULT_MUSCLE_MAX_LEN 1
#define ssk_DEFAULT_MUSCLE_PHASE_SHIFT 1
#define ssk_DEFAULT_MUSCLE_FREQUENCY 0
#define ssk_DEFAULT_DOT_DAMPING 1
#define ssk_DEFAULT_DOT_STICKINESS 0
#define ssk_DEFAULT_DOT_REACTIVITY 1
#define ssk_DEFAULT_DOT_PESSURE 0
// groups default names
......@@ -105,7 +106,8 @@
#define PROP_GROUP_MUSCLE_MIN_LEN "muscle_min"
#define PROP_GROUP_MUSCLE_MAX_LEN "muscle_max"
#define PROP_GROUP_MUSCLE_FREQUENCY "muscle_freq"
#define PROP_GROUP_DOT_DAMPING "dot_damping"
#define PROP_GROUP_DOT_STICKINESS "dot_stickiness"
#define PROP_GROUP_DOT_REACTIVITY "dot_reactivity"
#define PROP_GROUP_DOT_PRESSURE "dot_pressure"
#define ID_GROUP_ALL_FIBERS 0
......
......@@ -95,7 +95,8 @@ void SoftskinDot::init_internal() {
_vert_origin = _vert.ref();
_total_push_length = 0;
_damping = ssk_DEFAULT_DOT_DAMPING;
_stickiness = ssk_DEFAULT_DOT_STICKINESS;
_reactivity = ssk_DEFAULT_DOT_REACTIVITY;
_kicks = 0;
_pressure = ssk_DEFAULT_DOT_PESSURE;
_nkicks = 0;
......@@ -141,12 +142,20 @@ Vector3 SoftskinDot::normal() const {
return _normal;
}
const float& SoftskinDot::get_damping() const {
return _damping;
const float& SoftskinDot::get_reactivity() const {
return _reactivity;
}
void SoftskinDot::set_damping(const float& d) {
_damping = d;
void SoftskinDot::set_reactivity(const float& d) {
_reactivity = d;
}
const float& SoftskinDot::get_stickiness() const {
return _stickiness;
}
void SoftskinDot::set_stickiness(const float& d) {
_stickiness = d;
}
const float& SoftskinDot::get_pressure() const {
......@@ -168,7 +177,8 @@ void SoftskinDot::vert(const float& x, const float& y, const float& z) {
void SoftskinDot::operator=(const SoftskinDot& src) {
_vert = src.vert();
_force = src.force();
_damping = src.get_damping();
_stickiness = src.get_stickiness();
_reactivity = src.get_reactivity();
_kicks = src.kicks();
}
......@@ -184,11 +194,15 @@ const Vector3& SoftskinDot::update(const float& delta_time) {
_nkicks = 0;
_force.ref() += _normal * _pressure;
}
_force.ref() *= delta_time;
Vector3 consumed = _force.ref() * _damping / sqrt(_kicks - 1);
Vector3 consumed = _force.ref() * _reactivity / sqrt(_kicks - 1);
_force -= consumed;
_vert += consumed;
_vert += (_vert_origin - _vert.ref()) * _stickiness * delta_time;
_total_push_length = _force.ref().length_squared();
_kicks = 0;
return _vert.ref();
......
......@@ -79,9 +79,13 @@ public:
// behaviour
const float& get_damping() const;
const float& get_reactivity() const;
void set_damping(const float& d);
void set_reactivity(const float& d);
const float& get_stickiness() const;
void set_stickiness(const float& d);
const float& get_pressure() const;
......@@ -130,7 +134,8 @@ private:
VectorPtr< Vector3 > _vert;
VectorPtr< Vector3 > _force;
float _damping;
float _stickiness;
float _reactivity;
uint16_t _kicks;
// normal computation
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment