Path: blob/master/scene/resources/2d/navigation_mesh_source_geometry_data_2d.h
9898 views
/**************************************************************************/1/* navigation_mesh_source_geometry_data_2d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/io/resource.h"33#include "core/os/rw_lock.h"3435class NavigationMeshSourceGeometryData2D : public Resource {36friend class NavMeshGenerator2D;3738GDCLASS(NavigationMeshSourceGeometryData2D, Resource);39RWLock geometry_rwlock;4041Vector<Vector<Vector2>> traversable_outlines;42Vector<Vector<Vector2>> obstruction_outlines;4344Rect2 bounds;45bool bounds_dirty = true;4647public:48struct ProjectedObstruction;4950private:51Vector<ProjectedObstruction> _projected_obstructions;5253protected:54bool _set(const StringName &p_name, const Variant &p_value);55bool _get(const StringName &p_name, Variant &r_ret) const;56static void _bind_methods();5758public:59struct ProjectedObstruction {60static inline uint32_t VERSION = 1; // Increase when format changes so we can detect outdated formats and provide compatibility.6162Vector<float> vertices;63bool carve = false;64};6566void _set_traversable_outlines(const Vector<Vector<Vector2>> &p_traversable_outlines);67const Vector<Vector<Vector2>> &_get_traversable_outlines() const;6869void _set_obstruction_outlines(const Vector<Vector<Vector2>> &p_obstruction_outlines);70const Vector<Vector<Vector2>> &_get_obstruction_outlines() const;7172void _add_traversable_outline(const Vector<Vector2> &p_shape_outline);73void _add_obstruction_outline(const Vector<Vector2> &p_shape_outline);7475// kept root node transform here on the geometry data76// if we add this transform to all exposed functions we need to break comp on all functions later77// when navmesh changes from global transform to relative to navregion78// but if it stays here we can just remove it and change the internal functions only79Transform2D root_node_transform;8081void set_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);82TypedArray<Vector<Vector2>> get_traversable_outlines() const;8384void set_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);85TypedArray<Vector<Vector2>> get_obstruction_outlines() const;8687void append_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);88void append_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);8990void add_traversable_outline(const PackedVector2Array &p_shape_outline);91void add_obstruction_outline(const PackedVector2Array &p_shape_outline);9293bool has_data();94void clear();95void clear_projected_obstructions();9697void add_projected_obstruction(const Vector<Vector2> &p_vertices, bool p_carve);98Vector<ProjectedObstruction> _get_projected_obstructions() const;99100void set_projected_obstructions(const Array &p_array);101Array get_projected_obstructions() const;102103void merge(const Ref<NavigationMeshSourceGeometryData2D> &p_other_geometry);104105void set_data(const Vector<Vector<Vector2>> &p_traversable_outlines, const Vector<Vector<Vector2>> &p_obstruction_outlines, Vector<ProjectedObstruction> &p_projected_obstructions);106void get_data(Vector<Vector<Vector2>> &r_traversable_outlines, Vector<Vector<Vector2>> &r_obstruction_outlines, Vector<ProjectedObstruction> &r_projected_obstructions);107108Rect2 get_bounds();109110~NavigationMeshSourceGeometryData2D() { clear(); }111};112113114