diff --git a/modules/material_maker/nodes/bases/curve_base.cpp b/modules/material_maker/nodes/bases/curve_base.cpp new file mode 100644 index 000000000..c75d65e8f --- /dev/null +++ b/modules/material_maker/nodes/bases/curve_base.cpp @@ -0,0 +1,274 @@ + +#include "curve_base.h" + + +Variant CurveBase::get_Variant() { + return Variant; +} + +void CurveBase::set_Variant(const Variant &val) { +Variant = val; +} + + + + //tool; + + Vector2 Point::get_p() { + return p; + } + + void Point::set_p(const Vector2 &val) { + p = val; + } + + + float Point::get_ls() const { + return ls; + } + + void Point::set_ls(const float val) { + ls = val; + } + + + float Point::get_rs() const { + return rs; + } + + void Point::set_rs(const float val) { + rs = val; + } + + + + Vector2 p = ; + float ls = ; + float rs = ; + + void Point::_init(const float x, const float y, const float nls, const float nrs) { + p = Vector2(x, y); + ls = nls; + rs = nrs; +} + + //export(PoolRealArray) ; +} + + Point::Point() { + p = ; + ls = ; + rs = ; + } + + Point::~Point() { + } + + + static void Point::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_p"), &Point::get_p); + ClassDB::bind_method(D_METHOD("set_p", "value"), &Point::set_p); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "p"), "set_p", "get_p"); + + + ClassDB::bind_method(D_METHOD("get_ls"), &Point::get_ls); + ClassDB::bind_method(D_METHOD("set_ls", "value"), &Point::set_ls); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "ls"), "set_ls", "get_ls"); + + + ClassDB::bind_method(D_METHOD("get_rs"), &Point::get_rs); + ClassDB::bind_method(D_METHOD("set_rs", "value"), &Point::set_rs); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rs"), "set_rs", "get_rs"); + + + ClassDB::bind_method(D_METHOD("_init", "x", "y", "nls", "nrs"), &Point::_init); + + } + + + Variant ; + + void CurveBase::init_points_01() { + + if (points.size() == 0) { + points = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 ]; +} + +} + + + void CurveBase::init_points_11() { + + if (points.size() == 0) { + points = [ 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0 ]; +} + +} + + + String CurveBase::to_string() { + Variant = PoolStringArray(); + + for (p in points) { + rv.append("("+str(p.x)+","+str(p.y)+","+str(p.ls)+","+str(p.rs)+")"); +} + + return rv.join(","); +} + + + void CurveBase::clear() { + points.clear(); + curve_changed(); +} + + + void CurveBase::add_point(const float x, const float y, const float ls, const float rs) { + int indx = points.size() / 4; + + for (i in indx) { + int ii = i * 4; + + if (x < points[ii]) { + + if (ls == INF) { + ls == 0; +} + + + if (rs == INF) { + rs == 0; +} + + points.insert(ii, x); + points.insert(ii + 1, y); + points.insert(ii + 2, ls); + points.insert(ii + 3, rs); + curve_changed(); + return; +} + +} + + points.append(x); + points.append(y); + points.append(ls); + points.append(rs); + curve_changed(); +} + + + bool CurveBase::remove_point(const int i) { + int index = i * 4; + + if (index <= 0 || index >= points.size() - 1) { + return false; +} + + + else { + points.remove(index); + points.remove(index); + points.remove(index); + points.remove(index); + curve_changed(); +} + + return true; +} + + + int CurveBase::get_point_count() { + return points.size() / 4; +} + + + void CurveBase::set_point(const int i, const Point &v) { + int indx = i * 4; + points[indx + 0] = v.p.x; + points[indx + 1] = v.p.y; + points[indx + 2] = v.ls; + points[indx + 3] = v.rs; + curve_changed(); +} + + + Point CurveBase::get_point(const int i) { + int indx = i * 4; + return Point.new(points[indx + 0], points[indx + 1], points[indx + 2], points[indx + 3]); +} + + + Array CurveBase::get_points() { + Array arr = Array(); + int c = get_point_count(); + + for (int i = 0; i < c; ++i) { //i in range(c) + arr.append(get_point(i)); +} + + return arr; +} + + + void CurveBase::set_points(const Array &arr, const bool notify) { + points.resize(0); + + for (p in arr) { + points.append(p.p.x); + points.append(p.p.y); + points.append(p.ls); + points.append(p.rs); +} + + + if (notify) { + curve_changed(); +} + +} + + + void CurveBase::curve_changed() { + _curve_changed(); +} + + + void CurveBase::_curve_changed() { + emit_changed(); +} + +} + + CurveBase::CurveBase() { + ; + } + + CurveBase::~CurveBase() { + } + + + static void CurveBase::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_Variant"), &CurveBase::get_Variant); + ClassDB::bind_method(D_METHOD("set_Variant", "value"), &CurveBase::set_Variant); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant"); + + + ClassDB::bind_method(D_METHOD("init_points_01"), &CurveBase::init_points_01); + ClassDB::bind_method(D_METHOD("init_points_11"), &CurveBase::init_points_11); + ClassDB::bind_method(D_METHOD("to_string"), &CurveBase::to_string); + ClassDB::bind_method(D_METHOD("clear"), &CurveBase::clear); + ClassDB::bind_method(D_METHOD("add_point", "x", "y", "ls", "rs"), &CurveBase::add_point, INF, INF); + ClassDB::bind_method(D_METHOD("remove_point", "i"), &CurveBase::remove_point); + ClassDB::bind_method(D_METHOD("get_point_count"), &CurveBase::get_point_count); + ClassDB::bind_method(D_METHOD("set_point", "i", "v"), &CurveBase::set_point); + ClassDB::bind_method(D_METHOD("get_point", "i"), &CurveBase::get_point); + ClassDB::bind_method(D_METHOD("get_points"), &CurveBase::get_points); + ClassDB::bind_method(D_METHOD("set_points", "arr", "notify"), &CurveBase::set_points, true); + ClassDB::bind_method(D_METHOD("curve_changed"), &CurveBase::curve_changed); + ClassDB::bind_method(D_METHOD("_curve_changed"), &CurveBase::_curve_changed); + + } + + + diff --git a/modules/material_maker/nodes/bases/curve_base.h b/modules/material_maker/nodes/bases/curve_base.h new file mode 100644 index 000000000..fe6bc3152 --- /dev/null +++ b/modules/material_maker/nodes/bases/curve_base.h @@ -0,0 +1,64 @@ +#ifndef CURVE_BASE_H +#define CURVE_BASE_H + + +class CurveBase : public MMNode { + GDCLASS(CurveBase, MMNode); + + public: + + Variant get_Variant(); + void set_Variant(const Variant &val); + + class Point { + public: + + Vector2 get_p(); + void set_p(const Vector2 &val); + + float get_ls() const; + void set_ls(const float val); + + float get_rs() const; + void set_rs(const float val); + + void _init(const float x, const float y, const float nls, const float nrs); + + Point(); + ~Point(); + + protected: + static void _bind_methods(); + + Vector2 p = ; + float ls = ; + float rs = ; + //export(PoolRealArray) +}; + + void init_points_01(); + void init_points_11(); + String to_string(); + void clear(); + void add_point(const float x, const float y, const float ls = INF, const float rs = INF); + bool remove_point(const int i); + int get_point_count(); + void set_point(const int i, const Point &v); + Point get_point(const int i); + Array get_points(); + void set_points(const Array &arr, const bool notify = true); + void curve_changed(); + void _curve_changed(); + + CurveBase(); + ~CurveBase(); + + protected: + static void _bind_methods(); + + //tool + Variant ; +}; + + +#endif diff --git a/modules/material_maker/nodes/bases/gradient_base.cpp b/modules/material_maker/nodes/bases/gradient_base.cpp new file mode 100644 index 000000000..3eff183b8 --- /dev/null +++ b/modules/material_maker/nodes/bases/gradient_base.cpp @@ -0,0 +1,137 @@ + +#include "gradient_base.h" + + +int GradientBase::get_interpolation_type() const { + return interpolation_type; +} + +void GradientBase::set_interpolation_type(const int val) { +interpolation_type = val; +} + + +PoolRealArray GradientBase::get_points() { + return points; +} + +void GradientBase::set_points(const PoolRealArray &val) { +points = val; +} + + + + //tool; + //var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd"); + //export(int) ; + // setget set_interpolation_type, get_interpolation_type; + int interpolation_type = 1; + //export(PoolRealArray) ; + PoolRealArray points = PoolRealArray(); + + Color GradientBase::get_gradient_color(const float x) { + // if interpolation_type == 0:; + // return Gradients.gradient_type_1(x, points); + // elif interpolation_type == 1:; + // return Gradients.gradient_type_2(x, points); + // elif interpolation_type == 2:; + // return Gradients.gradient_type_3(x, points); + // elif interpolation_type == 3:; + // return Gradients.gradient_type_4(x, points); + return Color(1, 1, 1, 1); +} + + + int GradientBase::get_interpolation_type() { + return interpolation_type; +} + + + void GradientBase::set_interpolation_type(const int val) { + interpolation_type = val; + set_dirty(true); +} + + + PoolRealArray GradientBase::get_points() { + return points; +} + + + void GradientBase::set_points(const PoolRealArray &val) { + points = val; + set_dirty(true); +} + + + float GradientBase::get_point_value(const int index) { + return points[index * 5]; +} + + + Color GradientBase::get_point_color(const int index) { + int indx = index * 5; + return Color(points[indx + 1], points[indx + 2], points[indx + 3], points[indx + 4]); +} + + + void GradientBase::add_point(const float val, const Color &color) { + int s = points.size(); + points.resize(s + 5); + points[s] = val; + points[s + 1] = color.r; + points[s + 2] = color.g; + points[s + 3] = color.b; + points[s + 4] = color.a; + set_dirty(true); +} + + + int GradientBase::get_point_count() { + return points.size() / 5; +} + + + void GradientBase::clear() { + points.resize(0); + set_dirty(true); +} + +} + + GradientBase::GradientBase() { + //#var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd"); + interpolation_type = 1; + points = PoolRealArray(); + } + + GradientBase::~GradientBase() { + } + + + static void GradientBase::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_interpolation_type"), &GradientBase::get_interpolation_type); + ClassDB::bind_method(D_METHOD("set_interpolation_type", "value"), &GradientBase::set_interpolation_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "interpolation_type"), "set_interpolation_type", "get_interpolation_type"); + + + ClassDB::bind_method(D_METHOD("get_points"), &GradientBase::get_points); + ClassDB::bind_method(D_METHOD("set_points", "value"), &GradientBase::set_points); + ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "points"), "set_points", "get_points"); + + + ClassDB::bind_method(D_METHOD("get_gradient_color", "x"), &GradientBase::get_gradient_color); + ClassDB::bind_method(D_METHOD("get_interpolation_type"), &GradientBase::get_interpolation_type); + ClassDB::bind_method(D_METHOD("set_interpolation_type", "val"), &GradientBase::set_interpolation_type); + ClassDB::bind_method(D_METHOD("get_points"), &GradientBase::get_points); + ClassDB::bind_method(D_METHOD("set_points", "val"), &GradientBase::set_points); + ClassDB::bind_method(D_METHOD("get_point_value", "index"), &GradientBase::get_point_value); + ClassDB::bind_method(D_METHOD("get_point_color", "index"), &GradientBase::get_point_color); + ClassDB::bind_method(D_METHOD("add_point", "val", "color"), &GradientBase::add_point); + ClassDB::bind_method(D_METHOD("get_point_count"), &GradientBase::get_point_count); + ClassDB::bind_method(D_METHOD("clear"), &GradientBase::clear); + + } + + + diff --git a/modules/material_maker/nodes/bases/gradient_base.h b/modules/material_maker/nodes/bases/gradient_base.h new file mode 100644 index 000000000..c55e41032 --- /dev/null +++ b/modules/material_maker/nodes/bases/gradient_base.h @@ -0,0 +1,43 @@ +#ifndef GRADIENT_BASE_H +#define GRADIENT_BASE_H + + +class GradientBase : public MMNode { + GDCLASS(GradientBase, MMNode); + + public: + + int get_interpolation_type() const; + void set_interpolation_type(const int val); + + PoolRealArray get_points(); + void set_points(const PoolRealArray &val); + + Color get_gradient_color(const float x); + int get_interpolation_type(); + void set_interpolation_type(const int val); + PoolRealArray get_points(); + void set_points(const PoolRealArray &val); + float get_point_value(const int index); + Color get_point_color(const int index); + void add_point(const float val, const Color &color); + int get_point_count(); + void clear(); + + GradientBase(); + ~GradientBase(); + + protected: + static void _bind_methods(); + + //tool + //var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd") + //export(int) + // setget set_interpolation_type, get_interpolation_type + int interpolation_type = 1; + //export(PoolRealArray) + PoolRealArray points = PoolRealArray(); +}; + + +#endif diff --git a/modules/material_maker/nodes/bases/polygon_base.cpp b/modules/material_maker/nodes/bases/polygon_base.cpp new file mode 100644 index 000000000..b57e7ecd8 --- /dev/null +++ b/modules/material_maker/nodes/bases/polygon_base.cpp @@ -0,0 +1,147 @@ + +#include "polygon_base.h" + + +PoolVector2Array PolygonBase::get_points() { + return points; +} + +void PolygonBase::set_points(const PoolVector2Array &val) { +points = val; +} + + + + //tool; + //export(PoolVector2Array) ; + PoolVector2Array points = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]; + + void PolygonBase::clear() { + points.resize(0); + _polygon_changed(); +} + + + void PolygonBase::add_point(const float x, const float y, const bool closed) { + Vector2 p = Vector2(x, y); + Variant = points.size(); + + if (points_count < 3) { + points.append(p); + _polygon_changed(); + return; +} + + float min_length = (p-Geometry.get_closest_point_to_segment_2d(p, points[0], points[points_count-1])).length(); + Variant = 0; + + for (i in points_count-1) { + Variant = (p - Geometry.get_closest_point_to_segment_2d(p, points[i], points[i+1])).length(); + + if (length < min_length) { + min_length = length; + insert_point = i+1; +} + +} + + + if (!closed && insert_point == 0 && (points[0]-p).length() > (points[points_count-1]-p).length()) { + insert_point = points_count; +} + + points.insert(insert_point, p); + _polygon_changed(); +} + + + bool PolygonBase::remove_point(const int index) { + Variant = points.size(); + + if (s < 4 || index < 0 || index >= s) { + return false; +} + + + else { + points.remove(index); + _polygon_changed(); +} + + return true; +} + + + int PolygonBase::get_point_count() { + return points.size(); +} + + + Vector2 PolygonBase::get_point(const int i) { + return points[i]; +} + + + void PolygonBase::set_point(const int i, const Vector2 &v) { + points[i] = v; + _polygon_changed(); +} + + + void PolygonBase::set_points(const PoolVector2Array &v) { + points = v; + _polygon_changed(); +} + + + void PolygonBase::polygon_changed() { + _polygon_changed(); +} + + + void PolygonBase::_polygon_changed() { + emit_changed(); +} + + + String PolygonBase::to_string() { + Variant = PoolStringArray(); + + for (p in points) { + rv.append("("+str(p.x)+","+str(p.y)+")"); +} + + return rv.join(","); +} + +} + + PolygonBase::PolygonBase() { + points = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]; + } + + PolygonBase::~PolygonBase() { + } + + + static void PolygonBase::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_points"), &PolygonBase::get_points); + ClassDB::bind_method(D_METHOD("set_points", "value"), &PolygonBase::set_points); + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points"); + + + ClassDB::bind_method(D_METHOD("clear"), &PolygonBase::clear); + ClassDB::bind_method(D_METHOD("add_point", "x", "y", "closed"), &PolygonBase::add_point, true); + ClassDB::bind_method(D_METHOD("remove_point", "index"), &PolygonBase::remove_point); + ClassDB::bind_method(D_METHOD("get_point_count"), &PolygonBase::get_point_count); + ClassDB::bind_method(D_METHOD("get_point", "i"), &PolygonBase::get_point); + ClassDB::bind_method(D_METHOD("set_point", "i", "v"), &PolygonBase::set_point); + ClassDB::bind_method(D_METHOD("set_points", "v"), &PolygonBase::set_points); + ClassDB::bind_method(D_METHOD("polygon_changed"), &PolygonBase::polygon_changed); + ClassDB::bind_method(D_METHOD("_polygon_changed"), &PolygonBase::_polygon_changed); + ClassDB::bind_method(D_METHOD("to_string"), &PolygonBase::to_string); + + } + + + diff --git a/modules/material_maker/nodes/bases/polygon_base.h b/modules/material_maker/nodes/bases/polygon_base.h new file mode 100644 index 000000000..6a1e7e56e --- /dev/null +++ b/modules/material_maker/nodes/bases/polygon_base.h @@ -0,0 +1,36 @@ +#ifndef POLYGON_BASE_H +#define POLYGON_BASE_H + + +class PolygonBase : public MMNode { + GDCLASS(PolygonBase, MMNode); + + public: + + PoolVector2Array get_points(); + void set_points(const PoolVector2Array &val); + + void clear(); + void add_point(const float x, const float y, const bool closed = true); + bool remove_point(const int index); + int get_point_count(); + Vector2 get_point(const int i); + void set_point(const int i, const Vector2 &v); + void set_points(const PoolVector2Array &v); + void polygon_changed(); + void _polygon_changed(); + String to_string(); + + PolygonBase(); + ~PolygonBase(); + + protected: + static void _bind_methods(); + + //tool + //export(PoolVector2Array) + PoolVector2Array points = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]; +}; + + +#endif