Add tracking behaviot & current label & Optmi running func & test fish scene

This commit is contained in:
2022-04-10 16:51:13 +08:00
parent f8fbb70608
commit 0e1a070390
15 changed files with 273 additions and 33 deletions
+12 -1
View File
@@ -3,12 +3,14 @@ import { Template } from "@Behavior/Template";
import { Dynamics } from "@Behavior/Dynamics";
import { Brownian } from "@Behavior/Brownian";
import { BoundaryConstraint } from "@Behavior/BoundaryConstraint";
import { Tracking } from "@Behavior/Tracking";
const AllBehaviors: IAnyBehaviorRecorder[] = [
new BehaviorRecorder(Template),
new BehaviorRecorder(Dynamics),
new BehaviorRecorder(Brownian),
new BehaviorRecorder(BoundaryConstraint),
new BehaviorRecorder(Tracking),
]
/**
@@ -54,4 +56,13 @@ function categoryBehaviors(behaviors: IAnyBehaviorRecorder[]): ICategory[] {
return res;
}
export { AllBehaviors, AllBehaviorsWithCategory, ICategory as ICategoryBehavior };
function getBehaviorById(id: string): IAnyBehaviorRecorder {
for (let i = 0; i < AllBehaviors.length; i++) {
if (AllBehaviors[i].behaviorId === id) {
return AllBehaviors[i];
}
}
return getBehaviorById("Template");
}
export { AllBehaviors, AllBehaviorsWithCategory, getBehaviorById, ICategory as ICategoryBehavior };
+1 -1
View File
@@ -28,7 +28,7 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter,
strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 }
};
public effect(individual: Individual, group: Group, model: Model, t: number): void {
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let rangeList: Range[] = this.parameter.range.objects;
let fx = 0;
+1 -1
View File
@@ -31,7 +31,7 @@ class Brownian extends Behavior<IBrownianBehaviorParameter, IBrownianBehaviorEve
minStrength: { type: "number", name: "$Min.Strength", defaultValue: 0, numberStep: .01, numberMin: 0 }
};
public effect(individual: Individual, group: Group, model: Model, t: number): void {
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
const {maxFrequency, minFrequency, maxStrength, minStrength} = this.parameter;
+1 -1
View File
@@ -31,7 +31,7 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
resistance: { name: "$Resistance", type: "number", defaultValue: 0.5, numberStep: .1, numberMin: 0 }
};
public override finalEffect(individual: Individual, group: Group, model: Model, t: number): void {
public override finalEffect = (individual: Individual, group: Group, model: Model, t: number): void => {
// 计算当前速度
const currentV = individual.vectorLength(individual.velocity);
+5 -1
View File
@@ -14,6 +14,8 @@ type ITemplateBehaviorParameter = {
testLR: "LR";
testLG: "LG";
testVec: "vec";
testCG: "CG",
testCLG: "CLG",
}
type ITemplateBehaviorEvent = {}
@@ -42,10 +44,12 @@ class Template extends Behavior<ITemplateBehaviorParameter, ITemplateBehaviorEve
testG: { name: "$Test", type: "G" },
testLR: { name: "$Test", type: "LR" },
testLG: { name: "$Test", type: "LG" },
testCG: { name: "$Test", type: "CG" },
testCLG: { name: "$Test", type: "CLG" },
testVec: { name: "$Test", type: "vec", defaultValue: [1, 2, 3], numberMax: 10, numberMin: 0, numberStep: 1 }
};
public effect(individual: Individual, group: Group, model: Model, t: number): void {
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
}
+84
View File
@@ -0,0 +1,84 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type ITrackingBehaviorParameter = {
target: "LG",
strength: "number"
}
type ITrackingBehaviorEvent = {}
class Tracking extends Behavior<ITrackingBehaviorParameter, ITrackingBehaviorEvent> {
public override behaviorId: string = "Tracking";
public override behaviorName: string = "$Title";
public override iconName: string = "BullseyeTarget";
public override describe: string = "$Intro";
public override category: string = "$Interactive";
public override parameterOption = {
target: { type: "CLG", name: "$Target" },
strength: { type: "number", name: "$Strength", defaultValue: 10, numberMin: 0, numberStep: .1 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let target: Individual | undefined;
let currentDistant: number = Infinity;
for (let i = 0; i < this.parameter.target.objects.length; i++) {
const targetGroup = this.parameter.target.objects[i];
targetGroup.individuals.forEach((targetIndividual) => {
// 排除自己
if (targetIndividual === individual) return;
let dis = targetIndividual.distanceTo(individual);
if (dis < currentDistant) {
target = targetIndividual;
currentDistant = dis;
}
});
}
if (target) {
individual.applyForce(
(target.position[0] - individual.position[0]) * this.parameter.strength,
(target.position[1] - individual.position[1]) * this.parameter.strength,
(target.position[2] - individual.position[2]) * this.parameter.strength
);
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "追踪",
"EN_US": "Tracking"
},
"$Target": {
"ZH_CN": "追踪目标",
"EN_US": "Tracking target"
},
"$Strength": {
"ZH_CN": "追踪强度系数",
"EN_US": "Tracking intensity coefficient"
},
"$Intro": {
"ZH_CN": "个体将主动向最近的目标群个体发起追踪",
"EN_US": "The individual will actively initiate tracking to the nearest target group individual"
},
"$Interactive": {
"ZH_CN": "交互",
"EN_US": "Interactive"
}
};
}
export { Tracking };