feat: added expression value to every primitive
This commit is contained in:
parent
63c391593d
commit
2b04362ecc
6 changed files with 121 additions and 48 deletions
|
|
@ -18,6 +18,7 @@ public:
|
|||
|
||||
protected:
|
||||
float blend(float under, float over) const;
|
||||
virtual void _parse_new_expression(String expression) = 0;
|
||||
|
||||
public:
|
||||
// evaluate the height of this primitive at point, returns the weight of the effect, out_height will be set to the closest point on the primitive
|
||||
|
|
@ -27,10 +28,18 @@ public:
|
|||
BlendMode get_blend_mode() const;
|
||||
void set_blend_range(float blend_range);
|
||||
float get_blend_range() const;
|
||||
void set_expression(String expression);
|
||||
String get_expression() const;
|
||||
String get_expression_error() const;
|
||||
|
||||
private:
|
||||
float blend_range{ 4.f };
|
||||
BlendMode blend_mode{ Peak };
|
||||
String expr_text{};
|
||||
|
||||
protected:
|
||||
bool expression_valid{};
|
||||
Ref<Expression> expression{ memnew(Expression) };
|
||||
};
|
||||
|
||||
MAKE_TYPE_INFO(TerrainPrimitive::BlendMode, Variant::INT);
|
||||
|
|
@ -39,6 +48,9 @@ class PlanePrimitive : public TerrainPrimitive {
|
|||
GDCLASS(PlanePrimitive, TerrainPrimitive);
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
void _parse_new_expression(String expression) override;
|
||||
|
||||
public:
|
||||
void evaluate(Vector2 at, float &io_height) const override;
|
||||
void set_baseline(float value);
|
||||
|
|
@ -52,6 +64,9 @@ class PointPrimitive : public TerrainPrimitive {
|
|||
GDCLASS(PointPrimitive, TerrainPrimitive);
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
void _parse_new_expression(String expression) override;
|
||||
|
||||
public:
|
||||
void evaluate(Vector2 at, float &io_height) const override;
|
||||
void set_center(Vector2 center);
|
||||
|
|
@ -71,6 +86,9 @@ class NoisePrimitive : public TerrainPrimitive {
|
|||
GDCLASS(NoisePrimitive, TerrainPrimitive);
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
void _parse_new_expression(String expression) override;
|
||||
|
||||
public:
|
||||
void evaluate(Vector2 at, float &io_height) const override;
|
||||
void set_noise(Ref<Noise> noise);
|
||||
|
|
@ -85,18 +103,3 @@ private:
|
|||
float noise_scale{ 1.f };
|
||||
float noise_amplitude{ 1.f };
|
||||
};
|
||||
|
||||
class ExpressionPrimitive : public TerrainPrimitive {
|
||||
GDCLASS(ExpressionPrimitive, TerrainPrimitive);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void evaluate(Vector2 at, float &io_height) const override;
|
||||
void set_expression(String expression);
|
||||
String get_expression() const;
|
||||
|
||||
private:
|
||||
Ref<Expression> expression{ memnew(Expression) };
|
||||
String expression_string{ "height" };
|
||||
bool valid{ false };
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue