mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2026-01-05 14:10:19 +03:00
574 lines
31 KiB
ReStructuredText
574 lines
31 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. DO NOT EDIT THIS FILE!!!
|
||
.. Generated automatically from Godot engine sources.
|
||
.. Generator: https://github.com/godotengine/godot/tree/4.3/doc/tools/make_rst.py.
|
||
.. XML source: https://github.com/godotengine/godot/tree/4.3/doc/classes/AStar3D.xml.
|
||
|
||
.. _class_AStar3D:
|
||
|
||
AStar3D
|
||
=======
|
||
|
||
**继承:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
A\* 的一种实现,用于寻找 3D 空间中连接图中的两个顶点之间的最短路径。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
描述
|
||
----
|
||
|
||
A\*(A 星)是一种计算机算法,用于寻路和图遍历,即穿过一组给定的边(线段),在顶点(点)之间绘制短路径的过程。由于其性能和准确性,它被广泛使用。Godot 的 A\* 实现默认使用 3D 空间中的点和欧几里德距离。
|
||
|
||
你需要使用 :ref:`add_point<class_AStar3D_method_add_point>` 手动添加点,并使用 :ref:`connect_points<class_AStar3D_method_connect_points>` 手动创建线段。完成后,可以使用 :ref:`are_points_connected<class_AStar3D_method_are_points_connected>` 函数,测试两点之间是否存在路径,通过 :ref:`get_id_path<class_AStar3D_method_get_id_path>` 获取包含索引的路径,或使用 :ref:`get_point_path<class_AStar3D_method_get_point_path>` 获取包含实际坐标的路径。
|
||
|
||
也可以使用非欧几里德距离。为此,创建一个扩展 **AStar3D** 的类,并覆盖方法 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 和 :ref:`_estimate_cost<class_AStar3D_private_method__estimate_cost>`\ 。两者都接受两个索引并返回一个长度,如以下示例所示。
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
class MyAStar:
|
||
extends AStar3D
|
||
|
||
func _compute_cost(u, v):
|
||
return abs(u - v)
|
||
|
||
func _estimate_cost(u, v):
|
||
return min(0, abs(u - v) - 1)
|
||
|
||
.. code-tab:: csharp
|
||
|
||
public partial class MyAStar : AStar3D
|
||
{
|
||
public override float _ComputeCost(long fromId, long toId)
|
||
{
|
||
return Mathf.Abs((int)(fromId - toId));
|
||
}
|
||
|
||
public override float _EstimateCost(long fromId, long toId)
|
||
{
|
||
return Mathf.Min(0, Mathf.Abs((int)(fromId - toId)) - 1);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
\ :ref:`_estimate_cost<class_AStar3D_private_method__estimate_cost>` 应该返回距离的下限,即 ``_estimate_cost(u, v) <= _compute_cost(u, v)``\ 。这可以作为算法的提示,因为自定义 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 可能计算量很大。如果不是这种情况,请使 :ref:`_estimate_cost<class_AStar3D_private_method__estimate_cost>` 返回与 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 相同的值,以便为算法提供最准确的信息。
|
||
|
||
如果使用默认的 :ref:`_estimate_cost<class_AStar3D_private_method__estimate_cost>` 和 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 方法,或者如果提供的 :ref:`_estimate_cost<class_AStar3D_private_method__estimate_cost>` 方法返回成本的下限,则 A\* 返回的路径将是成本最低的路径。这里,路径的代价等于路径中所有段的 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 结果乘以各个段端点的权重 ``weight_scale`` 之和。如果使用默认方法,并且所有点的 ``weight_scale`` 设置为 ``1.0``\ ,则这等于路径中所有段的欧几里德距离之和。
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
方法
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`\ ) |virtual| |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`_estimate_cost<class_AStar3D_private_method__estimate_cost>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`\ ) |virtual| |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`add_point<class_AStar3D_method_add_point>`\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector3<class_Vector3>`, weight_scale\: :ref:`float<class_float>` = 1.0\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`are_points_connected<class_AStar3D_method_are_points_connected>`\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`clear<class_AStar3D_method_clear>`\ (\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`connect_points<class_AStar3D_method_connect_points>`\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`disconnect_points<class_AStar3D_method_disconnect_points>`\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_available_point_id<class_AStar3D_method_get_available_point_id>`\ (\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_closest_point<class_AStar3D_method_get_closest_point>`\ (\ to_position\: :ref:`Vector3<class_Vector3>`, include_disabled\: :ref:`bool<class_bool>` = false\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector3<class_Vector3>` | :ref:`get_closest_position_in_segment<class_AStar3D_method_get_closest_position_in_segment>`\ (\ to_position\: :ref:`Vector3<class_Vector3>`\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`get_id_path<class_AStar3D_method_get_id_path>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_point_capacity<class_AStar3D_method_get_point_capacity>`\ (\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`get_point_connections<class_AStar3D_method_get_point_connections>`\ (\ id\: :ref:`int<class_int>`\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_point_count<class_AStar3D_method_get_point_count>`\ (\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedInt64Array<class_PackedInt64Array>` | :ref:`get_point_ids<class_AStar3D_method_get_point_ids>`\ (\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PackedVector3Array<class_PackedVector3Array>` | :ref:`get_point_path<class_AStar3D_method_get_point_path>`\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector3<class_Vector3>` | :ref:`get_point_position<class_AStar3D_method_get_point_position>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_point_weight_scale<class_AStar3D_method_get_point_weight_scale>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_point<class_AStar3D_method_has_point>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_point_disabled<class_AStar3D_method_is_point_disabled>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`remove_point<class_AStar3D_method_remove_point>`\ (\ id\: :ref:`int<class_int>`\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`reserve_space<class_AStar3D_method_reserve_space>`\ (\ num_nodes\: :ref:`int<class_int>`\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_point_disabled<class_AStar3D_method_set_point_disabled>`\ (\ id\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>` = true\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_point_position<class_AStar3D_method_set_point_position>`\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector3<class_Vector3>`\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_point_weight_scale<class_AStar3D_method_set_point_weight_scale>`\ (\ id\: :ref:`int<class_int>`, weight_scale\: :ref:`float<class_float>`\ ) |
|
||
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
方法说明
|
||
--------
|
||
|
||
.. _class_AStar3D_private_method__compute_cost:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **_compute_cost**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`\ ) |virtual| |const| :ref:`🔗<class_AStar3D_private_method__compute_cost>`
|
||
|
||
计算两个连接点之间的成本时调用。
|
||
|
||
请注意,这个函数在默认的 **AStar3D** 类中是隐藏的。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_private_method__estimate_cost:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **_estimate_cost**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`\ ) |virtual| |const| :ref:`🔗<class_AStar3D_private_method__estimate_cost>`
|
||
|
||
估算某个点和路径终点之间的成本时调用。
|
||
|
||
请注意,这个函数在默认的 **AStar3D** 类中是隐藏的。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_add_point:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **add_point**\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector3<class_Vector3>`, weight_scale\: :ref:`float<class_float>` = 1.0\ ) :ref:`🔗<class_AStar3D_method_add_point>`
|
||
|
||
在给定的位置添加一个新的点,并使用给定的标识符。\ ``id`` 必须大于等于 0,\ ``weight_scale`` 必须大于等于 0.0。
|
||
|
||
在确定从邻点到此点的一段路程的总成本时,\ ``weight_scale`` 要乘以 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 的结果。因此,在其他条件相同的情况下,算法优先选择 ``weight_scale`` 较低的点来形成路径。
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var astar = AStar3D.new()
|
||
astar.add_point(1, Vector3(1, 0, 0), 4) # 添加点 (1, 0, 0),其 weight_scale 为 4 且 id 为 1
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var astar = new AStar3D();
|
||
astar.AddPoint(1, new Vector3(1, 0, 0), 4); // 添加点 (1, 0, 0),其 weight_scale 为 4 且 id 为 1
|
||
|
||
|
||
|
||
如果对于给定的 ``id`` 已经存在一个点,它的位置和权重将被更新为给定的值。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_are_points_connected:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **are_points_connected**\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) |const| :ref:`🔗<class_AStar3D_method_are_points_connected>`
|
||
|
||
返回两个给定点是否通过线段直接连接。如果 ``bidirectional`` 为 ``false``\ ,则返回是否可以通过该线段从 ``id`` 移动到 ``to_id``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_clear:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **clear**\ (\ ) :ref:`🔗<class_AStar3D_method_clear>`
|
||
|
||
清除所有点和线段。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_connect_points:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **connect_points**\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStar3D_method_connect_points>`
|
||
|
||
在给定的点之间创建一条线段。如果 ``bidirectional`` 为 ``false``\ ,则只允许从 ``id`` 到 ``to_id`` 的移动,而不允许反向移动。
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var astar = AStar3D.new()
|
||
astar.add_point(1, Vector3(1, 1, 0))
|
||
astar.add_point(2, Vector3(0, 5, 0))
|
||
astar.connect_points(1, 2, false)
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var astar = new AStar3D();
|
||
astar.AddPoint(1, new Vector3(1, 1, 0));
|
||
astar.AddPoint(2, new Vector3(0, 5, 0));
|
||
astar.ConnectPoints(1, 2, false);
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_disconnect_points:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **disconnect_points**\ (\ id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, bidirectional\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStar3D_method_disconnect_points>`
|
||
|
||
删除给定点之间的线段。如果 ``bidirectional`` 为 ``false``\ ,则仅阻止从 ``id`` 到 ``to_id`` 的移动,并且可能会保留一个单向线段。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_available_point_id:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_available_point_id**\ (\ ) |const| :ref:`🔗<class_AStar3D_method_get_available_point_id>`
|
||
|
||
返回下一个没有关联点的可用点 ID。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_closest_point:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_closest_point**\ (\ to_position\: :ref:`Vector3<class_Vector3>`, include_disabled\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_AStar3D_method_get_closest_point>`
|
||
|
||
返回距离 ``to_position`` 最近的点的 ID,可以选择将禁用的点考虑在内。如果点池中没有点,则返回 ``-1``\ 。
|
||
|
||
\ **注意:**\ 如果有多个点距离 ``to_position`` 最近,则返回 ID 最小的那个点,以保证结果的确定性。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_closest_position_in_segment:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector3<class_Vector3>` **get_closest_position_in_segment**\ (\ to_position\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_AStar3D_method_get_closest_position_in_segment>`
|
||
|
||
返回位于两个连接点之间的线段中离 ``to_position`` 最近的位置。
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var astar = AStar3D.new()
|
||
astar.add_point(1, Vector3(0, 0, 0))
|
||
astar.add_point(2, Vector3(0, 5, 0))
|
||
astar.connect_points(1, 2)
|
||
var res = astar.get_closest_position_in_segment(Vector3(3, 3, 0)) # 返回 (0, 3, 0)
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var astar = new AStar3D();
|
||
astar.AddPoint(1, new Vector3(0, 0, 0));
|
||
astar.AddPoint(2, new Vector3(0, 5, 0));
|
||
astar.ConnectPoints(1, 2);
|
||
Vector3 res = astar.GetClosestPositionInSegment(new Vector3(3, 3, 0)); // 返回 (0, 3, 0)
|
||
|
||
|
||
|
||
结果是在从 ``y = 0`` 到 ``y = 5`` 的线段中。它是线段中距离给定点最近的位置。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_id_path:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedInt64Array<class_PackedInt64Array>` **get_id_path**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AStar3D_method_get_id_path>`
|
||
|
||
返回一个数组,其中包含构成 AStar3D 在给定点之间找到的路径中的点的 ID。数组从路径的起点到终点排序。
|
||
|
||
如果没有能够到达目标的有效路径,并且 ``allow_partial_path`` 为\ ``true``\ ,则返回能够到达的最接近目标点的路径。
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var astar = AStar3D.new()
|
||
astar.add_point(1, Vector3(0, 0, 0))
|
||
astar.add_point(2, Vector3(0, 1, 0), 1) # 默认权重为 1
|
||
astar.add_point(3, Vector3(1, 1, 0))
|
||
astar.add_point(4, Vector3(2, 0, 0))
|
||
|
||
astar.connect_points(1, 2, false)
|
||
astar.connect_points(2, 3, false)
|
||
astar.connect_points(4, 3, false)
|
||
astar.connect_points(1, 4, false)
|
||
|
||
var res = astar.get_id_path(1, 3) # 返回 [1, 2, 3]
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var astar = new AStar3D();
|
||
astar.AddPoint(1, new Vector3(0, 0, 0));
|
||
astar.AddPoint(2, new Vector3(0, 1, 0), 1); // 默认权重为 1
|
||
astar.AddPoint(3, new Vector3(1, 1, 0));
|
||
astar.AddPoint(4, new Vector3(2, 0, 0));
|
||
astar.ConnectPoints(1, 2, false);
|
||
astar.ConnectPoints(2, 3, false);
|
||
astar.ConnectPoints(4, 3, false);
|
||
astar.ConnectPoints(1, 4, false);
|
||
long[] res = astar.GetIdPath(1, 3); // 返回 [1, 2, 3]
|
||
|
||
|
||
|
||
如果将第2个点的权重更改为 3,则结果将改为 ``[1, 4, 3]``\ ,因为现在即使距离更长,但通过第 4 点也比通过第 2 点“更容易”。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_capacity:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_point_capacity**\ (\ ) |const| :ref:`🔗<class_AStar3D_method_get_point_capacity>`
|
||
|
||
该函数返回支持点的数据结构的容量,可以与 :ref:`reserve_space<class_AStar3D_method_reserve_space>` 方法一起使用。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_connections:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedInt64Array<class_PackedInt64Array>` **get_point_connections**\ (\ id\: :ref:`int<class_int>`\ ) :ref:`🔗<class_AStar3D_method_get_point_connections>`
|
||
|
||
返回一个数组,其中包含与给定点形成连接的点的 ID。
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var astar = AStar3D.new()
|
||
astar.add_point(1, Vector3(0, 0, 0))
|
||
astar.add_point(2, Vector3(0, 1, 0))
|
||
astar.add_point(3, Vector3(1, 1, 0))
|
||
astar.add_point(4, Vector3(2, 0, 0))
|
||
|
||
astar.connect_points(1, 2, true)
|
||
astar.connect_points(1, 3, true)
|
||
|
||
var neighbors = astar.get_point_connections(1) # 返回 [2, 3]
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var astar = new AStar3D();
|
||
astar.AddPoint(1, new Vector3(0, 0, 0));
|
||
astar.AddPoint(2, new Vector3(0, 1, 0));
|
||
astar.AddPoint(3, new Vector3(1, 1, 0));
|
||
astar.AddPoint(4, new Vector3(2, 0, 0));
|
||
astar.ConnectPoints(1, 2, true);
|
||
astar.ConnectPoints(1, 3, true);
|
||
|
||
long[] neighbors = astar.GetPointConnections(1); // 返回 [2, 3]
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_count:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_point_count**\ (\ ) |const| :ref:`🔗<class_AStar3D_method_get_point_count>`
|
||
|
||
返回点池中当前的点数。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_ids:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedInt64Array<class_PackedInt64Array>` **get_point_ids**\ (\ ) :ref:`🔗<class_AStar3D_method_get_point_ids>`
|
||
|
||
返回所有点 ID 的数组。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_path:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PackedVector3Array<class_PackedVector3Array>` **get_point_path**\ (\ from_id\: :ref:`int<class_int>`, to_id\: :ref:`int<class_int>`, allow_partial_path\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AStar3D_method_get_point_path>`
|
||
|
||
返回一个数组,其中包含 AStar3D 在给定点之间找到的路径中的点。数组从路径的起点到终点进行排序。
|
||
|
||
如果没有通往目标的有效路径并且 ``allow_partial_path`` 为 ``true``\ ,则会返回通往距离目标最近的可达点的路径。
|
||
|
||
\ **注意:**\ 这种方法不是线程安全的。如果从 :ref:`Thread<class_Thread>` 调用,它将返回一个空的 :ref:`PackedVector3Array<class_PackedVector3Array>`\ ,并打印一条错误消息。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_position:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector3<class_Vector3>` **get_point_position**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar3D_method_get_point_position>`
|
||
|
||
返回与给定 ``id`` 相关联的点的位置。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_get_point_weight_scale:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_point_weight_scale**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar3D_method_get_point_weight_scale>`
|
||
|
||
返回与给定 ``id`` 关联的点的权重比例。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_has_point:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_point**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar3D_method_has_point>`
|
||
|
||
返回与给定 ``id`` 相关联的点是否存在。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_is_point_disabled:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_point_disabled**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_AStar3D_method_is_point_disabled>`
|
||
|
||
返回用于寻路时点是否被禁用。默认情况下,所有点均被启用。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_remove_point:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **remove_point**\ (\ id\: :ref:`int<class_int>`\ ) :ref:`🔗<class_AStar3D_method_remove_point>`
|
||
|
||
从点池中移除与给定 ``id`` 关联的点。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_reserve_space:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **reserve_space**\ (\ num_nodes\: :ref:`int<class_int>`\ ) :ref:`🔗<class_AStar3D_method_reserve_space>`
|
||
|
||
该函数为 ``num_nodes`` 个点内部预留空间。如果一次添加了大量已知数量的点,例如网格上的点,则此函数很有用。新的容量必须大于或等于旧的容量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_set_point_disabled:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_point_disabled**\ (\ id\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>` = true\ ) :ref:`🔗<class_AStar3D_method_set_point_disabled>`
|
||
|
||
用于寻路时禁用或启用指定的点。适用于制作临时障碍物。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_set_point_position:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_point_position**\ (\ id\: :ref:`int<class_int>`, position\: :ref:`Vector3<class_Vector3>`\ ) :ref:`🔗<class_AStar3D_method_set_point_position>`
|
||
|
||
为具有给定 ``id`` 的点设置位置 ``position``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_AStar3D_method_set_point_weight_scale:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_point_weight_scale**\ (\ id\: :ref:`int<class_int>`, weight_scale\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AStar3D_method_set_point_weight_scale>`
|
||
|
||
为给定的 ``id`` 的点设置 ``weight_scale``\ 。在确定从邻接点到这个点的一段路程的总成本时,\ ``weight_scale`` 要乘以 :ref:`_compute_cost<class_AStar3D_private_method__compute_cost>` 的结果。
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
|
||
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
|
||
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
|
||
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
|
||
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
|
||
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
|
||
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
|
||
.. |void| replace:: :abbr:`void (无返回值。)`
|