From 95ed38ab897ff8be70b2ad9c99dcb1408e8c2323 Mon Sep 17 00:00:00 2001 From: Markus Lerner Date: Sun, 5 Nov 2023 19:44:29 +0100 Subject: [PATCH] Add inital API documentation --- README.md | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4f84202..7d1d85f 100644 --- a/README.md +++ b/README.md @@ -95,12 +95,98 @@ The files from the src folder will we re-built automatically into a virtual buil ### API Docs -To be created ... - -- Particle extends Vector3 -- Vector3 API is fully compatible with [THREE.js](https://github.com/mrdoob/three.js/) Vector3. - -Available Behaviors: +#### SimplePhysics class + +**Constructor** + +`new SimplePhysics({ friction = 0.95, springIterationsCount = 50 } = {});` + +**Members:** + +Member | Type | Default | Description +:----- | :--- | :------ | :---------- +`behaviors` | Set | new Set() | Behaviors for all particles +`constraints` | Set | new Set() | Constraints for all particles +`groups` | Set | new Set() | Groups of particles (not implemented yet) +`particles` | Set | new Set() | All particles +`springs` | Set | new Set() | All springs (not implemented yet) +`friction` | number | 0.95; +`springIterationsCount` | number | 50; + +**Public Methods:** + +Method | Return value | Description +:----- | :----------- | :---------- +`addBehavior(behavior: Object)` | | Add behavior to all particles +`addParticle(particle: Particle)` | | Add particle +`addSpring(spring: Spring)` | | Not implmemented yet +`addGroup(group: Group)` | | Not implmemented yet +`clear()` | | Clear particles, groups and springs +`getSpring(a: Particle, b: Particle)` | Spring | Attempts to find the spring element between the 2 particles supplied +`getnumConnected(spring: Spring)` | number | Get the count of how many springs are connected to A +`hasBehavior(behavior: Behavior)` | Behavior | Check, if physics has this behavior +`hasGroup(group: Group)` | Group | Check, if physics has this group +`hasParticle(particle: Particle)` | Particle | Check, if physics has this particle +`hasSpring(spring: Spring)` | Spring | Check, if physics has this spring +`removeBehavior(behavior: Behavior)` | boolean | Remove behavior +`removeParticle(particle: Particle)` | boolean | Remove particle +`removeSpring(spring: Spring)` | boolean | Remove spring +`removeSpringElements(spring: Spring)` | boolean | Removes a spring connector and its both end point particles +`removeGroup(group: Group)` | boolean | Remove group +`update(deltaTime: number = 1)` | | Update simulation + + +#### Particle class + +Extends Vector3 class + +Vector3 API is fully compatible with [THREE.js](https://github.com/mrdoob/three.js/) Vector3. + +**Constructor** + +`new Particle(x: number = 0.0, y: number = 0.0, z: number = 0.0, mass: number = 1.0, radius: number = 1.0);` + +**Members:** + +Member | Type | Default | Description +:----- | :--- | :------ | :---------- +`x` | number | 0.0 +`y` | number | 0.0 +`z` | number | 0.0 +`locked` | boolean | false | Particle lock status +`behaviors` | Set | null | Particle behaviors +`neighbors` | Set | null | Particle neighbors +`mass` | number | 1.0 +`radius` | number | 1.0 +`friction` | number | 0.0 +`maxSpeed` | number | 3.0 +`force` | Vector3 | new Vector3() +`velocity` | Vector3 | new Vector3() +`velocitySmooth` | Vector3 | new Vector3() +`followers` | Set | new Set() | Follower which will copy this particle’s position + +**Public Methods:** + +Method | Return value | Description +:----- | :----------- | :---------- +`addBehavior(behavior: Object, addEvenIfExists: boolean = false)` | this | Add behavior to this particle only +`getBehavior(behaviorClass: Class)` | Instance of Behavior | Get behavior by behavior class +`addFollower(vector: Vector3)` | | Will copy this particle’s position +`addForce(force: Vector3)` | this | Add force to this particle, used by behaviors +`clearForce()` | this | Clear force +`clearVelocity()` | this | Clear velocity +`getVelocity()` | Vector3 | Get velocity +`lock()` | this | Lock this particle’s position +`removeBehavior(behavior: Object)` | boolean | Remove behavior, returns true, if behavior was found +`removeFollower(follower: Object)` | boolean | Remove follower, returns true, if follower was found +`unlock()` | this | Unlock this particle’s position +`constrainX(min: number, max: number)` | | Constrain x +`constrainY(min: number, max: number)` | | Constrain y +`constrainZ(min: number, max: number)` | | Constrain z + + + +### Available Behaviors: - Align: align movement with neighbors - Avoid: avoid single target @@ -133,7 +219,6 @@ The files in the `build` folder will automatically be rebuilt when modified. - Add missing behaviors and params to all behaviors example - Consider writing behaviors as a plugin for matter.js - Create other shapes (box, polygon) -- Create tabular api docs like https://swiperjs.com/swiper-api ### License