Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/3d/navigation_mesh_source_geometry_data_3d.h
9898 views
1
/**************************************************************************/
2
/* navigation_mesh_source_geometry_data_3d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/os/rw_lock.h"
34
#include "scene/resources/mesh.h"
35
36
class NavigationMeshSourceGeometryData3D : public Resource {
37
GDCLASS(NavigationMeshSourceGeometryData3D, Resource);
38
RWLock geometry_rwlock;
39
40
Vector<float> vertices;
41
Vector<int> indices;
42
43
AABB bounds;
44
bool bounds_dirty = true;
45
46
public:
47
struct ProjectedObstruction;
48
49
private:
50
Vector<ProjectedObstruction> _projected_obstructions;
51
52
protected:
53
bool _set(const StringName &p_name, const Variant &p_value);
54
bool _get(const StringName &p_name, Variant &r_ret) const;
55
static void _bind_methods();
56
57
private:
58
void _add_vertex(const Vector3 &p_vec3);
59
void _add_mesh(const Ref<Mesh> &p_mesh, const Transform3D &p_xform);
60
void _add_mesh_array(const Array &p_array, const Transform3D &p_xform);
61
void _add_faces(const PackedVector3Array &p_faces, const Transform3D &p_xform);
62
63
public:
64
struct ProjectedObstruction {
65
static inline uint32_t VERSION = 1; // Increase when format changes so we can detect outdated formats and provide compatibility.
66
67
Vector<float> vertices;
68
float elevation = 0.0;
69
float height = 0.0;
70
bool carve = false;
71
};
72
73
// kept root node transform here on the geometry data
74
// if we add this transform to all exposed functions we need to break comp on all functions later
75
// when navmesh changes from global transform to relative to navregion
76
// but if it stays here we can just remove it and change the internal functions only
77
Transform3D root_node_transform;
78
79
void set_vertices(const Vector<float> &p_vertices);
80
const Vector<float> &get_vertices() const;
81
82
void set_indices(const Vector<int> &p_indices);
83
const Vector<int> &get_indices() const;
84
85
void append_arrays(const Vector<float> &p_vertices, const Vector<int> &p_indices);
86
87
bool has_data();
88
void clear();
89
void clear_projected_obstructions();
90
91
void add_mesh(const Ref<Mesh> &p_mesh, const Transform3D &p_xform);
92
void add_mesh_array(const Array &p_mesh_array, const Transform3D &p_xform);
93
void add_faces(const PackedVector3Array &p_faces, const Transform3D &p_xform);
94
95
void merge(const Ref<NavigationMeshSourceGeometryData3D> &p_other_geometry);
96
97
void add_projected_obstruction(const Vector<Vector3> &p_vertices, float p_elevation, float p_height, bool p_carve);
98
Vector<ProjectedObstruction> _get_projected_obstructions() const;
99
100
void set_projected_obstructions(const Array &p_array);
101
Array get_projected_obstructions() const;
102
103
void set_data(const Vector<float> &p_vertices, const Vector<int> &p_indices, Vector<ProjectedObstruction> &p_projected_obstructions);
104
void get_data(Vector<float> &r_vertices, Vector<int> &r_indices, Vector<ProjectedObstruction> &r_projected_obstructions);
105
106
AABB get_bounds();
107
108
~NavigationMeshSourceGeometryData3D() { clear(); }
109
};
110
111