#include #include #include #include #include class StaticBody; class Roads: public MeshInstance { GDCLASS(Roads, MeshInstance); protected: Mutex mutex; Ref curve; Ref noise; Ref mat; Ref road_data; HashMap mesh_data; HashMap offsets; bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List *p_list) const; static void _bind_methods(); void update_all(); PoolVector vertices; struct thread_data { Thread thread; Ref mat; int vshape; float width; float sidewalk_width; int flags; Node *root; Ref mesh; MeshInstance *xmi; }; struct thread_data thread; static void generate_threaded(void *p_userdata); StaticBody *body; Transform cam_xform; #if 0 struct edge_data { int a; int b; float width; bool sidewalk; float sidewalk_width; edge_data(): a(-1), b(-1), width(1.0f), sidewalk(false), sidewalk_width(1.0f) {} }; #endif struct vshape { AABB area; int instance; int e1, e2; int site; Vector3 p1, p2, p3; }; #if 0 PoolVector edges; #endif PoolVector vshapes; void setup_vshapes(); void sort_angle(Vector &sort_data); #if 0 void extrude_direct(Array &out, const Array &arrays, const struct edge_data *data) const; void extrude_vshape(Array &out, const Array &arrays, const struct vshape *data) const; #endif void _notification(int p_what); int counter; friend class RoadsData; public: #if 0 void update(Ref roads, Vector3 where, float radius); #endif Roads(); ~Roads(); Vector3 calculate_offsets(const Array &data) const; Vector3 quadratic_bezier(const Vector3 &p1, const Vector3 &p2, const Vector3 &p3, float t) const; void all_offsets(); PoolVector build_item_list(float width, int flags, float sidewalk_width) const; Ref build_curve(Vector3 p1, Vector3 p2, Vector3 p3, float total_width) const; Array curve_mesh(PoolVector points, float width, int flags, float sidewalk_width); int make_vmesh(Node *root, Ref mat, Ref mesh, MeshInstance *xmi, Vector3 p1, Vector3 p2, Vector3 p3, float width, int flags, float sidewalk_width); void process_vshapes(); void add_scene_element(Node *root, Node *xnode, const Vector3 &p2, Ref shape); }; class RoadsData: public Object { GDCLASS(RoadsData, Object); protected: RoadGrid *rg; static void _bind_methods(); Ref curve; Ref noise; Mutex sdf_mutex; HashMap sdf_data; public: RoadsData(); ~RoadsData(); static RoadsData *get_singleton(); static void create_singleton(); static void destroy_singleton(); RoadGrid *get_road_grid() const; void set_noise(Ref noise); void set_curve(Ref curve); float get_sdf(int x, int y, int z); };