@safe-engine/pixi 8.4.6 → 8.5.1
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 +14 -23
- package/dist/box2d-wasm/ContactListener.d.ts +1 -1
- package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
- package/dist/box2d-wasm/ContactListener.js +50 -18
- package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsComponent.js +44 -11
- package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSprite.js +24 -3
- package/dist/box2d-wasm/PhysicsSystem.d.ts +4 -2
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +134 -44
- package/dist/collider/CollideComponent.d.ts +27 -10
- package/dist/collider/CollideComponent.d.ts.map +1 -1
- package/dist/collider/CollideComponent.js +10 -12
- package/dist/collider/helper/Intersection.d.ts +6 -6
- package/dist/collider/helper/Intersection.d.ts.map +1 -1
- package/dist/collider/helper/Intersection.js +4 -4
- package/dist/components/NodeComp.js +1 -1
- package/dist/helper/utils.d.ts +0 -6
- package/dist/helper/utils.d.ts.map +1 -1
- package/dist/helper/utils.js +0 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/{src/spine/lib/require-shim.ts → dist/spine/lib/assets/atlasLoader.d.ts} +5 -14
- package/dist/spine/lib/assets/atlasLoader.d.ts.map +1 -0
- package/dist/spine/lib/assets/atlasLoader.js +122 -0
- package/{src/spine/lib/darktint/DarkTintShader.ts → dist/spine/lib/assets/skeletonLoader.d.ts} +3 -47
- package/dist/spine/lib/assets/skeletonLoader.d.ts.map +1 -0
- package/dist/spine/lib/assets/skeletonLoader.js +70 -0
- package/package.json +6 -2
- package/.github/workflows/npm-publish.yml +0 -35
- package/dist/@types/safex.d.ts +0 -15
- package/src/@types/index.d.ts +0 -2
- package/src/app.ts +0 -91
- package/src/base/EnhancedComponent.ts +0 -38
- package/src/base/gworld.ts +0 -20
- package/src/base/index.ts +0 -14
- package/src/base/utils.ts +0 -23
- package/src/box2d-wasm/ContactListener.ts +0 -66
- package/src/box2d-wasm/PhysicsComponent.ts +0 -83
- package/src/box2d-wasm/PhysicsSprite.ts +0 -42
- package/src/box2d-wasm/PhysicsSystem.ts +0 -142
- package/src/box2d-wasm/debugDraw.ts +0 -249
- package/src/box2d-wasm/index.ts +0 -19
- package/src/collider/CollideComponent.ts +0 -257
- package/src/collider/CollideSystem.ts +0 -166
- package/src/collider/helper/Intersection.ts +0 -139
- package/src/collider/helper/utils.ts +0 -37
- package/src/collider/index.ts +0 -16
- package/src/components/BaseComponent.ts +0 -17
- package/src/components/NodeComp.ts +0 -442
- package/src/components/Scene.ts +0 -17
- package/src/core/Color.ts +0 -7
- package/src/core/LoadingBar.ts +0 -63
- package/src/core/NodePool.ts +0 -28
- package/src/core/Size.ts +0 -21
- package/src/core/Vec2.ts +0 -108
- package/src/core/director.ts +0 -11
- package/src/core/index.ts +0 -7
- package/src/core/loader.ts +0 -14
- package/src/core/math.ts +0 -22
- package/src/dragonbones/DragonBonesComponent.ts +0 -32
- package/src/dragonbones/DragonBonesSystem.ts +0 -35
- package/src/dragonbones/index.ts +0 -11
- package/src/gui/GUIComponent.ts +0 -155
- package/src/gui/GUISystem.ts +0 -125
- package/src/helper/utils.ts +0 -50
- package/src/index.ts +0 -19
- package/src/norender/NoRenderComponent.ts +0 -60
- package/src/norender/NoRenderSystem.ts +0 -67
- package/src/norender/Touch.ts +0 -37
- package/src/planck/PhysicsComponent.ts +0 -83
- package/src/planck/PhysicsSprite.ts +0 -43
- package/src/planck/PhysicsSystem.ts +0 -201
- package/src/planck/index.ts +0 -3
- package/src/render/RenderComponent.ts +0 -132
- package/src/render/RenderSystem.ts +0 -64
- package/src/richtext/RichTextComp.ts +0 -50
- package/src/richtext/RichTextSystem.ts +0 -26
- package/src/richtext/html-text-parser.ts +0 -87
- package/src/richtext/index.ts +0 -8
- package/src/spine/SpineComponent.ts +0 -18
- package/src/spine/SpineSystem.ts +0 -30
- package/src/spine/index.ts +0 -11
- package/src/spine/lib/BatchableSpineSlot.ts +0 -138
- package/src/spine/lib/Spine.ts +0 -894
- package/src/spine/lib/SpineDebugRenderer.ts +0 -615
- package/src/spine/lib/SpinePipe.ts +0 -203
- package/src/spine/lib/SpineTexture.ts +0 -143
- package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
- package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
- package/src/spine/lib/darktint/darkTintBit.ts +0 -77
- package/src/spine/lib/index.ts +0 -43
- package/tsconfig.json +0 -18
- /package/{dist/@types → @types}/index.d.ts +0 -0
package/README.md
CHANGED
|
@@ -13,11 +13,12 @@ Safex is an open-source game engine written in TypeScript, combining the power o
|
|
|
13
13
|
- All components must be extends from `ComponentX` or `NoRenderComponentX`
|
|
14
14
|
- `NoRenderComponentX` will append to component of parent node have `ComponentX`, `ComponentX` will be `addChild` to parent node
|
|
15
15
|
- `node` property represent node, and can pass properties to assign
|
|
16
|
-
- Example `<SpriteRender node={{
|
|
16
|
+
- Example `<SpriteRender node={{ xy: [5, 9] }} />`
|
|
17
17
|
- `$ref` bind component with current class property as string
|
|
18
18
|
- `$push` push component to list
|
|
19
|
-
- `
|
|
20
|
-
- `
|
|
19
|
+
- `$refNode` and `$pushNode` for `NodeComp` component from any component.
|
|
20
|
+
- `Array(2).map(_, i)` iteration repeat component 2 times
|
|
21
|
+
- `Loading.listItems.map(item, i = 1)` iteration in class static property
|
|
21
22
|
- `listItems.map(item, i)` iteration in const variable
|
|
22
23
|
|
|
23
24
|
## Benefits
|
|
@@ -32,7 +33,7 @@ Safex is an open-source game engine written in TypeScript, combining the power o
|
|
|
32
33
|
npm install @safe-engine/pixi
|
|
33
34
|
```
|
|
34
35
|
|
|
35
|
-
#
|
|
36
|
+
# Show case
|
|
36
37
|
|
|
37
38
|
```sh
|
|
38
39
|
git clone https://github.com/Safe-engine/pixi-safe-engine-demo
|
|
@@ -40,18 +41,8 @@ npm install @safe-engine/pixi
|
|
|
40
41
|
|
|
41
42
|
## Basic Example
|
|
42
43
|
|
|
43
|
-
```tsx game.ts
|
|
44
|
-
import { addGameCanvasTo, loadScene, startGameSystems } from 'safex'
|
|
45
|
-
async function start() {
|
|
46
|
-
await addGameCanvasTo('canvasId')
|
|
47
|
-
startGameSystems()
|
|
48
|
-
loadScene(GameScene)
|
|
49
|
-
}
|
|
50
|
-
start()
|
|
51
|
-
```
|
|
52
|
-
|
|
53
44
|
```tsx GameScene.tsx
|
|
54
|
-
import { SceneComponent, LabelComp, ButtonComp, SpriteRender, instantiate } from '
|
|
45
|
+
import { SceneComponent, LabelComp, ButtonComp, SpriteRender, instantiate } from '@safe-engine/pixi'
|
|
55
46
|
import ColliderSprite from './ColliderSprite'
|
|
56
47
|
|
|
57
48
|
export class GameScene extends ComponentX {
|
|
@@ -79,8 +70,8 @@ export class GameScene extends ComponentX {
|
|
|
79
70
|
// onTouchEnd={this.onTouchEnd}
|
|
80
71
|
onTouchMove={this.onTouchMove}
|
|
81
72
|
/>
|
|
82
|
-
<LabelComp $ref={this.label} node={{
|
|
83
|
-
<SpriteRender $ref={this.sprite} node={{
|
|
73
|
+
<LabelComp $ref={this.label} node={{ xy: [106, 240] }} string="Hello safex" font={defaultFont} />
|
|
74
|
+
<SpriteRender $ref={this.sprite} node={{ xy: [500, 600] }} spriteFrame={'path/to/sprite.png'}>
|
|
84
75
|
<ButtonComp onPress={this.onPress} />
|
|
85
76
|
</SpriteRender>
|
|
86
77
|
</SceneComponent>
|
|
@@ -92,17 +83,17 @@ export class GameScene extends ComponentX {
|
|
|
92
83
|
## Collider Events
|
|
93
84
|
|
|
94
85
|
```tsx
|
|
95
|
-
import { BoxCollider, Collider, ComponentX, SpriteRender } from '
|
|
86
|
+
import { BoxCollider, Collider, ComponentX, SpriteRender } from '@safe-engine/pixi'
|
|
96
87
|
import { sf_crash } from '../assets'
|
|
97
88
|
|
|
98
89
|
export class ColliderSprite extends ComponentX {
|
|
99
90
|
onCollisionEnter(other: Collider) {
|
|
100
|
-
console.log(other.tag)
|
|
91
|
+
console.log(other.props.tag)
|
|
101
92
|
}
|
|
102
93
|
|
|
103
94
|
render() {
|
|
104
95
|
return (
|
|
105
|
-
<SpriteRender node={{
|
|
96
|
+
<SpriteRender node={{ xy: [640, 360] }} spriteFrame={sf_crash}>
|
|
106
97
|
<BoxCollider height={100} width={100}></BoxCollider>
|
|
107
98
|
</SpriteRender>
|
|
108
99
|
)
|
|
@@ -113,17 +104,17 @@ export class ColliderSprite extends ComponentX {
|
|
|
113
104
|
## Physics Events
|
|
114
105
|
|
|
115
106
|
```tsx
|
|
116
|
-
import { PhysicsBoxCollider, PhysicsCollider, RigidBody, ComponentX, SpriteRender } from '
|
|
107
|
+
import { PhysicsBoxCollider, PhysicsCollider, RigidBody, ComponentX, SpriteRender } from '@safe-engine/pixi'
|
|
117
108
|
import { sf_crash } from '../assets'
|
|
118
109
|
|
|
119
110
|
export class PhysicsCollider extends ComponentX {
|
|
120
|
-
onCollisionEnter(col:
|
|
111
|
+
onCollisionEnter(col: RigidBody) {
|
|
121
112
|
console.log('onCollisionEnter', col)
|
|
122
113
|
}
|
|
123
114
|
|
|
124
115
|
render() {
|
|
125
116
|
return (
|
|
126
|
-
<SpriteRender node={{
|
|
117
|
+
<SpriteRender node={{ xy: [640, 360] }} spriteFrame={sf_crash}>
|
|
127
118
|
<RigidBody type="static"></RigidBody>
|
|
128
119
|
<PhysicsBoxCollider height={100} width={100}></PhysicsBoxCollider>
|
|
129
120
|
</SpriteRender>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactListener.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/ContactListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"ContactListener.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/ContactListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAG7B,KAAK,IAAI,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AACvC,eAAO,MAAM,mBAAmB,GAAI,OAAO,KAAK,CAAC,OAAO,EAAE,UAAU,IAAI,EAAE,OAAO,OAAO,KAAK;0BAWnE,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;wBAwBjC,KAAK,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI;sBAmBjC,KAAK,CAAC,SAAS,GAAG,MAAM,eAAe,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI;uBAmBtE,KAAK,CAAC,SAAS,GAAG,MAAM,WAAW,KAAK,CAAC,gBAAgB,GAAG,MAAM,GAAG,IAAI;CAqB/F,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RigidBody } from './PhysicsComponent';
|
|
2
2
|
export const makeContactListener = (world, metadata, box2D) => {
|
|
3
3
|
const { JSContactListener, getPointer, NULL } = box2D;
|
|
4
4
|
function getContactById(contact) {
|
|
5
5
|
for (let contactList = world.GetContactList(); getPointer(contactList) !== getPointer(NULL); contactList = contactList.GetNext()) {
|
|
6
6
|
if (getPointer(contactList) === contact) {
|
|
7
|
-
console.log('contactBegin', contact, getPointer(contactList), getPointer(NULL))
|
|
7
|
+
// console.log('contactBegin', contact, getPointer(contactList), getPointer(NULL))
|
|
8
8
|
return contactList;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -17,20 +17,20 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
17
17
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
18
18
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
19
19
|
// world.addPostStepCallback(() => {
|
|
20
|
-
// // log('addPostStepCallback');
|
|
21
20
|
// listRemoveShape.forEach((s) => world.removeShape(s))
|
|
22
21
|
// listRemoveBody.forEach((b) => world.removeBody(b))
|
|
23
22
|
// listRemoveBody = []
|
|
24
23
|
// listRemoveShape = []
|
|
25
24
|
// })
|
|
26
|
-
const phys1 = ett1.getComponent(
|
|
27
|
-
const phys2 = ett2.getComponent(
|
|
25
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
26
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
27
|
+
// console.log('addPostStepCallback', ett1, phys1.props.onBeginContact, phys2.props)
|
|
28
28
|
if (phys1 && phys2) {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(phys1, '
|
|
30
|
-
phys1.props.
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onBeginContact')) {
|
|
30
|
+
phys1.props.onBeginContact(phys2);
|
|
31
31
|
}
|
|
32
|
-
if (Object.prototype.hasOwnProperty.call(phys2, '
|
|
33
|
-
phys2.props.
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(phys2.props, 'onBeginContact')) {
|
|
33
|
+
phys2.props.onBeginContact(phys1);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
},
|
|
@@ -41,24 +41,56 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
41
41
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
42
42
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
43
43
|
// const event1 = ett1.getComponent(NodeComp)
|
|
44
|
-
const phys1 = ett1.getComponent(
|
|
45
|
-
const phys2 = ett2.getComponent(
|
|
44
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
45
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
46
46
|
// const event2 = ett2.getComponent(NodeComp)
|
|
47
47
|
if (phys1 && phys2) {
|
|
48
|
-
if (Object.prototype.hasOwnProperty.call(phys1, '
|
|
49
|
-
phys1.props.
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onEndContact')) {
|
|
49
|
+
phys1.props.onEndContact(phys2);
|
|
50
50
|
}
|
|
51
|
-
if (Object.prototype.hasOwnProperty.call(phys2, '
|
|
52
|
-
phys2.props.
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(phys2.props, 'onEndContact')) {
|
|
52
|
+
phys2.props.onEndContact(phys1);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
PreSolve(contact, oldManifold) {
|
|
57
|
-
|
|
57
|
+
if (typeof contact === 'number') {
|
|
58
|
+
contact = getContactById(contact);
|
|
59
|
+
}
|
|
60
|
+
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
61
|
+
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
62
|
+
// const event1 = ett1.getComponent(NodeComp)
|
|
63
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
64
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
65
|
+
// const event2 = ett2.getComponent(NodeComp)
|
|
66
|
+
if (phys1 && phys2) {
|
|
67
|
+
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
|
|
68
|
+
phys1.props.onPostSolve(phys2, oldManifold);
|
|
69
|
+
}
|
|
70
|
+
if (Object.prototype.hasOwnProperty.call(phys2.props, 'onPostSolve')) {
|
|
71
|
+
phys2.props.onPostSolve(phys1, oldManifold);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
58
74
|
},
|
|
59
75
|
PostSolve(contact, impulse) {
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
if (typeof contact === 'number') {
|
|
77
|
+
contact = getContactById(contact);
|
|
78
|
+
}
|
|
79
|
+
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
80
|
+
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
81
|
+
// const event1 = ett1.getComponent(NodeComp)
|
|
82
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
83
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
84
|
+
// const event2 = ett2.getComponent(NodeComp)
|
|
85
|
+
if (phys1 && phys2) {
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
|
|
87
|
+
phys1.props.onPostSolve(phys2, impulse);
|
|
88
|
+
}
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(phys2.props, 'onPostSolve')) {
|
|
90
|
+
phys2.props.onPostSolve(phys1, impulse);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
62
94
|
});
|
|
63
95
|
return listener;
|
|
64
96
|
};
|
|
@@ -1,50 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NoRenderComponentX } from '
|
|
1
|
+
import { BaseComponentProps, Vec2 } from '..';
|
|
2
|
+
import { NoRenderComponentX } from '../components/BaseComponent';
|
|
3
3
|
import { PhysicsSprite } from './PhysicsSprite';
|
|
4
4
|
interface RigidBodyProps {
|
|
5
|
-
type?:
|
|
5
|
+
type?: 0 | 1 | 2;
|
|
6
6
|
density?: Float;
|
|
7
7
|
restitution?: Float;
|
|
8
8
|
friction?: Float;
|
|
9
9
|
gravityScale?: Float;
|
|
10
|
+
isSensor?: boolean;
|
|
11
|
+
tag?: number;
|
|
12
|
+
onBeginContact?: (other: RigidBody) => void;
|
|
13
|
+
onEndContact?: (other: RigidBody) => void;
|
|
14
|
+
onPreSolve?: (other: RigidBody, impulse?: any) => void;
|
|
15
|
+
onPostSolve?: (other: RigidBody, oldManifold?: any) => void;
|
|
10
16
|
}
|
|
11
17
|
export declare class RigidBody extends NoRenderComponentX<RigidBodyProps> {
|
|
12
18
|
body: Box2D.b2Body;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
interface
|
|
22
|
-
tag?: number;
|
|
23
|
-
group?: number;
|
|
24
|
-
offset?: Vec2;
|
|
25
|
-
onCollisionEnter?: (other: ColliderPhysics) => void;
|
|
26
|
-
onCollisionExit?: (other: ColliderPhysics) => void;
|
|
27
|
-
onCollisionStay?: (other: ColliderPhysics) => void;
|
|
28
|
-
}
|
|
29
|
-
export declare class ColliderPhysics<T extends ColliderPhysicsProps = ColliderPhysicsProps> extends NoRenderComponentX<T, PhysicsSprite['node']> {
|
|
30
|
-
enabled: boolean;
|
|
31
|
-
instance: PhysicsSprite;
|
|
32
|
-
}
|
|
33
|
-
interface BoxColliderPhysicsProps extends ColliderPhysicsProps {
|
|
19
|
+
physicSprite: PhysicsSprite;
|
|
20
|
+
set linearVelocity(vel: Vec2);
|
|
21
|
+
get linearVelocity(): Vec2;
|
|
22
|
+
applyForceToCenter(vel: Vec2): void;
|
|
23
|
+
applyLinearImpulseToCenter(vel: Vec2): void;
|
|
24
|
+
set position(pos: Vec2);
|
|
25
|
+
get position(): Vec2;
|
|
26
|
+
}
|
|
27
|
+
interface BoxColliderPhysicsProps {
|
|
34
28
|
width: number;
|
|
35
29
|
height: number;
|
|
30
|
+
offset?: [number, number];
|
|
36
31
|
}
|
|
37
|
-
export declare class
|
|
32
|
+
export declare class PhysicsBoxCollider extends NoRenderComponentX<BoxColliderPhysicsProps & BaseComponentProps<PhysicsBoxCollider>> {
|
|
38
33
|
}
|
|
39
|
-
interface CircleColliderPhysicsProps
|
|
34
|
+
interface CircleColliderPhysicsProps {
|
|
40
35
|
radius: number;
|
|
36
|
+
offset?: [number, number];
|
|
41
37
|
}
|
|
42
|
-
export declare class
|
|
38
|
+
export declare class PhysicsCircleCollider extends NoRenderComponentX<CircleColliderPhysicsProps & BaseComponentProps<PhysicsCircleCollider>> {
|
|
43
39
|
}
|
|
44
|
-
interface PolygonColliderPhysicsProps
|
|
45
|
-
points: Array<Vec2
|
|
40
|
+
interface PolygonColliderPhysicsProps {
|
|
41
|
+
points: Array<Vec2> | [number, number][];
|
|
42
|
+
offset?: [number, number];
|
|
46
43
|
}
|
|
47
|
-
export declare class
|
|
44
|
+
export declare class PhysicsPolygonCollider extends NoRenderComponentX<PolygonColliderPhysicsProps & BaseComponentProps<PhysicsPolygonCollider>> {
|
|
48
45
|
}
|
|
49
46
|
export {};
|
|
50
47
|
//# sourceMappingURL=PhysicsComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG/C,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IAC3C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;IACzC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,KAAA,KAAK,IAAI,CAAA;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,KAAA,KAAK,IAAI,CAAA;CACvD;AAED,qBAAa,SAAU,SAAQ,kBAAkB,CAAC,cAAc,CAAC;IAC/D,IAAI,EAAE,KAAK,CAAC,MAAM,CAAA;IAClB,YAAY,EAAE,aAAa,CAAA;IAC3B,IAAI,cAAc,CAAC,GAAG,EAAE,IAAI,EAK3B;IAED,IAAI,cAAc,IAPM,IAAI,CAa3B;IAED,kBAAkB,CAAC,GAAG,EAAE,IAAI;IAO5B,0BAA0B,CAAC,GAAG,EAAE,IAAI;IAQpC,IAAI,QAAQ,CAAC,GAAG,EAAE,IAAI,EASrB;IAED,IAAI,QAAQ,IAXM,IAAI,CAarB;CACF;AAED,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,kBAAmB,SAAQ,kBAAkB,CAAC,uBAAuB,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;CAS3H;AACD,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,qBAAsB,SAAQ,kBAAkB,CAAC,0BAA0B,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CAAI;AACzI,UAAU,2BAA2B;IACnC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;IACxC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,sBAAuB,SAAQ,kBAAkB,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;CAAI"}
|
|
@@ -1,17 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vec2 } from '..';
|
|
2
|
+
import { NoRenderComponentX } from '../components/BaseComponent';
|
|
3
|
+
import { box2D } from './PhysicsSystem';
|
|
2
4
|
export class RigidBody extends NoRenderComponentX {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
set linearVelocity(vel) {
|
|
6
|
+
if (!this.node) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
this.body.SetLinearVelocity(new box2D.b2Vec2(vel.x, vel.y));
|
|
10
|
+
}
|
|
11
|
+
get linearVelocity() {
|
|
12
|
+
if (!this.node) {
|
|
13
|
+
return Vec2.ZERO;
|
|
14
|
+
}
|
|
15
|
+
const vel = this.body.GetLinearVelocity();
|
|
16
|
+
return Vec2(vel);
|
|
17
|
+
}
|
|
18
|
+
applyForceToCenter(vel) {
|
|
19
|
+
if (!this.node) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.body.ApplyForceToCenter(new box2D.b2Vec2(vel.x, vel.y), true);
|
|
23
|
+
}
|
|
24
|
+
applyLinearImpulseToCenter(vel) {
|
|
25
|
+
if (!this.node) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// console.log('applyLinearImpulseToCenter', new box2D.b2Vec2(vel.x, vel.y))
|
|
29
|
+
this.body.ApplyLinearImpulseToCenter(new box2D.b2Vec2(vel.x, vel.y), true);
|
|
30
|
+
}
|
|
31
|
+
set position(pos) {
|
|
32
|
+
this.physicSprite.node.position = Vec2(pos.x, pos.y);
|
|
33
|
+
const physicsPos = new box2D.b2Vec2(pos.x, pos.y);
|
|
34
|
+
// console.log('SetTransform', pos, physicsPos)
|
|
35
|
+
const body = this.body;
|
|
36
|
+
body.SetLinearVelocity(new box2D.b2Vec2(0, 0));
|
|
37
|
+
body.SetAngularVelocity(0);
|
|
38
|
+
body.SetAwake(true);
|
|
39
|
+
body.SetTransform(physicsPos, this.node.rotation);
|
|
40
|
+
}
|
|
41
|
+
get position() {
|
|
42
|
+
return Vec2(this.physicSprite.getBody().GetPosition());
|
|
10
43
|
}
|
|
11
44
|
}
|
|
12
|
-
export class
|
|
45
|
+
export class PhysicsBoxCollider extends NoRenderComponentX {
|
|
13
46
|
}
|
|
14
|
-
export class
|
|
47
|
+
export class PhysicsCircleCollider extends NoRenderComponentX {
|
|
15
48
|
}
|
|
16
|
-
export class
|
|
49
|
+
export class PhysicsPolygonCollider extends NoRenderComponentX {
|
|
17
50
|
}
|
|
@@ -3,6 +3,9 @@ export declare class PhysicsSprite {
|
|
|
3
3
|
node: Container;
|
|
4
4
|
physicsBody: Box2D.b2Body;
|
|
5
5
|
constructor(node: Container, body: Box2D.b2Body);
|
|
6
|
+
update(dt: number): void;
|
|
7
|
+
getBody(): Box2D.b2Body;
|
|
8
|
+
set position(val: Box2D.b2Vec2);
|
|
6
9
|
get x(): number;
|
|
7
10
|
get y(): number;
|
|
8
11
|
get angle(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsSprite.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"PhysicsSprite.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGnC,qBAAa,aAAa;IACxB,IAAI,EAAE,SAAS,CAAA;IACf,WAAW,EAAE,KAAK,CAAC,MAAM,CAAA;gBAEb,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM;IAK/C,MAAM,CAAC,EAAE,EAAE,MAAM;IAkBjB,OAAO;IAIP,IAAI,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,EAE7B;IASD,IAAI,CAAC,WAEJ;IAED,IAAI,CAAC,WAEJ;IAMD,IAAI,KAAK,WAER;IAED,QAAQ,CAAC,KAAK,EAAE,SAAS;CAG1B"}
|
|
@@ -1,11 +1,29 @@
|
|
|
1
|
+
import { Vec2, radiansToDegrees } from '..';
|
|
1
2
|
export class PhysicsSprite {
|
|
2
3
|
constructor(node, body) {
|
|
3
4
|
this.node = node;
|
|
4
5
|
this.physicsBody = body;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
update(dt) {
|
|
8
|
+
if (!this.physicsBody) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
// const pos = this.physicsBody.GetPosition()
|
|
12
|
+
// use lerp to smooth the position update
|
|
13
|
+
const pos = Vec2(lerp(this.node.x, this.physicsBody.GetPosition().x, dt * 10), lerp(this.node.y, this.physicsBody.GetPosition().y, dt * 10));
|
|
14
|
+
this.node.position = Vec2(pos.x, pos.y);
|
|
15
|
+
// lerp the rotation
|
|
16
|
+
this.node.rotation = lerp(this.node.rotation, radiansToDegrees(-this.physicsBody.GetAngle()), dt * 10);
|
|
17
|
+
// this.node.setRotation(radiansToDegrees(this.physicsBody.GetAngle()))
|
|
18
|
+
// this.node.setScale(1 / pixelsPerMeter)
|
|
19
|
+
// this.node.setScale(1 / this.physicsBody.GetFixtureList().GetShape().GetRadius())
|
|
20
|
+
}
|
|
21
|
+
getBody() {
|
|
22
|
+
return this.physicsBody;
|
|
23
|
+
}
|
|
24
|
+
set position(val) {
|
|
25
|
+
this.physicsBody.SetTransform(val, this.node.rotation);
|
|
26
|
+
}
|
|
9
27
|
// set x(val) {
|
|
10
28
|
// this.physicsBody.setPosition(Vec2(val, this.y))
|
|
11
29
|
// }
|
|
@@ -28,3 +46,6 @@ export class PhysicsSprite {
|
|
|
28
46
|
this.node.addChild(child);
|
|
29
47
|
}
|
|
30
48
|
}
|
|
49
|
+
function lerp(a, b, t) {
|
|
50
|
+
return a + (b - a) * t;
|
|
51
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { EntityManager, EventManager, System } from 'entityx-ts';
|
|
2
2
|
import { Graphics } from 'pixi.js';
|
|
3
3
|
import { Vec2 } from '..';
|
|
4
|
+
export declare const DynamicBody = 2;
|
|
5
|
+
export declare const KinematicBody = 1;
|
|
6
|
+
export declare const StaticBody = 0;
|
|
4
7
|
export declare let box2D: typeof Box2D;
|
|
5
8
|
export declare function initBox2d(): Promise<void>;
|
|
6
9
|
export declare function setColliderMatrix(colliderMatrix?: boolean[][]): void;
|
|
7
10
|
export declare class PhysicsSystem implements System {
|
|
8
11
|
world: Box2D.b2World;
|
|
9
|
-
listRemoveBody:
|
|
10
|
-
listRemoveShape: Box2D.b2Shape[];
|
|
12
|
+
listRemoveBody: Box2D.b2Body[];
|
|
11
13
|
colliderMatrix: boolean[][];
|
|
12
14
|
graphics: Graphics;
|
|
13
15
|
addDebug(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAoC,IAAI,EAAE,MAAM,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAoC,IAAI,EAAE,MAAM,IAAI,CAAA;AAY3D,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,UAAU,IAAI,CAAA;AAC3B,eAAO,IAAI,KAAK,EAAE,OAAO,KAAK,CAAA;AAE9B,wBAAsB,SAAS,kBAE9B;AAED,wBAAgB,iBAAiB,CAAC,cAAc,cAAW,QAG1D;AAOD,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,EAAE,KAAK,CAAC,OAAO,CAAA;IACpB,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,CAAK;IAEnC,cAAc,cAAW;IACzB,QAAQ,EAAE,QAAQ,CAAA;IAElB,QAAQ;IAKR,SAAS,CAAC,aAAa,EAAE,YAAY;IA8JrC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IA0BhE,IAAI,OAAO,CAAC,GAAG,EAAE,IAAI,EAIpB;CACF"}
|