@safe-engine/cocos 1.5.8 → 1.6.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/dist/box2d-wasm/ContactListener.js +9 -9
- package/dist/box2d-wasm/PhysicsComponent.d.ts +12 -14
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsComponent.js +0 -3
- package/dist/box2d-wasm/PhysicsSystem.d.ts +1 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +18 -33
- package/dist/box2d-wasm/debugDraw.js +1 -1
- package/dist/box2d-wasm/index.d.ts +1 -1
- package/dist/box2d-wasm/index.d.ts.map +1 -1
- package/dist/box2d-wasm/index.js +4 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
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) {
|
|
@@ -22,8 +22,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
22
22
|
// listRemoveBody = []
|
|
23
23
|
// listRemoveShape = []
|
|
24
24
|
// })
|
|
25
|
-
const phys1 = ett1.getComponent(
|
|
26
|
-
const phys2 = ett2.getComponent(
|
|
25
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
26
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
27
27
|
// console.log('addPostStepCallback', ett1, phys1.props.onBeginContact, phys2.props)
|
|
28
28
|
if (phys1 && phys2) {
|
|
29
29
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onBeginContact')) {
|
|
@@ -41,8 +41,8 @@ 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
48
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onEndContact')) {
|
|
@@ -60,8 +60,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
60
60
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
61
61
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
62
62
|
// const event1 = ett1.getComponent(NodeComp)
|
|
63
|
-
const phys1 = ett1.getComponent(
|
|
64
|
-
const phys2 = ett2.getComponent(
|
|
63
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
64
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
65
65
|
// const event2 = ett2.getComponent(NodeComp)
|
|
66
66
|
if (phys1 && phys2) {
|
|
67
67
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
|
|
@@ -79,8 +79,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
79
79
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
80
80
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
81
81
|
// const event1 = ett1.getComponent(NodeComp)
|
|
82
|
-
const phys1 = ett1.getComponent(
|
|
83
|
-
const phys2 = ett2.getComponent(
|
|
82
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
83
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
84
84
|
// const event2 = ett2.getComponent(NodeComp)
|
|
85
85
|
if (phys1 && phys2) {
|
|
86
86
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
|
|
@@ -8,37 +8,35 @@ interface RigidBodyProps {
|
|
|
8
8
|
restitution?: Float;
|
|
9
9
|
friction?: Float;
|
|
10
10
|
gravityScale?: Float;
|
|
11
|
+
isSensor?: boolean;
|
|
12
|
+
tag?: number;
|
|
13
|
+
onBeginContact?: (other: RigidBody) => void;
|
|
14
|
+
onEndContact?: (other: RigidBody) => void;
|
|
15
|
+
onPreSolve?: (other: RigidBody, impulse?: any) => void;
|
|
16
|
+
onPostSolve?: (other: RigidBody, oldManifold?: any) => void;
|
|
11
17
|
}
|
|
12
18
|
export declare class RigidBody extends NoRenderComponentX<RigidBodyProps> {
|
|
13
19
|
body: Box2D.b2Body;
|
|
14
|
-
}
|
|
15
|
-
interface ColliderPhysicsProps {
|
|
16
|
-
tag?: number;
|
|
17
|
-
offset?: Vec2;
|
|
18
|
-
onBeginContact?: (other: PhysicsCollider) => void;
|
|
19
|
-
onEndContact?: (other: PhysicsCollider) => void;
|
|
20
|
-
onPreSolve?: (other: PhysicsCollider, impulse?: any) => void;
|
|
21
|
-
onPostSolve?: (other: PhysicsCollider, oldManifold?: any) => void;
|
|
22
|
-
}
|
|
23
|
-
export declare class PhysicsCollider extends NoRenderComponentX<ColliderPhysicsProps & BaseComponentProps<PhysicsCollider>> {
|
|
24
|
-
enabled: boolean;
|
|
25
20
|
physicSprite: PhysicsSprite;
|
|
26
21
|
}
|
|
27
22
|
interface BoxColliderPhysicsProps {
|
|
28
23
|
width: number;
|
|
29
24
|
height: number;
|
|
25
|
+
offset?: Vec2;
|
|
30
26
|
}
|
|
31
|
-
export declare class PhysicsBoxCollider extends NoRenderComponentX<BoxColliderPhysicsProps & BaseComponentProps<
|
|
27
|
+
export declare class PhysicsBoxCollider extends NoRenderComponentX<BoxColliderPhysicsProps & BaseComponentProps<PhysicsBoxCollider>> {
|
|
32
28
|
}
|
|
33
29
|
interface CircleColliderPhysicsProps {
|
|
34
30
|
radius: number;
|
|
31
|
+
offset?: Vec2;
|
|
35
32
|
}
|
|
36
|
-
export declare class PhysicsCircleCollider extends NoRenderComponentX<CircleColliderPhysicsProps & BaseComponentProps<
|
|
33
|
+
export declare class PhysicsCircleCollider extends NoRenderComponentX<CircleColliderPhysicsProps & BaseComponentProps<PhysicsCircleCollider>> {
|
|
37
34
|
}
|
|
38
35
|
interface PolygonColliderPhysicsProps {
|
|
39
36
|
points: Array<Vec2> | [number, number][];
|
|
37
|
+
offset?: Vec2;
|
|
40
38
|
}
|
|
41
|
-
export declare class PhysicsPolygonCollider extends NoRenderComponentX<PolygonColliderPhysicsProps & BaseComponentProps<
|
|
39
|
+
export declare class PhysicsPolygonCollider extends NoRenderComponentX<PolygonColliderPhysicsProps & BaseComponentProps<PhysicsPolygonCollider>> {
|
|
42
40
|
}
|
|
43
41
|
export {};
|
|
44
42
|
//# 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,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/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;
|
|
1
|
+
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,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Aa,qBAAsB,SAAQ,kBAAkB,CAAC,0BAA0B,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CAAG;AACxI,UAAU,2BAA2B;IACnC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;IACxC,MAAM,CAAC,EAAE,IAAI,CAAA;CACd;AACD,qBAAa,sBAAuB,SAAQ,kBAAkB,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;CAAG"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { NoRenderComponentX } from '../gworld/core/decorator';
|
|
2
2
|
export class RigidBody extends NoRenderComponentX {
|
|
3
3
|
body;
|
|
4
|
-
}
|
|
5
|
-
export class PhysicsCollider extends NoRenderComponentX {
|
|
6
|
-
enabled = true;
|
|
7
4
|
physicSprite;
|
|
8
5
|
}
|
|
9
6
|
export class PhysicsBoxCollider extends NoRenderComponentX {
|
|
@@ -11,6 +11,7 @@ export declare class PhysicsSystem implements System {
|
|
|
11
11
|
listRemoveShape: Box2D.b2Shape[];
|
|
12
12
|
colliderMatrix: boolean[][];
|
|
13
13
|
graphics: cc.DrawNode;
|
|
14
|
+
addDebug(): void;
|
|
14
15
|
configure(event_manager: EventManager): void;
|
|
15
16
|
update(entities: EntityManager, events: EventManager, dt: number): void;
|
|
16
17
|
set enabled(val: any);
|
|
@@ -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;AAQ5E,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,UAAU,IAAI,CAAA;AAC3B,eAAO,IAAI,KAAK,EAAE,OAAO,KAAK,CAA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3,7 @@ import { EventTypes } from 'entityx-ts';
|
|
|
3
3
|
import { GameWorld, instantiate, NodeComp, Vec2 } from '..';
|
|
4
4
|
import { makeContactListener } from './ContactListener';
|
|
5
5
|
import { makeDebugDraw } from './debugDraw';
|
|
6
|
-
import { PhysicsBoxCollider, PhysicsCircleCollider,
|
|
6
|
+
import { PhysicsBoxCollider, PhysicsCircleCollider, PhysicsPolygonCollider, RigidBody } from './PhysicsComponent';
|
|
7
7
|
import { PhysicsSprite } from './PhysicsSprite';
|
|
8
8
|
export const DynamicBody = 2;
|
|
9
9
|
export const KinematicBody = 1;
|
|
@@ -36,20 +36,20 @@ export class PhysicsSystem {
|
|
|
36
36
|
listRemoveShape = [];
|
|
37
37
|
colliderMatrix = [[true]];
|
|
38
38
|
graphics;
|
|
39
|
+
addDebug() {
|
|
40
|
+
const debugDraw = makeDebugDraw(this.graphics, pixelsPerMeter, box2D);
|
|
41
|
+
this.world.SetDebugDraw(debugDraw);
|
|
42
|
+
}
|
|
39
43
|
configure(event_manager) {
|
|
40
44
|
const { b2BodyDef, b2FixtureDef, b2PolygonShape, b2CircleShape, b2Vec2, b2World, pointsToVec2Array, getPointer } = box2D;
|
|
41
45
|
const gravity = new b2Vec2(0, -10);
|
|
42
46
|
this.world = new b2World(gravity);
|
|
43
47
|
console.log('configure PhysicsSystem world', this.world);
|
|
44
|
-
// event_manager.world.physicsManager = this
|
|
45
48
|
const graphics = new cc.DrawNode();
|
|
46
49
|
this.graphics = graphics;
|
|
47
50
|
graphics.zIndex = 1000;
|
|
48
51
|
const scene = cc.director.getRunningScene();
|
|
49
52
|
scene.addChild(graphics);
|
|
50
|
-
const debugDraw = makeDebugDraw(graphics, pixelsPerMeter, box2D);
|
|
51
|
-
this.world.SetDebugDraw(debugDraw);
|
|
52
|
-
// event_manager.subscribe(ComponentAddedEvent(RigidBody), this);
|
|
53
53
|
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsBoxCollider, ({ entity, component }) => {
|
|
54
54
|
console.log('ComponentAddedEvent PhysicsBoxCollider', component);
|
|
55
55
|
let rigidBody = entity.getComponent(RigidBody);
|
|
@@ -57,16 +57,11 @@ export class PhysicsSystem {
|
|
|
57
57
|
rigidBody = instantiate(RigidBody);
|
|
58
58
|
entity.assign(rigidBody);
|
|
59
59
|
}
|
|
60
|
-
let physicsCollide = entity.getComponent(PhysicsCollider);
|
|
61
|
-
if (!physicsCollide) {
|
|
62
|
-
physicsCollide = instantiate(PhysicsCollider);
|
|
63
|
-
entity.assign(physicsCollide);
|
|
64
|
-
}
|
|
65
60
|
const { type = StaticBody, gravityScale = 1, density = 1, friction = 0.5, restitution = 0.3 } = rigidBody.props;
|
|
66
61
|
const box = component;
|
|
67
62
|
const node = entity.getComponent(NodeComp);
|
|
68
|
-
const { width, height } = box.props;
|
|
69
|
-
const { x = 0, y = 0 } =
|
|
63
|
+
const { width, height, offset } = box.props;
|
|
64
|
+
const { x = 0, y = 0 } = offset || {};
|
|
70
65
|
const zero = new b2Vec2(x, y);
|
|
71
66
|
const position = new b2Vec2(node.posX, node.posY);
|
|
72
67
|
const bd = new b2BodyDef();
|
|
@@ -91,8 +86,8 @@ export class PhysicsSystem {
|
|
|
91
86
|
body.SetAwake(true);
|
|
92
87
|
body.SetEnabled(true);
|
|
93
88
|
metadata[getPointer(body)] = node;
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
rigidBody.physicSprite = physicsNode;
|
|
90
|
+
rigidBody.node = node;
|
|
96
91
|
box.node = node;
|
|
97
92
|
});
|
|
98
93
|
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsCircleCollider, ({ entity, component }) => {
|
|
@@ -102,15 +97,10 @@ export class PhysicsSystem {
|
|
|
102
97
|
rigidBody = instantiate(RigidBody);
|
|
103
98
|
entity.assign(rigidBody);
|
|
104
99
|
}
|
|
105
|
-
let physicsCollide = entity.getComponent(PhysicsCollider);
|
|
106
|
-
if (!physicsCollide) {
|
|
107
|
-
physicsCollide = instantiate(PhysicsCollider);
|
|
108
|
-
entity.assign(physicsCollide);
|
|
109
|
-
}
|
|
110
100
|
const { type = StaticBody, gravityScale = 1, density = 1, friction = 0.5, restitution = 0.3 } = rigidBody.props;
|
|
111
101
|
const node = entity.getComponent(NodeComp);
|
|
112
|
-
const { radius } = component.props;
|
|
113
|
-
const { x = 0, y = 0 } =
|
|
102
|
+
const { radius, offset } = component.props;
|
|
103
|
+
const { x = 0, y = 0 } = offset || {};
|
|
114
104
|
const zero = new b2Vec2(x, y);
|
|
115
105
|
const position = new b2Vec2(node.posX, node.posY);
|
|
116
106
|
const bd = new b2BodyDef();
|
|
@@ -135,8 +125,8 @@ export class PhysicsSystem {
|
|
|
135
125
|
body.SetAwake(true);
|
|
136
126
|
body.SetEnabled(true);
|
|
137
127
|
metadata[getPointer(body)] = node;
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
rigidBody.physicSprite = physicsNode;
|
|
129
|
+
rigidBody.node = node;
|
|
140
130
|
component.node = node;
|
|
141
131
|
});
|
|
142
132
|
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsPolygonCollider, ({ entity, component }) => {
|
|
@@ -146,16 +136,11 @@ export class PhysicsSystem {
|
|
|
146
136
|
rigidBody = instantiate(RigidBody);
|
|
147
137
|
entity.assign(rigidBody);
|
|
148
138
|
}
|
|
149
|
-
let physicsCollide = entity.getComponent(PhysicsCollider);
|
|
150
|
-
if (!physicsCollide) {
|
|
151
|
-
physicsCollide = instantiate(PhysicsCollider);
|
|
152
|
-
entity.assign(physicsCollide);
|
|
153
|
-
}
|
|
154
139
|
const { type = StaticBody, gravityScale = 1, density = 1, friction = 0.5, restitution = 0.3 } = rigidBody.props;
|
|
155
140
|
const node = entity.getComponent(NodeComp);
|
|
156
|
-
const { points } = component.props;
|
|
141
|
+
const { points, offset } = component.props;
|
|
157
142
|
// ett.assign(instantiate(PhysicsCollider, { tag, offset }))
|
|
158
|
-
const { x = 0, y = 0 } =
|
|
143
|
+
const { x = 0, y = 0 } = offset || {};
|
|
159
144
|
const zero = new b2Vec2(0, 0);
|
|
160
145
|
const position = new b2Vec2(node.posX, node.posY);
|
|
161
146
|
const { width, height } = node.getContentSize();
|
|
@@ -189,11 +174,11 @@ export class PhysicsSystem {
|
|
|
189
174
|
body.SetAwake(true);
|
|
190
175
|
body.SetEnabled(true);
|
|
191
176
|
metadata[getPointer(body)] = node;
|
|
192
|
-
|
|
193
|
-
|
|
177
|
+
rigidBody.physicSprite = physicsNode;
|
|
178
|
+
rigidBody.node = node;
|
|
194
179
|
component.node = node;
|
|
195
180
|
});
|
|
196
|
-
event_manager.subscribe(EventTypes.ComponentRemoved,
|
|
181
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, RigidBody, ({ component }) => {
|
|
197
182
|
// console.log('ComponentRemovedEvent NodeComp', component)
|
|
198
183
|
if (component.physicSprite instanceof PhysicsSprite) {
|
|
199
184
|
const body = component.physicSprite.getBody();
|
|
@@ -69,7 +69,7 @@ export const makeDebugDraw = (graphics, pixelsPerMeter, box2D) => {
|
|
|
69
69
|
* @returns {void}
|
|
70
70
|
*/
|
|
71
71
|
const drawCircle = (center, radius, axis, fill) => {
|
|
72
|
-
graphics.drawCircle(center, radius, 0,
|
|
72
|
+
graphics.drawCircle(center, radius, 0, 32, true, 2, fill);
|
|
73
73
|
};
|
|
74
74
|
/**
|
|
75
75
|
* @param {Box2D.b2Vec2} vert1
|
|
@@ -2,5 +2,5 @@ import { GameWorld } from '..';
|
|
|
2
2
|
export * from './PhysicsComponent';
|
|
3
3
|
export * from './PhysicsSprite';
|
|
4
4
|
export * from './PhysicsSystem';
|
|
5
|
-
export declare function setupPhysics(world?: GameWorld): void;
|
|
5
|
+
export declare function setupPhysics(world?: GameWorld, isDebugDraw?: any): void;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAG9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,YAAY,CAAC,KAAK,YAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAG9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,YAAY,CAAC,KAAK,YAAqB,EAAE,WAAW,CAAC,KAAA,QAOpE"}
|
package/dist/box2d-wasm/index.js
CHANGED
|
@@ -3,8 +3,11 @@ import { PhysicsSystem } from './PhysicsSystem';
|
|
|
3
3
|
export * from './PhysicsComponent';
|
|
4
4
|
export * from './PhysicsSprite';
|
|
5
5
|
export * from './PhysicsSystem';
|
|
6
|
-
export function setupPhysics(world = GameWorld.Instance) {
|
|
6
|
+
export function setupPhysics(world = GameWorld.Instance, isDebugDraw) {
|
|
7
7
|
world.systems.add(PhysicsSystem);
|
|
8
8
|
world.systems.configureOnce(PhysicsSystem);
|
|
9
9
|
world.listUpdate.push(PhysicsSystem);
|
|
10
|
+
if (isDebugDraw) {
|
|
11
|
+
world.systems.get(PhysicsSystem).addDebug();
|
|
12
|
+
}
|
|
10
13
|
}
|