AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

fromPolygons

简介

fromPolygons是Yuka js库中的一个NavMesh类方法,它可以根据多边形构建导航网格。

语法

NavMesh.fromPolygons( polygons, options )

参数

  • polygons:一个包含多个多边形的数组,每个多边形由一系列点组成。
  • options:可选参数对象,包含以下属性:
    • tolerance:点之间的容差范围,默认值为0.005。
    • convexHullMode:多边形的凸包模式,可选值为:'none'、'ccw'、'cw'。默认值为'none'。

用法

import { NavMesh } from 'yuka';

const polygons = [
  [ new Vector3( 0, 0, 0 ), new Vector3( 10, 0, 0 ), new Vector3( 10, 0, 10 ) ],
  [ new Vector3( 0, 0, 0 ), new Vector3( 10, 0, 10 ), new Vector3( 0, 0, 10 ) ],
];

const navMesh = NavMesh.fromPolygons( polygons );

返回值

返回一个新的NavMesh实例。

示例

以下示例展示了如何使用fromPolygons方法创建一个导航网格。

import { NavMesh, Vector3 } from 'yuka';

const polygons = [
  [ new Vector3( 0, 0, 0 ), new Vector3( 10, 0, 0 ), new Vector3( 10, 0, 10 ) ],
  [ new Vector3( 0, 0, 0 ), new Vector3( 10, 0, 10 ), new Vector3( 0, 0, 10 ) ],
];

const navMesh = NavMesh.fromPolygons( polygons );

备注

  • 当从多边形构建导航网格时,多边形应该为凸多边形。

参考资料