29 Commits
Author SHA1 Message Date
MrKBear 8ede304664 Merge pull request 'Add statistics panel' (#56) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/living-together/pulls/56
2022-05-27 20:02:00 +08:00
MrKBear 3e6bef2ee7 Merge branch 'master' into dev-mrkbear 2022-05-27 20:01:46 +08:00
MrKBear bd8a9d1cdb Add statistics panel 2022-05-26 21:47:42 +08:00
MrKBear 4ea3c9e1f4 Add statistics panel 2022-05-26 17:08:04 +08:00
MrKBear 2dbbd0952a Add statistics panel 2022-05-25 22:00:13 +08:00
MrKBear ce99b17fcb Add statistics panel 2022-05-24 14:07:47 +08:00
MrKBear fcbe646b67 Merge branch 'dev-mrkbear' of http://git.mrkbear.com/MrKBear/living-together into dev-mrkbear 2022-05-24 11:39:06 +08:00
MrKBear a8b1c21ed6 Fix ZH_CN I18N num error 2022-05-24 11:38:56 +08:00
MrKBear 7adadb6d46 Merge pull request 'Add setting option' (#55) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/living-together/pulls/55
2022-05-20 14:45:26 +08:00
MrKBear 8b35074fe8 Merge branch 'master' into dev-mrkbear 2022-05-20 14:45:22 +08:00
MrKBear c582388317 Merge branch 'dev-mrkbear' of http://git.mrkbear.com/MrKBear/living-together into dev-mrkbear 2022-05-20 14:44:00 +08:00
MrKBear 70ff9fa0ad Add setting option 2022-05-20 14:41:52 +08:00
MrKBear ac0fef2901 Merge pull request 'Add ant behavior' (#54) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/living-together/pulls/54
2022-05-12 20:23:20 +08:00
MrKBear 7e2281add1 Merge branch 'master' into dev-mrkbear 2022-05-12 20:23:16 +08:00
MrKBear 4eb6637062 fix brownian behavior 2022-05-12 20:22:18 +08:00
MrKBear 8670b577f9 Add sample tracking behavior 2022-05-11 13:09:51 +08:00
MrKBear 4768667803 Add sample tracking behavior 2022-05-11 11:43:41 +08:00
MrKBear 571e80d542 Fix boundary logic & Add wastage behavior 2022-05-10 14:55:45 +08:00
MrKBear da493bc6ae Contact Attacking behavior add assimilate & Tracking add view range 2022-05-09 23:26:17 +08:00
MrKBear 904de02140 Brownian behavior add limit by range 2022-05-09 21:24:28 +08:00
MrKBear 4ade5d4bc3 Add manufacture behavior 2022-05-08 21:33:38 +08:00
MrKBear 920958b1a2 Merge pull request 'Add avoidance behavior & direction cluster behavior & central cluster behavior' (#53) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/living-together/pulls/53
2022-05-07 12:10:39 +08:00
MrKBear e814f5e061 Merge branch 'master' into dev-mrkbear 2022-05-07 12:10:33 +08:00
MrKBear dfb3905c9b Add central cluster behavior 2022-05-07 12:09:05 +08:00
MrKBear 974cd2951d Add direction cluster behavior 2022-05-06 23:12:00 +08:00
MrKBear f660aefa4c Add avoidance behavior 2022-05-06 18:55:31 +08:00
MrKBear c6b0f84cef Merge pull request 'Add line info into spline first point' (#52) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/living-together/pulls/52
2022-05-06 11:36:35 +08:00
MrKBear 456c21f6c2 Merge branch 'master' into dev-mrkbear 2022-05-06 11:36:31 +08:00
MrKBear 658765141c Merge pull request 'Add parse to obj function & Bind clip recoder & loader event' (#51) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/living-together/pulls/51
2022-05-04 14:53:24 +08:00
28 changed files with 1308 additions and 36 deletions
+27
View File
@@ -11,11 +11,13 @@
"dependencies": { "dependencies": {
"@fluentui/react": "^8.56.0", "@fluentui/react": "^8.56.0",
"@juggle/resize-observer": "^3.3.1", "@juggle/resize-observer": "^3.3.1",
"chart.js": "^3.7.1",
"detect-port": "^1.3.0", "detect-port": "^1.3.0",
"downloadjs": "^1.4.7", "downloadjs": "^1.4.7",
"express": "^4.17.3", "express": "^4.17.3",
"gl-matrix": "^3.4.3", "gl-matrix": "^3.4.3",
"react": "^17.0.2", "react": "^17.0.2",
"react-chartjs-2": "^4.1.0",
"react-dnd": "^16.0.1", "react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1", "react-dnd-html5-backend": "^16.0.1",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
@@ -2200,6 +2202,11 @@
"url": "https://github.com/chalk/chalk?sponsor=1" "url": "https://github.com/chalk/chalk?sponsor=1"
} }
}, },
"node_modules/chart.js": {
"version": "3.7.1",
"resolved": "https://registry.npmmirror.com/chart.js/-/chart.js-3.7.1.tgz",
"integrity": "sha512-8knRegQLFnPQAheZV8MjxIXc5gQEfDFD897BJgv/klO/vtIyFFmgMXrNfgrXpbTr/XbTturxRgxIXx/Y+ASJBA=="
},
"node_modules/chokidar": { "node_modules/chokidar": {
"version": "3.5.3", "version": "3.5.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz",
@@ -6210,6 +6217,15 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/react-chartjs-2": {
"version": "4.1.0",
"resolved": "https://registry.npmmirror.com/react-chartjs-2/-/react-chartjs-2-4.1.0.tgz",
"integrity": "sha512-AsUihxEp8Jm1oBhbEovE+w50m9PVNhz1sfwEIT4hZduRC0m14gHWHd0cUaxkFDb8HNkdMIGzsNlmVqKiOpU74g==",
"peerDependencies": {
"chart.js": "^3.5.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/react-dnd": { "node_modules/react-dnd": {
"version": "16.0.1", "version": "16.0.1",
"resolved": "https://registry.npmmirror.com/react-dnd/-/react-dnd-16.0.1.tgz", "resolved": "https://registry.npmmirror.com/react-dnd/-/react-dnd-16.0.1.tgz",
@@ -10113,6 +10129,11 @@
"supports-color": "^7.1.0" "supports-color": "^7.1.0"
} }
}, },
"chart.js": {
"version": "3.7.1",
"resolved": "https://registry.npmmirror.com/chart.js/-/chart.js-3.7.1.tgz",
"integrity": "sha512-8knRegQLFnPQAheZV8MjxIXc5gQEfDFD897BJgv/klO/vtIyFFmgMXrNfgrXpbTr/XbTturxRgxIXx/Y+ASJBA=="
},
"chokidar": { "chokidar": {
"version": "3.5.3", "version": "3.5.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz",
@@ -13200,6 +13221,12 @@
"object-assign": "^4.1.1" "object-assign": "^4.1.1"
} }
}, },
"react-chartjs-2": {
"version": "4.1.0",
"resolved": "https://registry.npmmirror.com/react-chartjs-2/-/react-chartjs-2-4.1.0.tgz",
"integrity": "sha512-AsUihxEp8Jm1oBhbEovE+w50m9PVNhz1sfwEIT4hZduRC0m14gHWHd0cUaxkFDb8HNkdMIGzsNlmVqKiOpU74g==",
"requires": {}
},
"react-dnd": { "react-dnd": {
"version": "16.0.1", "version": "16.0.1",
"resolved": "https://registry.npmmirror.com/react-dnd/-/react-dnd-16.0.1.tgz", "resolved": "https://registry.npmmirror.com/react-dnd/-/react-dnd-16.0.1.tgz",
+2
View File
@@ -71,11 +71,13 @@
"dependencies": { "dependencies": {
"@fluentui/react": "^8.56.0", "@fluentui/react": "^8.56.0",
"@juggle/resize-observer": "^3.3.1", "@juggle/resize-observer": "^3.3.1",
"chart.js": "^3.7.1",
"detect-port": "^1.3.0", "detect-port": "^1.3.0",
"downloadjs": "^1.4.7", "downloadjs": "^1.4.7",
"express": "^4.17.3", "express": "^4.17.3",
"gl-matrix": "^3.4.3", "gl-matrix": "^3.4.3",
"react": "^17.0.2", "react": "^17.0.2",
"react-chartjs-2": "^4.1.0",
"react-dnd": "^16.0.1", "react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1", "react-dnd-html5-backend": "^16.0.1",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
+86
View File
@@ -0,0 +1,86 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type IAvoidanceBehaviorParameter = {
avoid: "CLG",
strength: "number",
range: "number"
}
type IAvoidanceBehaviorEvent = {}
class Avoidance extends Behavior<IAvoidanceBehaviorParameter, IAvoidanceBehaviorEvent> {
public override behaviorId: string = "Avoidance";
public override behaviorName: string = "$Title";
public override iconName: string = "FastMode";
public override describe: string = "$Intro";
public override category: string = "$Interactive";
public override parameterOption = {
avoid: { name: "$Avoid", type: "CLG" },
strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 },
range: { type: "number", name: "$Range", defaultValue: 4, numberMin: 0, numberStep: .1 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let currentDistant: number = Infinity;
let avoidTarget = undefined as Individual | undefined;
for (let i = 0; i < this.parameter.avoid.objects.length; i++) {
const targetGroup = this.parameter.avoid.objects[i];
targetGroup.individuals.forEach((targetIndividual) => {
// 排除自己
if (targetIndividual === individual) return;
let dis = targetIndividual.distanceTo(individual);
if (dis < currentDistant && dis <= this.parameter.range) {
avoidTarget = targetIndividual;
currentDistant = dis;
}
});
}
if (avoidTarget && currentDistant !== Infinity) {
individual.applyForce(
(individual.position[0] - avoidTarget.position[0]) * this.parameter.strength / currentDistant,
(individual.position[1] - avoidTarget.position[1]) * this.parameter.strength / currentDistant,
(individual.position[2] - avoidTarget.position[2]) * this.parameter.strength / currentDistant
);
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "躲避",
"EN_US": "Avoidance"
},
"$Intro": {
"ZH_CN": "远离视野范围内最近的躲避目标",
"EN_US": "Stay away from the nearest evasive target in the field of vision"
},
"$Avoid": {
"ZH_CN": "躲避对象",
"EN_US": "Avoid object"
},
"$Strength": {
"ZH_CN": "躲避强度",
"EN_US": "Avoidance intensity"
},
"$Range": {
"ZH_CN": "视野范围",
"EN_US": "Field of vision"
}
};
}
export { Avoidance };
+12
View File
@@ -7,6 +7,12 @@ import { Tracking } from "@Behavior/Tracking";
import { ContactAttacking } from "@Behavior/ContactAttacking"; import { ContactAttacking } from "@Behavior/ContactAttacking";
import { ContactAssimilate } from "@Behavior/ContactAssimilate"; import { ContactAssimilate } from "@Behavior/ContactAssimilate";
import { DelayAssimilate } from "@Behavior/DelayAssimilate"; import { DelayAssimilate } from "@Behavior/DelayAssimilate";
import { Avoidance } from "@Behavior/Avoidance";
import { DirectionCluster } from "@Behavior/DirectionCluster";
import { CentralCluster } from "@Behavior/CentralCluster";
import { Manufacture } from "@Behavior/Manufacture";
import { Wastage } from "@Behavior/Wastage";
import { SampleTracking } from "@Behavior/SampleTracking";
const AllBehaviors: IAnyBehaviorRecorder[] = [ const AllBehaviors: IAnyBehaviorRecorder[] = [
new BehaviorRecorder(Template), new BehaviorRecorder(Template),
@@ -17,6 +23,12 @@ const AllBehaviors: IAnyBehaviorRecorder[] = [
new BehaviorRecorder(ContactAttacking), new BehaviorRecorder(ContactAttacking),
new BehaviorRecorder(ContactAssimilate), new BehaviorRecorder(ContactAssimilate),
new BehaviorRecorder(DelayAssimilate), new BehaviorRecorder(DelayAssimilate),
new BehaviorRecorder(Avoidance),
new BehaviorRecorder(DirectionCluster),
new BehaviorRecorder(CentralCluster),
new BehaviorRecorder(Manufacture),
new BehaviorRecorder(Wastage),
new BehaviorRecorder(SampleTracking),
] ]
/** /**
+10 -4
View File
@@ -48,11 +48,17 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter,
if (ox || oy || oz) { if (ox || oy || oz) {
let currentFLen = individual.vectorLength(rx, ry, rz); const backFocus: number[] = [0, 0, 0];
if (ox) backFocus[0] = rx - rx * rangeList[i].radius[0] / Math.abs(rx);
if (oy) backFocus[1] = ry - ry * rangeList[i].radius[1] / Math.abs(ry);
if (oz) backFocus[2] = rz - rz * rangeList[i].radius[2] / Math.abs(rz);
let currentFLen = individual.vectorLength(backFocus);
if (currentFLen < fLen) { if (currentFLen < fLen) {
fx = rx; fx = backFocus[0];
fy = ry; fy = backFocus[1];
fz = rz; fz = backFocus[2];
fLen = currentFLen; fLen = currentFLen;
} }
+133 -6
View File
@@ -7,7 +7,9 @@ type IBrownianBehaviorParameter = {
maxFrequency: "number", maxFrequency: "number",
minFrequency: "number", minFrequency: "number",
maxStrength: "number", maxStrength: "number",
minStrength: "number" minStrength: "number",
dirLimit: "boolean",
angle: "number"
} }
type IBrownianBehaviorEvent = {} type IBrownianBehaviorEvent = {}
@@ -28,9 +30,88 @@ class Brownian extends Behavior<IBrownianBehaviorParameter, IBrownianBehaviorEve
maxFrequency: { type: "number", name: "$Max.Frequency", defaultValue: 5, numberStep: .1, numberMin: 0 }, maxFrequency: { type: "number", name: "$Max.Frequency", defaultValue: 5, numberStep: .1, numberMin: 0 },
minFrequency: { type: "number", name: "$Min.Frequency", defaultValue: 0, numberStep: .1, numberMin: 0 }, minFrequency: { type: "number", name: "$Min.Frequency", defaultValue: 0, numberStep: .1, numberMin: 0 },
maxStrength: { type: "number", name: "$Max.Strength", defaultValue: 10, numberStep: .01, numberMin: 0 }, maxStrength: { type: "number", name: "$Max.Strength", defaultValue: 10, numberStep: .01, numberMin: 0 },
minStrength: { type: "number", name: "$Min.Strength", defaultValue: 0, numberStep: .01, numberMin: 0 } minStrength: { type: "number", name: "$Min.Strength", defaultValue: 0, numberStep: .01, numberMin: 0 },
dirLimit: { type: "boolean", name: "$Direction.Limit", defaultValue: false },
angle: {
type: "number", name: "$Angle", defaultValue: 180, numberStep: 5,
numberMin: 0, numberMax: 360, condition: { key: "dirLimit", value: true }
}
}; };
private randomFocus360(): number[] {
let randomVec = [
Math.random() * 2 - 1,
Math.random() * 2 - 1,
Math.random() * 2 - 1
];
let randomVecLen = (randomVec[0] ** 2 + randomVec[1] ** 2 + randomVec[2] ** 2) ** 0.5;
return [randomVec[0] / randomVecLen, randomVec[1] / randomVecLen, randomVec[2] / randomVecLen];
}
private rotateWithVec(vec: number[], r: number[], ang: number) {
const cos = Math.cos(ang); const sin = Math.sin(ang);
const a1 = r[0] ?? 0; const a2 = r[1] ?? 0; const a3 = r[2] ?? 0;
return [
(cos + (1 - cos) * a1 * a1) * (vec[0] ?? 0) +
((1 - cos) * a1 * a2 - sin * a3) * (vec[1] ?? 0) +
((1 - cos) * a1 * a3 + sin * a2) * (vec[2] ?? 0),
((1 - cos) * a1 * a2 + sin * a3) * (vec[0] ?? 0) +
(cos + (1 - cos) * a2 * a2) * (vec[1] ?? 0) +
((1 - cos) * a2 * a3 - sin * a1) * (vec[2] ?? 0),
((1 - cos) * a1 * a3 - sin * a2) * (vec[0] ?? 0) +
((1 - cos) * a2 * a3 + sin * a1) * (vec[1] ?? 0) +
(cos + (1 - cos) * a3 * a3) * (vec[2] ?? 0)
]
}
private angle2Vector(v1: number[], v2: number[]): number {
return Math.acos(
(v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]) /
(
(v1[0] ** 2 + v1[1] ** 2 + v1[2] ** 2) ** 0.5 *
(v2[0] ** 2 + v2[1] ** 2 + v2[2] ** 2) ** 0.5
)
) * 180 / Math.PI;
}
private randomFocusRange(dir: number[], angle: number): number[] {
// 计算 X-Z 投影
let pxz = [dir[0] ?? 0, 0, dir[2] ?? 0];
// 通过叉乘计算垂直向量
let dxz: number[];
// 如果投影向量没有长度,使用单位向量
if (pxz[0] ** 2 + pxz[2] ** 2 === 0) {
dxz = [0, 0, 1];
}
// 通过叉乘计算垂直轴线
else {
dxz = [
dir[1] * pxz[2] - pxz[1] * dir[2],
dir[2] * pxz[0] - pxz[2] * dir[0],
dir[0] * pxz[1] - pxz[0] * dir[1]
];
let lenDxz = (dxz[0] ** 2 + dxz[1] ** 2 + dxz[2] ** 2) ** 0.5;
dxz = [dxz[0] / lenDxz, dxz[1] / lenDxz, dxz[2] / lenDxz];
}
// 航偏角 360 随机旋转
let randomH = this.rotateWithVec(dxz, dir, Math.random() * Math.PI * 2);
// 俯仰角 180 * R 随机旋转
let randomP = this.rotateWithVec(dir, randomH, (Math.random() - 0.5) * 2 * angle * Math.PI / 180);
return randomP;
}
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; const {maxFrequency, minFrequency, maxStrength, minStrength} = this.parameter;
@@ -41,11 +122,49 @@ class Brownian extends Behavior<IBrownianBehaviorParameter, IBrownianBehaviorEve
currentTime += t; currentTime += t;
if (currentTime > nextTime) { if (currentTime > nextTime) {
let randomDir: number[];
// 开启角度限制
if (this.parameter.dirLimit) {
// 计算当前速度大小
const vLen = individual.vectorLength(individual.velocity);
// 随机旋转算法
if (vLen > 0) {
randomDir = this.randomFocusRange(
[
individual.velocity[0] / vLen,
individual.velocity[1] / vLen,
individual.velocity[2] / vLen
],
this.parameter.angle / 2
);
if (isNaN(randomDir[0]) || isNaN(randomDir[1]) || isNaN(randomDir[2])) {
randomDir = this.randomFocus360()
}
}
else {
randomDir = this.randomFocus360()
}
}
// 随机生成算法
else {
randomDir = this.randomFocus360()
}
const randomLength = minStrength + Math.random() * (maxStrength - minStrength);
individual.applyForce( individual.applyForce(
minStrength + (Math.random() * 2 - 1) * (maxStrength - minStrength), randomDir[0] * randomLength,
minStrength + (Math.random() * 2 - 1) * (maxStrength - minStrength), randomDir[1] * randomLength,
minStrength + (Math.random() * 2 - 1) * (maxStrength - minStrength) randomDir[2] * randomLength
); );
nextTime = minFrequency + Math.random() * (maxFrequency - minFrequency); nextTime = minFrequency + Math.random() * (maxFrequency - minFrequency);
currentTime = 0; currentTime = 0;
} }
@@ -78,7 +197,15 @@ class Brownian extends Behavior<IBrownianBehaviorParameter, IBrownianBehaviorEve
"$Min.Strength": { "$Min.Strength": {
"ZH_CN": "最小强度", "ZH_CN": "最小强度",
"EN_US": "Minimum strength" "EN_US": "Minimum strength"
} },
"$Direction.Limit": {
"ZH_CN": "开启角度限制",
"EN_US": "Enable limit angle"
},
"$Angle": {
"ZH_CN": "限制立体角 (deg)",
"EN_US": "Restricted solid angle (deg)"
}
}; };
} }
+96
View File
@@ -0,0 +1,96 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type ICentralClusterBehaviorParameter = {
cluster: "CLG",
strength: "number",
range: "number"
}
type ICentralClusterBehaviorEvent = {}
class CentralCluster extends Behavior<ICentralClusterBehaviorParameter, ICentralClusterBehaviorEvent> {
public override behaviorId: string = "CentralCluster";
public override behaviorName: string = "$Title";
public override iconName: string = "ZoomToFit";
public override describe: string = "$Intro";
public override category: string = "$Interactive";
public override parameterOption = {
cluster: { name: "$Cluster", type: "CLG" },
strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 },
range: { type: "number", name: "$Range", defaultValue: 4, numberMin: 0, numberStep: .1 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let findCount = 0;
let centerPos: number[] = [0, 0, 0];
for (let i = 0; i < this.parameter.cluster.objects.length; i++) {
const targetGroup = this.parameter.cluster.objects[i];
targetGroup.individuals.forEach((targetIndividual) => {
// 排除自己
if (targetIndividual === individual) return;
let dis = targetIndividual.distanceTo(individual);
if (dis <= this.parameter.range) {
centerPos[0] += targetIndividual.position[0];
centerPos[1] += targetIndividual.position[1];
centerPos[2] += targetIndividual.position[2];
findCount ++;
}
});
}
if (findCount > 0) {
let dirX = centerPos[0] / findCount - individual.position[0];
let dirY = centerPos[1] / findCount - individual.position[1];
let dirZ = centerPos[2] / findCount - individual.position[2];
let length = individual.vectorLength(dirX, dirY, dirZ);
if (length > 0) {
individual.applyForce(
dirX * this.parameter.strength / length,
dirY * this.parameter.strength / length,
dirZ * this.parameter.strength / length
);
}
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "中心结群",
"EN_US": "Central cluster"
},
"$Intro": {
"ZH_CN": "个体将按照视野范围内目标方向结群对象个体的几何中心移动",
"EN_US": "The individual will move according to the geometric center of the grouped object individual in the target direction within the field of view"
},
"$Cluster": {
"ZH_CN": "中心结群对象",
"EN_US": "Central clustering object"
},
"$Strength": {
"ZH_CN": "结群强度",
"EN_US": "Clustering strength"
},
"$Range": {
"ZH_CN": "视野范围",
"EN_US": "Field of vision"
}
};
}
export { CentralCluster };
+18 -4
View File
@@ -6,6 +6,7 @@ import { Model } from "@Model/Model";
type IContactAssimilateBehaviorParameter = { type IContactAssimilateBehaviorParameter = {
target: "CLG", target: "CLG",
assimilate: "CG", assimilate: "CG",
self: "CG",
success: "number", success: "number",
range: "number" range: "number"
} }
@@ -27,15 +28,13 @@ class ContactAssimilate extends Behavior<IContactAssimilateBehaviorParameter, IC
public override parameterOption = { public override parameterOption = {
target: { type: "CLG", name: "$Target" }, target: { type: "CLG", name: "$Target" },
assimilate: { type: "CG", name: "$Assimilate" }, assimilate: { type: "CG", name: "$Assimilate" },
self: { type: "CG", name: "$Self" },
range: { type: "number", name: "$Range", defaultValue: .05, numberMin: 0, numberStep: .01 }, range: { type: "number", name: "$Range", defaultValue: .05, numberMin: 0, numberStep: .01 },
success: { type: "number", name: "$Success", defaultValue: 90, numberMin: 0, numberMax: 100, numberStep: 5 } success: { type: "number", name: "$Success", defaultValue: 90, numberMin: 0, numberMax: 100, numberStep: 5 }
}; };
public effect = (individual: Individual, group: Group, model: Model, t: number): void => { public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let assimilateGroup = this.parameter.assimilate.objects;
if (!assimilateGroup) return;
for (let i = 0; i < this.parameter.target.objects.length; i++) { for (let i = 0; i < this.parameter.target.objects.length; i++) {
const targetGroup = this.parameter.target.objects[i]; const targetGroup = this.parameter.target.objects[i];
@@ -50,7 +49,18 @@ class ContactAssimilate extends Behavior<IContactAssimilateBehaviorParameter, IC
// 成功判定 // 成功判定
if (Math.random() * 100 < this.parameter.success) { if (Math.random() * 100 < this.parameter.success) {
targetIndividual.transfer(assimilateGroup!);
// 同化目标
let assimilateGroup = this.parameter.assimilate.objects;
if (assimilateGroup) {
targetIndividual.transfer(assimilateGroup);
}
// 同化目标
let selfGroup = this.parameter.self.objects;
if (selfGroup) {
individual.transfer(selfGroup);
}
} }
} }
}); });
@@ -70,6 +80,10 @@ class ContactAssimilate extends Behavior<IContactAssimilateBehaviorParameter, IC
"ZH_CN": "到哪个群...", "ZH_CN": "到哪个群...",
"EN_US": "To group..." "EN_US": "To group..."
}, },
"$Self": {
"ZH_CN": "自身同化到...",
"EN_US": "Self assimilate to..."
},
"$Range": { "$Range": {
"ZH_CN": "同化范围 (m)", "ZH_CN": "同化范围 (m)",
"EN_US": "Assimilate range (m)" "EN_US": "Assimilate range (m)"
+12 -2
View File
@@ -6,7 +6,8 @@ import { Model } from "@Model/Model";
type IContactAttackingBehaviorParameter = { type IContactAttackingBehaviorParameter = {
target: "CLG", target: "CLG",
success: "number", success: "number",
range: "number" range: "number",
assimilate: "CG",
} }
type IContactAttackingBehaviorEvent = {} type IContactAttackingBehaviorEvent = {}
@@ -26,7 +27,8 @@ class ContactAttacking extends Behavior<IContactAttackingBehaviorParameter, ICon
public override parameterOption = { public override parameterOption = {
target: { type: "CLG", name: "$Target" }, target: { type: "CLG", name: "$Target" },
range: { type: "number", name: "$Range", defaultValue: .05, numberMin: 0, numberStep: .01 }, range: { type: "number", name: "$Range", defaultValue: .05, numberMin: 0, numberStep: .01 },
success: { type: "number", name: "$Success", defaultValue: 90, numberMin: 0, numberMax: 100, numberStep: 5 } success: { type: "number", name: "$Success", defaultValue: 90, numberMin: 0, numberMax: 100, numberStep: 5 },
assimilate: { type: "CG", name: "$Assimilate"}
}; };
public effect = (individual: Individual, group: Group, model: Model, t: number): void => { public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
@@ -46,6 +48,10 @@ class ContactAttacking extends Behavior<IContactAttackingBehaviorParameter, ICon
// 成功判定 // 成功判定
if (Math.random() * 100 < this.parameter.success) { if (Math.random() * 100 < this.parameter.success) {
targetIndividual.die(); targetIndividual.die();
if (this.parameter.assimilate?.objects) {
individual.transfer(this.parameter.assimilate.objects);
}
} }
} }
}); });
@@ -72,6 +78,10 @@ class ContactAttacking extends Behavior<IContactAttackingBehaviorParameter, ICon
"$Intro": { "$Intro": {
"ZH_CN": "攻击进入共进范围的目标群个体", "ZH_CN": "攻击进入共进范围的目标群个体",
"EN_US": "Attack the target group and individual entering the range" "EN_US": "Attack the target group and individual entering the range"
},
"$Assimilate": {
"ZH_CN": "同化",
"EN_US": "Assimilate"
} }
}; };
} }
+93
View File
@@ -0,0 +1,93 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type IDirectionClusterBehaviorParameter = {
cluster: "CLG",
strength: "number",
range: "number"
}
type IDirectionClusterBehaviorEvent = {}
class DirectionCluster extends Behavior<IDirectionClusterBehaviorParameter, IDirectionClusterBehaviorEvent> {
public override behaviorId: string = "DirectionCluster";
public override behaviorName: string = "$Title";
public override iconName: string = "RawSource";
public override describe: string = "$Intro";
public override category: string = "$Interactive";
public override parameterOption = {
cluster: { name: "$Cluster", type: "CLG" },
strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 },
range: { type: "number", name: "$Range", defaultValue: 4, numberMin: 0, numberStep: .1 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let findCount = 0;
let centerDir: number[] = [0, 0, 0];
for (let i = 0; i < this.parameter.cluster.objects.length; i++) {
const targetGroup = this.parameter.cluster.objects[i];
targetGroup.individuals.forEach((targetIndividual) => {
// 排除自己
if (targetIndividual === individual) return;
let dis = targetIndividual.distanceTo(individual);
if (dis <= this.parameter.range) {
centerDir[0] += targetIndividual.velocity[0];
centerDir[1] += targetIndividual.velocity[1];
centerDir[2] += targetIndividual.velocity[2];
findCount ++;
}
});
}
if (findCount > 0) {
let length = individual.vectorLength(centerDir);
if (length) {
individual.applyForce(
centerDir[0] * this.parameter.strength / length,
centerDir[1] * this.parameter.strength / length,
centerDir[2] * this.parameter.strength / length
);
}
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "方向结群",
"EN_US": "Directional clustering"
},
"$Intro": {
"ZH_CN": "个体将按照视野范围内目标方向结群对象个体的平均移动方向移动",
"EN_US": "Individuals will move according to the average moving direction of the grouped object individuals in the target direction within the field of vision"
},
"$Cluster": {
"ZH_CN": "方向结群对象",
"EN_US": "Directional clustering object"
},
"$Strength": {
"ZH_CN": "结群强度",
"EN_US": "Clustering strength"
},
"$Range": {
"ZH_CN": "视野范围",
"EN_US": "Field of vision"
}
};
}
export { DirectionCluster };
+83
View File
@@ -0,0 +1,83 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type IManufactureBehaviorParameter = {
maxFrequency: "number",
minFrequency: "number",
genTarget: "CG",
}
type IManufactureBehaviorEvent = {}
class Manufacture extends Behavior<IManufactureBehaviorParameter, IManufactureBehaviorEvent> {
public override behaviorId: string = "Manufacture";
public override behaviorName: string = "$Title";
public override iconName: string = "ProductionFloorManagement";
public override describe: string = "$Intro";
public override category: string = "$Initiative";
public override parameterOption = {
genTarget: { type: "CG", name: "$Gen.Target" },
maxFrequency: { type: "number", name: "$Max.Frequency", defaultValue: 5, numberStep: .1, numberMin: 0 },
minFrequency: { type: "number", name: "$Min.Frequency", defaultValue: 0, numberStep: .1, numberMin: 0 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
const {genTarget, maxFrequency, minFrequency} = this.parameter;
if (genTarget.objects) {
let nextTime = individual.getData("Manufacture.nextTime") ??
minFrequency + Math.random() * (maxFrequency - minFrequency);
let currentTime = individual.getData("Manufacture.currentTime") ?? 0;
if (currentTime > nextTime) {
// 生成个体
let newIndividual = genTarget.objects.new(1);
newIndividual.position = individual.position.concat([]);
nextTime = minFrequency + Math.random() * (maxFrequency - minFrequency);
currentTime = 0;
}
currentTime += t;
individual.setData("Manufacture.nextTime", nextTime);
individual.setData("Manufacture.currentTime", currentTime);
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "生产",
"EN_US": "Manufacture"
},
"$Intro": {
"ZH_CN": "在指定的群创造新的个体",
"EN_US": "Create new individuals in a given group"
},
"$Gen.Target": {
"ZH_CN": "目标群",
"EN_US": "Target group"
},
"$Max.Frequency": {
"ZH_CN": "最大频率",
"EN_US": "Maximum frequency"
},
"$Min.Frequency": {
"ZH_CN": "最小频率",
"EN_US": "Minimum frequency"
}
};
}
export { Manufacture };
+4 -4
View File
@@ -31,11 +31,11 @@ class PhysicsDynamics extends Behavior<IPhysicsDynamicsBehaviorParameter, IPhysi
limit: { name: "$Limit", type: "boolean", defaultValue: true }, limit: { name: "$Limit", type: "boolean", defaultValue: true },
maxAcceleration: { maxAcceleration: {
name: "$Max.Acceleration", type: "number", defaultValue: 6.25, name: "$Max.Acceleration", type: "number", defaultValue: 6.25,
numberStep: .1, numberMin: 0, condition: { key: "limit", value: true } numberStep: .1, numberMin: 0.0001, condition: { key: "limit", value: true }
}, },
maxVelocity: { maxVelocity: {
name: "$Max.Velocity", type: "number", defaultValue: 12.5, name: "$Max.Velocity", type: "number", defaultValue: 12.5,
numberStep: .1, numberMin: 0, condition: { key: "limit", value: true } numberStep: .1, numberMin: 0.0001, condition: { key: "limit", value: true }
}, },
}; };
@@ -64,7 +64,7 @@ class PhysicsDynamics extends Behavior<IPhysicsDynamicsBehaviorParameter, IPhysi
// 加速度约束 // 加速度约束
if (this.parameter.limit) { if (this.parameter.limit) {
const lengthA = individual.vectorLength(individual.acceleration); const lengthA = individual.vectorLength(individual.acceleration);
if (lengthA > this.parameter.maxAcceleration) { if (lengthA > this.parameter.maxAcceleration && lengthA) {
individual.acceleration[0] = individual.acceleration[0] * this.parameter.maxAcceleration / lengthA; individual.acceleration[0] = individual.acceleration[0] * this.parameter.maxAcceleration / lengthA;
individual.acceleration[1] = individual.acceleration[1] * this.parameter.maxAcceleration / lengthA; individual.acceleration[1] = individual.acceleration[1] * this.parameter.maxAcceleration / lengthA;
individual.acceleration[2] = individual.acceleration[2] * this.parameter.maxAcceleration / lengthA; individual.acceleration[2] = individual.acceleration[2] * this.parameter.maxAcceleration / lengthA;
@@ -79,7 +79,7 @@ class PhysicsDynamics extends Behavior<IPhysicsDynamicsBehaviorParameter, IPhysi
// 速度约束 // 速度约束
if (this.parameter.limit) { if (this.parameter.limit) {
const lengthV = individual.vectorLength(individual.velocity); const lengthV = individual.vectorLength(individual.velocity);
if (lengthV > this.parameter.maxVelocity) { if (lengthV > this.parameter.maxVelocity && lengthV) {
individual.velocity[0] = individual.velocity[0] * this.parameter.maxVelocity / lengthV; individual.velocity[0] = individual.velocity[0] * this.parameter.maxVelocity / lengthV;
individual.velocity[1] = individual.velocity[1] * this.parameter.maxVelocity / lengthV; individual.velocity[1] = individual.velocity[1] * this.parameter.maxVelocity / lengthV;
individual.velocity[2] = individual.velocity[2] * this.parameter.maxVelocity / lengthV; individual.velocity[2] = individual.velocity[2] * this.parameter.maxVelocity / lengthV;
+160
View File
@@ -0,0 +1,160 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type ISampleTrackingBehaviorParameter = {
target: "CLG",
key: "string",
strength: "number",
range: "number",
angle: "number",
accuracy: "number"
}
type ISampleTrackingBehaviorEvent = {}
class SampleTracking extends Behavior<ISampleTrackingBehaviorParameter, ISampleTrackingBehaviorEvent> {
public override behaviorId: string = "SampleTracking";
public override behaviorName: string = "$Title";
public override iconName: string = "Video360Generic";
public override describe: string = "$Intro";
public override category: string = "$Initiative";
public override parameterOption = {
target: { type: "CLG", name: "$Target" },
key: { type: "string", name: "$Key"},
range: { type: "number", name: "$Range", defaultValue: 4, numberMin: 0, numberStep: .1 },
angle: { type: "number", name: "$Angle", defaultValue: 180, numberMin: 0, numberMax: 360, numberStep: 5 },
strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 },
accuracy: { type: "number", name: "$Accuracy", defaultValue: 5, numberMin: 0, numberMax: 180, numberStep: 1 }
};
private angle2Vector(v1: number[], v2: number[]): number {
return Math.acos(
(v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]) /
(
(v1[0] ** 2 + v1[1] ** 2 + v1[2] ** 2) ** 0.5 *
(v2[0] ** 2 + v2[1] ** 2 + v2[2] ** 2) ** 0.5
)
) * 180 / Math.PI;
}
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
const dirArr: number[][] = []; const valArr: number[] = [];
for (let i = 0; i < this.parameter.target.objects.length; i++) {
const targetGroup = this.parameter.target.objects[i];
targetGroup.individuals.forEach((targetIndividual) => {
// 计算距离
let dis = targetIndividual.distanceTo(individual);
if (dis > this.parameter.range) return;
// 计算方向
let targetDir = [
targetIndividual.position[0] - individual.position[0],
targetIndividual.position[1] - individual.position[1],
targetIndividual.position[2] - individual.position[2]
];
// 计算视线角度
let angle = this.angle2Vector(individual.velocity, targetDir);
// 在可视角度内
if (angle < (this.parameter.angle ?? 360) / 2) {
// 采样
let isFindNest = false;
for (let i = 0; i < valArr.length; i++) {
// 计算采样角度
let sampleAngle = this.angle2Vector(dirArr[i], targetDir);
// 小于采样精度,合并
if (sampleAngle < this.parameter.accuracy ?? 5) {
dirArr[i][0] += targetDir[0];
dirArr[i][1] += targetDir[1];
dirArr[i][2] += targetDir[2];
valArr[i] += targetIndividual.getData(this.parameter.key) ?? 0;
isFindNest = true;
}
}
if (!isFindNest) {
// 保存
dirArr.push(targetDir);
valArr.push(targetIndividual.getData(this.parameter.key) ?? 0);
}
}
});
}
// 计算最大方向
let maxVal = -1; let maxDir: number[] | undefined;
for (let i = 0; i < valArr.length; i++) {
if (valArr[i] > maxVal) {
maxVal = valArr[i];
maxDir = dirArr[i];
}
}
if (maxDir) {
const dir = individual.vectorNormalize(maxDir);
individual.applyForce(
dir[0] * this.parameter.strength,
dir[1] * this.parameter.strength,
dir[2] * this.parameter.strength
);
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "采样追踪",
"EN_US": "Sample tracking"
},
"$Target": {
"ZH_CN": "追踪目标",
"EN_US": "Tracking target"
},
"$Key": {
"ZH_CN": "计算键值",
"EN_US": "Calculate key value"
},
"$Accuracy": {
"ZH_CN": "采样精度",
"EN_US": "Sampling accuracy"
},
"$Range": {
"ZH_CN": "追踪范围 (m)",
"EN_US": "Tracking range (m)"
},
"$Strength": {
"ZH_CN": "追踪强度系数",
"EN_US": "Tracking intensity coefficient"
},
"$Intro": {
"ZH_CN": "个体将主动向目标个体较多的方向发起追踪",
"EN_US": "Individuals will actively initiate tracking in the direction of more target individuals"
},
"$Interactive": {
"ZH_CN": "交互",
"EN_US": "Interactive"
},
"$Angle": {
"ZH_CN": "可视角度",
"EN_US": "Viewing angle"
}
};
}
export { SampleTracking };
+32 -3
View File
@@ -7,6 +7,7 @@ type ITrackingBehaviorParameter = {
target: "CLG", target: "CLG",
strength: "number", strength: "number",
range: "number", range: "number",
angle: "number",
lock: "boolean" lock: "boolean"
} }
@@ -28,12 +29,23 @@ class Tracking extends Behavior<ITrackingBehaviorParameter, ITrackingBehaviorEve
target: { type: "CLG", name: "$Target" }, target: { type: "CLG", name: "$Target" },
lock: { type: "boolean", name: "$Lock", defaultValue: false }, lock: { type: "boolean", name: "$Lock", defaultValue: false },
range: { type: "number", name: "$Range", defaultValue: 4, numberMin: 0, numberStep: .1 }, range: { type: "number", name: "$Range", defaultValue: 4, numberMin: 0, numberStep: .1 },
angle: { type: "number", name: "$Angle", defaultValue: 180, numberMin: 0, numberMax: 360, numberStep: 5 },
strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 } strength: { type: "number", name: "$Strength", defaultValue: 1, numberMin: 0, numberStep: .1 }
}; };
private target: Individual | undefined = undefined; private target: Individual | undefined = undefined;
private currentDistant: number = Infinity; private currentDistant: number = Infinity;
private angle2Vector(v1: number[], v2: number[]): number {
return Math.acos(
(v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]) /
(
(v1[0] ** 2 + v1[1] ** 2 + v1[2] ** 2) ** 0.5 *
(v2[0] ** 2 + v2[1] ** 2 + v2[2] ** 2) ** 0.5
)
) * 180 / Math.PI;
}
private searchTarget(individual: Individual) { private searchTarget(individual: Individual) {
for (let i = 0; i < this.parameter.target.objects.length; i++) { for (let i = 0; i < this.parameter.target.objects.length; i++) {
@@ -46,8 +58,21 @@ class Tracking extends Behavior<ITrackingBehaviorParameter, ITrackingBehaviorEve
let dis = targetIndividual.distanceTo(individual); let dis = targetIndividual.distanceTo(individual);
if (dis < this.currentDistant && dis <= this.parameter.range) { if (dis < this.currentDistant && dis <= this.parameter.range) {
this.target = targetIndividual;
this.currentDistant = dis; // 计算目标方位
const targetDir = [
targetIndividual.position[0] - individual.position[0],
targetIndividual.position[1] - individual.position[1],
targetIndividual.position[2] - individual.position[2]
];
// 计算角度
const angle = this.angle2Vector(individual.velocity, targetDir);
if (angle < (this.parameter.angle ?? 360) / 2) {
this.target = targetIndividual;
this.currentDistant = dis;
}
} }
}); });
@@ -150,7 +175,11 @@ class Tracking extends Behavior<ITrackingBehaviorParameter, ITrackingBehaviorEve
"$Interactive": { "$Interactive": {
"ZH_CN": "交互", "ZH_CN": "交互",
"EN_US": "Interactive" "EN_US": "Interactive"
} },
"$Angle": {
"ZH_CN": "可视角度",
"EN_US": "Viewing angle"
}
}; };
} }
+100
View File
@@ -0,0 +1,100 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type IWastageBehaviorParameter = {
key: "string",
value: "number",
speed: "number",
threshold: "number",
kill: "boolean",
assimilate: "CG"
}
type IWastageBehaviorEvent = {}
class Wastage extends Behavior<IWastageBehaviorParameter, IWastageBehaviorEvent> {
public override behaviorId: string = "Wastage";
public override behaviorName: string = "$Title";
public override iconName: string = "BackgroundColor";
public override describe: string = "$Intro";
public override category: string = "$Initiative";
public override parameterOption = {
key: { type: "string", name: "$Key" },
value: { type: "number", name: "$Value", defaultValue: 100, numberStep: 1 },
speed: { type: "number", name: "$Speed", defaultValue: 1, numberStep: .1 },
threshold: { type: "number", name: "$Threshold", defaultValue: 0, numberStep: 1 },
kill: { type: "boolean", name: "$Kill", defaultValue: true },
assimilate: { type: "CG", name: "$Assimilate", condition: { key: "kill", value: false } }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
const key = this.parameter.key;
if (!key) return;
let currentValue = individual.getData(`Wastage.${key}`) ?? this.parameter.value;
currentValue -= this.parameter.speed * t;
// 超过阈值
if (currentValue < this.parameter.threshold) {
currentValue = undefined;
// 杀死个体
if (this.parameter.kill) {
individual.die();
}
// 开启同化
else if (this.parameter.assimilate.objects) {
individual.transfer(this.parameter.assimilate.objects);
}
}
individual.setData(`Wastage.${key}`, currentValue);
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "流逝",
"EN_US": "Wastage"
},
"$Intro": {
"ZH_CN": "随着时间流逝",
"EN_US": "As time goes by"
},
"$Key": {
"ZH_CN": "元数据",
"EN_US": "Metadata"
},
"$Value": {
"ZH_CN": "默认数值",
"EN_US": "Default value"
},
"$Speed": {
"ZH_CN": "流逝速度 (c/s)",
"EN_US": "Passing speed (c/s)"
},
"$Threshold": {
"ZH_CN": "阈值",
"EN_US": "Threshold"
},
"$Kill": {
"ZH_CN": "死亡",
"EN_US": "Death"
},
"$Assimilate": {
"ZH_CN": "同化",
"EN_US": "Assimilate"
}
};
}
export { Wastage };
@@ -188,11 +188,6 @@ class CommandBar extends Component<IMixinSettingProps & IMixinStatusProps, IComm
this.props.status ? this.props.status.newLabel() : undefined; this.props.status ? this.props.status.newLabel() : undefined;
}} }}
/> />
<CommandButton
iconName="Camera"
i18NKey="Command.Bar.Camera.Info"
/>
</div> </div>
<div> <div>
<CommandButton <CommandButton
@@ -3,4 +3,6 @@
div.setting-popup { div.setting-popup {
width: 100%; width: 100%;
height: 100%; height: 100%;
box-sizing: border-box;
padding: 10px;
} }
+37 -2
View File
@@ -2,8 +2,11 @@ import { Component, ReactNode } from "react";
import { Popup } from "@Context/Popups"; import { Popup } from "@Context/Popups";
import { Theme } from "@Component/Theme/Theme"; import { Theme } from "@Component/Theme/Theme";
import { Localization } from "@Component/Localization/Localization"; import { Localization } from "@Component/Localization/Localization";
import { useSettingWithEvent, IMixinSettingProps, Themes } from "@Context/Setting";
import { ComboInput } from "@Input/ComboInput/ComboInput";
import "./SettingPopup.scss"; import "./SettingPopup.scss";
interface ISettingPopupProps { interface ISettingPopupProps {
} }
@@ -24,10 +27,42 @@ class SettingPopup extends Popup<ISettingPopupProps> {
} }
} }
class SettingPopupComponent extends Component<ISettingPopupProps> { @useSettingWithEvent("themes", "language")
class SettingPopupComponent extends Component<ISettingPopupProps & IMixinSettingProps> {
public render(): ReactNode { public render(): ReactNode {
return <Theme className="setting-popup"></Theme> return <Theme className="setting-popup">
<ComboInput
keyI18n="Language"
allOption={[
{ key: "EN_US", i18n: "EN_US" },
{ key: "ZH_CN", i18n: "ZH_CN" }
]}
value={{
key: this.props.setting?.language ?? "EN_US",
i18n: this.props.setting?.language ?? "EN_US"
}}
valueChange={(data) => {
this.props.setting?.setProps("language", data.key as any);
}}
/>
<ComboInput
keyI18n="Themes"
allOption={[
{ key: Themes.dark as any, i18n: "Themes.Dark" },
{ key: Themes.light as any, i18n: "Themes.Light" }
]}
value={{
key: this.props.setting?.themes ?? Themes.dark as any,
i18n: this.props.setting?.themes === Themes.dark ? "Themes.Dark" : "Themes.Light"
}}
valueChange={(data) => {
this.props.setting?.setProps("themes", parseInt(data.key));
}}
/>
</Theme>
} }
} }
+5
View File
@@ -44,6 +44,11 @@ class Setting extends Emitter<ISettingEvents> {
*/ */
public layout: Layout = new Layout(); public layout: Layout = new Layout();
/**
* 是否显示线性图表
*/
public lineChartType: boolean = false;
/** /**
* 设置参数 * 设置参数
*/ */
+2
View File
@@ -38,6 +38,7 @@ interface IStatusEvent {
physicsLoop: number; physicsLoop: number;
recordLoop: number; recordLoop: number;
offlineLoop: number; offlineLoop: number;
modelUpdate: void;
mouseModChange: void; mouseModChange: void;
focusObjectChange: void; focusObjectChange: void;
focusLabelChange: void; focusLabelChange: void;
@@ -132,6 +133,7 @@ class Status extends Emitter<IStatusEvent> {
this.actuator.on("loop", (t) => { this.emit("physicsLoop", t) }); this.actuator.on("loop", (t) => { this.emit("physicsLoop", t) });
this.actuator.on("record", (t) => { this.emit("recordLoop", t) }); this.actuator.on("record", (t) => { this.emit("recordLoop", t) });
this.actuator.on("offline", (t) => { this.emit("offlineLoop", t) }); this.actuator.on("offline", (t) => { this.emit("offlineLoop", t) });
this.actuator.on("modelUpdate", () => { this.emit("modelUpdate") });
// 对象变化事件 // 对象变化事件
this.model.on("objectChange", () => this.emit("objectChange")); this.model.on("objectChange", () => this.emit("objectChange"));
+7
View File
@@ -1,6 +1,10 @@
const EN_US = { const EN_US = {
"Language": "Language",
"EN_US": "English (US)", "EN_US": "English (US)",
"ZH_CN": "Chinese (Simplified)", "ZH_CN": "Chinese (Simplified)",
"Themes": "Themes",
"Themes.Dark": "Dark",
"Themes.Light": "Light",
"Header.Bar.Title": "Living Together | Emulator", "Header.Bar.Title": "Living Together | Emulator",
"Header.Bar.Title.Info": "Group Behavior Research Emulator", "Header.Bar.Title.Info": "Group Behavior Research Emulator",
"Header.Bar.File.Name.Info": "{file} ({status})", "Header.Bar.File.Name.Info": "{file} ({status})",
@@ -58,6 +62,8 @@ const EN_US = {
"Panel.Info.Behavior.Clip.Player": "Pre render recorded data", "Panel.Info.Behavior.Clip.Player": "Pre render recorded data",
"Panel.Title.Behavior.Clip.Details": "Clip", "Panel.Title.Behavior.Clip.Details": "Clip",
"Panel.Info.Behavior.Clip.Details": "Edit view clip attributes", "Panel.Info.Behavior.Clip.Details": "Edit view clip attributes",
"Panel.Info.Statistics": "View statistics",
"Panel.Title.Statistics": "Statistics",
"Panel.Info.Behavior.Clip.Time.Formate": "{current} / {all} / {fps}fps", "Panel.Info.Behavior.Clip.Time.Formate": "{current} / {all} / {fps}fps",
"Panel.Info.Behavior.Clip.Record.Formate": "Record: {time}", "Panel.Info.Behavior.Clip.Record.Formate": "Record: {time}",
"Panel.Info.Behavior.Clip.Uname.Clip": "Waiting for recording...", "Panel.Info.Behavior.Clip.Uname.Clip": "Waiting for recording...",
@@ -164,6 +170,7 @@ const EN_US = {
"Panel.Info.Behavior.Details.Parameter.Key.Vec.Z": "{key} Z", "Panel.Info.Behavior.Details.Parameter.Key.Vec.Z": "{key} Z",
"Panel.Info.Clip.List.Error.Nodata": "There is no clip, please click the record button to record, or click the plus sign to create", "Panel.Info.Clip.List.Error.Nodata": "There is no clip, please click the record button to record, or click the plus sign to create",
"Panel.Info.Clip.Details.Error.Nodata": "Specify a clip to view an attribute", "Panel.Info.Clip.Details.Error.Nodata": "Specify a clip to view an attribute",
"Panel.Info.Statistics.Nodata": "There are no groups in the model or clip",
"Info.Hint.Save.After.Close": "Any unsaved progress will be lost. Are you sure you want to continue?", "Info.Hint.Save.After.Close": "Any unsaved progress will be lost. Are you sure you want to continue?",
"Info.Hint.Load.File.Title": "Load save", "Info.Hint.Load.File.Title": "Load save",
"Info.Hint.Load.File.Intro": "Release to load the dragged save file", "Info.Hint.Load.File.Intro": "Release to load the dragged save file",
+11 -4
View File
@@ -1,6 +1,10 @@
const ZH_CN = { const ZH_CN = {
"Language": "语言",
"EN_US": "英语 (美国)", "EN_US": "英语 (美国)",
"ZH_CN": "中文 (简体)", "ZH_CN": "中文 (简体)",
"Themes": "主题",
"Themes.Dark": "黑暗",
"Themes.Light": "亮色",
"Header.Bar.Title": "群生共进 | 仿真器", "Header.Bar.Title": "群生共进 | 仿真器",
"Header.Bar.Title.Info": "群体行为研究仿真器", "Header.Bar.Title.Info": "群体行为研究仿真器",
"Header.Bar.File.Name.Info": "{file} ({status})", "Header.Bar.File.Name.Info": "{file} ({status})",
@@ -22,10 +26,10 @@ const ZH_CN = {
"Command.Bar.Camera.Info": "渲染器设置", "Command.Bar.Camera.Info": "渲染器设置",
"Command.Bar.Setting.Info": "全局设置", "Command.Bar.Setting.Info": "全局设置",
"Input.Error.Not.Number": "请输入数字", "Input.Error.Not.Number": "请输入数字",
"Input.Error.Max": "输入数值须小于 {number}", "Input.Error.Max": "输入数值须小于 {num}",
"Input.Error.Min": "输入数值须大于 {number}", "Input.Error.Min": "输入数值须大于 {num}",
"Input.Error.Length": "输入内容长度须小于 {number}", "Input.Error.Length": "输入内容长度须小于 {num}",
"Input.Error.Length.Less": "输入内容长度须大于 {number}", "Input.Error.Length.Less": "输入内容长度须大于 {num}",
"Input.Error.Select": "选择对象 ...", "Input.Error.Select": "选择对象 ...",
"Input.Error.Combo": "选择选项 ...", "Input.Error.Combo": "选择选项 ...",
"Object.List.New.Group": "群对象 {id}", "Object.List.New.Group": "群对象 {id}",
@@ -58,6 +62,8 @@ const ZH_CN = {
"Panel.Info.Behavior.Clip.Player": "预渲染录制数据", "Panel.Info.Behavior.Clip.Player": "预渲染录制数据",
"Panel.Title.Behavior.Clip.Details": "剪辑", "Panel.Title.Behavior.Clip.Details": "剪辑",
"Panel.Info.Behavior.Clip.Details": "编辑查看剪辑片段属性", "Panel.Info.Behavior.Clip.Details": "编辑查看剪辑片段属性",
"Panel.Info.Statistics": "查看统计信息",
"Panel.Title.Statistics": "统计",
"Panel.Info.Behavior.Clip.Time.Formate": "{current} / {all} / {fps} fps", "Panel.Info.Behavior.Clip.Time.Formate": "{current} / {all} / {fps} fps",
"Panel.Info.Behavior.Clip.Record.Formate": "录制: {time}", "Panel.Info.Behavior.Clip.Record.Formate": "录制: {time}",
"Panel.Info.Behavior.Clip.Uname.Clip": "等待录制...", "Panel.Info.Behavior.Clip.Uname.Clip": "等待录制...",
@@ -164,6 +170,7 @@ const ZH_CN = {
"Panel.Info.Behavior.Details.Parameter.Key.Vec.Z": "{key} Z 坐标", "Panel.Info.Behavior.Details.Parameter.Key.Vec.Z": "{key} Z 坐标",
"Panel.Info.Clip.List.Error.Nodata": "没有剪辑片段,请点击录制按钮录制,或者点击加号创建", "Panel.Info.Clip.List.Error.Nodata": "没有剪辑片段,请点击录制按钮录制,或者点击加号创建",
"Panel.Info.Clip.Details.Error.Nodata": "请指定一个剪辑片段以查看属性", "Panel.Info.Clip.Details.Error.Nodata": "请指定一个剪辑片段以查看属性",
"Panel.Info.Statistics.Nodata": "模型或剪辑中不存在任何群",
"Info.Hint.Save.After.Close": "任何未保存的进度都会丢失, 确定要继续吗?", "Info.Hint.Save.After.Close": "任何未保存的进度都会丢失, 确定要继续吗?",
"Info.Hint.Load.File.Title": "加载存档", "Info.Hint.Load.File.Title": "加载存档",
"Info.Hint.Load.File.Intro": "释放以加载拽入的存档", "Info.Hint.Load.File.Intro": "释放以加载拽入的存档",
+2
View File
@@ -14,6 +14,7 @@ interface IActuatorEvent {
record: number; record: number;
loop: number; loop: number;
offline: number; offline: number;
modelUpdate: void;
} }
/** /**
@@ -401,6 +402,7 @@ class Actuator extends Emitter<IActuatorEvent> {
} }
this.emit("loop", this.alignTimer); this.emit("loop", this.alignTimer);
this.emit("modelUpdate");
this.alignTimer = 0; this.alignTimer = 0;
} }
} }
@@ -74,7 +74,7 @@ class SimulatorDesktop extends Component {
}, },
{ {
items: [{ items: [{
panels: ["ObjectList"] panels: ["ObjectList", "Statistics"]
}, { }, {
panels: ["GroupDetails", "RangeDetails", "LabelDetails", "BehaviorDetails", "ClipDetails"] panels: ["GroupDetails", "RangeDetails", "LabelDetails", "BehaviorDetails", "ClipDetails"]
}], }],
+1 -1
View File
@@ -65,7 +65,7 @@ class SimulatorWeb extends Component {
}, },
{ {
items: [{ items: [{
panels: ["ObjectList"] panels: ["ObjectList", "Statistics"]
}, { }, {
panels: ["GroupDetails", "RangeDetails", "LabelDetails", "BehaviorDetails", "ClipDetails"] panels: ["GroupDetails", "RangeDetails", "LabelDetails", "BehaviorDetails", "ClipDetails"]
}], }],
+6
View File
@@ -13,6 +13,7 @@ import { BehaviorDetails } from "@Panel/BehaviorDetails/BehaviorDetails";
import { ClipPlayer } from "@Panel/ClipPlayer/ClipPlayer"; import { ClipPlayer } from "@Panel/ClipPlayer/ClipPlayer";
import { ClipRecorder } from "@Panel/ClipPlayer/ClipRecorder"; import { ClipRecorder } from "@Panel/ClipPlayer/ClipRecorder";
import { ClipDetails } from "@Panel/ClipDetails/ClipDetails"; import { ClipDetails } from "@Panel/ClipDetails/ClipDetails";
import { Statistics } from "@Panel/Statistics/Statistics";
interface IPanelInfo { interface IPanelInfo {
nameKey: string; nameKey: string;
@@ -36,6 +37,7 @@ type PanelId = ""
| "BehaviorDetails" // 行为属性 | "BehaviorDetails" // 行为属性
| "ClipPlayer" // 剪辑影片 | "ClipPlayer" // 剪辑影片
| "ClipDetails" // 剪辑详情 | "ClipDetails" // 剪辑详情
| "Statistics" // 统计信息
; ;
const PanelInfoMap = new Map<PanelId, IPanelInfo>(); const PanelInfoMap = new Map<PanelId, IPanelInfo>();
@@ -79,6 +81,10 @@ PanelInfoMap.set("ClipDetails", {
nameKey: "Panel.Title.Behavior.Clip.Details", introKay: "Panel.Info.Behavior.Clip.Details", nameKey: "Panel.Title.Behavior.Clip.Details", introKay: "Panel.Info.Behavior.Clip.Details",
class: ClipDetails class: ClipDetails
}); });
PanelInfoMap.set("Statistics", {
nameKey: "Panel.Title.Statistics", introKay: "Panel.Info.Statistics",
class: Statistics
});
function getPanelById(panelId: PanelId): ReactNode { function getPanelById(panelId: PanelId): ReactNode {
switch (panelId) { switch (panelId) {
+63
View File
@@ -0,0 +1,63 @@
@import "../../Component/Theme/Theme.scss";
div.statistics-panel {
width: 100%;
height: 100%;
min-height: 100%;
div.statistics-chart {
box-sizing: border-box;
padding-top: 10px;
max-width: 400px;
min-height: 100%;
height: 100%;
width: 100%;
}
div.statistics-switch {
width: 100%;
height: 0;
display: flex;
justify-content: flex-end;
div.switch-button {
width: 24px;
height: 24px;
position: relative;
user-select: none;
right: -10px;
top: -2px;
border-radius: 3px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
}
}
div.statistics-panel.dark {
div.switch-button {
background-color: $lt-bg-color-lvl2-dark;
color: $lt-font-color-lvl2-dark;
}
div.switch-button:hover {
background-color: $lt-bg-color-lvl1-dark;
color: $lt-font-color-lvl1-dark;
}
}
div.statistics-panel.light {
div.switch-button {
background-color: $lt-bg-color-lvl2-light;
color: $lt-font-color-lvl2-light;
}
div.switch-button:hover {
background-color: $lt-bg-color-lvl1-light;
color: $lt-font-color-lvl1-light;
}
}
+303
View File
@@ -0,0 +1,303 @@
import { Component, ReactNode } from "react";
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
import { useSettingWithEvent, IMixinSettingProps, Themes } from "@Context/Setting";
import {
Chart as ChartJS, CategoryScale, LinearScale,
BarElement, Tooltip, Legend, Decimation,
PointElement, LineElement, Title
} from 'chart.js';
import { Bar, Line } from 'react-chartjs-2';
import { Theme } from "@Component/Theme/Theme";
import { Icon } from "@fluentui/react";
import { IAnyObject, Model } from "@Model/Model";
import { Group } from "@Model/Group";
import { ActuatorModel } from "@Model/Actuator";
import { Message } from "@Input/Message/Message";
import { Clip, IFrame } from "@Model/Clip";
import "./Statistics.scss";
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
Tooltip,
Legend,
PointElement,
LineElement,
Title,
Decimation
);
interface IStatisticsProps {
}
@useSettingWithEvent("themes", "language", "lineChartType")
@useStatusWithEvent("focusClipChange", "actuatorStartChange", "fileLoad", "modelUpdate", "recordLoop", "individualChange")
class Statistics extends Component<IStatisticsProps & IMixinStatusProps & IMixinSettingProps> {
public barDarkOption = {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: {
position: 'bottom' as const,
labels: { boxWidth: 10, boxHeight: 10, color: 'rgba(255, 255, 255, .5)' }
}},
scales: {
x: { grid: { color: 'rgba(255, 255, 255, .2)' }, title: { color: 'rgba(255, 255, 255, .5)'} },
y: { grid: { color: 'rgba(255, 255, 255, .2)', borderDash: [3, 3] }, title: { color: 'rgba(255, 255, 255, .5)'} }
}
};
public barLightOption = {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: {
position: 'bottom' as const,
labels: { boxWidth: 10, boxHeight: 10, color: 'rgba(0, 0, 0, .5)' }
}},
scales: {
x: { grid: { color: 'rgba(0, 0, 0, .2)' }, title: { color: 'rgba(0, 0, 0, .5)'} },
y: { grid: { color: 'rgba(0, 0, 0, .2)', borderDash: [3, 3] }, title: { color: 'rgba(0, 0, 0, .5)'} }
}
};
private modelBarChart(model: Model, theme: boolean) {
const datasets: any[] = [];
const labels: any[] = ["Group"];
// 收集数据
model.objectPool.forEach((obj) => {
let label = obj.displayName;
let color = `rgb(${obj.color.map((v) => Math.floor(v * 255)).join(",")})`;
if (obj instanceof Group) {
datasets.push({label, data: [obj.individuals.size], backgroundColor: color});
}
});
if (datasets.length <= 0) {
return <Message i18nKey="Panel.Info.Statistics.Nodata"/>
}
return <Bar
data={{datasets, labels}}
options={theme ? this.barLightOption : this.barDarkOption }
/>
}
private clipBarChart(frame: IFrame, theme: boolean) {
const datasets: any[] = [];
const labels: any[] = ["Group"];
// 收集数据
frame.commands.forEach((command) => {
let label = command.name;
let color = `rgb(${command.parameter?.color.map((v: number) => Math.floor(v * 255)).join(",")})`;
if (command.type === "points") {
datasets.push({label, data: [(command.data?.length ?? 0) / 3], backgroundColor: color});
}
});
if (datasets.length <= 0) {
return <Message i18nKey="Panel.Info.Statistics.Nodata"/>
}
return <Bar
data={{datasets, labels}}
options={ theme ? this.barLightOption : this.barDarkOption }
/>
}
public lineDarkOption = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom' as const,
labels: { boxWidth: 10, boxHeight: 10, color: 'rgba(255, 255, 255, .5)' },
decimation: { enabled: true }
},
decimation: { enabled: true, algorithm: "lttb" as const, samples: 100 }
},
scales: {
x: { grid: { color: 'rgba(255, 255, 255, .2)' }, type: "linear", title: { color: 'rgba(255, 255, 255, .5)'} },
y: { grid: { color: 'rgba(255, 255, 255, .2)', borderDash: [3, 3] }, title: { color: 'rgba(255, 255, 255, .5)'} }
}
};
public lineLightOption = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom' as const,
labels: { boxWidth: 10, boxHeight: 10, color: 'rgba(0, 0, 0, .5)' },
},
decimation: { enabled: true, algorithm: "lttb" as const, samples: 100 }
},
scales: {
x: { grid: { color: 'rgba(0, 0, 0, .2)' }, title: { color: 'rgba(0, 0, 0, .5)'} },
y: { grid: { color: 'rgba(0, 0, 0, .2)', borderDash: [3, 3] }, title: { color: 'rgba(0, 0, 0, .5)'} }
}
};
private clipLineChart(clip: Clip, theme: boolean) {
type IDataSet = {label: string, data: number[], id: string} & IAnyObject;
const datasets: IDataSet[] = [];
const labels: number[] = [];
let frameLen: number = 0;
let lastDataSet: Map<string, number> | undefined;
let lastProcess: number | undefined;
// 收集数据
clip.frames.forEach((frame) => {
const frameData = new Map<string, number>();
frame.commands.forEach((command) => {
if (command.type !== "points") return;
let findKey: IDataSet | undefined;
for (let i = 0; i < datasets.length; i++) {
if (datasets[i].id === command.id) {
findKey = datasets[i];
break;
}
}
// 记录当前数据
frameData.set(command.id, (command.data?.length ?? 0) / 3);
// 新建数据
if (!findKey) {
const color = `rgb(${command.parameter?.color.map((v: number) => Math.floor(v * 255)).join(",")})`;
findKey = {} as any;
findKey!.label = command.name ?? "";
findKey!.backgroundColor = color;
findKey!.borderColor = color;
findKey!.id = command.id;
findKey!.pointRadius = 0;
findKey!.borderWidth = 1.5;
findKey!.borderCapStyle = "round";
findKey!.borderJoinStyle = "round";
findKey!.pointHitRadius = 8;
// 补充数据
findKey!.data = new Array(frameLen).fill(0);
datasets.push(findKey!);
}
});
// 与上一帧数据进行对比
const isSameData = datasets.every((value: IDataSet) => {
if (value.data[frameLen - 1] === frameData.get(value.id)) {
return true;
} else {
return false;
}
});
lastDataSet = frameData;
lastProcess = frame.process;
// 如果是不同数据 纪录
if (!isSameData) {
datasets.forEach((value: IDataSet) => {
value.data.push(frameData.get(value.id) ?? 0);
});
frameLen ++;
labels.push(frame.process);
}
});
// 记录最后一帧数据
if (lastDataSet && lastProcess !== labels[labels.length - 1]) {
datasets.forEach((value: IDataSet) => {
value.data.push(lastDataSet!.get(value.id) ?? 0);
});
frameLen ++;
labels.push(lastProcess!);
}
if (datasets.length <= 0) {
return <Message i18nKey="Panel.Info.Statistics.Nodata"/>
}
return <Line
options={ theme ? this.lineLightOption : this.lineDarkOption }
data={{labels, datasets }}
/>;
}
private renderChart() {
let themes = this.props.setting?.themes === Themes.light;
let lineChartType = this.props.setting?.lineChartType;
// 播放模式
if (this.props.status?.focusClip) {
if (this.props.status.actuator.playClip && lineChartType) {
return this.clipLineChart(this.props.status.actuator.playClip, themes);
}
if (this.props.status.actuator.playFrame) {
return this.clipBarChart(this.props.status.actuator.playFrame, themes);
}
}
// 正在录制中
else if (
this.props.status?.actuator.mod === ActuatorModel.Record ||
this.props.status?.actuator.mod === ActuatorModel.Offline
) {
if (this.props.status.actuator.recordClip && lineChartType) {
return this.clipLineChart(this.props.status.actuator.recordClip, themes);
}
return this.modelBarChart(this.props.status.model, themes);
}
// 主时钟运行
else if (this.props.status) {
return this.modelBarChart(this.props.status.model, themes);
}
}
public render(): ReactNode {
return <Theme className="statistics-panel">
{
(
this.props.status?.focusClip ||
this.props.status?.actuator.mod === ActuatorModel.Record ||
this.props.status?.actuator.mod === ActuatorModel.Offline
) ?
<div className="statistics-switch">
<div className="switch-button" onClick={() => {
this.props.setting?.setProps("lineChartType", !this.props.setting?.lineChartType);
}}>
<Icon iconName={
this.props.setting?.lineChartType ? "BarChartVertical" : "LineChart"
}/>
</div>
</div>
: null
}
<div className="statistics-chart">
{ this.renderChart() }
</div>
</Theme>;
}
}
export { Statistics };