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

fromJSON

fromJSON函数用于将一个JSON表示的路径转换为一个Path对象。

语法

Path.fromJSON(jsonString: string): Path

参数

  • jsonString:一个表示路径的JSON字符串。

返回值

一个表示路径的Path对象。

示例

const jsonString = '{"commands":[{"code":"M","params":[10,10]},{"code":"L","params":[20,20]}]}';

const path = Path.fromJSON(jsonString);

console.log(path.toString());
// 输出:M 10 10 L 20 20

此例中,从一个JSON字符串中,生成了一个Path对象,并通过调用该对象的toString方法将路径以字符串形式呈现出来。

注意事项

JSON字符串必须符合Path对象的JSON表示格式。具体格式请查看Path类的toJSON方法的文档。如果JSON字符串无法被解析为Path对象,则该方法会抛出SyntaxError异常。