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

toArray

简介

toArray是Yuka js库中Vector3类的一个方法。该方法将该Vector3的X、Y、Z三个分量的值以数组形式返回。

语法

vector.toArray(array: Array, offset: Number): Array

参数

  • array:Array类型。当其不为空数组时,将会直接将X、Y、Z分量推入该数组中。否则将会新建一个数组并返回出去。该参数是可选的。
  • offset:Number类型。对数组进行推入操作时的初始位置,即将X轴推入的位置。该参数是可选的,默认值为0。

返回值

Array类型。存有当前Vector3的X、Y、Z三个数值。

示例

import { Vector3 } from 'yuka'; // ES6 module导入

const vector = new Vector3(1, 2, 3);

const array1 = vector.toArray();
console.log(array1); // 输出 [1, 2, 3]

const array2 = [];
vector.toArray(array2, 1);
console.log(array2); // 输出 [empty, 1, 2, 3]

注记

  • array参数引用不为空时,该方法将直接推入X、Y、Z分量值到该数组中,并返回该数组。若array参数引用为空时,则将新建一个数组并返回。
  • offset参数用于控制执行推入操作的初始位置。该参数为可选项,默认的初始位置为0。

参见