mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 04:46:48 +01:00
Updated navigation geometry parsers, and added them to the build.
This commit is contained in:
parent
de7d96cc6d
commit
b96e013bed
@ -10,7 +10,7 @@ env_navigation = env_modules.Clone()
|
||||
module_obj = []
|
||||
|
||||
env_navigation.add_source_files(module_obj, "*.cpp")
|
||||
#env_navigation.add_source_files(module_obj, "geometry_parser_2d/*.cpp")
|
||||
#env_navigation.add_source_files(module_obj, "geometry_parser_3d/*.cpp")
|
||||
env_navigation.add_source_files(module_obj, "geometry_parser_2d/*.cpp")
|
||||
env_navigation.add_source_files(module_obj, "geometry_parser_3d/*.cpp")
|
||||
|
||||
env.modules_sources += module_obj
|
||||
|
@ -1,5 +1,7 @@
|
||||
|
||||
def can_build(env, platform):
|
||||
env.module_add_dependencies("navigation_geometry_parsers", ["navigation_mesh_generator"], False)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class MeshInstance2DNavigationGeometryParser2D : public NavigationGeometryParser2D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node) ;
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) ;
|
||||
};
|
||||
|
||||
#endif // MESHINSTANCE2D_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class MultiMeshInstance2DNavigationGeometryParser2D : public NavigationGeometryParser2D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node) ;
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) ;
|
||||
};
|
||||
|
||||
#endif // MULTIMESHINSTANCE2D_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||
|
@ -32,6 +32,9 @@
|
||||
|
||||
#include "scene/2d/polygon_2d.h"
|
||||
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/navigation_polygon.h"
|
||||
|
||||
bool Polygon2DNavigationGeometryParser2D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<Polygon2D>(p_node) != nullptr);
|
||||
}
|
||||
@ -44,9 +47,10 @@ void Polygon2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<Navig
|
||||
|
||||
const Transform2D transform = polygon_2d->get_global_transform();
|
||||
|
||||
Vector<Vector2> shape_outline = polygon_2d->get_polygon();
|
||||
PoolVector<Vector2> shape_outline = polygon_2d->get_polygon();
|
||||
PoolVector<Vector2>::Write shape_outline_write = shape_outline.write();
|
||||
for (int i = 0; i < shape_outline.size(); i++) {
|
||||
shape_outline.write[i] = transform.xform(shape_outline[i]);
|
||||
shape_outline_write[i] = transform.xform(shape_outline[i]);
|
||||
}
|
||||
|
||||
p_source_geometry->add_obstruction_outline(shape_outline);
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class Polygon2DNavigationGeometryParser2D : public NavigationGeometryParser2D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node);
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry);
|
||||
};
|
||||
|
||||
#endif // POLYGON2D_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||
|
@ -40,6 +40,9 @@
|
||||
#include "scene/resources/rectangle_shape_2d.h"
|
||||
#include "scene/resources/shape_2d.h"
|
||||
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/navigation_polygon.h"
|
||||
|
||||
bool StaticBody2DNavigationGeometryParser2D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<StaticBody2D>(p_node) != nullptr);
|
||||
}
|
||||
@ -53,7 +56,10 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<Na
|
||||
if (static_body->get_collision_layer() & navigation_polygon_collision_mask) {
|
||||
List<uint32_t> shape_owners;
|
||||
static_body->get_shape_owners(&shape_owners);
|
||||
for (uint32_t shape_owner : shape_owners) {
|
||||
|
||||
for (List<uint32_t>::Element *E = shape_owners.front(); E; E = E->next()) {
|
||||
uint32_t shape_owner = E->get();
|
||||
|
||||
if (static_body->is_shape_owner_disabled(shape_owner)) {
|
||||
continue;
|
||||
}
|
||||
@ -69,16 +75,17 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<Na
|
||||
|
||||
RectangleShape2D *rectangle_shape = Object::cast_to<RectangleShape2D>(*s);
|
||||
if (rectangle_shape) {
|
||||
Vector<Vector2> shape_outline;
|
||||
PoolVector<Vector2> shape_outline;
|
||||
|
||||
const Vector2 &rectangle_size = rectangle_shape->get_size();
|
||||
const Vector2 rectangle_size = rectangle_shape->get_extents();
|
||||
|
||||
shape_outline.resize(5);
|
||||
shape_outline.write[0] = transform.xform(-rectangle_size * 0.5);
|
||||
shape_outline.write[1] = transform.xform(Vector2(rectangle_size.x, -rectangle_size.y) * 0.5);
|
||||
shape_outline.write[2] = transform.xform(rectangle_size * 0.5);
|
||||
shape_outline.write[3] = transform.xform(Vector2(-rectangle_size.x, rectangle_size.y) * 0.5);
|
||||
shape_outline.write[4] = transform.xform(-rectangle_size * 0.5);
|
||||
PoolVector<Vector2>::Write shape_outline_write = shape_outline.write();
|
||||
shape_outline_write[0] = transform.xform(-rectangle_size * 0.5);
|
||||
shape_outline_write[1] = transform.xform(Vector2(rectangle_size.x, -rectangle_size.y) * 0.5);
|
||||
shape_outline_write[2] = transform.xform(rectangle_size * 0.5);
|
||||
shape_outline_write[3] = transform.xform(Vector2(-rectangle_size.x, rectangle_size.y) * 0.5);
|
||||
shape_outline_write[4] = transform.xform(-rectangle_size * 0.5);
|
||||
|
||||
p_source_geometry->add_obstruction_outline(shape_outline);
|
||||
}
|
||||
@ -93,13 +100,14 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<Na
|
||||
|
||||
CircleShape2D *circle_shape = Object::cast_to<CircleShape2D>(*s);
|
||||
if (circle_shape) {
|
||||
Vector<Vector2> shape_outline;
|
||||
PoolVector<Vector2> shape_outline;
|
||||
int circle_edge_count = 12;
|
||||
shape_outline.resize(circle_edge_count);
|
||||
PoolVector<Vector2>::Write shape_outline_write = shape_outline.write();
|
||||
|
||||
const real_t turn_step = Math_TAU / real_t(circle_edge_count);
|
||||
for (int i = 0; i < circle_edge_count; i++) {
|
||||
shape_outline.write[i] = transform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_shape->get_radius());
|
||||
shape_outline_write[i] = transform.xform(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * circle_shape->get_radius());
|
||||
}
|
||||
|
||||
p_source_geometry->add_obstruction_outline(shape_outline);
|
||||
@ -107,10 +115,11 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<Na
|
||||
|
||||
ConcavePolygonShape2D *concave_polygon_shape = Object::cast_to<ConcavePolygonShape2D>(*s);
|
||||
if (concave_polygon_shape) {
|
||||
Vector<Vector2> shape_outline = concave_polygon_shape->get_segments();
|
||||
PoolVector<Vector2> shape_outline = concave_polygon_shape->get_segments();
|
||||
PoolVector<Vector2>::Write shape_outline_write = shape_outline.write();
|
||||
|
||||
for (int i = 0; i < shape_outline.size(); i++) {
|
||||
shape_outline.write[i] = transform.xform(shape_outline[i]);
|
||||
shape_outline_write[i] = transform.xform(shape_outline[i]);
|
||||
}
|
||||
|
||||
p_source_geometry->add_obstruction_outline(shape_outline);
|
||||
@ -118,10 +127,14 @@ void StaticBody2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<Na
|
||||
|
||||
ConvexPolygonShape2D *convex_polygon_shape = Object::cast_to<ConvexPolygonShape2D>(*s);
|
||||
if (convex_polygon_shape) {
|
||||
Vector<Vector2> shape_outline = convex_polygon_shape->get_points();
|
||||
Vector<Vector2> shape_outlinev = convex_polygon_shape->get_points();
|
||||
|
||||
PoolVector<Vector2> shape_outline;
|
||||
shape_outline.resize(shape_outlinev.size());
|
||||
PoolVector<Vector2>::Write shape_outline_write = shape_outline.write();
|
||||
|
||||
for (int i = 0; i < shape_outline.size(); i++) {
|
||||
shape_outline.write[i] = transform.xform(shape_outline[i]);
|
||||
shape_outline_write[i] = transform.xform(shape_outlinev[i]);
|
||||
}
|
||||
|
||||
p_source_geometry->add_obstruction_outline(shape_outline);
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class StaticBody2DNavigationGeometryParser2D : public NavigationGeometryParser2D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node);
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry);
|
||||
};
|
||||
|
||||
#endif // STATICBODY2D_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||
|
@ -30,14 +30,18 @@
|
||||
|
||||
#include "tilemap_navigation_geometry_parser_2d.h"
|
||||
|
||||
#include "scene/2d/tile_map.h"
|
||||
//#include "scene/2d/tile_map.h"
|
||||
|
||||
#include "scene/resources/navigation_polygon.h"
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_2d.h"
|
||||
|
||||
#ifdef CLIPPER_ENABLED
|
||||
#include "thirdparty/clipper2/include/clipper2/clipper.h"
|
||||
#endif // CLIPPER_ENABLED
|
||||
|
||||
bool TileMap2DNavigationGeometryParser2D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<TileMap>(p_node) != nullptr);
|
||||
//return (Object::cast_to<TileMap>(p_node) != nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
void TileMap2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) {
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class TileMap2DNavigationGeometryParser2D : public NavigationGeometryParser2D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node);
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry);
|
||||
};
|
||||
|
||||
#endif // TILEMAP_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||
|
@ -30,17 +30,20 @@
|
||||
|
||||
#include "meshinstance3d_navigation_geometry_parser_3d.h"
|
||||
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/resources/navigation_mesh.h"
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_3d.h"
|
||||
|
||||
bool MeshInstance3DNavigationGeometryParser3D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<MeshInstance3D>(p_node) != nullptr);
|
||||
return (Object::cast_to<MeshInstance>(p_node) != nullptr);
|
||||
}
|
||||
|
||||
void MeshInstance3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) {
|
||||
NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type();
|
||||
|
||||
if (Object::cast_to<MeshInstance3D>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
|
||||
MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(p_node);
|
||||
if (Object::cast_to<MeshInstance>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
|
||||
MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(p_node);
|
||||
Ref<Mesh> mesh = mesh_instance->get_mesh();
|
||||
if (mesh.is_valid()) {
|
||||
p_source_geometry->add_mesh(mesh, mesh_instance->get_global_transform());
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class MeshInstance3DNavigationGeometryParser3D : public NavigationGeometryParser3D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node);
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry);
|
||||
};
|
||||
|
||||
#endif // MESHINSTANCE3D_NAVIGATION_GEOMETRY_PARSER_3D_H
|
||||
|
@ -30,17 +30,21 @@
|
||||
|
||||
#include "multimeshinstance3d_navigation_geometry_parser_3d.h"
|
||||
|
||||
#include "scene/3d/multimesh_instance_3d.h"
|
||||
#include "scene/3d/multimesh_instance.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/resources/multimesh.h"
|
||||
#include "scene/resources/navigation_mesh.h"
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_3d.h"
|
||||
|
||||
bool MultiMeshInstance3DNavigationGeometryParser3D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<MultiMeshInstance3D>(p_node) != nullptr);
|
||||
return (Object::cast_to<MultiMeshInstance>(p_node) != nullptr);
|
||||
}
|
||||
|
||||
void MultiMeshInstance3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) {
|
||||
NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type();
|
||||
|
||||
if (Object::cast_to<MultiMeshInstance3D>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
|
||||
MultiMeshInstance3D *multimesh_instance = Object::cast_to<MultiMeshInstance3D>(p_node);
|
||||
if (Object::cast_to<MultiMeshInstance>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
|
||||
MultiMeshInstance *multimesh_instance = Object::cast_to<MultiMeshInstance>(p_node);
|
||||
Ref<MultiMesh> multimesh = multimesh_instance->get_multimesh();
|
||||
if (multimesh.is_valid()) {
|
||||
Ref<Mesh> mesh = multimesh->get_mesh();
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class MultiMeshInstance3DNavigationGeometryParser3D : public NavigationGeometryParser3D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node);
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry);
|
||||
};
|
||||
|
||||
#endif // MULTIMESHINSTANCE3D_NAVIGATION_GEOMETRY_PARSER_3D_H
|
||||
|
@ -31,54 +31,61 @@
|
||||
#include "staticbody3d_navigation_geometry_parser_3d.h"
|
||||
|
||||
#include "core/math/convex_hull.h"
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/3d/physics_body_3d.h"
|
||||
#include "scene/resources/box_shape_3d.h"
|
||||
#include "scene/resources/capsule_shape_3d.h"
|
||||
#include "scene/resources/concave_polygon_shape_3d.h"
|
||||
#include "scene/resources/convex_polygon_shape_3d.h"
|
||||
#include "scene/resources/cylinder_shape_3d.h"
|
||||
#include "scene/resources/height_map_shape_3d.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/3d/physics_body.h"
|
||||
#include "scene/resources/box_shape.h"
|
||||
#include "scene/resources/capsule_shape.h"
|
||||
#include "scene/resources/concave_polygon_shape.h"
|
||||
#include "scene/resources/convex_polygon_shape.h"
|
||||
#include "scene/resources/cylinder_shape.h"
|
||||
#include "scene/resources/height_map_shape.h"
|
||||
#include "scene/resources/plane_shape.h"
|
||||
#include "scene/resources/primitive_meshes.h"
|
||||
#include "scene/resources/shape_3d.h"
|
||||
#include "scene/resources/sphere_shape_3d.h"
|
||||
#include "scene/resources/world_boundary_shape_3d.h"
|
||||
#include "scene/resources/shape.h"
|
||||
#include "scene/resources/sphere_shape.h"
|
||||
|
||||
#include "scene/resources/navigation_mesh.h"
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_3d.h"
|
||||
|
||||
bool StaticBody3DNavigationGeometryParser3D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<StaticBody3D>(p_node) != nullptr);
|
||||
return (Object::cast_to<StaticBody>(p_node) != nullptr);
|
||||
}
|
||||
|
||||
void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) {
|
||||
NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type();
|
||||
uint32_t navigationmesh_collision_mask = p_navigationmesh->get_collision_mask();
|
||||
|
||||
if (Object::cast_to<StaticBody3D>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) {
|
||||
StaticBody3D *static_body = Object::cast_to<StaticBody3D>(p_node);
|
||||
if (Object::cast_to<StaticBody>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES) {
|
||||
StaticBody *static_body = Object::cast_to<StaticBody>(p_node);
|
||||
if (static_body->get_collision_layer() & navigationmesh_collision_mask) {
|
||||
List<uint32_t> shape_owners;
|
||||
static_body->get_shape_owners(&shape_owners);
|
||||
for (uint32_t shape_owner : shape_owners) {
|
||||
|
||||
for (List<uint32_t>::Element *E = shape_owners.front(); E; E = E->next()) {
|
||||
uint32_t shape_owner = E->get();
|
||||
|
||||
if (static_body->is_shape_owner_disabled(shape_owner)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int shape_count = static_body->shape_owner_get_shape_count(shape_owner);
|
||||
for (int shape_index = 0; shape_index < shape_count; shape_index++) {
|
||||
Ref<Shape3D> s = static_body->shape_owner_get_shape(shape_owner, shape_index);
|
||||
Ref<Shape> s = static_body->shape_owner_get_shape(shape_owner, shape_index);
|
||||
if (s.is_null()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Transform3D transform = static_body->get_global_transform() * static_body->shape_owner_get_transform(shape_owner);
|
||||
const Transform transform = static_body->get_global_transform() * static_body->shape_owner_get_transform(shape_owner);
|
||||
|
||||
BoxShape3D *box = Object::cast_to<BoxShape3D>(*s);
|
||||
BoxShape *box = Object::cast_to<BoxShape>(*s);
|
||||
if (box) {
|
||||
Array arr;
|
||||
arr.resize(RS::ARRAY_MAX);
|
||||
BoxMesh::create_mesh_array(arr, box->get_size());
|
||||
CubeMesh::create_mesh_array(arr, box->get_extents());
|
||||
p_source_geometry->add_mesh_array(arr, transform);
|
||||
}
|
||||
|
||||
CapsuleShape3D *capsule = Object::cast_to<CapsuleShape3D>(*s);
|
||||
CapsuleShape *capsule = Object::cast_to<CapsuleShape>(*s);
|
||||
if (capsule) {
|
||||
Array arr;
|
||||
arr.resize(RS::ARRAY_MAX);
|
||||
@ -86,7 +93,7 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<Na
|
||||
p_source_geometry->add_mesh_array(arr, transform);
|
||||
}
|
||||
|
||||
CylinderShape3D *cylinder = Object::cast_to<CylinderShape3D>(*s);
|
||||
CylinderShape *cylinder = Object::cast_to<CylinderShape>(*s);
|
||||
if (cylinder) {
|
||||
Array arr;
|
||||
arr.resize(RS::ARRAY_MAX);
|
||||
@ -94,7 +101,7 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<Na
|
||||
p_source_geometry->add_mesh_array(arr, transform);
|
||||
}
|
||||
|
||||
SphereShape3D *sphere = Object::cast_to<SphereShape3D>(*s);
|
||||
SphereShape *sphere = Object::cast_to<SphereShape>(*s);
|
||||
if (sphere) {
|
||||
Array arr;
|
||||
arr.resize(RS::ARRAY_MAX);
|
||||
@ -102,23 +109,25 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<Na
|
||||
p_source_geometry->add_mesh_array(arr, transform);
|
||||
}
|
||||
|
||||
ConcavePolygonShape3D *concave_polygon = Object::cast_to<ConcavePolygonShape3D>(*s);
|
||||
ConcavePolygonShape *concave_polygon = Object::cast_to<ConcavePolygonShape>(*s);
|
||||
if (concave_polygon) {
|
||||
p_source_geometry->add_faces(concave_polygon->get_faces(), transform);
|
||||
}
|
||||
|
||||
ConvexPolygonShape3D *convex_polygon = Object::cast_to<ConvexPolygonShape3D>(*s);
|
||||
ConvexPolygonShape *convex_polygon = Object::cast_to<ConvexPolygonShape>(*s);
|
||||
if (convex_polygon) {
|
||||
Vector<Vector3> varr = Variant(convex_polygon->get_points());
|
||||
Geometry3D::MeshData md;
|
||||
Geometry::MeshData md;
|
||||
|
||||
Error err = ConvexHullComputer::convex_hull(varr, md);
|
||||
|
||||
if (err == OK) {
|
||||
PackedVector3Array faces;
|
||||
PoolVector3Array faces;
|
||||
|
||||
for (const Geometry3D::MeshData::Face &face : md.faces) {
|
||||
for (uint32_t k = 2; k < face.indices.size(); ++k) {
|
||||
for (int i = 0; i < md.faces.size(); ++i) {
|
||||
const Geometry::MeshData::Face &face = md.faces[i];
|
||||
|
||||
for (int k = 2; k < face.indices.size(); ++k) {
|
||||
faces.push_back(md.vertices[face.indices[0]]);
|
||||
faces.push_back(md.vertices[face.indices[k - 1]]);
|
||||
faces.push_back(md.vertices[face.indices[k]]);
|
||||
@ -129,18 +138,18 @@ void StaticBody3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<Na
|
||||
}
|
||||
}
|
||||
|
||||
HeightMapShape3D *heightmap_shape = Object::cast_to<HeightMapShape3D>(*s);
|
||||
HeightMapShape *heightmap_shape = Object::cast_to<HeightMapShape>(*s);
|
||||
if (heightmap_shape) {
|
||||
int heightmap_depth = heightmap_shape->get_map_depth();
|
||||
int heightmap_width = heightmap_shape->get_map_width();
|
||||
|
||||
if (heightmap_depth >= 2 && heightmap_width >= 2) {
|
||||
const Vector<real_t> &map_data = heightmap_shape->get_map_data();
|
||||
const PoolVector<real_t> &map_data = heightmap_shape->get_map_data();
|
||||
|
||||
Vector2 heightmap_gridsize(heightmap_width - 1, heightmap_depth - 1);
|
||||
Vector2 start = heightmap_gridsize * -0.5;
|
||||
|
||||
Vector<Vector3> vertex_array;
|
||||
PoolVector<Vector3> vertex_array;
|
||||
vertex_array.resize((heightmap_depth - 1) * (heightmap_width - 1) * 6);
|
||||
int map_data_current_index = 0;
|
||||
|
||||
|
@ -35,9 +35,9 @@
|
||||
|
||||
class StaticBody3DNavigationGeometryParser3D : public NavigationGeometryParser3D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
virtual bool parses_node(Node *p_node) ;
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) override;
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) ;
|
||||
};
|
||||
|
||||
#endif // STATICBODY3D_NAVIGATION_GEOMETRY_PARSER_3D_H
|
||||
|
@ -32,8 +32,31 @@
|
||||
|
||||
#include "core/config/engine.h"
|
||||
|
||||
#include "servers/navigation/navigation_mesh_generator.h"
|
||||
|
||||
#include "geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h"
|
||||
#include "geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h"
|
||||
#include "geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h"
|
||||
#include "geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h"
|
||||
#include "geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h"
|
||||
#ifndef _3D_DISABLED
|
||||
#include "geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h"
|
||||
#include "geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h"
|
||||
#include "geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h"
|
||||
#endif // _3D_DISABLED
|
||||
|
||||
void register_navigation_geometry_parsers_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(MeshInstance2DNavigationGeometryParser2D));
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(MultiMeshInstance2DNavigationGeometryParser2D));
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(Polygon2DNavigationGeometryParser2D));
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(StaticBody2DNavigationGeometryParser2D));
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(TileMap2DNavigationGeometryParser2D));
|
||||
#ifndef _3D_DISABLED
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MeshInstance3DNavigationGeometryParser3D));
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MultiMeshInstance3DNavigationGeometryParser3D));
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(StaticBody3DNavigationGeometryParser3D));
|
||||
#endif // _3D_DISABLED
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,22 +40,8 @@
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_2d.h"
|
||||
#include "scene/resources/navigation_mesh_source_geometry_data_3d.h"
|
||||
|
||||
/*
|
||||
#include "servers/navigation/geometry_parser_2d/meshinstance2d_navigation_geometry_parser_2d.h"
|
||||
#include "servers/navigation/geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h"
|
||||
#include "servers/navigation/geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h"
|
||||
#include "servers/navigation/geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h"
|
||||
#include "servers/navigation/geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h"
|
||||
*/
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
|
||||
/*
|
||||
#include "servers/navigation/geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h"
|
||||
#include "servers/navigation/geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h"
|
||||
#include "servers/navigation/geometry_parser_3d/staticbody3d_navigation_geometry_parser_3d.h"
|
||||
*/
|
||||
#endif // _3D_DISABLED
|
||||
|
||||
#ifdef CLIPPER_ENABLED
|
||||
|
Loading…
Reference in New Issue
Block a user