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是Yuka js库中的一种FuzzyRule方法。该方法可以将一个JSON对象转换成FuzzyRule,使得FuzzyRule可以在不同应用场景中进行重复利用。

语法

FuzzyRule.fromJSON(obj: Object): FuzzyRule

参数

  • obj:一个包含了FuzzyRule数据的JSON对象。

返回

一个FuzzyRule对象,根据参数中的数据构建而成。

示例

以下是一个JSON对象的示例:

{
  "antecedent": [
    { "variable": "distance", "term": "near" },
    { "variable": "speed", "term": "slow" }
  ],
  "consequent": [
    { "variable": "brake", "term": "hard" }
  ],
  "weight": 1.0
}

使用fromJSON方法将该JSON对象转换成FuzzyRule实例的示例:

const ruleObj = {
  "antecedent": [
    { "variable": "distance", "term": "near" },
    { "variable": "speed", "term": "slow" }
  ],
  "consequent": [
    { "variable": "brake", "term": "hard" }
  ],
  "weight": 1.0
};

const rule = FuzzyRule.fromJSON(ruleObj);

以上示例中,我们将包含FuzzyRule数据的JSON对象传递给了fromJSON方法,并通过该方法创建了一个新的FuzzyRule实例。该实例可以在不同应用场景中进行重复利用。

异常

  • 如果obj参数不是一个有效的JSON对象,则会抛出TypeError类型异常。

备注

在将JSON数据转换成FuzzyRule实例时,必须确保JSON数据结构和FuzzyRule的定义完全一致,否则可能会出现错误的结果。特别是在处理嵌套对象或数组时,需要特别小心。建议使用单元测试来验证fromJSON方法的正确性。