diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/resource_importer.cpp | 5 | ||||
-rw-r--r-- | core/io/resource_importer.h | 1 | ||||
-rw-r--r-- | core/math/geometry.cpp | 35 | ||||
-rw-r--r-- | core/math/geometry.h | 2 | ||||
-rw-r--r-- | core/object.cpp | 25 |
5 files changed, 55 insertions, 13 deletions
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 69907a710a..b5fa412576 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -183,6 +183,11 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_ } } +bool ResourceFormatImporter::exists(const String &p_path) const { + + return FileAccess::exists(p_path + ".import"); +} + bool ResourceFormatImporter::recognize_path(const String &p_path, const String &p_for_type) const { return FileAccess::exists(p_path + ".import"); diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index ca40b47b85..1c146c33d7 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -69,6 +69,7 @@ public: virtual bool is_import_valid(const String &p_path) const; virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); virtual bool is_imported(const String &p_path) const { return recognize_path(p_path); } + virtual bool exists(const String &p_path) const; virtual bool can_be_imported(const String &p_path) const; virtual int get_import_order(const String &p_path) const; diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 12c88f43b3..194a6f6352 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -31,6 +31,7 @@ #include "geometry.h" #include "core/print_string.h" +#include "thirdparty/misc/triangulator.h" /* this implementation is very inefficient, commenting unless bugs happen. See the other one. bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) { @@ -737,6 +738,40 @@ PoolVector<Face3> Geometry::wrap_geometry(PoolVector<Face3> p_array, real_t *p_e return wrapped_faces; } +Vector<Vector<Vector2> > Geometry::decompose_polygon_in_convex(Vector<Point2> polygon) { + Vector<Vector<Vector2> > decomp; + List<TriangulatorPoly> in_poly, out_poly; + + TriangulatorPoly inp; + inp.Init(polygon.size()); + for (int i = 0; i < polygon.size(); i++) { + inp.GetPoint(i) = polygon[i]; + } + inp.SetOrientation(TRIANGULATOR_CCW); + in_poly.push_back(inp); + TriangulatorPartition tpart; + if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { //failed! + ERR_PRINT("Convex decomposing failed!"); + return decomp; + } + + decomp.resize(out_poly.size()); + int idx = 0; + for (List<TriangulatorPoly>::Element *I = out_poly.front(); I; I = I->next()) { + TriangulatorPoly &tp = I->get(); + + decomp.write[idx].resize(tp.GetNumPoints()); + + for (int i = 0; i < tp.GetNumPoints(); i++) { + decomp.write[idx].write[i] = tp.GetPoint(i); + } + + idx++; + } + + return decomp; +} + Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes) { MeshData mesh; diff --git a/core/math/geometry.h b/core/math/geometry.h index f927a63ed5..4b478b6b16 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -950,6 +950,8 @@ public: return H; } + static Vector<Vector<Vector2> > decompose_polygon_in_convex(Vector<Point2> polygon); + static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes); static PoolVector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis = Vector3::AXIS_Z); static PoolVector<Plane> build_box_planes(const Vector3 &p_extents); diff --git a/core/object.cpp b/core/object.cpp index c46ecc5193..8b693f039c 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -832,23 +832,22 @@ void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) } Variant Object::callv(const StringName &p_method, const Array &p_args) { + const Variant **argptrs = NULL; - if (p_args.size() == 0) { - return call(p_method); - } - - Vector<Variant> args; - args.resize(p_args.size()); - Vector<const Variant *> argptrs; - argptrs.resize(p_args.size()); - - for (int i = 0; i < p_args.size(); i++) { - args.write[i] = p_args[i]; - argptrs.write[i] = &args[i]; + if (p_args.size() > 0) { + argptrs = (const Variant **)alloca(sizeof(Variant *) * p_args.size()); + for (int i = 0; i < p_args.size(); i++) { + argptrs[i] = &p_args[i]; + } } Variant::CallError ce; - return call(p_method, (const Variant **)argptrs.ptr(), p_args.size(), ce); + Variant ret = call(p_method, argptrs, p_args.size(), ce); + if (ce.error != Variant::CallError::CALL_OK) { + ERR_EXPLAIN("Error calling method from 'callv': " + Variant::get_call_error_text(this, p_method, argptrs, p_args.size(), ce)); + ERR_FAIL_V(Variant()); + } + return ret; } Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { |