diff --git a/modules/procedural_tree_3d/procedural_tree_mesh.cpp b/modules/procedural_tree_3d/procedural_tree_mesh.cpp index 99d3a9b53..87199823f 100644 --- a/modules/procedural_tree_3d/procedural_tree_mesh.cpp +++ b/modules/procedural_tree_3d/procedural_tree_mesh.cpp @@ -5,6 +5,163 @@ #include "servers/rendering_server.h" +// General +int ProceduralTreeMesh::get_seed() const { + return _seed; +} +void ProceduralTreeMesh::set_seed(const int p_value) { + _seed = p_value; +} + +int ProceduralTreeMesh::get_branch_segments() const { + return _branch_segments; +} +void ProceduralTreeMesh::set_branch_segments(const int p_value) { + _branch_segments = p_value; +} + +int ProceduralTreeMesh::get_branch_levels() const { + return _branch_levels; +} +void ProceduralTreeMesh::set_branch_levels(const int p_value) { + _branch_levels = p_value; +} + +int ProceduralTreeMesh::get_trunk_forks() const { + return _trunk_forks; +} +void ProceduralTreeMesh::set_trunk_forks(const int p_value) { + _trunk_forks = p_value; +} + +float ProceduralTreeMesh::get_texture_v_multiplier() const { + return _texture_v_multiplier; +} +void ProceduralTreeMesh::set_texture_v_multiplier(const float p_value) { + _texture_v_multiplier = p_value; +} + +float ProceduralTreeMesh::get_twig_scale() const { + return _twig_scale; +} +void ProceduralTreeMesh::set_twig_scale(const float p_value) { + _twig_scale = p_value; +} + +// Branching +float ProceduralTreeMesh::get_initial_length() const { + return _initial_length; +} +void ProceduralTreeMesh::set_initial_length(const float p_value) { + _initial_length = p_value; +} + +float ProceduralTreeMesh::get_length_falloff_rate() const { + return _length_falloff_rate; +} +void ProceduralTreeMesh::set_length_falloff_rate(const float p_value) { + _length_falloff_rate = p_value; +} + +float ProceduralTreeMesh::get_length_falloff_power() const { + return _length_falloff_power; +} +void ProceduralTreeMesh::set_length_falloff_power(const float p_value) { + _length_falloff_power = p_value; +} + +float ProceduralTreeMesh::get_max_clumping() const { + return _max_clumping; +} +void ProceduralTreeMesh::set_max_clumping(const float p_value) { + _max_clumping = p_value; +} + +float ProceduralTreeMesh::get_min_clumping() const { + return _min_clumping; +} +void ProceduralTreeMesh::set_min_clumping(const float p_value) { + _min_clumping = p_value; +} + +float ProceduralTreeMesh::get_symmetry() const { + return _symmetry; +} +void ProceduralTreeMesh::set_symmetry(const float p_value) { + _symmetry = p_value; +} + +float ProceduralTreeMesh::get_droop() const { + return _droop; +} +void ProceduralTreeMesh::set_droop(const float p_value) { + _droop = p_value; +} + +float ProceduralTreeMesh::get_growth() const { + return _growth; +} +void ProceduralTreeMesh::set_growth(const float p_value) { + _growth = p_value; +} + +float ProceduralTreeMesh::get_sweep() const { + return _sweep; +} +void ProceduralTreeMesh::set_sweep(const float p_value) { + _sweep = p_value; +} + +// Trunk +float ProceduralTreeMesh::get_trunk_radius() const { + return _trunk_radius; +} +void ProceduralTreeMesh::set_trunk_radius(const float p_value) { + _trunk_radius = p_value; +} + +float ProceduralTreeMesh::get_radius_falloff() const { + return _radius_falloff; +} +void ProceduralTreeMesh::set_radius_falloff(const float p_value) { + _radius_falloff = p_value; +} + +float ProceduralTreeMesh::get_climb_rate() const { + return _climb_rate; +} +void ProceduralTreeMesh::set_climb_rate(const float p_value) { + _climb_rate = p_value; +} + +float ProceduralTreeMesh::get_kink() const { + return _kink; +} +void ProceduralTreeMesh::set_kink(const float p_value) { + _kink = p_value; +} + +float ProceduralTreeMesh::get_taper_rate() const { + return _taper_rate; +} +void ProceduralTreeMesh::set_taper_rate(const float p_value) { + _taper_rate = p_value; +} + +float ProceduralTreeMesh::get_twists() const { + return _twists; +} +void ProceduralTreeMesh::set_twists(const float p_value) { + _twists = p_value; +} + +float ProceduralTreeMesh::get_trunk_length() const { + return _trunk_length; +} +void ProceduralTreeMesh::set_trunk_length(const float p_value) { + _trunk_length = p_value; +} + void ProceduralTreeMesh::_update() const { Array arr; arr.resize(RS::ARRAY_MAX); @@ -32,8 +189,8 @@ void ProceduralTreeMesh::_update() const { RenderingServer::get_singleton()->mesh_add_surface_from_arrays(mesh, RenderingServer::PRIMITIVE_TRIANGLES, arr); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(mesh, RenderingServer::PRIMITIVE_TRIANGLES, arr); - RenderingServer::get_singleton()->mesh_surface_set_material(mesh, TREE_SURFACE_TRUNK, _surfaces[TREE_SURFACE_TRUNK].material.is_null() ? RID() : _surfaces[TREE_SURFACE_TRUNK].material->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(mesh, TREE_SURFACE_TWIG, _surfaces[TREE_SURFACE_TWIG].material.is_null() ? RID() : _surfaces[TREE_SURFACE_TWIG].material->get_rid()); + RenderingServer::get_singleton()->mesh_surface_set_material(mesh, TREE_SURFACE_TRUNK, _surfaces[TREE_SURFACE_TRUNK].material.is_null() ? RID() : _surfaces[TREE_SURFACE_TRUNK].material->get_rid()); pending_request = false; @@ -109,12 +266,12 @@ void ProceduralTreeMesh::surface_set_material(int p_idx, const Ref &p_ ERR_FAIL_INDEX(p_idx, TREE_SURFACE_COUNT); switch (p_idx) { - case TREE_SURFACE_TRUNK: - set_trunk_material(p_material); - break; case TREE_SURFACE_TWIG: set_twig_material(p_material); break; + case TREE_SURFACE_TRUNK: + set_trunk_material(p_material); + break; case TREE_SURFACE_COUNT: default: break; @@ -153,21 +310,6 @@ RID ProceduralTreeMesh::get_rid() const { return mesh; } -void ProceduralTreeMesh::set_trunk_material(const Ref &p_material) { - _surfaces[TREE_SURFACE_TRUNK].material = p_material; - if (!pending_request) { - // just apply it, else it'll happen when _update is called. - RenderingServer::get_singleton()->mesh_surface_set_material(mesh, TREE_SURFACE_TRUNK, _surfaces[TREE_SURFACE_TRUNK].material.is_null() ? RID() : _surfaces[TREE_SURFACE_TRUNK].material->get_rid()); - _change_notify(); - emit_changed(); - }; -} - -Ref ProceduralTreeMesh::get_trunk_material() const { - return _surfaces[TREE_SURFACE_TRUNK].material; -} - - void ProceduralTreeMesh::set_twig_material(const Ref &p_material) { _surfaces[TREE_SURFACE_TWIG].material = p_material; if (!pending_request) { @@ -182,6 +324,19 @@ Ref ProceduralTreeMesh::get_twig_material() const { return _surfaces[TREE_SURFACE_TWIG].material; } +void ProceduralTreeMesh::set_trunk_material(const Ref &p_material) { + _surfaces[TREE_SURFACE_TRUNK].material = p_material; + if (!pending_request) { + // just apply it, else it'll happen when _update is called. + RenderingServer::get_singleton()->mesh_surface_set_material(mesh, TREE_SURFACE_TRUNK, _surfaces[TREE_SURFACE_TRUNK].material.is_null() ? RID() : _surfaces[TREE_SURFACE_TRUNK].material->get_rid()); + _change_notify(); + emit_changed(); + }; +} + +Ref ProceduralTreeMesh::get_trunk_material() const { + return _surfaces[TREE_SURFACE_TRUNK].material; +} Array ProceduralTreeMesh::get_mesh_arrays() const { Array arr; @@ -209,6 +364,34 @@ ProceduralTreeMesh::ProceduralTreeMesh() { // make sure we do an update after we've finished constructing our object pending_request = true; + + // General + _seed = 262; + _branch_segments = 6; + _branch_levels = 5; + _twig_scale = 0.39; + _trunk_forks = 5; + _texture_v_multiplier = 0.36; + + // Branching + _initial_length = 0.49; + _length_falloff_rate = 0.85; + _length_falloff_power = 0.99; + _max_clumping = 0.454; + _min_clumping = 0.404; + _symmetry = 2.45; + _droop = -0.1; + _growth = 0.235; + _sweep = 0.01; + + // Trunk + _trunk_radius = 0.139; + _radius_falloff = 0.73; + _climb_rate = 0.371; + _kink = 0.093; + _taper_rate = 0.947; + _twists = 3.02; + _trunk_length = 2.4; } ProceduralTreeMesh::~ProceduralTreeMesh() { @@ -216,21 +399,114 @@ ProceduralTreeMesh::~ProceduralTreeMesh() { } void ProceduralTreeMesh::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update"), &ProceduralTreeMesh::_update); + ADD_GROUP("General", ""); + ClassDB::bind_method(D_METHOD("get_seed"), &ProceduralTreeMesh::get_seed); + ClassDB::bind_method(D_METHOD("set_seed", "value"), &ProceduralTreeMesh::set_seed); + ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed"); - ClassDB::bind_method(D_METHOD("set_trunk_material", "material"), &ProceduralTreeMesh::set_trunk_material); - ClassDB::bind_method(D_METHOD("get_trunk_material"), &ProceduralTreeMesh::get_trunk_material); + ClassDB::bind_method(D_METHOD("get_branch_segments"), &ProceduralTreeMesh::get_branch_segments); + ClassDB::bind_method(D_METHOD("set_branch_segments", "value"), &ProceduralTreeMesh::set_branch_segments); + ADD_PROPERTY(PropertyInfo(Variant::INT, "branch_segments"), "set_branch_segments", "get_branch_segments"); + + ClassDB::bind_method(D_METHOD("get_branch_levels"), &ProceduralTreeMesh::get_branch_levels); + ClassDB::bind_method(D_METHOD("set_branch_levels", "value"), &ProceduralTreeMesh::set_branch_levels); + ADD_PROPERTY(PropertyInfo(Variant::INT, "branch_levels"), "set_branch_levels", "get_branch_levels"); + + ClassDB::bind_method(D_METHOD("get_trunk_forks"), &ProceduralTreeMesh::get_trunk_forks); + ClassDB::bind_method(D_METHOD("set_trunk_forks", "value"), &ProceduralTreeMesh::set_trunk_forks); + ADD_PROPERTY(PropertyInfo(Variant::INT, "trunk_forks"), "set_trunk_forks", "get_trunk_forks"); + + ClassDB::bind_method(D_METHOD("get_texture_v_multiplier"), &ProceduralTreeMesh::get_texture_v_multiplier); + ClassDB::bind_method(D_METHOD("set_texture_v_multiplier", "value"), &ProceduralTreeMesh::set_texture_v_multiplier); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_v_multiplier"), "set_texture_v_multiplier", "get_texture_v_multiplier"); + + ClassDB::bind_method(D_METHOD("get_twig_scale"), &ProceduralTreeMesh::get_twig_scale); + ClassDB::bind_method(D_METHOD("set_twig_scale", "value"), &ProceduralTreeMesh::set_twig_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "twig_scale"), "set_twig_scale", "get_twig_scale"); + + ADD_GROUP("Branching", ""); + ClassDB::bind_method(D_METHOD("get_initial_length"), &ProceduralTreeMesh::get_initial_length); + ClassDB::bind_method(D_METHOD("set_initial_length", "value"), &ProceduralTreeMesh::set_initial_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "initial_length"), "set_initial_length", "get_initial_length"); + + ClassDB::bind_method(D_METHOD("get_length_falloff_rate"), &ProceduralTreeMesh::get_length_falloff_rate); + ClassDB::bind_method(D_METHOD("set_length_falloff_rate", "value"), &ProceduralTreeMesh::set_length_falloff_rate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length_falloff_rate"), "set_length_falloff_rate", "get_length_falloff_rate"); + + ClassDB::bind_method(D_METHOD("get_length_falloff_power"), &ProceduralTreeMesh::get_length_falloff_power); + ClassDB::bind_method(D_METHOD("set_length_falloff_power", "value"), &ProceduralTreeMesh::set_length_falloff_power); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length_falloff_power"), "set_length_falloff_power", "get_length_falloff_power"); + + ClassDB::bind_method(D_METHOD("get_max_clumping"), &ProceduralTreeMesh::get_max_clumping); + ClassDB::bind_method(D_METHOD("set_max_clumping", "value"), &ProceduralTreeMesh::set_max_clumping); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_clumping"), "set_max_clumping", "get_max_clumping"); + + ClassDB::bind_method(D_METHOD("get_min_clumping"), &ProceduralTreeMesh::get_min_clumping); + ClassDB::bind_method(D_METHOD("set_min_clumping", "value"), &ProceduralTreeMesh::set_min_clumping); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_clumping"), "set_min_clumping", "get_min_clumping"); + + ClassDB::bind_method(D_METHOD("get_symmetry"), &ProceduralTreeMesh::get_symmetry); + ClassDB::bind_method(D_METHOD("set_symmetry", "value"), &ProceduralTreeMesh::set_symmetry); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "symmetry"), "set_symmetry", "get_symmetry"); + + ClassDB::bind_method(D_METHOD("get_droop"), &ProceduralTreeMesh::get_droop); + ClassDB::bind_method(D_METHOD("set_droop", "value"), &ProceduralTreeMesh::set_droop); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "droop"), "set_droop", "get_droop"); + + ClassDB::bind_method(D_METHOD("get_growth"), &ProceduralTreeMesh::get_growth); + ClassDB::bind_method(D_METHOD("set_growth", "value"), &ProceduralTreeMesh::set_growth); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "growth"), "set_growth", "get_growth"); + + ClassDB::bind_method(D_METHOD("get_sweep"), &ProceduralTreeMesh::get_sweep); + ClassDB::bind_method(D_METHOD("set_sweep", "value"), &ProceduralTreeMesh::set_sweep); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "sweep"), "set_sweep", "get_sweep"); + + ADD_GROUP("Trunk", ""); + ClassDB::bind_method(D_METHOD("get_trunk_radius"), &ProceduralTreeMesh::get_trunk_radius); + ClassDB::bind_method(D_METHOD("set_trunk_radius", "value"), &ProceduralTreeMesh::set_trunk_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "trunk_radius"), "set_trunk_radius", "get_trunk_radius"); + + ClassDB::bind_method(D_METHOD("get_radius_falloff"), &ProceduralTreeMesh::get_radius_falloff); + ClassDB::bind_method(D_METHOD("set_radius_falloff", "value"), &ProceduralTreeMesh::set_radius_falloff); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius_falloff"), "set_radius_falloff", "get_radius_falloff"); + + ClassDB::bind_method(D_METHOD("get_climb_rate"), &ProceduralTreeMesh::get_climb_rate); + ClassDB::bind_method(D_METHOD("set_climb_rate", "value"), &ProceduralTreeMesh::set_climb_rate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "climb_rate"), "set_climb_rate", "get_climb_rate"); + + ClassDB::bind_method(D_METHOD("get_kink"), &ProceduralTreeMesh::get_kink); + ClassDB::bind_method(D_METHOD("set_kink", "value"), &ProceduralTreeMesh::set_kink); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "kink"), "set_kink", "get_kink"); + + ClassDB::bind_method(D_METHOD("get_taper_rate"), &ProceduralTreeMesh::get_taper_rate); + ClassDB::bind_method(D_METHOD("set_taper_rate", "value"), &ProceduralTreeMesh::set_taper_rate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "taper_rate"), "set_taper_rate", "get_taper_rate"); + + ClassDB::bind_method(D_METHOD("get_twists"), &ProceduralTreeMesh::get_twists); + ClassDB::bind_method(D_METHOD("set_twists", "value"), &ProceduralTreeMesh::set_twists); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "twists"), "set_twists", "get_twists"); + + ClassDB::bind_method(D_METHOD("get_trunk_length"), &ProceduralTreeMesh::get_trunk_length); + ClassDB::bind_method(D_METHOD("set_trunk_length", "value"), &ProceduralTreeMesh::set_trunk_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "trunk_length"), "set_trunk_length", "get_trunk_length"); + + ADD_GROUP("Mesh", ""); + + ClassDB::bind_method(D_METHOD("_update"), &ProceduralTreeMesh::_update); ClassDB::bind_method(D_METHOD("set_twig_material", "material"), &ProceduralTreeMesh::set_twig_material); ClassDB::bind_method(D_METHOD("get_twig_material"), &ProceduralTreeMesh::get_twig_material); + ClassDB::bind_method(D_METHOD("set_trunk_material", "material"), &ProceduralTreeMesh::set_trunk_material); + ClassDB::bind_method(D_METHOD("get_trunk_material"), &ProceduralTreeMesh::get_trunk_material); + ClassDB::bind_method(D_METHOD("get_mesh_arrays"), &ProceduralTreeMesh::get_mesh_arrays); ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &ProceduralTreeMesh::set_custom_aabb); ClassDB::bind_method(D_METHOD("get_custom_aabb"), &ProceduralTreeMesh::get_custom_aabb); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "trunk_material", PROPERTY_HINT_RESOURCE_TYPE, "SpatialMaterial,ShaderMaterial"), "set_trunk_material", "get_trunk_material"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "twig_material", PROPERTY_HINT_RESOURCE_TYPE, "SpatialMaterial,ShaderMaterial"), "set_twig_material", "get_twig_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "trunk_material", PROPERTY_HINT_RESOURCE_TYPE, "SpatialMaterial,ShaderMaterial"), "set_trunk_material", "get_trunk_material"); ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, ""), "set_custom_aabb", "get_custom_aabb"); diff --git a/modules/procedural_tree_3d/procedural_tree_mesh.h b/modules/procedural_tree_3d/procedural_tree_mesh.h index cf1ec1698..fa2bbc67d 100644 --- a/modules/procedural_tree_3d/procedural_tree_mesh.h +++ b/modules/procedural_tree_3d/procedural_tree_mesh.h @@ -6,10 +6,80 @@ class ProceduralTreeMesh : public Mesh { GDCLASS(ProceduralTreeMesh, Mesh); +public: + // General + int get_seed() const; + void set_seed(const int p_value); + + int get_branch_segments() const; + void set_branch_segments(const int p_value); + + int get_branch_levels() const; + void set_branch_levels(const int p_value); + + int get_trunk_forks() const; + void set_trunk_forks(const int p_value); + + float get_texture_v_multiplier() const; + void set_texture_v_multiplier(const float p_value); + + float get_twig_scale() const; + void set_twig_scale(const float p_value); + + // Branching + float get_initial_length() const; + void set_initial_length(const float p_value); + + float get_length_falloff_rate() const; + void set_length_falloff_rate(const float p_value); + + float get_length_falloff_power() const; + void set_length_falloff_power(const float p_value); + + float get_max_clumping() const; + void set_max_clumping(const float p_value); + + float get_min_clumping() const; + void set_min_clumping(const float p_value); + + float get_symmetry() const; + void set_symmetry(const float p_value); + + float get_droop() const; + void set_droop(const float p_value); + + float get_growth() const; + void set_growth(const float p_value); + + float get_sweep() const; + void set_sweep(const float p_value); + + // Trunk + float get_trunk_radius() const; + void set_trunk_radius(const float p_value); + + float get_radius_falloff() const; + void set_radius_falloff(const float p_value); + + float get_climb_rate() const; + void set_climb_rate(const float p_value); + + float get_kink() const; + void set_kink(const float p_value); + + float get_taper_rate() const; + void set_taper_rate(const float p_value); + + float get_twists() const; + void set_twists(const float p_value); + + float get_trunk_length() const; + void set_trunk_length(const float p_value); + public: enum TreeSurfaces { - TREE_SURFACE_TRUNK = 0, - TREE_SURFACE_TWIG = 1, + TREE_SURFACE_TWIG = 0, + TREE_SURFACE_TRUNK = 1, TREE_SURFACE_COUNT, }; @@ -28,12 +98,12 @@ public: virtual AABB get_aabb() const; virtual RID get_rid() const; - void set_trunk_material(const Ref &p_material); - Ref get_trunk_material() const; - void set_twig_material(const Ref &p_material); Ref get_twig_material() const; + void set_trunk_material(const Ref &p_material); + Ref get_trunk_material() const; + Array get_mesh_arrays() const; void set_custom_aabb(const AABB &p_custom); @@ -47,6 +117,35 @@ protected: void _request_update(); +private: + // General + int _seed; //mProperties.mSeed + int _branch_segments; //mProperties.mSegments + int _branch_levels; //mProperties.mLevels + int _trunk_forks; //mProperties.mTreeSteps + float _texture_v_multiplier; //mProperties.mVMultiplier + float _twig_scale; //mProperties.mTwigScale + + // Branching + float _initial_length; //mProperties.mInitialBranchLength + float _length_falloff_rate; //mProperties.mLengthFalloffFactor + float _length_falloff_power; //mProperties.mLengthFalloffPower + float _max_clumping; //mProperties.mClumpMax + float _min_clumping; //mProperties.mClumpMin + float _symmetry; //mProperties.mBranchFactor + float _droop; //mProperties.mDropAmount + float _growth; //mProperties.mGrowAmount + float _sweep; //mProperties.mSweepAmount + + // Trunk + float _trunk_radius; //mProperties.mMaxRadius + float _radius_falloff; //mProperties.mRadiusFalloffRate + float _climb_rate; //mProperties.mClimbRate + float _kink; //mProperties.mTrunkKink + float _taper_rate; //mProperties.mTaperRate + float _twists; //mProperties.mTwistRate + float _trunk_length; //mProperties.mTrunkLength + private: RID mesh;