@playcraft/build 0.0.4 → 0.0.8
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/analyzers/scene-asset-collector.js +210 -1
- package/dist/base-builder.d.ts +15 -0
- package/dist/base-builder.js +192 -16
- package/dist/generators/config-generator.js +29 -3
- package/dist/loaders/playcanvas-loader.d.ts +7 -0
- package/dist/loaders/playcanvas-loader.js +53 -3
- package/dist/platforms/adikteev.d.ts +10 -0
- package/dist/platforms/adikteev.js +72 -0
- package/dist/platforms/base.d.ts +12 -0
- package/dist/platforms/base.js +208 -0
- package/dist/platforms/facebook.js +5 -2
- package/dist/platforms/index.d.ts +4 -0
- package/dist/platforms/index.js +16 -0
- package/dist/platforms/inmobi.d.ts +10 -0
- package/dist/platforms/inmobi.js +68 -0
- package/dist/platforms/ironsource.js +5 -2
- package/dist/platforms/moloco.js +5 -2
- package/dist/platforms/playcraft.d.ts +33 -0
- package/dist/platforms/playcraft.js +44 -0
- package/dist/platforms/remerge.d.ts +10 -0
- package/dist/platforms/remerge.js +56 -0
- package/dist/templates/__loading__.js +100 -0
- package/dist/templates/__modules__.js +47 -0
- package/dist/templates/__settings__.template.js +20 -0
- package/dist/templates/__start__.js +332 -0
- package/dist/templates/index.html +18 -0
- package/dist/templates/logo.png +0 -0
- package/dist/templates/manifest.json +1 -0
- package/dist/templates/patches/cannon.min.js +28 -0
- package/dist/templates/patches/lz4.js +10 -0
- package/dist/templates/patches/one-page-http-get.js +20 -0
- package/dist/templates/patches/one-page-inline-game-scripts.js +52 -0
- package/dist/templates/patches/one-page-mraid-resize-canvas.js +46 -0
- package/dist/templates/patches/p2.min.js +27 -0
- package/dist/templates/patches/playcraft-no-xhr.js +76 -0
- package/dist/templates/playcanvas-stable.min.js +16363 -0
- package/dist/templates/styles.css +43 -0
- package/dist/types.d.ts +14 -1
- package/dist/utils/build-mode-detector.d.ts +9 -0
- package/dist/utils/build-mode-detector.js +42 -0
- package/dist/vite/config-builder.d.ts +29 -1
- package/dist/vite/config-builder.js +169 -25
- package/dist/vite/platform-configs.d.ts +4 -0
- package/dist/vite/platform-configs.js +97 -13
- package/dist/vite/plugin-esm-html-generator.d.ts +22 -0
- package/dist/vite/plugin-esm-html-generator.js +1061 -0
- package/dist/vite/plugin-platform.js +56 -17
- package/dist/vite/plugin-playcanvas.d.ts +2 -0
- package/dist/vite/plugin-playcanvas.js +497 -40
- package/dist/vite/plugin-source-builder.d.ts +3 -0
- package/dist/vite/plugin-source-builder.js +886 -19
- package/dist/vite-builder.d.ts +19 -2
- package/dist/vite-builder.js +162 -12
- package/package.json +2 -1
- package/physics/cannon-es-bundle.js +13092 -0
- package/physics/cannon-rigidbody-adapter.js +375 -0
- package/physics/connon-integration.js +411 -0
- package/templates/__start__.js +8 -3
- package/templates/index.esm.html +20 -0
- package/templates/index.esm.mjs +502 -0
- package/templates/patches/one-page-inline-game-scripts.js +25 -1
- package/templates/patches/playcraft-cta-adapter.js +297 -0
- package/templates/patches/playcraft-no-xhr.js +25 -1
- package/templates/playcanvas-esm-wrapper.mjs +827 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cannon.js Rigidbody Adapter for PlayCanvas
|
|
3
|
+
*
|
|
4
|
+
* This adapter creates a compatibility layer between PlayCanvas's native rigidbody API
|
|
5
|
+
* and Cannon.js physics engine. It allows existing PlayCanvas projects using
|
|
6
|
+
* Ammo.js to seamlessly switch to Cannon.js without code changes.
|
|
7
|
+
*
|
|
8
|
+
* Usage: This script is automatically injected when using Cannon.js replacement.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
(function() {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
// Wait for PlayCanvas to be ready
|
|
15
|
+
if (typeof pc === 'undefined' || typeof CANNON === 'undefined') {
|
|
16
|
+
console.error('[Cannon Adapter] PlayCanvas or Cannon.js not loaded');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
console.log('[Cannon Adapter] Initializing Cannon.js rigidbody adapter...');
|
|
21
|
+
|
|
22
|
+
// Store references
|
|
23
|
+
var cannonWorld = null;
|
|
24
|
+
var rigidBodyMap = []; // Array of { entity, body } pairs
|
|
25
|
+
var initialized = false;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initialize Cannon World
|
|
29
|
+
*/
|
|
30
|
+
function initCannonWorld(app) {
|
|
31
|
+
if (cannonWorld) return cannonWorld;
|
|
32
|
+
|
|
33
|
+
// Create Cannon world
|
|
34
|
+
var world = new CANNON.World();
|
|
35
|
+
|
|
36
|
+
// Get gravity from settings or use default
|
|
37
|
+
var gravity = (window.SCENE_SETTINGS && window.SCENE_SETTINGS.physics && window.SCENE_SETTINGS.physics.gravity)
|
|
38
|
+
|| [0, -9.8, 0];
|
|
39
|
+
|
|
40
|
+
world.gravity.set(gravity[0], gravity[1], gravity[2]);
|
|
41
|
+
|
|
42
|
+
// Setup collision events
|
|
43
|
+
world.addEventListener('beginContact', function(event) {
|
|
44
|
+
var bodyA = event.bodyA;
|
|
45
|
+
var bodyB = event.bodyB;
|
|
46
|
+
|
|
47
|
+
if (bodyA.entity && bodyB.entity) {
|
|
48
|
+
bodyA.entity.fire('collisionstart', { other: bodyB.entity });
|
|
49
|
+
bodyB.entity.fire('collisionstart', { other: bodyA.entity });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
world.addEventListener('endContact', function(event) {
|
|
54
|
+
var bodyA = event.bodyA;
|
|
55
|
+
var bodyB = event.bodyB;
|
|
56
|
+
|
|
57
|
+
if (bodyA.entity && bodyB.entity) {
|
|
58
|
+
bodyA.entity.fire('collisionend', { other: bodyB.entity });
|
|
59
|
+
bodyB.entity.fire('collisionend', { other: bodyA.entity });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
cannonWorld = world;
|
|
64
|
+
console.log('[Cannon Adapter] Cannon world created with gravity:', gravity);
|
|
65
|
+
return world;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Create Cannon shape from PlayCanvas collision component
|
|
70
|
+
*/
|
|
71
|
+
function createCannonShape(entity) {
|
|
72
|
+
var collision = entity.collision;
|
|
73
|
+
if (!collision) return null;
|
|
74
|
+
|
|
75
|
+
var shape;
|
|
76
|
+
var type = collision.type;
|
|
77
|
+
|
|
78
|
+
if (type === 'box') {
|
|
79
|
+
var halfExtents = collision.halfExtents;
|
|
80
|
+
shape = new CANNON.Box(new CANNON.Vec3(
|
|
81
|
+
halfExtents.x,
|
|
82
|
+
halfExtents.y,
|
|
83
|
+
halfExtents.z
|
|
84
|
+
));
|
|
85
|
+
} else if (type === 'sphere') {
|
|
86
|
+
shape = new CANNON.Sphere(collision.radius);
|
|
87
|
+
} else if (type === 'capsule') {
|
|
88
|
+
// Cannon doesn't have capsule, use cylinder
|
|
89
|
+
shape = new CANNON.Cylinder(
|
|
90
|
+
collision.radius,
|
|
91
|
+
collision.radius,
|
|
92
|
+
collision.height,
|
|
93
|
+
8
|
|
94
|
+
);
|
|
95
|
+
} else if (type === 'cylinder') {
|
|
96
|
+
shape = new CANNON.Cylinder(
|
|
97
|
+
collision.radius,
|
|
98
|
+
collision.radius,
|
|
99
|
+
collision.height,
|
|
100
|
+
8
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
console.warn('[Cannon Adapter] Unsupported collision type:', type);
|
|
104
|
+
// Default to box
|
|
105
|
+
shape = new CANNON.Box(new CANNON.Vec3(0.5, 0.5, 0.5));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return shape;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Create Cannon body from PlayCanvas rigidbody component
|
|
113
|
+
*/
|
|
114
|
+
function createCannonBody(entity, world) {
|
|
115
|
+
if (!entity.rigidbody || !entity.collision) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var rb = entity.rigidbody;
|
|
120
|
+
var shape = createCannonShape(entity);
|
|
121
|
+
if (!shape) return null;
|
|
122
|
+
|
|
123
|
+
var pos = entity.getPosition();
|
|
124
|
+
var rot = entity.getRotation();
|
|
125
|
+
|
|
126
|
+
var mass = rb.mass || 0;
|
|
127
|
+
var bodyType = rb.type;
|
|
128
|
+
|
|
129
|
+
// Map PlayCanvas body types to Cannon
|
|
130
|
+
// PlayCanvas: 'static' | 'dynamic' | 'kinematic'
|
|
131
|
+
if (bodyType === 'static') {
|
|
132
|
+
mass = 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var body = new CANNON.Body({
|
|
136
|
+
mass: mass,
|
|
137
|
+
position: new CANNON.Vec3(pos.x, pos.y, pos.z),
|
|
138
|
+
quaternion: new CANNON.Quaternion(rot.x, rot.y, rot.z, rot.w),
|
|
139
|
+
shape: shape
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (bodyType === 'kinematic') {
|
|
143
|
+
body.type = CANNON.Body.KINEMATIC;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Store entity reference
|
|
147
|
+
body.entity = entity;
|
|
148
|
+
|
|
149
|
+
// Store friction and restitution
|
|
150
|
+
if (rb.friction !== undefined) {
|
|
151
|
+
body.material = body.material || new CANNON.Material();
|
|
152
|
+
body.material.friction = rb.friction;
|
|
153
|
+
}
|
|
154
|
+
if (rb.restitution !== undefined) {
|
|
155
|
+
body.material = body.material || new CANNON.Material();
|
|
156
|
+
body.material.restitution = rb.restitution;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Add to world
|
|
160
|
+
world.addBody(body);
|
|
161
|
+
rigidBodyMap.push({ entity: entity, body: body });
|
|
162
|
+
|
|
163
|
+
console.log('[Cannon Adapter] Created body for entity:', entity.name, 'type:', bodyType);
|
|
164
|
+
return body;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Create compatibility layer for rigidbody API
|
|
169
|
+
*/
|
|
170
|
+
function wrapRigidbodyAPI(entity, cannonBody) {
|
|
171
|
+
var rb = entity.rigidbody;
|
|
172
|
+
if (!rb) return;
|
|
173
|
+
|
|
174
|
+
// Store original rigidbody component
|
|
175
|
+
var originalRb = {};
|
|
176
|
+
for (var key in rb) {
|
|
177
|
+
if (rb.hasOwnProperty(key)) {
|
|
178
|
+
originalRb[key] = rb[key];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Override rigidbody methods to use Cannon.js
|
|
183
|
+
rb.applyForce = function(x, y, z, px, py, pz) {
|
|
184
|
+
var force = new CANNON.Vec3(x, y, z);
|
|
185
|
+
if (px !== undefined && py !== undefined && pz !== undefined) {
|
|
186
|
+
var point = new CANNON.Vec3(px, py, pz);
|
|
187
|
+
cannonBody.applyForce(force, point);
|
|
188
|
+
} else {
|
|
189
|
+
cannonBody.applyForce(force);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
rb.applyImpulse = function(impulse, relativePoint) {
|
|
194
|
+
var cannonImpulse;
|
|
195
|
+
if (impulse.x !== undefined) {
|
|
196
|
+
cannonImpulse = new CANNON.Vec3(impulse.x, impulse.y, impulse.z);
|
|
197
|
+
} else {
|
|
198
|
+
cannonImpulse = new CANNON.Vec3(impulse, relativePoint || 0, arguments[2] || 0);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (relativePoint && relativePoint.x !== undefined) {
|
|
202
|
+
var point = new CANNON.Vec3(relativePoint.x, relativePoint.y, relativePoint.z);
|
|
203
|
+
cannonBody.applyImpulse(cannonImpulse, point);
|
|
204
|
+
} else {
|
|
205
|
+
cannonBody.applyImpulse(cannonImpulse);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
rb.applyTorque = function(x, y, z) {
|
|
210
|
+
var torque = new CANNON.Vec3(x, y, z);
|
|
211
|
+
cannonBody.applyTorque(torque);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
rb.applyTorqueImpulse = function(x, y, z) {
|
|
215
|
+
// Cannon doesn't have applyTorqueImpulse, use velocity directly
|
|
216
|
+
cannonBody.angularVelocity.x += x / cannonBody.mass;
|
|
217
|
+
cannonBody.angularVelocity.y += y / cannonBody.mass;
|
|
218
|
+
cannonBody.angularVelocity.z += z / cannonBody.mass;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
rb.teleport = function(x, y, z, rx, ry, rz, rw) {
|
|
222
|
+
if (typeof x === 'object') {
|
|
223
|
+
// Called with Vec3
|
|
224
|
+
cannonBody.position.set(x.x, x.y, x.z);
|
|
225
|
+
if (y && y.x !== undefined) {
|
|
226
|
+
// Second argument is rotation Quat
|
|
227
|
+
cannonBody.quaternion.set(y.x, y.y, y.z, y.w);
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
cannonBody.position.set(x, y, z);
|
|
231
|
+
if (rx !== undefined) {
|
|
232
|
+
cannonBody.quaternion.set(rx, ry, rz, rw);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
cannonBody.velocity.set(0, 0, 0);
|
|
236
|
+
cannonBody.angularVelocity.set(0, 0, 0);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// Velocity properties
|
|
240
|
+
Object.defineProperty(rb, 'linearVelocity', {
|
|
241
|
+
get: function() {
|
|
242
|
+
return new pc.Vec3(
|
|
243
|
+
cannonBody.velocity.x,
|
|
244
|
+
cannonBody.velocity.y,
|
|
245
|
+
cannonBody.velocity.z
|
|
246
|
+
);
|
|
247
|
+
},
|
|
248
|
+
set: function(v) {
|
|
249
|
+
cannonBody.velocity.set(v.x, v.y, v.z);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
Object.defineProperty(rb, 'angularVelocity', {
|
|
254
|
+
get: function() {
|
|
255
|
+
return new pc.Vec3(
|
|
256
|
+
cannonBody.angularVelocity.x,
|
|
257
|
+
cannonBody.angularVelocity.y,
|
|
258
|
+
cannonBody.angularVelocity.z
|
|
259
|
+
);
|
|
260
|
+
},
|
|
261
|
+
set: function(v) {
|
|
262
|
+
cannonBody.angularVelocity.set(v.x, v.y, v.z);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Store cannon body reference
|
|
267
|
+
entity.cannonBody = cannonBody;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Sync Cannon bodies with PlayCanvas entities
|
|
272
|
+
*/
|
|
273
|
+
function syncBodies() {
|
|
274
|
+
if (!cannonWorld) return;
|
|
275
|
+
|
|
276
|
+
for (var i = 0; i < rigidBodyMap.length; i++) {
|
|
277
|
+
var pair = rigidBodyMap[i];
|
|
278
|
+
var entity = pair.entity;
|
|
279
|
+
var cannonBody = pair.body;
|
|
280
|
+
|
|
281
|
+
if (cannonBody.type === CANNON.Body.STATIC) {
|
|
282
|
+
// Sync static bodies from entity to cannon
|
|
283
|
+
var pos = entity.getPosition();
|
|
284
|
+
var rot = entity.getRotation();
|
|
285
|
+
cannonBody.position.set(pos.x, pos.y, pos.z);
|
|
286
|
+
cannonBody.quaternion.set(rot.x, rot.y, rot.z, rot.w);
|
|
287
|
+
} else if (cannonBody.sleepState !== CANNON.Body.SLEEPING) {
|
|
288
|
+
// Sync dynamic/kinematic bodies from cannon to entity
|
|
289
|
+
entity.setPosition(
|
|
290
|
+
cannonBody.position.x,
|
|
291
|
+
cannonBody.position.y,
|
|
292
|
+
cannonBody.position.z
|
|
293
|
+
);
|
|
294
|
+
entity.setRotation(
|
|
295
|
+
cannonBody.quaternion.x,
|
|
296
|
+
cannonBody.quaternion.y,
|
|
297
|
+
cannonBody.quaternion.z,
|
|
298
|
+
cannonBody.quaternion.w
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Initialize all rigidbodies in the scene
|
|
306
|
+
*/
|
|
307
|
+
function initializeRigidbodies(app) {
|
|
308
|
+
if (initialized) return;
|
|
309
|
+
|
|
310
|
+
console.log('[Cannon Adapter] Scanning for rigidbody components...');
|
|
311
|
+
|
|
312
|
+
var world = initCannonWorld(app);
|
|
313
|
+
var count = 0;
|
|
314
|
+
|
|
315
|
+
// Find all entities with rigidbody component
|
|
316
|
+
function processEntity(entity) {
|
|
317
|
+
if (entity.rigidbody && entity.collision) {
|
|
318
|
+
var body = createCannonBody(entity, world);
|
|
319
|
+
if (body) {
|
|
320
|
+
wrapRigidbodyAPI(entity, body);
|
|
321
|
+
count++;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Process children
|
|
326
|
+
var children = entity.children;
|
|
327
|
+
for (var i = 0; i < children.length; i++) {
|
|
328
|
+
processEntity(children[i]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
processEntity(app.root);
|
|
333
|
+
|
|
334
|
+
console.log('[Cannon Adapter] Initialized', count, 'rigidbodies');
|
|
335
|
+
initialized = true;
|
|
336
|
+
|
|
337
|
+
// Hook into update loop
|
|
338
|
+
var fixedTimeStep = 1/60;
|
|
339
|
+
var maxSubSteps = 3;
|
|
340
|
+
|
|
341
|
+
app.on('update', function(dt) {
|
|
342
|
+
if (cannonWorld) {
|
|
343
|
+
cannonWorld.step(fixedTimeStep, dt, maxSubSteps);
|
|
344
|
+
syncBodies();
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Expose world on app for debugging
|
|
349
|
+
app.cannonWorld = cannonWorld;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Wait for app to be ready and initialize
|
|
354
|
+
*/
|
|
355
|
+
function waitForApp() {
|
|
356
|
+
if (typeof pc !== 'undefined' && pc.Application && pc.Application.getApplication) {
|
|
357
|
+
var app = pc.Application.getApplication();
|
|
358
|
+
if (app) {
|
|
359
|
+
// Wait for first frame to ensure all scripts are loaded
|
|
360
|
+
setTimeout(function() {
|
|
361
|
+
initializeRigidbodies(app);
|
|
362
|
+
}, 100);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Retry after a short delay
|
|
368
|
+
setTimeout(waitForApp, 50);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Start initialization
|
|
372
|
+
waitForApp();
|
|
373
|
+
|
|
374
|
+
console.log('[Cannon Adapter] Adapter loaded, waiting for app initialization...');
|
|
375
|
+
})();
|