Mod boundary constraint func & Separate parameter model & Add parameter component #36
| @ -5,7 +5,7 @@ import { Brownian } from "./Brownian"; | |||||||
| import { BoundaryConstraint } from "./BoundaryConstraint";  | import { BoundaryConstraint } from "./BoundaryConstraint";  | ||||||
| 
 | 
 | ||||||
| const AllBehaviors: IAnyBehaviorRecorder[] = [ | const AllBehaviors: IAnyBehaviorRecorder[] = [ | ||||||
|     new BehaviorRecorder(Template), |     // new BehaviorRecorder(Template),
 | ||||||
|     new BehaviorRecorder(Dynamics), |     new BehaviorRecorder(Dynamics), | ||||||
|     new BehaviorRecorder(Brownian), |     new BehaviorRecorder(Brownian), | ||||||
|     new BehaviorRecorder(BoundaryConstraint), |     new BehaviorRecorder(BoundaryConstraint), | ||||||
|  | |||||||
| @ -1,12 +1,12 @@ | |||||||
| import { Behavior } from "@Model/Behavior"; | import { Behavior } from "@Model/Behavior"; | ||||||
| import { Group } from "@Model/Group"; | import { Group } from "@Model/Group"; | ||||||
| import { Individual } from "@Model/Individual"; | import { Individual } from "@Model/Individual"; | ||||||
| import { Label } from "@Model/Label"; |  | ||||||
| import { Model } from "@Model/Model"; | import { Model } from "@Model/Model"; | ||||||
| import { Range } from "@Model/Range"; | import { Range } from "@Model/Range"; | ||||||
| 
 | 
 | ||||||
| type IBoundaryConstraintBehaviorParameter = { | type IBoundaryConstraintBehaviorParameter = { | ||||||
|     range: "LR" |     range: "LR", | ||||||
|  | 	strength: "number" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type IBoundaryConstraintBehaviorEvent = {} | type IBoundaryConstraintBehaviorEvent = {} | ||||||
| @ -27,6 +27,13 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter, | |||||||
| 		range: { | 		range: { | ||||||
| 			type: "LR", | 			type: "LR", | ||||||
| 			name: "$range" | 			name: "$range" | ||||||
|  | 		}, | ||||||
|  | 		strength: { | ||||||
|  | 			type: "number", | ||||||
|  | 			name: "$Strength", | ||||||
|  | 			defaultValue: 1, | ||||||
|  |             numberMin: 0, | ||||||
|  |             numberStep: .1 | ||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| @ -35,6 +42,14 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter, | |||||||
|             "ZH_CN": "边界约束", |             "ZH_CN": "边界约束", | ||||||
|             "EN_US": "Boundary constraint" |             "EN_US": "Boundary constraint" | ||||||
|         }, |         }, | ||||||
|  | 		"$range": { | ||||||
|  | 			"ZH_CN": "约束范围", | ||||||
|  | 			"EN_US": "Constraint range" | ||||||
|  | 		}, | ||||||
|  | 		"$Strength": { | ||||||
|  | 			"ZH_CN": "约束强度系数", | ||||||
|  | 			"EN_US": "Restraint strength coefficient" | ||||||
|  | 		}, | ||||||
|         "$Intro": { |         "$Intro": { | ||||||
|             "ZH_CN": "个体越出边界后将主动返回", |             "ZH_CN": "个体越出边界后将主动返回", | ||||||
|             "EN_US": "Individuals will return actively after crossing the border" |             "EN_US": "Individuals will return actively after crossing the border" | ||||||
| @ -43,6 +58,12 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter, | |||||||
| 
 | 
 | ||||||
|     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 rangeList: Range[] = this.parameter.range.objects; | ||||||
|  | 
 | ||||||
|  | 		let fx = 0; | ||||||
|  | 		let fy = 0; | ||||||
|  | 		let fz = 0; | ||||||
|  | 		let fLen = Infinity; | ||||||
|  | 
 | ||||||
| 		for (let i = 0; i < rangeList.length; i++) { | 		for (let i = 0; i < rangeList.length; i++) { | ||||||
| 
 | 
 | ||||||
| 			let rx = rangeList[i].position[0] - individual.position[0]; | 			let rx = rangeList[i].position[0] - individual.position[0]; | ||||||
| @ -53,12 +74,30 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter, | |||||||
| 			let oy = Math.abs(ry) > rangeList[i].radius[1]; | 			let oy = Math.abs(ry) > rangeList[i].radius[1]; | ||||||
| 			let oz = Math.abs(rz) > rangeList[i].radius[2]; | 			let oz = Math.abs(rz) > rangeList[i].radius[2]; | ||||||
| 
 | 
 | ||||||
| 			individual.applyForce( | 			if (ox || oy || oz) { | ||||||
| 				ox ? rx : 0, | 
 | ||||||
| 				oy ? ry : 0, | 				let currentFLen = individual.vectorLength(rx, ry, rz); | ||||||
| 				oz ? rz : 0 | 				if (currentFLen < fLen) { | ||||||
| 			) | 					fx = rx; | ||||||
|  | 					fy = ry; | ||||||
|  | 					fz = rz; | ||||||
|  | 					fLen = currentFLen; | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 			} else { | ||||||
|  | 
 | ||||||
|  | 				fx = 0; | ||||||
|  | 				fy = 0; | ||||||
|  | 				fz = 0; | ||||||
|  | 				fLen = 0; | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
|  | 		individual.applyForce( | ||||||
|  | 			fx * this.parameter.strength, | ||||||
|  | 			fy * this.parameter.strength, | ||||||
|  | 			fz * this.parameter.strength | ||||||
|  | 		); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve | |||||||
| 		resistance: { | 		resistance: { | ||||||
| 			name: "$Resistance", | 			name: "$Resistance", | ||||||
| 			type: "number", | 			type: "number", | ||||||
| 			defaultValue: 0.1, | 			defaultValue: 0.5, | ||||||
| 			numberStep: .1, | 			numberStep: .1, | ||||||
| 			numberMin: 0 | 			numberMin: 0 | ||||||
| 		} | 		} | ||||||
| @ -76,6 +76,10 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve | |||||||
| 			"ZH_CN": "最大速度 (m/s)", | 			"ZH_CN": "最大速度 (m/s)", | ||||||
|             "EN_US": "Maximum velocity (m/s)" |             "EN_US": "Maximum velocity (m/s)" | ||||||
| 		}, | 		}, | ||||||
|  | 		"$Resistance": { | ||||||
|  | 			"ZH_CN": "阻力系数", | ||||||
|  | 			"EN_US": "Resistance coefficient" | ||||||
|  | 		}, | ||||||
| 		"$Physics": { | 		"$Physics": { | ||||||
| 			"ZH_CN": "物理", | 			"ZH_CN": "物理", | ||||||
|             "EN_US": "Physics" |             "EN_US": "Physics" | ||||||
|  | |||||||
| @ -55,16 +55,16 @@ class SimulatorWeb extends Component { | |||||||
|             this.status.model.update(0); |             this.status.model.update(0); | ||||||
|             this.status.newLabel().name = "New Label"; |             this.status.newLabel().name = "New Label"; | ||||||
|             this.status.newLabel().name = "Test Label 01"; |             this.status.newLabel().name = "Test Label 01"; | ||||||
|             let template = this.status.model.addBehavior(AllBehaviors[0]); |             // let template = this.status.model.addBehavior(AllBehaviors[0]);
 | ||||||
|             template.name = "Template"; template.color = [150, 20, 220]; |             // template.name = "Template"; template.color = [150, 20, 220];
 | ||||||
|             let dynamic = this.status.model.addBehavior(AllBehaviors[1]); |             let dynamic = this.status.model.addBehavior(AllBehaviors[0]); | ||||||
|             dynamic.name = "Dynamic"; dynamic.color = [250, 200, 80]; |             dynamic.name = "Dynamic"; dynamic.color = [250, 200, 80]; | ||||||
|             let brownian = this.status.model.addBehavior(AllBehaviors[2]); |             let brownian = this.status.model.addBehavior(AllBehaviors[1]); | ||||||
|             brownian.name = "Brownian"; brownian.color = [200, 80, 250]; |             brownian.name = "Brownian"; brownian.color = [200, 80, 250]; | ||||||
|             let boundary = this.status.model.addBehavior(AllBehaviors[3]); |             let boundary = this.status.model.addBehavior(AllBehaviors[2]); | ||||||
|             boundary.name = "Boundary"; boundary.color = [80, 200, 250]; |             boundary.name = "Boundary"; boundary.color = [80, 200, 250]; | ||||||
|             // boundary.parameter.range = this.status.model.allRangeLabel;
 |             // boundary.parameter.range.picker = this.status.model.allRangeLabel;
 | ||||||
|             group.addBehavior(template); |             // group.addBehavior(template);
 | ||||||
|             group.addBehavior(dynamic); |             group.addBehavior(dynamic); | ||||||
|             group.addBehavior(brownian); |             group.addBehavior(brownian); | ||||||
|             group.addBehavior(boundary); |             group.addBehavior(boundary); | ||||||
|  | |||||||
| @ -126,7 +126,7 @@ class BehaviorDetails extends Component<IBehaviorDetailsProps & IMixinStatusProp | |||||||
|             return <ObjectPicker |             return <ObjectPicker | ||||||
|                 keyI18n="Panel.Info.Behavior.Details.Parameter.Key" |                 keyI18n="Panel.Info.Behavior.Details.Parameter.Key" | ||||||
|                 keyI18nOption={{ key: behavior.getTerms(type.name, this.props.setting?.language) }} |                 keyI18nOption={{ key: behavior.getTerms(type.name, this.props.setting?.language) }} | ||||||
|                 type={type.type} value={(value as any).picker} |                 type={type.type} value={(value as any).picker} key={indexKey} | ||||||
|                 valueChange={(obj) => { |                 valueChange={(obj) => { | ||||||
|                     (value as any).picker = obj; |                     (value as any).picker = obj; | ||||||
|                     this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); |                     this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user