.. _program_listing_file_src_polyhedron_hex_polyhedron.h: Program Listing for File hex_polyhedron.h ========================================= |exhale_lsh| :ref:`Return to documentation for file ` (``src/polyhedron/hex_polyhedron.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include // for map #include #include #include // for unordered_map #include // for pair #include // for vector #include "core/tile_mesh.h" // for TileMesh #include "discretizer.h" #include "misc/dynamic_wrapper.h" #include "misc/types.h" // for Biome #include "polygon.h" #include "polyhedron/polyhedron_mesh_processor.h" #include "polyhedron/polyhedron_noise_processor.h" #include "polyhedron/polyhedron_prism_processor.h" #include "polyhedron/polyhedron_ridge_processor.h" #include "primitives/hexagon.h" #include "primitives/pentagon.h" #include "tal/arrays.h" // for Vector3Array #include "tal/engine.h" #include "tal/material.h" // for ShaderMaterial #include "tal/mesh.h" #include "tal/node.h" // for Node3D #include "tal/noise.h" // for FastNoiseLite #include "tal/reference.h" // for Ref #include "tal/shader.h" // for Shader #include "tal/texture.h" // for Texture #include "tal/vector3.h" // for Vector3 #include "tal/vector3i.h" // for Vector3i namespace sota { class Hexagon; class Pentagon; class PolygonWrapper : public Node3D { public: explicit PolygonWrapper(std::unique_ptr polygon) : _id(CNT++), _polygon(std::move(polygon)) {} ~PolygonWrapper() = default; PolygonWrapper(const PolygonWrapper& other) = delete; PolygonWrapper(PolygonWrapper&& other) = default; PolygonWrapper& operator=(const PolygonWrapper& other) = delete; PolygonWrapper& operator=(PolygonWrapper&& other) = delete; // getters RegularPolygon* polygon() { return _polygon.get(); } Ref mesh() { return _tile_mesh; } int id() const { return _id; } // setters void set_mesh(Ref tile_mesh, Node3D* parent) { parent->add_child(this); _tile_mesh = tile_mesh; _mesh_instance_wrapper = memnew(DynamicWrapper(_tile_mesh->inner_mesh(), this)); } private: static int CNT; int _id; std::unique_ptr _polygon; Ref _tile_mesh; DynamicWrapper* _mesh_instance_wrapper; }; class Polyhedron : public Node3D { GDCLASS(Polyhedron, Node3D) public: Polyhedron(); Polyhedron(const Polyhedron& other) = delete; Polyhedron(Polyhedron&& other) = delete; // copying operator= defined inside GDCLASS Polyhedron& operator=(Polyhedron&& rhs) = delete; void set_divisions(const int p_divisions); int get_divisions() const; void set_patch_resolution(const int p_patch_resolution); int get_patch_resolution() const; void set_shader(const Ref p_shader); Ref get_shader() const; void set_biomes_noise(const Ref p_biomes_noise); Ref get_biomes_noise() const; // textures void set_plain_texture(const Ref p_texture); Ref get_plain_texture() const; void set_hill_texture(const Ref p_texture); Ref get_hill_texture() const; void set_water_texture(const Ref p_texture); Ref get_water_texture() const; void set_mountain_texture(const Ref p_texture); Ref get_mountain_texture() const; protected: Ref _shader; Ref _biomes_noise; std::unordered_map> _texture; std::vector _hexagons; std::vector _pentagons; static void _bind_methods(); virtual void configure_hexagon(PolygonWrapper& wrapper, Biome biome, int& id, Ref mat) = 0; virtual void configure_pentagon(PolygonWrapper& wrapper, Biome biome, int& id, Ref mat) = 0; virtual void process_cells() = 0; virtual void set_material_parameters(Ref mat) = 0; virtual void calculate_normals() = 0; void init(); template void process_ngons(std::vector& ngons, float min_z, float max_z); private: friend class PolyhedronRidgeProcessor; friend class PolyhedronNoiseProcessor; friend class PolyhedronPrismProcessor; int _divisions{1}; int _patch_resolution{1}; mutable std::map> _neighbours_map; std::pair, std::vector> calculate_shapes() const; template std::optional insert_to_polygons(Vector3 start_point, float diameter, float R, float r, int i, int j, Vector3Array icosahedron_points, Vector3i triangle, std::map& polygons) const; void clear(); }; } // namespace sota