Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NavigationMeshSourceGeometryData append functions #90935

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/classes/NavigationMeshSourceGeometryData2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
Adds the outline points of a shape as traversable area.
</description>
</method>
<method name="append_obstruction_outlines">
<return type="void" />
<param index="0" name="obstruction_outlines" type="PackedVector2Array[]" />
<description>
Appends another array of [param obstruction_outlines] at the end of the existing obstruction outlines array.
</description>
</method>
<method name="append_traversable_outlines">
<return type="void" />
<param index="0" name="traversable_outlines" type="PackedVector2Array[]" />
<description>
Appends another array of [param traversable_outlines] at the end of the existing traversable outlines array.
</description>
</method>
<method name="clear">
<return type="void" />
<description>
Expand Down
8 changes: 8 additions & 0 deletions doc/classes/NavigationMeshSourceGeometryData3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
Adds a projected obstruction shape to the source geometry. The [param vertices] are considered projected on a xz-axes plane, placed at the global y-axis [param elevation] and extruded by [param height]. If [param carve] is [code]true[/code] the carved shape will not be affected by additional offsets (e.g. agent radius) of the navigation mesh baking process.
</description>
</method>
<method name="append_arrays">
<return type="void" />
<param index="0" name="vertices" type="PackedFloat32Array" />
<param index="1" name="indices" type="PackedInt32Array" />
<description>
Appends arrays of [param vertices] and [param indices] at the end of the existing arrays. Adds the existing index as an offset to the appended indices.
</description>
</method>
<method name="clear">
<return type="void" />
<description>
Expand Down
21 changes: 21 additions & 0 deletions scene/resources/2d/navigation_mesh_source_geometry_data_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ TypedArray<Vector<Vector2>> NavigationMeshSourceGeometryData2D::get_obstruction_
return typed_array_obstruction_outlines;
}

void NavigationMeshSourceGeometryData2D::append_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines) {
RWLockWrite write_lock(geometry_rwlock);
int traversable_outlines_size = traversable_outlines.size();
traversable_outlines.resize(traversable_outlines_size + p_traversable_outlines.size());
for (int i = traversable_outlines_size; i < p_traversable_outlines.size(); i++) {
traversable_outlines.write[i] = p_traversable_outlines[i];
}
}

void NavigationMeshSourceGeometryData2D::append_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines) {
smix8 marked this conversation as resolved.
Show resolved Hide resolved
RWLockWrite write_lock(geometry_rwlock);
int obstruction_outlines_size = obstruction_outlines.size();
obstruction_outlines.resize(obstruction_outlines_size + p_obstruction_outlines.size());
for (int i = obstruction_outlines_size; i < p_obstruction_outlines.size(); i++) {
obstruction_outlines.write[i] = p_obstruction_outlines[i];
}
}

void NavigationMeshSourceGeometryData2D::add_traversable_outline(const PackedVector2Array &p_shape_outline) {
if (p_shape_outline.size() > 1) {
Vector<Vector2> traversable_outline;
Expand Down Expand Up @@ -240,6 +258,9 @@ void NavigationMeshSourceGeometryData2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_obstruction_outlines", "obstruction_outlines"), &NavigationMeshSourceGeometryData2D::set_obstruction_outlines);
ClassDB::bind_method(D_METHOD("get_obstruction_outlines"), &NavigationMeshSourceGeometryData2D::get_obstruction_outlines);

ClassDB::bind_method(D_METHOD("append_traversable_outlines", "traversable_outlines"), &NavigationMeshSourceGeometryData2D::append_traversable_outlines);
ClassDB::bind_method(D_METHOD("append_obstruction_outlines", "obstruction_outlines"), &NavigationMeshSourceGeometryData2D::append_obstruction_outlines);

ClassDB::bind_method(D_METHOD("add_traversable_outline", "shape_outline"), &NavigationMeshSourceGeometryData2D::add_traversable_outline);
ClassDB::bind_method(D_METHOD("add_obstruction_outline", "shape_outline"), &NavigationMeshSourceGeometryData2D::add_obstruction_outline);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class NavigationMeshSourceGeometryData2D : public Resource {
void set_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);
TypedArray<Vector<Vector2>> get_obstruction_outlines() const;

void append_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);
void append_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);

void add_traversable_outline(const PackedVector2Array &p_shape_outline);
void add_obstruction_outline(const PackedVector2Array &p_shape_outline);

Expand Down
26 changes: 18 additions & 8 deletions scene/resources/3d/navigation_mesh_source_geometry_data_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,24 @@ void NavigationMeshSourceGeometryData3D::set_vertices(const Vector<float> &p_ver
}

void NavigationMeshSourceGeometryData3D::set_indices(const Vector<int> &p_indices) {
ERR_FAIL_COND(vertices.size() < p_indices.size());
indices = p_indices;
}

void NavigationMeshSourceGeometryData3D::append_arrays(const Vector<float> &p_vertices, const Vector<int> &p_indices) {
RWLockWrite write_lock(geometry_rwlock);

const int64_t number_of_vertices_before_merge = vertices.size();
const int64_t number_of_indices_before_merge = indices.size();

vertices.append_array(p_vertices);
indices.append_array(p_indices);

for (int64_t i = number_of_indices_before_merge; i < indices.size(); i++) {
indices.set(i, indices[i] + number_of_vertices_before_merge / 3);
}
}

void NavigationMeshSourceGeometryData3D::clear() {
vertices.clear();
indices.clear();
Expand Down Expand Up @@ -174,14 +189,7 @@ void NavigationMeshSourceGeometryData3D::add_faces(const PackedVector3Array &p_f
void NavigationMeshSourceGeometryData3D::merge(const Ref<NavigationMeshSourceGeometryData3D> &p_other_geometry) {
ERR_FAIL_NULL(p_other_geometry);

// No need to worry about `root_node_transform` here as the vertices are already xformed.
const int64_t number_of_vertices_before_merge = vertices.size();
const int64_t number_of_indices_before_merge = indices.size();
vertices.append_array(p_other_geometry->vertices);
indices.append_array(p_other_geometry->indices);
for (int64_t i = number_of_indices_before_merge; i < indices.size(); i++) {
indices.set(i, indices[i] + number_of_vertices_before_merge / 3);
}
append_arrays(p_other_geometry->vertices, p_other_geometry->indices);

if (p_other_geometry->_projected_obstructions.size() > 0) {
RWLockWrite write_lock(geometry_rwlock);
Expand Down Expand Up @@ -306,6 +314,8 @@ void NavigationMeshSourceGeometryData3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_indices", "indices"), &NavigationMeshSourceGeometryData3D::set_indices);
ClassDB::bind_method(D_METHOD("get_indices"), &NavigationMeshSourceGeometryData3D::get_indices);

ClassDB::bind_method(D_METHOD("append_arrays", "vertices", "indices"), &NavigationMeshSourceGeometryData3D::append_arrays);

ClassDB::bind_method(D_METHOD("clear"), &NavigationMeshSourceGeometryData3D::clear);
ClassDB::bind_method(D_METHOD("has_data"), &NavigationMeshSourceGeometryData3D::has_data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class NavigationMeshSourceGeometryData3D : public Resource {
void set_indices(const Vector<int> &p_indices);
const Vector<int> &get_indices() const { return indices; }

void append_arrays(const Vector<float> &p_vertices, const Vector<int> &p_indices);

bool has_data() { return vertices.size() && indices.size(); };
void clear();
void clear_projected_obstructions();
Expand Down
Loading