diff --git a/source/Behavior/Dynamics.ts b/source/Behavior/Dynamics.ts index 444af6f..ef0ad2b 100644 --- a/source/Behavior/Dynamics.ts +++ b/source/Behavior/Dynamics.ts @@ -7,7 +7,8 @@ type IDynamicsBehaviorParameter = { mass: "number", maxAcceleration: "number", maxVelocity: "number", - resistance: "number" + resistance: "number", + limit: "boolean" } type IDynamicsBehaviorEvent = {} @@ -26,9 +27,16 @@ class Dynamics extends Behavior { @@ -54,24 +62,28 @@ class Dynamics extends Behavior this.parameter.maxAcceleration) { - individual.acceleration[0] = individual.acceleration[0] * this.parameter.maxAcceleration / lengthA; - individual.acceleration[1] = individual.acceleration[1] * this.parameter.maxAcceleration / lengthA; - individual.acceleration[2] = individual.acceleration[2] * this.parameter.maxAcceleration / lengthA; + if (this.parameter.limit) { + const lengthA = individual.vectorLength(individual.acceleration); + if (lengthA > this.parameter.maxAcceleration) { + individual.acceleration[0] = individual.acceleration[0] * 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.velocity[0] = individual.velocity[0] + individual.acceleration[0] * t; individual.velocity[1] = individual.velocity[1] + individual.acceleration[1] * t; individual.velocity[2] = individual.velocity[2] + individual.acceleration[2] * t; // 速度约束 - const lengthV = individual.vectorLength(individual.velocity); - if (lengthV > this.parameter.maxVelocity) { - individual.velocity[0] = individual.velocity[0] * this.parameter.maxVelocity / lengthV; - individual.velocity[1] = individual.velocity[1] * this.parameter.maxVelocity / lengthV; - individual.velocity[2] = individual.velocity[2] * this.parameter.maxVelocity / lengthV; + if (this.parameter.limit) { + const lengthV = individual.vectorLength(individual.velocity); + if (lengthV > this.parameter.maxVelocity) { + individual.velocity[0] = individual.velocity[0] * this.parameter.maxVelocity / lengthV; + individual.velocity[1] = individual.velocity[1] * this.parameter.maxVelocity / lengthV; + individual.velocity[2] = individual.velocity[2] * this.parameter.maxVelocity / lengthV; + } } // 应用速度 @@ -94,6 +106,10 @@ class Dynamics extends Behavior extends Component & IMi private renderParameter (key: K, option: IParameterOptionItem, value: IParamValue): ReactNode { - const language = this.props.setting?.language ?? "EN_US"; const indexKey = `${this.props.key}-${key}`; + + // 条件检测 + if (option.condition && this.props.value[option.condition.key] !== option.condition.value) { + return ; + } + const type = option.type; + const language = this.props.setting?.language ?? "EN_US"; let keyI18n: string, keyI18nOption: Record | undefined; // Custom I18N diff --git a/source/Model/Parameter.ts b/source/Model/Parameter.ts index 20705cd..a40eb8b 100644 --- a/source/Model/Parameter.ts +++ b/source/Model/Parameter.ts @@ -115,6 +115,11 @@ interface IParameterOptionItem { */ colorNormal?: boolean; + /** + * 显示条件 + */ + condition?: {key: string, value: any}; + /** * 全部选项 */