Merge pull request from Calinou/tubetrailmesh-add-cap-properties

Add properties to disable top/bottom cap generation in TubeTrailMesh
This commit is contained in:
Rémi Verschelde 2022-12-20 10:32:47 +01:00
commit 5d97889d1a
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 132 additions and 87 deletions

View file

@ -7,6 +7,12 @@
<tutorials>
</tutorials>
<members>
<member name="cap_bottom" type="bool" setter="set_cap_bottom" getter="is_cap_bottom" default="true">
If [code]true[/code], generates a cap at the bottom of the tube. This can be set to [code]false[/code] to speed up generation and rendering when the cap is never seen by the camera.
</member>
<member name="cap_top" type="bool" setter="set_cap_top" getter="is_cap_top" default="true">
If [code]true[/code], generates a cap at the top of the tube. This can be set to [code]false[/code] to speed up generation and rendering when the cap is never seen by the camera.
</member>
<member name="curve" type="Curve" setter="set_curve" getter="get_curve">
</member>
<member name="radial_steps" type="int" setter="set_radial_steps" getter="get_radial_steps" default="8">

View file

@ -2171,6 +2171,24 @@ int TubeTrailMesh::get_section_rings() const {
return section_rings;
}
void TubeTrailMesh::set_cap_top(bool p_cap_top) {
cap_top = p_cap_top;
_request_update();
}
bool TubeTrailMesh::is_cap_top() const {
return cap_top;
}
void TubeTrailMesh::set_cap_bottom(bool p_cap_bottom) {
cap_bottom = p_cap_bottom;
_request_update();
}
bool TubeTrailMesh::is_cap_bottom() const {
return cap_bottom;
}
void TubeTrailMesh::set_curve(const Ref<Curve> &p_curve) {
if (curve == p_curve) {
return;
@ -2284,6 +2302,7 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
thisrow = point;
}
if (cap_top) {
// add top
float scale_pos = 1.0;
if (curve.is_valid() && curve->get_point_count() > 0) {
@ -2346,14 +2365,16 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
}
}
}
}
if (cap_bottom) {
float scale_neg = 1.0;
if (curve.is_valid() && curve->get_point_count() > 0) {
scale_neg = curve->sample_baked(1.0);
}
// add bottom
if (scale_neg > CMP_EPSILON) {
// add bottom
float y = depth * -0.5;
thisrow = point;
@ -2409,6 +2430,7 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
}
}
}
}
p_arr[RS::ARRAY_VERTEX] = points;
p_arr[RS::ARRAY_NORMAL] = normals;
@ -2435,6 +2457,12 @@ void TubeTrailMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_section_rings", "section_rings"), &TubeTrailMesh::set_section_rings);
ClassDB::bind_method(D_METHOD("get_section_rings"), &TubeTrailMesh::get_section_rings);
ClassDB::bind_method(D_METHOD("set_cap_top", "cap_top"), &TubeTrailMesh::set_cap_top);
ClassDB::bind_method(D_METHOD("is_cap_top"), &TubeTrailMesh::is_cap_top);
ClassDB::bind_method(D_METHOD("set_cap_bottom", "cap_bottom"), &TubeTrailMesh::set_cap_bottom);
ClassDB::bind_method(D_METHOD("is_cap_bottom"), &TubeTrailMesh::is_cap_bottom);
ClassDB::bind_method(D_METHOD("set_curve", "curve"), &TubeTrailMesh::set_curve);
ClassDB::bind_method(D_METHOD("get_curve"), &TubeTrailMesh::get_curve);
@ -2447,13 +2475,16 @@ void TubeTrailMesh::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "section_rings", PROPERTY_HINT_RANGE, "1,128,1"), "set_section_rings", "get_section_rings");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cap_top"), "set_cap_top", "is_cap_top");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cap_bottom"), "set_cap_bottom", "is_cap_bottom");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve");
}
TubeTrailMesh::TubeTrailMesh() {
}
// TUBE TRAIL
// RIBBON TRAIL
void RibbonTrailMesh::set_shape(Shape p_shape) {
shape = p_shape;

View file

@ -431,6 +431,8 @@ private:
int sections = 5;
float section_length = 0.2;
int section_rings = 3;
bool cap_top = true;
bool cap_bottom = true;
Ref<Curve> curve;
@ -456,6 +458,12 @@ public:
void set_section_rings(const int p_section_rings);
int get_section_rings() const;
void set_cap_top(bool p_cap_top);
bool is_cap_top() const;
void set_cap_bottom(bool p_cap_bottom);
bool is_cap_bottom() const;
void set_curve(const Ref<Curve> &p_curve);
Ref<Curve> get_curve() const;