emeraldengine 2.2.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2198 -968
- package/dist/types/index.d.ts +75 -32
- package/dist/types/src/Animator.d.ts +50 -0
- package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
- package/dist/types/src/Camera.d.ts +122 -0
- package/dist/types/src/CameraController.d.ts +107 -0
- package/dist/types/src/CanvasText.d.ts +91 -0
- package/dist/types/src/CollisionLayers.d.ts +58 -0
- package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
- package/dist/types/src/Coroutine.d.ts +111 -0
- package/dist/types/src/DebugOverlay.d.ts +86 -0
- package/dist/types/src/Drawable.d.ts +271 -0
- package/dist/types/src/Easing.d.ts +22 -0
- package/dist/types/src/Emerald.d.ts +420 -0
- package/dist/types/src/EmeraldDB.d.ts +159 -0
- package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
- package/dist/types/src/GLUtils.d.ts +4 -0
- package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
- package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
- package/dist/types/src/Interpolator.d.ts +66 -0
- package/dist/types/src/Material.d.ts +87 -0
- package/dist/types/src/MathUtils.d.ts +81 -0
- package/dist/types/src/ParticleEmitter.d.ts +131 -0
- package/dist/types/src/Physics.d.ts +337 -0
- package/dist/types/src/Pool.d.ts +53 -0
- package/dist/types/src/PostEffects.d.ts +68 -0
- package/dist/types/src/PostProcessor.d.ts +124 -0
- package/dist/types/src/RenderTarget.d.ts +56 -0
- package/dist/types/src/Scene.d.ts +62 -0
- package/dist/types/src/ScreenEffects.d.ts +111 -0
- package/dist/types/src/Serializer.d.ts +86 -0
- package/dist/types/src/Shaders.d.ts +2 -0
- package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
- package/dist/types/src/SpatialGrid.d.ts +50 -0
- package/dist/types/src/SpriteBatch.d.ts +89 -0
- package/dist/types/src/StateMachine.d.ts +59 -0
- package/dist/types/src/Storage.d.ts +89 -0
- package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
- package/dist/types/src/TextureAtlas.d.ts +55 -0
- package/dist/types/src/Tilemap.d.ts +91 -0
- package/dist/types/src/Time.d.ts +53 -0
- package/dist/types/src/Timer.d.ts +54 -0
- package/dist/types/src/Transform.d.ts +94 -0
- package/dist/types/src/Tween.d.ts +81 -0
- package/dist/types/src/UI.d.ts +121 -0
- package/dist/types/src/components/Behaviour.d.ts +71 -0
- package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
- package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
- package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
- package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
- package/dist/types/src/components/Collider.d.ts +102 -0
- package/dist/types/src/components/GameObject.d.ts +135 -0
- package/dist/types/src/components/PolygonCollider.d.ts +33 -0
- package/dist/types/src/components/RigidBody.d.ts +456 -0
- package/dist/types/src/importers/Aseprite.d.ts +79 -0
- package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
- package/dist/types/src/importers/TiledMap.d.ts +62 -0
- package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
- package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
- package/dist/types/src/managers/AssetManager.d.ts +116 -0
- package/dist/types/src/managers/AudioManager.d.ts +259 -0
- package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
- package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
- package/dist/types/src/managers/GLManager.d.ts +84 -0
- package/dist/types/src/managers/GLState.d.ts +37 -0
- package/dist/types/src/managers/Gamepad.d.ts +102 -0
- package/dist/types/src/managers/IDManager.d.ts +31 -0
- package/dist/types/src/managers/InputManager.d.ts +381 -0
- package/dist/types/src/managers/NetworkManager.d.ts +93 -0
- package/dist/types/src/managers/RenderStats.d.ts +34 -0
- package/dist/types/src/managers/SceneManager.d.ts +44 -0
- package/dist/types/src/managers/ShaderManager.d.ts +55 -0
- package/dist/types/src/managers/TextureManager.d.ts +102 -0
- package/dist/types/src/particlesystem/Particle.d.ts +64 -0
- package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
- package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
- package/dist/types/src/physics/AABB.d.ts +92 -0
- package/dist/types/src/physics/Body.d.ts +435 -0
- package/dist/types/src/physics/BodyType.d.ts +6 -0
- package/dist/types/src/physics/BroadPhase.d.ts +210 -0
- package/dist/types/src/physics/Collision.d.ts +102 -0
- package/dist/types/src/physics/Contact.d.ts +206 -0
- package/dist/types/src/physics/ContactSolver.d.ts +108 -0
- package/dist/types/src/physics/Distance.d.ts +54 -0
- package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
- package/dist/types/src/physics/Fixture.d.ts +221 -0
- package/dist/types/src/physics/Island.d.ts +52 -0
- package/dist/types/src/physics/Joint.d.ts +59 -0
- package/dist/types/src/physics/Math2D.d.ts +371 -0
- package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
- package/dist/types/src/physics/Settings.d.ts +22 -0
- package/dist/types/src/physics/Shapes.d.ts +207 -0
- package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
- package/dist/types/src/physics/World.d.ts +274 -0
- package/dist/types/src/physics/index.d.ts +34 -0
- package/index.js +78 -0
- package/package.json +73 -60
- package/src/Animator.js +95 -0
- package/src/BitmapText.js +6 -5
- package/src/Camera.js +183 -0
- package/src/CameraController.js +192 -0
- package/src/CanvasText.js +281 -0
- package/src/CollisionLayers.js +86 -0
- package/src/Color.js +26 -18
- package/src/Coroutine.js +259 -0
- package/src/DebugOverlay.js +246 -0
- package/src/Drawable.js +842 -582
- package/src/Easing.js +57 -0
- package/src/Emerald.js +1150 -459
- package/src/EmeraldDB.js +328 -0
- package/src/FPSCounter.js +43 -43
- package/src/GLUtils.js +60 -67
- package/src/Instance.js +41 -5
- package/src/InstancedTexture.js +308 -127
- package/src/Interpolator.js +124 -0
- package/src/Material.js +202 -0
- package/src/MathUtils.js +134 -0
- package/src/ParticleEmitter.js +284 -0
- package/src/Physics.js +431 -40
- package/src/Pool.js +85 -0
- package/src/PostEffects.js +296 -0
- package/src/PostProcessor.js +304 -0
- package/src/RenderTarget.js +134 -0
- package/src/Scene.js +115 -83
- package/src/ScreenEffects.js +266 -0
- package/src/Serializer.js +131 -0
- package/src/Shaders.js +150 -165
- package/src/Shapes.js +118 -129
- package/src/SpatialGrid.js +111 -0
- package/src/SpriteBatch.js +299 -0
- package/src/StateMachine.js +82 -0
- package/src/Storage.js +175 -47
- package/src/Texture.js +58 -67
- package/src/TextureAtlas.js +96 -0
- package/src/Tilemap.js +274 -0
- package/src/Time.js +51 -6
- package/src/Timer.js +99 -0
- package/src/Transform.js +100 -7
- package/src/Tween.js +160 -0
- package/src/UI.js +394 -0
- package/src/components/Behaviour.js +90 -0
- package/src/components/BoxCollider.js +29 -12
- package/src/components/BoxColliderDebug.js +3 -4
- package/src/components/CircleCollider.js +26 -12
- package/src/components/CircleColliderDebug.js +25 -24
- package/src/components/Collider.js +150 -34
- package/src/components/GameObject.js +130 -21
- package/src/components/PolygonCollider.js +55 -0
- package/src/components/RigidBody.js +556 -8
- package/src/importers/Aseprite.js +142 -0
- package/src/importers/ForgeLevel.js +581 -0
- package/src/importers/TiledMap.js +158 -0
- package/src/lights/DirectionalLight.js +6 -15
- package/src/lights/PointLight.js +4 -4
- package/src/managers/AssetManager.js +239 -0
- package/src/managers/AudioManager.js +565 -146
- package/src/managers/EventManager.js +488 -477
- package/src/managers/GLManager.js +57 -0
- package/src/managers/GLState.js +70 -0
- package/src/managers/Gamepad.js +126 -0
- package/src/managers/IDManager.js +24 -2
- package/src/managers/InputManager.js +905 -0
- package/src/managers/NetworkManager.js +178 -0
- package/src/managers/RenderStats.js +34 -0
- package/src/managers/SceneManager.js +30 -0
- package/src/managers/ShaderManager.js +0 -2
- package/src/managers/TextureManager.js +218 -0
- package/src/particlesystem/Particle.js +82 -7
- package/src/particlesystem/ParticleSettings.js +21 -3
- package/src/particlesystem/Particles.js +80 -31
- package/src/physics/AABB.js +207 -0
- package/src/physics/Body.js +862 -0
- package/src/physics/BodyType.js +16 -0
- package/src/physics/BroadPhase.js +641 -0
- package/src/physics/Collision.js +534 -0
- package/src/physics/Contact.js +500 -0
- package/src/physics/ContactSolver.js +526 -0
- package/src/physics/Distance.js +403 -0
- package/src/physics/DistanceJoint.js +227 -0
- package/src/physics/Fixture.js +346 -0
- package/src/physics/Island.js +203 -0
- package/src/physics/Joint.js +78 -0
- package/src/physics/Math2D.js +573 -0
- package/src/physics/RevoluteJoint.js +278 -0
- package/src/physics/Settings.js +78 -0
- package/src/physics/Shapes.js +549 -0
- package/src/physics/TimeOfImpact.js +87 -0
- package/src/physics/World.js +731 -0
- package/src/physics/index.js +79 -0
- package/dist/types/Drawable.d.ts +0 -157
- package/dist/types/Emerald.d.ts +0 -73
- package/dist/types/GLUtils.d.ts +0 -6
- package/dist/types/Physics.d.ts +0 -139
- package/dist/types/Scene.d.ts +0 -39
- package/dist/types/Shaders.d.ts +0 -4
- package/dist/types/Storage.d.ts +0 -46
- package/dist/types/Time.d.ts +0 -22
- package/dist/types/Transform.d.ts +0 -41
- package/dist/types/components/BoxColliderDebug.d.ts +0 -19
- package/dist/types/components/CircleColliderDebug.d.ts +0 -19
- package/dist/types/components/Collider.d.ts +0 -53
- package/dist/types/components/GameObject.d.ts +0 -72
- package/dist/types/components/RigidBody.d.ts +0 -104
- package/dist/types/managers/AudioManager.d.ts +0 -60
- package/dist/types/managers/GLManager.d.ts +0 -47
- package/dist/types/managers/IDManager.d.ts +0 -21
- package/dist/types/managers/SceneManager.d.ts +0 -22
- package/dist/types/particlesystem/Particle.d.ts +0 -42
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export default RevoluteJoint;
|
|
2
|
+
/**
|
|
3
|
+
* @class RevoluteJoint
|
|
4
|
+
* @extends Joint
|
|
5
|
+
* @description Pins two bodies together at a shared point while leaving
|
|
6
|
+
* rotation free, like a door hinge or a pendulum arm. Optionally driven by a
|
|
7
|
+
* motor that spins the joint toward a target angular speed, up to a torque
|
|
8
|
+
* limit; set `enableMotor` for a turntable, a windmill blade, or a wheel.
|
|
9
|
+
* @param {Object} def - `{ bodyA, bodyB, localAnchorA, localAnchorB,
|
|
10
|
+
* enableMotor, motorSpeed, maxMotorTorque, collideConnected, userData }`
|
|
11
|
+
*/
|
|
12
|
+
declare class RevoluteJoint extends Joint {
|
|
13
|
+
localAnchorA: Vec2;
|
|
14
|
+
localAnchorB: Vec2;
|
|
15
|
+
referenceAngle: any;
|
|
16
|
+
enableMotor: boolean;
|
|
17
|
+
motorSpeed: any;
|
|
18
|
+
maxMotorTorque: any;
|
|
19
|
+
impulse: Vec2;
|
|
20
|
+
motorImpulse: number;
|
|
21
|
+
axialMass: number;
|
|
22
|
+
motorMass: number;
|
|
23
|
+
K: {
|
|
24
|
+
k11: number;
|
|
25
|
+
k12: number;
|
|
26
|
+
k22: number;
|
|
27
|
+
};
|
|
28
|
+
rA: Vec2;
|
|
29
|
+
rB: Vec2;
|
|
30
|
+
/** @private */
|
|
31
|
+
private indexA;
|
|
32
|
+
/** @private */
|
|
33
|
+
private indexB;
|
|
34
|
+
/**
|
|
35
|
+
* @method getAnchorA
|
|
36
|
+
* @returns {Vec2}
|
|
37
|
+
*/
|
|
38
|
+
getAnchorA(): Vec2;
|
|
39
|
+
/**
|
|
40
|
+
* @method getAnchorB
|
|
41
|
+
* @returns {Vec2}
|
|
42
|
+
*/
|
|
43
|
+
getAnchorB(): Vec2;
|
|
44
|
+
/**
|
|
45
|
+
* @method getReactionForce
|
|
46
|
+
* @param {number} invDt
|
|
47
|
+
* @returns {Vec2}
|
|
48
|
+
*/
|
|
49
|
+
getReactionForce(invDt: number): Vec2;
|
|
50
|
+
/**
|
|
51
|
+
* @method getReactionTorque
|
|
52
|
+
* @param {number} invDt
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
getReactionTorque(invDt: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* @method getJointAngle
|
|
58
|
+
* @description Current angle of body B relative to body A, minus the angle
|
|
59
|
+
* they started at.
|
|
60
|
+
* @returns {number}
|
|
61
|
+
*/
|
|
62
|
+
getJointAngle(): number;
|
|
63
|
+
/**
|
|
64
|
+
* @method setMotorSpeed
|
|
65
|
+
* @param {number} speed
|
|
66
|
+
*/
|
|
67
|
+
setMotorSpeed(speed: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* @method getMotorSpeed
|
|
70
|
+
* @returns {number}
|
|
71
|
+
*/
|
|
72
|
+
getMotorSpeed(): number;
|
|
73
|
+
/**
|
|
74
|
+
* @method setMaxMotorTorque
|
|
75
|
+
* @param {number} torque
|
|
76
|
+
*/
|
|
77
|
+
setMaxMotorTorque(torque: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* @method setEnableMotor
|
|
80
|
+
* @param {boolean} flag
|
|
81
|
+
*/
|
|
82
|
+
setEnableMotor(flag: boolean): void;
|
|
83
|
+
/**
|
|
84
|
+
* @method isMotorEnabled
|
|
85
|
+
* @returns {boolean}
|
|
86
|
+
*/
|
|
87
|
+
isMotorEnabled(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* @method getMotorTorque
|
|
90
|
+
* @param {number} invDt
|
|
91
|
+
* @returns {number}
|
|
92
|
+
*/
|
|
93
|
+
getMotorTorque(invDt: number): number;
|
|
94
|
+
/**
|
|
95
|
+
* @method initVelocityConstraints
|
|
96
|
+
* @param {Object} step - `{ dt, warmStarting }`
|
|
97
|
+
* @param {Array<Object>} positions
|
|
98
|
+
* @param {Array<Object>} velocities
|
|
99
|
+
*/
|
|
100
|
+
initVelocityConstraints(step: any, positions: Array<any>, velocities: Array<any>): void;
|
|
101
|
+
invMassA: any;
|
|
102
|
+
invMassB: any;
|
|
103
|
+
invIA: any;
|
|
104
|
+
invIB: any;
|
|
105
|
+
/**
|
|
106
|
+
* @method solveVelocityConstraints
|
|
107
|
+
* @param {Object} step - `{ dt }`
|
|
108
|
+
* @param {Array<Object>} velocities
|
|
109
|
+
*/
|
|
110
|
+
solveVelocityConstraints(step: any, velocities: Array<any>): void;
|
|
111
|
+
/**
|
|
112
|
+
* @method solvePositionConstraints
|
|
113
|
+
* @param {Array<Object>} positions
|
|
114
|
+
* @returns {boolean}
|
|
115
|
+
*/
|
|
116
|
+
solvePositionConstraints(positions: Array<any>): boolean;
|
|
117
|
+
}
|
|
118
|
+
import { Joint } from "./Joint.js";
|
|
119
|
+
import { Vec2 } from "./Math2D.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default Settings;
|
|
2
|
+
declare namespace Settings {
|
|
3
|
+
let linearSlop: number;
|
|
4
|
+
let angularSlop: number;
|
|
5
|
+
let polygonRadius: number;
|
|
6
|
+
let maxLinearCorrection: number;
|
|
7
|
+
let maxAngularCorrection: number;
|
|
8
|
+
let maxTranslation: number;
|
|
9
|
+
let maxRotation: number;
|
|
10
|
+
let baumgarte: number;
|
|
11
|
+
let toiBaumgarte: number;
|
|
12
|
+
let velocityThreshold: number;
|
|
13
|
+
let timeToSleep: number;
|
|
14
|
+
let linearSleepTolerance: number;
|
|
15
|
+
let angularSleepTolerance: number;
|
|
16
|
+
let aabbExtension: number;
|
|
17
|
+
let aabbMultiplier: number;
|
|
18
|
+
let velocityIterations: number;
|
|
19
|
+
let positionIterations: number;
|
|
20
|
+
let maxTOIIterations: number;
|
|
21
|
+
let maxTOIPasses: number;
|
|
22
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Shape
|
|
3
|
+
* @description Base class for collision shapes. A shape is pure geometry in a
|
|
4
|
+
* body's local frame: it carries no position of its own and can be shared
|
|
5
|
+
* between fixtures.
|
|
6
|
+
*/
|
|
7
|
+
export class Shape {
|
|
8
|
+
constructor(type: any, radius: any);
|
|
9
|
+
type: any;
|
|
10
|
+
radius: any;
|
|
11
|
+
/**
|
|
12
|
+
* @method getType
|
|
13
|
+
* @description Returns the shape type ("circle" or "polygon").
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
getType(): string;
|
|
17
|
+
/**
|
|
18
|
+
* @method getRadius
|
|
19
|
+
* @description Returns the shape's skin radius.
|
|
20
|
+
* @returns {number}
|
|
21
|
+
*/
|
|
22
|
+
getRadius(): number;
|
|
23
|
+
}
|
|
24
|
+
export type ShapeType = ShapeType;
|
|
25
|
+
export namespace ShapeType {
|
|
26
|
+
let CIRCLE: string;
|
|
27
|
+
let POLYGON: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @class CircleShape
|
|
31
|
+
* @extends Shape
|
|
32
|
+
* @description A circle, optionally offset from the body origin.
|
|
33
|
+
* @param {number} [radius=0] - Radius in physics units
|
|
34
|
+
* @param {Object} [center] - Local center `{ x, y }`, defaults to the origin
|
|
35
|
+
*/
|
|
36
|
+
export class CircleShape extends Shape {
|
|
37
|
+
constructor(radius?: number, center?: any);
|
|
38
|
+
p: Vec2;
|
|
39
|
+
/**
|
|
40
|
+
* @method getVertexCount
|
|
41
|
+
* @description A circle is a single-point proxy plus a radius.
|
|
42
|
+
* @returns {number}
|
|
43
|
+
*/
|
|
44
|
+
getVertexCount(): number;
|
|
45
|
+
/**
|
|
46
|
+
* @method getVertex
|
|
47
|
+
* @description Returns the circle's local center (its only support point).
|
|
48
|
+
* @returns {Vec2}
|
|
49
|
+
*/
|
|
50
|
+
getVertex(): Vec2;
|
|
51
|
+
/**
|
|
52
|
+
* @method getSupport
|
|
53
|
+
* @description Index of the vertex furthest along a direction (always 0).
|
|
54
|
+
* @returns {number}
|
|
55
|
+
*/
|
|
56
|
+
getSupport(): number;
|
|
57
|
+
/**
|
|
58
|
+
* @method computeAABB
|
|
59
|
+
* @description Writes this shape's world AABB under a transform.
|
|
60
|
+
* @param {AABB} aabb - Output box
|
|
61
|
+
* @param {Transform2} xf - The owning body's transform
|
|
62
|
+
*/
|
|
63
|
+
computeAABB(aabb: AABB, xf: Transform2): void;
|
|
64
|
+
/**
|
|
65
|
+
* @method computeMass
|
|
66
|
+
* @description Writes mass, center and rotational inertia for a density.
|
|
67
|
+
* @param {Object} massData - Output `{ mass, center, I }`
|
|
68
|
+
* @param {number} density
|
|
69
|
+
*/
|
|
70
|
+
computeMass(massData: any, density: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* @method testPoint
|
|
73
|
+
* @description True when a world point is inside the circle.
|
|
74
|
+
* @param {Transform2} xf
|
|
75
|
+
* @param {Object} p - World point
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
testPoint(xf: Transform2, p: any): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* @method rayCast
|
|
81
|
+
* @description Casts a ray against the circle.
|
|
82
|
+
* @param {Object} output - Written as `{ fraction, normal }` on a hit
|
|
83
|
+
* @param {Object} input - `{ p1, p2, maxFraction }` in world space
|
|
84
|
+
* @param {Transform2} xf
|
|
85
|
+
* @returns {boolean} - Whether the ray hit
|
|
86
|
+
*/
|
|
87
|
+
rayCast(output: any, input: any, xf: Transform2): boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @class PolygonShape
|
|
91
|
+
* @extends Shape
|
|
92
|
+
* @description A convex polygon with up to `MAX_VERTICES` corners, wound
|
|
93
|
+
* counter-clockwise. Boxes, by far the common case, come from
|
|
94
|
+
* {@link PolygonShape.box}.
|
|
95
|
+
* @param {Array<Object>} [points] - Optional points to build a convex hull from
|
|
96
|
+
*/
|
|
97
|
+
export class PolygonShape extends Shape {
|
|
98
|
+
/**
|
|
99
|
+
* @method box
|
|
100
|
+
* @description Builds an axis-aligned box from half-extents, optionally
|
|
101
|
+
* offset and rotated in the body's local frame.
|
|
102
|
+
* @param {number} hx - Half width
|
|
103
|
+
* @param {number} hy - Half height
|
|
104
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
105
|
+
* @param {number} [angle=0] - Local rotation in radians
|
|
106
|
+
* @returns {PolygonShape}
|
|
107
|
+
*/
|
|
108
|
+
static box(hx: number, hy: number, center?: any, angle?: number): PolygonShape;
|
|
109
|
+
constructor(points?: any);
|
|
110
|
+
vertices: any[];
|
|
111
|
+
normals: any[];
|
|
112
|
+
centroid: Vec2;
|
|
113
|
+
/**
|
|
114
|
+
* @method setAsBox
|
|
115
|
+
* @description Turns this polygon into a box in place.
|
|
116
|
+
* @param {number} hx - Half width
|
|
117
|
+
* @param {number} hy - Half height
|
|
118
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
119
|
+
* @param {number} [angle=0] - Local rotation in radians
|
|
120
|
+
* @returns {PolygonShape} - this
|
|
121
|
+
*/
|
|
122
|
+
setAsBox(hx: number, hy: number, center?: any, angle?: number): PolygonShape;
|
|
123
|
+
/**
|
|
124
|
+
* @method set
|
|
125
|
+
* @description Builds the convex hull of a point cloud. Points inside the
|
|
126
|
+
* hull are dropped, so callers can pass a rough outline.
|
|
127
|
+
* @param {Array<Object>} points - `{ x, y }` points
|
|
128
|
+
* @returns {PolygonShape} - this
|
|
129
|
+
*/
|
|
130
|
+
set(points: Array<any>): PolygonShape;
|
|
131
|
+
/**
|
|
132
|
+
* @method getVertexCount
|
|
133
|
+
* @description Number of corners.
|
|
134
|
+
* @returns {number}
|
|
135
|
+
*/
|
|
136
|
+
getVertexCount(): number;
|
|
137
|
+
/**
|
|
138
|
+
* @method getVertex
|
|
139
|
+
* @description Returns a corner by index.
|
|
140
|
+
* @param {number} index
|
|
141
|
+
* @returns {Vec2}
|
|
142
|
+
*/
|
|
143
|
+
getVertex(index: number): Vec2;
|
|
144
|
+
/**
|
|
145
|
+
* @method getSupport
|
|
146
|
+
* @description Index of the vertex furthest along a local direction: the
|
|
147
|
+
* support function GJK is built on.
|
|
148
|
+
* @param {Object} d - Local direction
|
|
149
|
+
* @returns {number}
|
|
150
|
+
*/
|
|
151
|
+
getSupport(d: any): number;
|
|
152
|
+
/**
|
|
153
|
+
* @method computeAABB
|
|
154
|
+
* @description Writes this shape's world AABB under a transform.
|
|
155
|
+
* @param {AABB} aabb - Output box
|
|
156
|
+
* @param {Transform2} xf
|
|
157
|
+
*/
|
|
158
|
+
computeAABB(aabb: AABB, xf: Transform2): void;
|
|
159
|
+
/**
|
|
160
|
+
* @method computeMass
|
|
161
|
+
* @description Writes mass, center and rotational inertia for a density by
|
|
162
|
+
* summing the triangle fan of the polygon.
|
|
163
|
+
* @param {Object} massData - Output `{ mass, center, I }`
|
|
164
|
+
* @param {number} density
|
|
165
|
+
*/
|
|
166
|
+
computeMass(massData: any, density: number): void;
|
|
167
|
+
/**
|
|
168
|
+
* @method testPoint
|
|
169
|
+
* @description True when a world point is inside the polygon.
|
|
170
|
+
* @param {Transform2} xf
|
|
171
|
+
* @param {Object} p - World point
|
|
172
|
+
* @returns {boolean}
|
|
173
|
+
*/
|
|
174
|
+
testPoint(xf: Transform2, p: any): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* @method rayCast
|
|
177
|
+
* @description Casts a ray against the polygon by clipping it against every
|
|
178
|
+
* edge plane and keeping the surviving interval.
|
|
179
|
+
* @param {Object} output - Written as `{ fraction, normal }` on a hit
|
|
180
|
+
* @param {Object} input - `{ p1, p2, maxFraction }` in world space
|
|
181
|
+
* @param {Transform2} xf
|
|
182
|
+
* @returns {boolean}
|
|
183
|
+
*/
|
|
184
|
+
rayCast(output: any, input: any, xf: Transform2): boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @function Box
|
|
188
|
+
* @description Convenience factory for a box polygon.
|
|
189
|
+
* @param {number} hx - Half width in physics units
|
|
190
|
+
* @param {number} hy - Half height in physics units
|
|
191
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
192
|
+
* @param {number} [angle=0] - Local rotation in radians
|
|
193
|
+
* @returns {PolygonShape}
|
|
194
|
+
*/
|
|
195
|
+
export function Box(hx: number, hy: number, center?: any, angle?: number): PolygonShape;
|
|
196
|
+
/**
|
|
197
|
+
* @function Circle
|
|
198
|
+
* @description Convenience factory for a circle shape.
|
|
199
|
+
* @param {number} radius - Radius in physics units
|
|
200
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
201
|
+
* @returns {CircleShape}
|
|
202
|
+
*/
|
|
203
|
+
export function Circle(radius: number, center?: any): CircleShape;
|
|
204
|
+
import AABB from "./AABB.js";
|
|
205
|
+
import { Vec2 } from "./Math2D.js";
|
|
206
|
+
import { Transform2 } from "./Math2D.js";
|
|
207
|
+
export { AABB };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function timeOfImpact
|
|
3
|
+
* @description Finds the first fraction of a step at which two moving shapes
|
|
4
|
+
* touch, by conservative advancement: measure the gap, work out the fastest the
|
|
5
|
+
* shapes could possibly close it, and skip ahead by exactly that much time,
|
|
6
|
+
* never further. Repeating this converges on the impact without ever stepping
|
|
7
|
+
* past it, which is what stops a fast body from tunnelling through a wall.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} input - `{ proxyA, proxyB, sweepA, sweepB, tMax }`
|
|
10
|
+
* @returns {{state: string, t: number}} - The outcome and the impact fraction
|
|
11
|
+
*/
|
|
12
|
+
export function timeOfImpact(input: any): {
|
|
13
|
+
state: string;
|
|
14
|
+
t: number;
|
|
15
|
+
};
|
|
16
|
+
export type TOIState = TOIState;
|
|
17
|
+
export namespace TOIState {
|
|
18
|
+
let SEPARATED: string;
|
|
19
|
+
let TOUCHING: string;
|
|
20
|
+
let OVERLAPPED: string;
|
|
21
|
+
let FAILED: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
export default World;
|
|
2
|
+
/**
|
|
3
|
+
* @class World
|
|
4
|
+
* @description The physics world: it owns the bodies, finds which ones touch,
|
|
5
|
+
* and advances them all by one time step. This is Emerald's own rigid-body
|
|
6
|
+
* engine: broadphase, narrowphase, an impulse solver and continuous collision
|
|
7
|
+
* detection, with no external physics dependency.
|
|
8
|
+
*
|
|
9
|
+
* Games normally reach it through {@link Physics}, which adds the pixel/meter
|
|
10
|
+
* conversion, a fixed-timestep accumulator and collision routing to
|
|
11
|
+
* {@link Behaviour} components.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} [def] - `{ gravity, allowSleep, warmStarting,
|
|
14
|
+
* continuousPhysics, velocityThreshold, velocityIterations,
|
|
15
|
+
* positionIterations }`
|
|
16
|
+
*/
|
|
17
|
+
declare class World {
|
|
18
|
+
constructor(def?: {});
|
|
19
|
+
gravity: Vec2;
|
|
20
|
+
broadPhase: BroadPhase;
|
|
21
|
+
contactManager: ContactManager;
|
|
22
|
+
/** Head of the body list; walk it with {@link Body#getNext}. @private */
|
|
23
|
+
private bodyList;
|
|
24
|
+
bodyCount: number;
|
|
25
|
+
/** Head of the joint list. @private */
|
|
26
|
+
private jointList;
|
|
27
|
+
jointCount: number;
|
|
28
|
+
allowSleep: boolean;
|
|
29
|
+
warmStarting: boolean;
|
|
30
|
+
continuousPhysics: boolean;
|
|
31
|
+
autoClearForces: boolean;
|
|
32
|
+
velocityThreshold: any;
|
|
33
|
+
velocityIterations: any;
|
|
34
|
+
positionIterations: any;
|
|
35
|
+
/** Optional `(fixtureA, fixtureB) => boolean` veto on new contacts. */
|
|
36
|
+
contactFilter: any;
|
|
37
|
+
/** @private */
|
|
38
|
+
private newContacts;
|
|
39
|
+
/** @private */
|
|
40
|
+
private locked;
|
|
41
|
+
/** @private */
|
|
42
|
+
private island;
|
|
43
|
+
/** @private */
|
|
44
|
+
private listeners;
|
|
45
|
+
/** @private */
|
|
46
|
+
private _toiProxyA;
|
|
47
|
+
/** @private */
|
|
48
|
+
private _toiProxyB;
|
|
49
|
+
/** What the last time-of-impact search hit. @private */
|
|
50
|
+
private _toiHitBody;
|
|
51
|
+
/**
|
|
52
|
+
* @method on
|
|
53
|
+
* @description Subscribes to a world event. Supported events:
|
|
54
|
+
* `begin-contact`, `end-contact`, `pre-solve`, `post-solve`, `remove-body`
|
|
55
|
+
* and `remove-fixture`.
|
|
56
|
+
* @param {string} name - Event name
|
|
57
|
+
* @param {Function} listener - Called with the contact (or body/fixture)
|
|
58
|
+
* @returns {World} - this
|
|
59
|
+
*/
|
|
60
|
+
on(name: string, listener: Function): World;
|
|
61
|
+
/**
|
|
62
|
+
* @method off
|
|
63
|
+
* @description Unsubscribes a listener.
|
|
64
|
+
* @param {string} name
|
|
65
|
+
* @param {Function} listener
|
|
66
|
+
* @returns {World} - this
|
|
67
|
+
*/
|
|
68
|
+
off(name: string, listener: Function): World;
|
|
69
|
+
/**
|
|
70
|
+
* @method dispatch
|
|
71
|
+
* @description Fires a world event. Listener errors are contained so one bad
|
|
72
|
+
* callback can't halt the simulation mid-step.
|
|
73
|
+
* @param {string} name
|
|
74
|
+
* @param {...*} args
|
|
75
|
+
*/
|
|
76
|
+
dispatch(name: string, ...args: any[]): void;
|
|
77
|
+
/**
|
|
78
|
+
* @method createBody
|
|
79
|
+
* @description Creates a body in this world.
|
|
80
|
+
* @param {Object} [def] - See {@link Body}
|
|
81
|
+
* @returns {Body}
|
|
82
|
+
*/
|
|
83
|
+
createBody(def?: any): Body;
|
|
84
|
+
/**
|
|
85
|
+
* @method destroyBody
|
|
86
|
+
* @description Removes a body, its fixtures and all its contacts.
|
|
87
|
+
* @param {Body} body
|
|
88
|
+
*/
|
|
89
|
+
destroyBody(body: Body): void;
|
|
90
|
+
/**
|
|
91
|
+
* @method getBodyList
|
|
92
|
+
* @description Returns the first body; walk the rest with
|
|
93
|
+
* {@link Body#getNext}.
|
|
94
|
+
* @returns {Body|null}
|
|
95
|
+
*/
|
|
96
|
+
getBodyList(): Body | null;
|
|
97
|
+
/**
|
|
98
|
+
* @method getBodyCount
|
|
99
|
+
* @description Number of bodies in the world.
|
|
100
|
+
* @returns {number}
|
|
101
|
+
*/
|
|
102
|
+
getBodyCount(): number;
|
|
103
|
+
/**
|
|
104
|
+
* @method createJoint
|
|
105
|
+
* @description Creates a constraint between two bodies, a
|
|
106
|
+
* {@link DistanceJoint} or a {@link RevoluteJoint}, chosen by `def.type`
|
|
107
|
+
* (see {@link JointType}). Wakes both bodies, since a joint pulling on a
|
|
108
|
+
* sleeping body needs it simulating again immediately.
|
|
109
|
+
* @param {Object} def - `{ type, bodyA, bodyB, ... }`, forwarded to the
|
|
110
|
+
* chosen joint's constructor
|
|
111
|
+
* @returns {Joint}
|
|
112
|
+
*/
|
|
113
|
+
createJoint(def: any): Joint;
|
|
114
|
+
/**
|
|
115
|
+
* @method destroyJoint
|
|
116
|
+
* @description Removes a joint. Safe to call as part of destroying one of
|
|
117
|
+
* its bodies (see {@link World#destroyBody}).
|
|
118
|
+
* @param {Joint} joint
|
|
119
|
+
*/
|
|
120
|
+
destroyJoint(joint: Joint): void;
|
|
121
|
+
/**
|
|
122
|
+
* @method getJointList
|
|
123
|
+
* @description Returns the first joint; walk the rest with `joint.next`.
|
|
124
|
+
* @returns {Joint|null}
|
|
125
|
+
*/
|
|
126
|
+
getJointList(): Joint | null;
|
|
127
|
+
/**
|
|
128
|
+
* @method getJointCount
|
|
129
|
+
* @returns {number}
|
|
130
|
+
*/
|
|
131
|
+
getJointCount(): number;
|
|
132
|
+
/**
|
|
133
|
+
* @method getContactList
|
|
134
|
+
* @description Returns every live contact (touching or merely close enough
|
|
135
|
+
* for their bounding boxes to overlap).
|
|
136
|
+
* @returns {Array<Contact>}
|
|
137
|
+
*/
|
|
138
|
+
getContactList(): Array<Contact>;
|
|
139
|
+
/**
|
|
140
|
+
* @method getContactCount
|
|
141
|
+
* @description Number of live contacts.
|
|
142
|
+
* @returns {number}
|
|
143
|
+
*/
|
|
144
|
+
getContactCount(): number;
|
|
145
|
+
/**
|
|
146
|
+
* @method setGravity
|
|
147
|
+
* @description Sets world gravity in physics units per second squared.
|
|
148
|
+
* @param {Object} gravity - `{ x, y }`
|
|
149
|
+
*/
|
|
150
|
+
setGravity(gravity: any): void;
|
|
151
|
+
/**
|
|
152
|
+
* @method getGravity
|
|
153
|
+
* @description Returns world gravity.
|
|
154
|
+
* @returns {Vec2}
|
|
155
|
+
*/
|
|
156
|
+
getGravity(): Vec2;
|
|
157
|
+
/**
|
|
158
|
+
* @method isLocked
|
|
159
|
+
* @description True while a step is in progress, when the body/fixture graph
|
|
160
|
+
* must not be modified.
|
|
161
|
+
* @returns {boolean}
|
|
162
|
+
*/
|
|
163
|
+
isLocked(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* @method setAllowSleeping
|
|
166
|
+
* @description Enables or disables sleeping world-wide.
|
|
167
|
+
* @param {boolean} flag
|
|
168
|
+
*/
|
|
169
|
+
setAllowSleeping(flag: boolean): void;
|
|
170
|
+
/**
|
|
171
|
+
* @method step
|
|
172
|
+
* @description Advances the simulation by `dt` seconds: refresh contacts,
|
|
173
|
+
* solve the islands, then sweep any continuous (bullet) bodies.
|
|
174
|
+
* @param {number} dt - Time step in seconds
|
|
175
|
+
* @param {number} [velocityIterations] - Solver velocity iterations
|
|
176
|
+
* @param {number} [positionIterations] - Solver position iterations
|
|
177
|
+
*/
|
|
178
|
+
step(dt: number, velocityIterations?: number, positionIterations?: number): void;
|
|
179
|
+
/**
|
|
180
|
+
* @method solve
|
|
181
|
+
* @description Groups the awake bodies into islands of things that touch and
|
|
182
|
+
* solves each island on its own.
|
|
183
|
+
* @param {Object} step
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
private solve;
|
|
187
|
+
/**
|
|
188
|
+
* @method solveContinuous
|
|
189
|
+
* @description Sweeps every bullet body against the static and kinematic
|
|
190
|
+
* geometry it passed through this step, and rewinds it to the first impact.
|
|
191
|
+
* Without this, a body moving further than its own size in one step would
|
|
192
|
+
* simply appear on the far side of a thin wall.
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
private solveContinuous;
|
|
196
|
+
/**
|
|
197
|
+
* @method _absorbImpactVelocity
|
|
198
|
+
* @description Takes the excess approach speed out of a body that a rewind
|
|
199
|
+
* stopped short of a *moving* obstacle, leaving it travelling with whatever
|
|
200
|
+
* it landed on.
|
|
201
|
+
*
|
|
202
|
+
* The rewind puts the body where the two first touched, but the obstacle
|
|
203
|
+
* carries on to the end of the step, so the body is left hovering by up to
|
|
204
|
+
* one step of the obstacle's travel, too far apart for the discrete solver
|
|
205
|
+
* to see a contact next step. Keeping the body's original velocity as well
|
|
206
|
+
* means it arrives even faster the following step, is rewound again, and
|
|
207
|
+
* never lands: a rider on a descending platform would fall for ever without
|
|
208
|
+
* ever standing on it. Dropping the approach speed to the obstacle's own
|
|
209
|
+
* closes that gap within a step or two, which is where the discrete solver
|
|
210
|
+
* takes over and the two stay in contact.
|
|
211
|
+
*
|
|
212
|
+
* Static obstacles are left alone: they do not run away from the body, so
|
|
213
|
+
* the overlap the rewind aims for survives into the next step and the
|
|
214
|
+
* discrete solver already handles them.
|
|
215
|
+
*
|
|
216
|
+
* @param {Body} body - The body that was rewound
|
|
217
|
+
* @param {number} dx - How far it swept this step, before the rewind
|
|
218
|
+
* @param {number} dy
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
private _absorbImpactVelocity;
|
|
222
|
+
/**
|
|
223
|
+
* @method _findTimeOfImpact
|
|
224
|
+
* @description Earliest fraction of this step at which `body` first touches
|
|
225
|
+
* non-dynamic geometry, or null when it hits nothing. The body that was hit
|
|
226
|
+
* is left in `_toiHitBody`.
|
|
227
|
+
* @param {Body} body
|
|
228
|
+
* @returns {number|null}
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
private _findTimeOfImpact;
|
|
232
|
+
/**
|
|
233
|
+
* @method clearForces
|
|
234
|
+
* @description Zeroes the accumulated forces and torques on every body.
|
|
235
|
+
* Called automatically at the end of each step.
|
|
236
|
+
*/
|
|
237
|
+
clearForces(): void;
|
|
238
|
+
/**
|
|
239
|
+
* @method rayCast
|
|
240
|
+
* @description Casts a ray from `p1` to `p2`, calling
|
|
241
|
+
* `callback(fixture, point, normal, fraction)` for every fixture hit.
|
|
242
|
+
*
|
|
243
|
+
* The callback controls what happens next, exactly like a filter: return the
|
|
244
|
+
* `fraction` to clip the ray there and keep looking for closer hits (the
|
|
245
|
+
* usual "closest hit" behaviour), `0` to stop immediately, `1` to keep the
|
|
246
|
+
* full ray and collect every hit, or `-1` to ignore this fixture entirely.
|
|
247
|
+
*
|
|
248
|
+
* @param {Object} p1 - Ray start `{ x, y }` in physics units
|
|
249
|
+
* @param {Object} p2 - Ray end `{ x, y }` in physics units
|
|
250
|
+
* @param {Function} callback
|
|
251
|
+
*/
|
|
252
|
+
rayCast(p1: any, p2: any, callback: Function): void;
|
|
253
|
+
/**
|
|
254
|
+
* @method queryAABB
|
|
255
|
+
* @description Calls `callback(fixture)` for every fixture whose bounding box
|
|
256
|
+
* overlaps `aabb`. Returning false from the callback ends the query.
|
|
257
|
+
* @param {AABB} aabb
|
|
258
|
+
* @param {Function} callback
|
|
259
|
+
*/
|
|
260
|
+
queryAABB(aabb: AABB, callback: Function): void;
|
|
261
|
+
/**
|
|
262
|
+
* @method queryPoint
|
|
263
|
+
* @description Calls `callback(fixture)` for every fixture containing a
|
|
264
|
+
* world-space point.
|
|
265
|
+
* @param {Object} point - `{ x, y }` in physics units
|
|
266
|
+
* @param {Function} callback
|
|
267
|
+
*/
|
|
268
|
+
queryPoint(point: any, callback: Function): void;
|
|
269
|
+
}
|
|
270
|
+
import { Vec2 } from "./Math2D.js";
|
|
271
|
+
import { BroadPhase } from "./BroadPhase.js";
|
|
272
|
+
import { ContactManager } from "./Contact.js";
|
|
273
|
+
import { Body } from "./Body.js";
|
|
274
|
+
import AABB from "./AABB.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import World from "./World.js";
|
|
2
|
+
import { Body } from "./Body.js";
|
|
3
|
+
import { BodyType } from "./Body.js";
|
|
4
|
+
import { Fixture } from "./Fixture.js";
|
|
5
|
+
import { Contact } from "./Contact.js";
|
|
6
|
+
import { ContactManager } from "./Contact.js";
|
|
7
|
+
import { shouldCollide } from "./Contact.js";
|
|
8
|
+
import { Shape } from "./Shapes.js";
|
|
9
|
+
import { ShapeType } from "./Shapes.js";
|
|
10
|
+
import { CircleShape } from "./Shapes.js";
|
|
11
|
+
import { PolygonShape } from "./Shapes.js";
|
|
12
|
+
import { Box } from "./Shapes.js";
|
|
13
|
+
import { Circle } from "./Shapes.js";
|
|
14
|
+
import { Vec2 } from "./Math2D.js";
|
|
15
|
+
import { Rot } from "./Math2D.js";
|
|
16
|
+
import { Transform2 } from "./Math2D.js";
|
|
17
|
+
import { Sweep } from "./Math2D.js";
|
|
18
|
+
import AABB from "./AABB.js";
|
|
19
|
+
import Settings from "./Settings.js";
|
|
20
|
+
import { Manifold } from "./Collision.js";
|
|
21
|
+
import { ManifoldType } from "./Collision.js";
|
|
22
|
+
import { WorldManifold } from "./Collision.js";
|
|
23
|
+
import { DistanceProxy } from "./Distance.js";
|
|
24
|
+
import { distance } from "./Distance.js";
|
|
25
|
+
import { testOverlap } from "./Distance.js";
|
|
26
|
+
import { timeOfImpact } from "./TimeOfImpact.js";
|
|
27
|
+
import { TOIState } from "./TimeOfImpact.js";
|
|
28
|
+
import { BroadPhase } from "./BroadPhase.js";
|
|
29
|
+
import { DynamicTree } from "./BroadPhase.js";
|
|
30
|
+
import { Joint } from "./Joint.js";
|
|
31
|
+
import { JointType } from "./Joint.js";
|
|
32
|
+
import DistanceJoint from "./DistanceJoint.js";
|
|
33
|
+
import RevoluteJoint from "./RevoluteJoint.js";
|
|
34
|
+
export { World, Body, BodyType, Fixture, Contact, ContactManager, shouldCollide, Shape, ShapeType, CircleShape, PolygonShape, Box, Circle, Vec2, Rot, Transform2, Sweep, AABB, Settings, Manifold, ManifoldType, WorldManifold, DistanceProxy, distance, testOverlap, timeOfImpact, TOIState, BroadPhase, DynamicTree, Joint, JointType, DistanceJoint, RevoluteJoint };
|