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

faces

简介

faces 是 Yuka js 库中 ConvexHull 类的一个属性,用于存储凸包的面(三角形)。每个面都由三个顶点组成。

用法

在创建 ConvexHull 的实例后,可以通过访问其 faces 属性来获取凸包的面数据。faces 是一个数组,其中每个元素都是一个形如 [a, b, c] 的数组,表示由凸包中的第 abc 个顶点组成的一个三角形面。

import { ConvexHull } from 'yuka';

const points = [
  new Vector3( 0, 0, 0 ),
  new Vector3( 1, 0, 0 ),
  new Vector3( 0, 1, 0 ),
  new Vector3( 0, 0, 1 ),
  new Vector3( 1, 1, 0 ),
  new Vector3( 1, 0, 1 ),
  new Vector3( 0, 1, 1 ),
  new Vector3( 1, 1, 1 )
];

const convexHull = new ConvexHull().setFromPoints( points );
const faces = convexHull.faces;

console.log( faces ); // [ [ 5, 0, 6 ], [ 6, 1, 5 ], [ 2, 5, 1 ], [ 7, 5, 2 ], [ 3, 2, 1 ], [ 3, 7, 2 ], [ 4, 5, 7 ], [ 7, 6, 4 ], [ 3, 1, 0 ], [ 0, 4, 3 ], [ 0, 5, 4 ], [ 7, 3, 4 ] ]

注意事项

  • 在访问 faces 属性之前,请先确保已经通过 setFromPoints 方法或其他方式,为 ConvexHull 实例添加了顶点数据。否则 faces 属性将会是一个空数组。

  • 由于 ConvexHull 的计算方式与设置的顶点顺序有关,因此不同的输入顶点可能得到不同的凸包面数据。具体计算过程请参考 ConvexHull 类的文档。