2020-02-19 19:26:14 +00:00
|
|
|
#ifndef VOXEL_GENERATOR_GRAPH_H
|
|
|
|
#define VOXEL_GENERATOR_GRAPH_H
|
|
|
|
|
|
|
|
#include "../voxel_generator.h"
|
|
|
|
#include "program_graph.h"
|
2020-02-29 00:17:47 +00:00
|
|
|
#include "voxel_graph_runtime.h"
|
2020-02-19 19:26:14 +00:00
|
|
|
|
|
|
|
class VoxelGeneratorGraph : public VoxelGenerator {
|
|
|
|
GDCLASS(VoxelGeneratorGraph, VoxelGenerator)
|
|
|
|
public:
|
2020-10-25 20:26:25 +00:00
|
|
|
static const char *SIGNAL_NODE_NAME_CHANGED;
|
|
|
|
|
2020-02-19 19:26:14 +00:00
|
|
|
enum NodeTypeID {
|
|
|
|
NODE_CONSTANT,
|
|
|
|
NODE_INPUT_X,
|
|
|
|
NODE_INPUT_Y,
|
|
|
|
NODE_INPUT_Z,
|
|
|
|
NODE_OUTPUT_SDF,
|
|
|
|
NODE_ADD,
|
|
|
|
NODE_SUBTRACT,
|
|
|
|
NODE_MULTIPLY,
|
2020-03-20 00:21:09 +00:00
|
|
|
NODE_DIVIDE,
|
|
|
|
NODE_SIN,
|
2020-02-19 19:26:14 +00:00
|
|
|
NODE_FLOOR,
|
|
|
|
NODE_ABS,
|
|
|
|
NODE_SQRT,
|
2020-03-20 00:21:09 +00:00
|
|
|
NODE_FRACT,
|
|
|
|
NODE_STEPIFY,
|
|
|
|
NODE_WRAP,
|
|
|
|
NODE_MIN,
|
|
|
|
NODE_MAX,
|
2020-02-19 19:26:14 +00:00
|
|
|
NODE_DISTANCE_2D,
|
|
|
|
NODE_DISTANCE_3D,
|
|
|
|
NODE_CLAMP,
|
|
|
|
NODE_MIX,
|
|
|
|
NODE_REMAP,
|
2020-04-05 19:53:07 +01:00
|
|
|
NODE_SMOOTHSTEP,
|
2020-02-19 19:26:14 +00:00
|
|
|
NODE_CURVE,
|
2020-07-11 17:03:09 +01:00
|
|
|
NODE_SELECT,
|
2020-02-19 19:26:14 +00:00
|
|
|
NODE_NOISE_2D,
|
|
|
|
NODE_NOISE_3D,
|
|
|
|
NODE_IMAGE_2D,
|
2020-03-20 00:21:09 +00:00
|
|
|
NODE_SDF_PLANE,
|
|
|
|
NODE_SDF_BOX,
|
|
|
|
NODE_SDF_SPHERE,
|
|
|
|
NODE_SDF_TORUS,
|
2020-07-07 23:28:02 +01:00
|
|
|
NODE_SDF_PREVIEW, // For debugging
|
2020-12-21 02:00:31 +00:00
|
|
|
NODE_SDF_SPHERE_HEIGHTMAP,
|
2020-12-21 20:06:20 +00:00
|
|
|
NODE_NORMALIZE_3D,
|
2021-01-03 20:23:45 +00:00
|
|
|
NODE_FAST_NOISE_2D,
|
|
|
|
NODE_FAST_NOISE_3D,
|
|
|
|
NODE_FAST_NOISE_GRADIENT_2D,
|
|
|
|
NODE_FAST_NOISE_GRADIENT_3D,
|
2020-02-19 19:26:14 +00:00
|
|
|
NODE_TYPE_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
VoxelGeneratorGraph();
|
|
|
|
~VoxelGeneratorGraph();
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2020-03-03 00:19:25 +00:00
|
|
|
uint32_t create_node(NodeTypeID type_id, Vector2 position, uint32_t id = ProgramGraph::NULL_ID);
|
2020-02-19 19:26:14 +00:00
|
|
|
void remove_node(uint32_t node_id);
|
2020-02-27 00:17:15 +00:00
|
|
|
|
2020-10-25 20:38:23 +00:00
|
|
|
bool can_connect(
|
|
|
|
uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index) const;
|
2020-02-24 23:03:41 +00:00
|
|
|
void add_connection(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index);
|
2020-10-25 20:38:23 +00:00
|
|
|
void remove_connection(
|
|
|
|
uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index);
|
2020-02-27 00:17:15 +00:00
|
|
|
void get_connections(std::vector<ProgramGraph::Connection> &connections) const;
|
2020-07-07 23:28:02 +01:00
|
|
|
bool try_get_connection_to(ProgramGraph::PortLocation dst, ProgramGraph::PortLocation &out_src) const;
|
2020-02-27 00:17:15 +00:00
|
|
|
|
2020-07-06 22:07:36 +01:00
|
|
|
bool has_node(uint32_t node_id) const;
|
|
|
|
|
2020-10-25 20:26:25 +00:00
|
|
|
void set_node_name(uint32_t node_id, StringName name);
|
|
|
|
StringName get_node_name(uint32_t node_id) const;
|
|
|
|
uint32_t find_node_by_name(StringName name) const;
|
|
|
|
|
2020-02-24 23:03:41 +00:00
|
|
|
Variant get_node_param(uint32_t node_id, uint32_t param_index) const;
|
|
|
|
void set_node_param(uint32_t node_id, uint32_t param_index, Variant value);
|
2020-02-27 00:17:15 +00:00
|
|
|
|
2020-03-08 19:23:48 +00:00
|
|
|
Variant get_node_default_input(uint32_t node_id, uint32_t input_index) const;
|
|
|
|
void set_node_default_input(uint32_t node_id, uint32_t input_index, Variant value);
|
|
|
|
|
2020-02-24 23:03:41 +00:00
|
|
|
Vector2 get_node_gui_position(uint32_t node_id) const;
|
|
|
|
void set_node_gui_position(uint32_t node_id, Vector2 pos);
|
2020-02-27 00:17:15 +00:00
|
|
|
|
2020-03-02 00:15:54 +00:00
|
|
|
NodeTypeID get_node_type_id(uint32_t node_id) const;
|
2020-02-24 23:03:41 +00:00
|
|
|
PoolIntArray get_node_ids() const;
|
2020-03-03 00:19:25 +00:00
|
|
|
uint32_t generate_node_id() { return _graph.generate_node_id(); }
|
2020-02-19 21:59:41 +00:00
|
|
|
|
2020-02-21 00:08:26 +00:00
|
|
|
int get_used_channels_mask() const override;
|
|
|
|
|
2020-02-19 19:26:14 +00:00
|
|
|
void generate_block(VoxelBlockRequest &input) override;
|
|
|
|
float generate_single(const Vector3i &position);
|
|
|
|
|
2020-02-23 02:50:04 +00:00
|
|
|
Ref<Resource> duplicate(bool p_subresources) const override;
|
|
|
|
|
2020-12-22 02:13:46 +00:00
|
|
|
// Utility
|
|
|
|
|
|
|
|
void bake_sphere_bumpmap(Ref<Image> im, float ref_radius, float min_height, float max_height);
|
|
|
|
void bake_sphere_normalmap(Ref<Image> im, float ref_radius, float strength);
|
|
|
|
|
2020-07-07 23:28:02 +01:00
|
|
|
// Internal
|
|
|
|
|
|
|
|
const VoxelGraphRuntime &get_runtime() const { return _runtime; }
|
2020-10-26 19:58:54 +00:00
|
|
|
bool compile();
|
|
|
|
|
|
|
|
const VoxelGraphRuntime::CompilationResult &get_compilation_result() const {
|
|
|
|
return _runtime.get_compilation_result();
|
|
|
|
}
|
2020-07-07 23:28:02 +01:00
|
|
|
|
2021-01-09 18:35:53 +00:00
|
|
|
void generate_set(ArraySlice<float> in_x, ArraySlice<float> in_y, ArraySlice<float> in_z,
|
|
|
|
ArraySlice<float> out_sdf);
|
|
|
|
|
2020-02-24 23:03:41 +00:00
|
|
|
// Debug
|
|
|
|
|
2021-01-04 22:19:13 +00:00
|
|
|
float debug_measure_microseconds_per_voxel(bool singular);
|
2020-02-24 23:03:41 +00:00
|
|
|
void debug_load_waves_preset();
|
2020-02-19 21:59:41 +00:00
|
|
|
|
2020-02-19 19:26:14 +00:00
|
|
|
private:
|
2020-02-22 22:11:07 +00:00
|
|
|
Interval analyze_range(Vector3i min_pos, Vector3i max_pos);
|
2020-02-19 19:26:14 +00:00
|
|
|
|
2020-03-07 01:34:30 +00:00
|
|
|
ProgramGraph::Node *create_node_internal(NodeTypeID type_id, Vector2 position, uint32_t id);
|
|
|
|
|
|
|
|
Dictionary get_graph_as_variant_data();
|
|
|
|
void load_graph_from_variant_data(Dictionary data);
|
|
|
|
|
2020-02-24 23:03:41 +00:00
|
|
|
int _b_get_node_type_count() const;
|
|
|
|
Dictionary _b_get_node_type_info(int type_id) const;
|
|
|
|
PoolIntArray _b_get_node_ids() const;
|
|
|
|
Array _b_get_connections() const;
|
2020-03-08 00:46:55 +00:00
|
|
|
// TODO Only exists because the UndoRedo API is confusing `null` with `absence of argument`...
|
|
|
|
// See https://github.com/godotengine/godot/issues/36895
|
|
|
|
void _b_set_node_param_null(int node_id, int param_index);
|
2020-07-07 18:53:54 +01:00
|
|
|
float _b_generate_single(Vector3 pos);
|
2020-02-24 23:03:41 +00:00
|
|
|
|
2020-07-07 23:28:02 +01:00
|
|
|
void _on_subresource_changed();
|
|
|
|
void connect_to_subresource_changes();
|
|
|
|
|
2020-02-19 19:26:14 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2020-02-23 02:50:04 +00:00
|
|
|
ProgramGraph _graph;
|
2020-02-29 00:17:47 +00:00
|
|
|
VoxelGraphRuntime _runtime;
|
2020-02-19 19:26:14 +00:00
|
|
|
VoxelBuffer::ChannelId _channel = VoxelBuffer::CHANNEL_SDF;
|
2021-01-08 21:04:49 +00:00
|
|
|
std::vector<float> _x_cache;
|
|
|
|
std::vector<float> _y_cache;
|
|
|
|
std::vector<float> _z_cache;
|
2021-01-05 18:59:52 +00:00
|
|
|
std::vector<float> _slice_cache;
|
2020-02-19 19:26:14 +00:00
|
|
|
};
|
|
|
|
|
2020-02-21 00:08:26 +00:00
|
|
|
VARIANT_ENUM_CAST(VoxelGeneratorGraph::NodeTypeID)
|
|
|
|
|
2020-02-19 19:26:14 +00:00
|
|
|
#endif // VOXEL_GENERATOR_GRAPH_H
|