|
|
@@ -7,7 +7,8 @@ type IDynamicsBehaviorParameter = {
|
|
|
|
mass: "number",
|
|
|
|
mass: "number",
|
|
|
|
maxAcceleration: "number",
|
|
|
|
maxAcceleration: "number",
|
|
|
|
maxVelocity: "number",
|
|
|
|
maxVelocity: "number",
|
|
|
|
resistance: "number"
|
|
|
|
resistance: "number",
|
|
|
|
|
|
|
|
limit: "boolean"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type IDynamicsBehaviorEvent = {}
|
|
|
|
type IDynamicsBehaviorEvent = {}
|
|
|
@@ -26,9 +27,16 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
|
|
|
|
|
|
|
|
|
|
|
|
public override parameterOption = {
|
|
|
|
public override parameterOption = {
|
|
|
|
mass: { name: "$Mass", type: "number", defaultValue: 1, numberStep: .01, numberMin: .001 },
|
|
|
|
mass: { name: "$Mass", type: "number", defaultValue: 1, numberStep: .01, numberMin: .001 },
|
|
|
|
maxAcceleration: { name: "$Max.Acceleration", type: "number", defaultValue: 5, numberStep: .1, numberMin: 0 },
|
|
|
|
resistance: { name: "$Resistance", type: "number", defaultValue: 0.5, numberStep: .1, numberMin: 0 },
|
|
|
|
maxVelocity: { name: "$Max.Velocity", type: "number", defaultValue: 10, numberStep: .1, numberMin: 0 },
|
|
|
|
limit: { name: "$Limit", type: "boolean", defaultValue: true },
|
|
|
|
resistance: { name: "$Resistance", type: "number", defaultValue: 0.5, numberStep: .1, numberMin: 0 }
|
|
|
|
maxAcceleration: {
|
|
|
|
|
|
|
|
name: "$Max.Acceleration", type: "number", defaultValue: 5,
|
|
|
|
|
|
|
|
numberStep: .1, numberMin: 0, condition: { key: "limit", value: true }
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
maxVelocity: {
|
|
|
|
|
|
|
|
name: "$Max.Velocity", type: "number", defaultValue: 10,
|
|
|
|
|
|
|
|
numberStep: .1, numberMin: 0, condition: { key: "limit", value: true }
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public override finalEffect = (individual: Individual, group: Group, model: Model, t: number): void => {
|
|
|
|
public override finalEffect = (individual: Individual, group: Group, model: Model, t: number): void => {
|
|
|
@@ -54,12 +62,14 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
|
|
|
|
individual.acceleration[2] = individual.force[2] / this.parameter.mass;
|
|
|
|
individual.acceleration[2] = individual.force[2] / this.parameter.mass;
|
|
|
|
|
|
|
|
|
|
|
|
// 加速度约束
|
|
|
|
// 加速度约束
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 计算速度
|
|
|
|
// 计算速度
|
|
|
|
individual.velocity[0] = individual.velocity[0] + individual.acceleration[0] * t;
|
|
|
|
individual.velocity[0] = individual.velocity[0] + individual.acceleration[0] * t;
|
|
|
@@ -67,12 +77,14 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
|
|
|
|
individual.velocity[2] = individual.velocity[2] + individual.acceleration[2] * t;
|
|
|
|
individual.velocity[2] = individual.velocity[2] + individual.acceleration[2] * t;
|
|
|
|
|
|
|
|
|
|
|
|
// 速度约束
|
|
|
|
// 速度约束
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 应用速度
|
|
|
|
// 应用速度
|
|
|
|
individual.position[0] = individual.position[0] + individual.velocity[0] * t;
|
|
|
|
individual.position[0] = individual.position[0] + individual.velocity[0] * t;
|
|
|
@@ -93,6 +105,10 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
|
|
|
|
"$Intro": {
|
|
|
|
"$Intro": {
|
|
|
|
"ZH_CN": "一切可以运动物体的必要行为,执行物理法则。",
|
|
|
|
"ZH_CN": "一切可以运动物体的必要行为,执行物理法则。",
|
|
|
|
"EN_US": "All necessary behaviors that can move objects and implement the laws of physics."
|
|
|
|
"EN_US": "All necessary behaviors that can move objects and implement the laws of physics."
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"$Limit": {
|
|
|
|
|
|
|
|
"ZH_CN": "开启限制",
|
|
|
|
|
|
|
|
"EN_US": "Enable limit"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"$Mass": {
|
|
|
|
"$Mass": {
|
|
|
|
"ZH_CN": "质量 (Kg)",
|
|
|
|
"ZH_CN": "质量 (Kg)",
|
|
|
|