@playcraft/build 0.0.3 → 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 +17 -0
- package/dist/base-builder.js +211 -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 -39
- package/dist/vite/platform-configs.d.ts +4 -0
- package/dist/vite/platform-configs.js +98 -14
- 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 +579 -49
- package/dist/vite/plugin-source-builder.d.ts +3 -0
- package/dist/vite/plugin-source-builder.js +920 -23
- 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 +33 -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,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name Application#cannonWorld
|
|
3
|
+
* @type {CannonWorld}
|
|
4
|
+
* @description The {@link CannonWorld} wrapper.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @name Entity#cannonBody
|
|
9
|
+
* @type {CANNON#RigidBody}
|
|
10
|
+
* @description The Cannon body object.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @class
|
|
15
|
+
* @name CannonWorld
|
|
16
|
+
* @description The CannonWorld is a script type instance that wraps the Cannon.js Physics Engine https://github.com/schteppe/cannon.js
|
|
17
|
+
* CannonWorld is accessible via the the application object `this.app.cannonWorld` and contains basic helper functions such
|
|
18
|
+
* as teleport and raycasting. For more advanced functionality, CannonWorld#world should be used directly with their API.
|
|
19
|
+
* @property {CANNON.World} The Cannon world object.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @function
|
|
24
|
+
* @name CannonWorld#teleport
|
|
25
|
+
* @description Teleports an object to world position and orientation
|
|
26
|
+
* @param {pc.Entity} entity The entity to teleport.
|
|
27
|
+
* @param {pc.Vec3} position The world space point to teleport to.
|
|
28
|
+
* @param {pc.Vec3 | null} eulerAngles The world rotation in euler angles to teleport to.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @name RaycastResult
|
|
34
|
+
* @property {pc.Entity} entity The entity that was hit.
|
|
35
|
+
* @property {pc.Vec3} point The point at which the ray hit the entity in world space.
|
|
36
|
+
* @property {pc.Vec3} normal The normal vector of the surface where the ray hit in world space.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @function
|
|
41
|
+
* @name CannonWorld#raycastFirst
|
|
42
|
+
* @description Raycast into the world and returns the first entity it hits.
|
|
43
|
+
* @return {RaycastResult | null} Returns the raycast result.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @function
|
|
48
|
+
* @name CannonWorld#raycastAll
|
|
49
|
+
* @description Raycast into the world and returns all the entities it hits.
|
|
50
|
+
* @return {RaycastResult[]} Returns the raycast results.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @event
|
|
56
|
+
* @name Entity#collisionstart
|
|
57
|
+
* @description Fired when the physics body collides with another body
|
|
58
|
+
* @param {Object} event - Event from the collision where:
|
|
59
|
+
* other: pc.Entity, // The other entity that this collided with
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @event
|
|
64
|
+
* @name Entity#collisionend
|
|
65
|
+
* @description Fired when the physics body stops touching another body
|
|
66
|
+
* @param {Object} event - Event from the collision where:
|
|
67
|
+
* other: pc.Entity, // The other entity that this entity was touching
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @event
|
|
72
|
+
* @name Entity#triggerenter
|
|
73
|
+
* @description Fired when the physics body enters a trigger
|
|
74
|
+
* @param {Object} event - Event from when a trigger is entered where:
|
|
75
|
+
* other: pc.Entity, // The other entity that was involved in the event
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @event
|
|
80
|
+
* @name Entity#triggerenter
|
|
81
|
+
* @description Fired when the physics body leaves a trigger
|
|
82
|
+
* @param {Object} event - Event from when a body leaves a trigger:
|
|
83
|
+
* other: pc.Entity, // The other entity that was involved in the event
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
var CannonWorld = pc.createScript('cannonWorld');
|
|
88
|
+
|
|
89
|
+
CannonWorld.attributes.add('fixedTimeStep', {type: 'number', default: 0.016666, title: 'Fixed Time Step'});
|
|
90
|
+
CannonWorld.attributes.add('iterations', {type: 'number', default: 3, title: 'Iterations'});
|
|
91
|
+
CannonWorld.attributes.add('gravity', {type: 'vec3', default: [0, -9.8, 0], title: 'Gravity'});
|
|
92
|
+
CannonWorld.attributes.add('debugMode', {type: 'boolean', title: 'Debug Mode'});
|
|
93
|
+
|
|
94
|
+
CannonWorld.BODYTYPE_STATIC = 0;
|
|
95
|
+
CannonWorld.BODYTYPE_DYNAMIC = 1;
|
|
96
|
+
CannonWorld.BODYTYPE_KINEMATIC = 2;
|
|
97
|
+
CannonWorld.BODYTYPE_TRIGGER = 3;
|
|
98
|
+
|
|
99
|
+
CannonWorld.EVENT_COLLISION_START = 'collisionstart';
|
|
100
|
+
CannonWorld.EVENT_COLLISION_END = 'collisionend';
|
|
101
|
+
|
|
102
|
+
CannonWorld.EVENT_TRIGGER_ENTER = 'triggerenter';
|
|
103
|
+
CannonWorld.EVENT_TRIGGER_LEAVE = 'triggerleave';
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// initialize code called once per entity
|
|
107
|
+
CannonWorld.prototype.initialize = function() {
|
|
108
|
+
if (this.app.cannonWorld) {
|
|
109
|
+
console.warn('An Cannon world has already been created. Not creating a new one.');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.world = new CANNON.World();
|
|
114
|
+
this.world.gravity.set(this.gravity.x, this.gravity.y, this.gravity.z);
|
|
115
|
+
|
|
116
|
+
this.world.addEventListener('beginContact', this._onBeginContact.bind(this));
|
|
117
|
+
this.world.addEventListener('endContact', this._onEndContact.bind(this));
|
|
118
|
+
|
|
119
|
+
this.app.cannonWorld = this;
|
|
120
|
+
|
|
121
|
+
this._rigidbodies = [];
|
|
122
|
+
|
|
123
|
+
// Hook into an update event that happens after script system update
|
|
124
|
+
this.app.systems.on('animationUpdate', this._update, this);
|
|
125
|
+
|
|
126
|
+
this.on('destroy', function () {
|
|
127
|
+
this.app.systems.off('animationUpdate', this._update, this);
|
|
128
|
+
|
|
129
|
+
this._rigidbodies = [];
|
|
130
|
+
this.world = null;
|
|
131
|
+
this.app.cannonWorld = null;
|
|
132
|
+
}, this);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
CannonWorld.prototype._update = (function() {
|
|
137
|
+
var tempQuat = new pc.Quat();
|
|
138
|
+
|
|
139
|
+
return function(dt) {
|
|
140
|
+
this.world.step(this.fixedTimeStep, dt, this.iterations);
|
|
141
|
+
|
|
142
|
+
// Update entity positions based on rigidBody position
|
|
143
|
+
var i, pos, rot;
|
|
144
|
+
for (i = 0; i < this._rigidbodies.length; ++i) {
|
|
145
|
+
var pair = this._rigidbodies[i];
|
|
146
|
+
if (pair.body.sleepState !== CANNON.Body.SLEEPING) {
|
|
147
|
+
if (pair.body.type === CANNON.Body.STATIC) {
|
|
148
|
+
pos = pair.entity.getPosition();
|
|
149
|
+
rot = pair.entity.getRotation();
|
|
150
|
+
pair.body.position.set(pos.x, pos.y, pos.z);
|
|
151
|
+
pair.body.quaternion.set(rot.x, rot.y, rot.z, rot.w);
|
|
152
|
+
} else {
|
|
153
|
+
pos = pair.body.position;
|
|
154
|
+
rot = pair.body.quaternion;
|
|
155
|
+
|
|
156
|
+
pair.entity.setPosition(pos.x, pos.y, pos.z);
|
|
157
|
+
|
|
158
|
+
tempQuat.set(rot.x, rot.y, rot.z, rot.w || 1);
|
|
159
|
+
pair.entity.setRotation(tempQuat);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
})();
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
CannonWorld.prototype._onBeginContact = (function () {
|
|
168
|
+
var collisionStartEvent = {
|
|
169
|
+
other: null
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return function(contactEvent) {
|
|
173
|
+
var bodyA = contactEvent.bodyA;
|
|
174
|
+
var bodyB = contactEvent.bodyB;
|
|
175
|
+
var eventType = ((bodyA && bodyA.isTrigger) || (bodyB && bodyB.isTrigger)) ? CannonWorld.EVENT_TRIGGER_ENTER : CannonWorld.EVENT_COLLISION_START;
|
|
176
|
+
|
|
177
|
+
collisionStartEvent.other = bodyB.entity;
|
|
178
|
+
bodyA.entity.fire(eventType, collisionStartEvent);
|
|
179
|
+
|
|
180
|
+
collisionStartEvent.other = bodyA.entity;
|
|
181
|
+
bodyB.entity.fire(eventType, collisionStartEvent);
|
|
182
|
+
};
|
|
183
|
+
})();
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
CannonWorld.prototype._onEndContact = (function () {
|
|
187
|
+
var collisionEndEvent = {
|
|
188
|
+
other: null
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return function(contactEvent) {
|
|
192
|
+
var bodyA = contactEvent.bodyA;
|
|
193
|
+
var bodyB = contactEvent.bodyB;
|
|
194
|
+
var eventType = ((bodyA && bodyA.isTrigger) || (bodyB && bodyB.isTrigger)) ? CannonWorld.EVENT_TRIGGER_LEAVE : CannonWorld.EVENT_COLLISION_END;
|
|
195
|
+
|
|
196
|
+
collisionEndEvent.other = bodyB && bodyB.entity;
|
|
197
|
+
if (bodyA) {
|
|
198
|
+
bodyA.entity.fire(eventType, collisionEndEvent);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
collisionEndEvent.other = bodyA && bodyA.entity;
|
|
202
|
+
if (bodyB) {
|
|
203
|
+
bodyB.entity.fire(eventType, collisionEndEvent);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
})();
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
CannonWorld.prototype._addRigidbody = function(entity) {
|
|
210
|
+
this.world.addBody(entity.cannonBody);
|
|
211
|
+
this._rigidbodies.push({ body: entity.cannonBody, entity: entity });
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
CannonWorld.prototype._removeRigidbody = function(entity) {
|
|
216
|
+
var i;
|
|
217
|
+
for (i = 0; i < this._rigidbodies.length; ++i) {
|
|
218
|
+
var pair = this._rigidbodies[i];
|
|
219
|
+
if (entity.cannonBody === pair.body) {
|
|
220
|
+
this._rigidbodies.splice(i, 1);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
this.world.removeBody(entity.cannonBody);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
CannonWorld.prototype._addShape = function (scriptType, shape, mass, rigidbodyType) {
|
|
230
|
+
var pos = scriptType.entity.getPosition();
|
|
231
|
+
var rot = scriptType.entity.getRotation();
|
|
232
|
+
|
|
233
|
+
if (rigidbodyType === CannonWorld.BODYTYPE_STATIC || rigidbodyType === CannonWorld.BODYTYPE_TRIGGER) {
|
|
234
|
+
mass = 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
scriptType.body = new CANNON.Body({
|
|
238
|
+
mass: mass,
|
|
239
|
+
position: new CANNON.Vec3(pos.x, pos.y, pos.z),
|
|
240
|
+
quaternion: new CANNON.Quaternion(rot.x, rot.y, rot.z, rot.w),
|
|
241
|
+
shape: shape,
|
|
242
|
+
isTrigger: rigidbodyType === CannonWorld.BODYTYPE_TRIGGER
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (rigidbodyType === CannonWorld.BODYTYPE_KINEMATIC) {
|
|
246
|
+
scriptType.body.type = CANNON.Body.KINEMATIC;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Two way reference between the Cannon body and the Entity
|
|
250
|
+
scriptType.entity.cannonBody = scriptType.body;
|
|
251
|
+
scriptType.body.entity = scriptType.entity;
|
|
252
|
+
|
|
253
|
+
this._addRigidbody(scriptType.entity);
|
|
254
|
+
|
|
255
|
+
scriptType.on('destroy', function() {
|
|
256
|
+
this.app.cannonWorld._removeRigidbody(this.entity);
|
|
257
|
+
this.entity.cannonBody = null;
|
|
258
|
+
this.body = null;
|
|
259
|
+
}, scriptType);
|
|
260
|
+
|
|
261
|
+
scriptType.on('state', function (enabled) {
|
|
262
|
+
if (enabled) {
|
|
263
|
+
this.app.cannonWorld._addRigidbody(this.entity);
|
|
264
|
+
} else {
|
|
265
|
+
this.app.cannonWorld._removeRigidbody(this.entity);
|
|
266
|
+
}
|
|
267
|
+
}, scriptType);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
CannonWorld.prototype.teleport = (function () {
|
|
272
|
+
return function (entity, position, rotation) {
|
|
273
|
+
entity.cannonBody.position.set(position.x, position.y, position.z);
|
|
274
|
+
|
|
275
|
+
if (rotation) {
|
|
276
|
+
entity.cannonBody.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
entity.cannonBody.velocity.set(0,0,0);
|
|
280
|
+
entity.cannonBody.angularVelocity.set(0,0,0);
|
|
281
|
+
};
|
|
282
|
+
}());
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
CannonWorld.prototype.raycastFirst = (function () {
|
|
286
|
+
if (window.CANNON) {
|
|
287
|
+
var cannonResult = new CANNON.RaycastResult();
|
|
288
|
+
var result = {
|
|
289
|
+
entity: null,
|
|
290
|
+
normal: new pc.Vec3(),
|
|
291
|
+
point: new pc.Vec3()
|
|
292
|
+
};
|
|
293
|
+
var cannonPosFrom = new CANNON.Vec3();
|
|
294
|
+
var cannonPosTo = new CANNON.Vec3();
|
|
295
|
+
var cannonOptions = {};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return function (from, to) {
|
|
299
|
+
cannonPosFrom.set(from.x, from.y, from.z);
|
|
300
|
+
cannonPosTo.set(to.x, to.y, to.z);
|
|
301
|
+
|
|
302
|
+
this.world.raycastClosest(cannonPosFrom, cannonPosTo, cannonOptions, cannonResult);
|
|
303
|
+
|
|
304
|
+
if (cannonResult.hasHit) {
|
|
305
|
+
result.entity = cannonResult.body.entity;
|
|
306
|
+
result.normal.set(cannonResult.hitNormalWorld.x, cannonResult.hitNormalWorld.y, cannonResult.hitNormalWorld.x);
|
|
307
|
+
result.point.set(cannonResult.hitPointWorld.x, cannonResult.hitPointWorld.y, cannonResult.hitPointWorld.z);
|
|
308
|
+
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return null;
|
|
313
|
+
};
|
|
314
|
+
}());
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
CannonWorld.prototype.raycastAll = (function () {
|
|
318
|
+
if (window.CANNON) {
|
|
319
|
+
var results = [];
|
|
320
|
+
var cannonPosFrom = new CANNON.Vec3();
|
|
321
|
+
var cannonPosTo = new CANNON.Vec3();
|
|
322
|
+
var cannonOptions = {};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
var cannonCallback = function(cannonResult) {
|
|
326
|
+
var result = {};
|
|
327
|
+
result.entity = cannonResult.body.entity;
|
|
328
|
+
result.normal = new pc.Vec3(cannonResult.hitNormalWorld.x, cannonResult.hitNormalWorld.y, cannonResult.hitNormalWorld.x);
|
|
329
|
+
result.point = new pc.Vec3(cannonResult.hitPointWorld.x, cannonResult.hitPointWorld.y, cannonResult.hitPointWorld.z);
|
|
330
|
+
|
|
331
|
+
results.push(result);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
return function (from, to) {
|
|
335
|
+
results.length = 0;
|
|
336
|
+
cannonPosFrom.set(from.x, from.y, from.z);
|
|
337
|
+
cannonPosTo.set(to.x, to.y, to.z);
|
|
338
|
+
|
|
339
|
+
this.world.raycastAll(cannonPosFrom, cannonPosTo, cannonOptions, cannonCallback);
|
|
340
|
+
|
|
341
|
+
return results;
|
|
342
|
+
};
|
|
343
|
+
}());
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
// Script type helper
|
|
348
|
+
///////
|
|
349
|
+
var CannonHelper = {
|
|
350
|
+
addCannonBodyDefaults: function (scriptType) {
|
|
351
|
+
scriptType.attributes.add('mass', {type: 'number', default: 1, title: 'Mass'});
|
|
352
|
+
scriptType.attributes.add('type',
|
|
353
|
+
{
|
|
354
|
+
type: 'number',
|
|
355
|
+
default: CannonWorld.BODYTYPE_DYNAMIC,
|
|
356
|
+
title: 'Type',
|
|
357
|
+
enum: [
|
|
358
|
+
{ 'Static': CannonWorld.BODYTYPE_STATIC },
|
|
359
|
+
{ 'Dynamic': CannonWorld.BODYTYPE_DYNAMIC },
|
|
360
|
+
{ 'Kinematic': CannonWorld.BODYTYPE_KINEMATIC },
|
|
361
|
+
{ 'Trigger': CannonWorld.BODYTYPE_TRIGGER }
|
|
362
|
+
]
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// Box
|
|
368
|
+
////////
|
|
369
|
+
var CannonBox = pc.createScript('cannonBox');
|
|
370
|
+
CannonHelper.addCannonBodyDefaults(CannonBox);
|
|
371
|
+
CannonBox.attributes.add('halfExtents', {type: 'vec3', default: [0.5, 0.5, 0.5], title: 'Half Extents'});
|
|
372
|
+
|
|
373
|
+
// initialize code called once per entity
|
|
374
|
+
CannonBox.prototype.postInitialize = function() {
|
|
375
|
+
if (this.app.cannonWorld) {
|
|
376
|
+
var shape = new CANNON.Box(new CANNON.Vec3(this.halfExtents.x, this.halfExtents.y, this.halfExtents.z));
|
|
377
|
+
this.app.cannonWorld._addShape(this, shape, this.mass, this.type);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
// Sphere
|
|
383
|
+
////////
|
|
384
|
+
var CannonSphere = pc.createScript('cannonSphere');
|
|
385
|
+
CannonHelper.addCannonBodyDefaults(CannonSphere);
|
|
386
|
+
CannonSphere.attributes.add('radius', {type: 'number', default: 0.5, title: 'Radius'});
|
|
387
|
+
|
|
388
|
+
// initialize code called once per entity
|
|
389
|
+
CannonSphere.prototype.postInitialize = function() {
|
|
390
|
+
if (this.app.cannonWorld) {
|
|
391
|
+
var shape = new CANNON.Sphere(this.radius);
|
|
392
|
+
this.app.cannonWorld._addShape(this, shape, this.mass, this.type);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
// Cyclinder
|
|
398
|
+
////////
|
|
399
|
+
var CannonCylinder = pc.createScript('cannonCylinder');
|
|
400
|
+
CannonHelper.addCannonBodyDefaults(CannonCylinder);
|
|
401
|
+
CannonCylinder.attributes.add('radius', {type: 'number', default: 0.5, title: 'Radius'});
|
|
402
|
+
CannonCylinder.attributes.add('height', {type: 'number', default: 1, title: 'Height'});
|
|
403
|
+
CannonCylinder.attributes.add('segmentCount', {type: 'number', default: 8, title: 'Segment Count'});
|
|
404
|
+
|
|
405
|
+
// initialize code called once per entity
|
|
406
|
+
CannonCylinder.prototype.postInitialize = function() {
|
|
407
|
+
if (this.app.cannonWorld) {
|
|
408
|
+
var shape = new CANNON.Cylinder(this.radius, this.radius, this.height, this.segmentCount);
|
|
409
|
+
this.app.cannonWorld._addShape(this, shape, this.mass, this.type);
|
|
410
|
+
}
|
|
411
|
+
};
|
package/templates/__start__.js
CHANGED
|
@@ -141,7 +141,10 @@
|
|
|
141
141
|
|
|
142
142
|
if (typeof window.Promise === 'function') {
|
|
143
143
|
var LEGACY_WEBGL = 'webgl';
|
|
144
|
-
|
|
144
|
+
// 确保 deviceTypes 存在,如果不存在则使用默认值
|
|
145
|
+
var deviceTypes = deviceOptions.deviceTypes
|
|
146
|
+
? [...deviceOptions.deviceTypes, LEGACY_WEBGL]
|
|
147
|
+
: ['webgl2', 'webgl1', LEGACY_WEBGL];
|
|
145
148
|
|
|
146
149
|
var gpuLibPath = window.ASSET_PREFIX ? (window.ASSET_PREFIX.replace(/\/$/g, '') + '/') : '';
|
|
147
150
|
|
|
@@ -163,8 +166,10 @@
|
|
|
163
166
|
callback(null);
|
|
164
167
|
})
|
|
165
168
|
} else {
|
|
166
|
-
|
|
167
|
-
var
|
|
169
|
+
// 确保 deviceTypes 存在用于旧版 WebGL 检测
|
|
170
|
+
var deviceTypesArray = deviceOptions.deviceTypes || ['webgl2', 'webgl1'];
|
|
171
|
+
var igl1 = deviceTypesArray.indexOf('webgl1');
|
|
172
|
+
var igl2 = deviceTypesArray.indexOf('webgl2');
|
|
168
173
|
|
|
169
174
|
// old webgl graphics device creation
|
|
170
175
|
var options = {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, viewport-fit=cover' />
|
|
5
|
+
<meta charset='utf-8'>
|
|
6
|
+
<link rel="stylesheet" type="text/css" href="styles.css">
|
|
7
|
+
<link rel="manifest" href="manifest.json">
|
|
8
|
+
<style></style>
|
|
9
|
+
<title>{{PROJECT_NAME}}</title>
|
|
10
|
+
|
|
11
|
+
<!-- import map -->
|
|
12
|
+
<script type="importmap">
|
|
13
|
+
{{IMPORT_MAP}}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
<script type='module' src="js/index.mjs"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|