littlejsengine 1.19.3 → 1.20.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.
Files changed (50) hide show
  1. package/FAQ.md +841 -820
  2. package/README.md +29 -25
  3. package/dist/littlejs.d.ts +2455 -935
  4. package/dist/littlejs.esm.js +30344 -21110
  5. package/dist/littlejs.esm.min.js +4 -3
  6. package/dist/littlejs.js +30259 -21052
  7. package/dist/littlejs.min.js +2 -2
  8. package/dist/littlejs.release.js +26567 -20455
  9. package/package.json +10 -5
  10. package/plugins/audioEffects.js +28 -24
  11. package/plugins/box2d.js +2516 -2073
  12. package/plugins/drawUtilities.js +206 -31
  13. package/plugins/gltf.js +740 -0
  14. package/plugins/jsconfig.json +19 -0
  15. package/plugins/lightSystem.js +719 -332
  16. package/plugins/math3d.js +58 -17
  17. package/plugins/medalSystem.js +326 -280
  18. package/plugins/newgrounds.js +400 -199
  19. package/plugins/pathFinder.js +208 -175
  20. package/plugins/pluginExport.js +15 -0
  21. package/plugins/postProcess.js +56 -13
  22. package/plugins/render3d.js +1643 -1577
  23. package/plugins/render3dDebug.js +109 -0
  24. package/plugins/render3dExtras.js +1754 -0
  25. package/plugins/render3dVoxels.js +502 -0
  26. package/plugins/textureSheet.js +496 -458
  27. package/plugins/threejs.js +183 -163
  28. package/plugins/tweakables.js +411 -0
  29. package/plugins/tweenSystem.js +263 -145
  30. package/plugins/uiSystem.js +2024 -1687
  31. package/plugins/zzfxm.js +159 -159
  32. package/src/engine.js +191 -75
  33. package/src/engineAudio.js +229 -125
  34. package/src/engineBuild.mjs +289 -256
  35. package/src/engineDebug.js +912 -742
  36. package/src/engineDraw.js +295 -193
  37. package/src/engineEditor.js +2431 -0
  38. package/src/engineExport.js +12 -0
  39. package/src/engineInput.js +1462 -1293
  40. package/src/engineMath.js +1274 -1252
  41. package/src/engineObject.js +194 -80
  42. package/src/engineParticles.js +583 -532
  43. package/src/engineRelease.js +67 -45
  44. package/src/engineSettings.js +77 -29
  45. package/src/engineTileLayer.js +995 -741
  46. package/src/engineUtilities.js +19 -13
  47. package/src/engineWebGL.js +239 -82
  48. package/src/jsconfig.json +17 -13
  49. package/plugins/box2d.wasm.js +0 -630
  50. package/plugins/box2d.wasm.wasm +0 -0
@@ -0,0 +1,109 @@
1
+ /*
2
+ * LittleJS 3D Debug Plugin
3
+ * - debugBox3D, debugSphere3D, debugLine3D and debugPoint3D, drawn on top of the 3D scene like the 2D debug functions
4
+ * - Debug builds only, like the 2D ones: engineRelease.js has empty stubs for these, so release builds carry none of it
5
+ * - Goes after the Render3D plugin, part of its Render3D namespace
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ ///////////////////////////////////////////////////////////////////////////////
11
+
12
+ const RENDER3D_DEBUG_WIDTH = .05; // line width of the debug primitives
13
+
14
+ let render3DDebugPrimitives = []; // each keeps the debugClear count it was made under, a debugClear since drops it
15
+
16
+ // draw the live debug primitives with depth test off so they show through walls, drop the expired ones
17
+ function render3DRenderDebug()
18
+ {
19
+ if (!render3DDebugPrimitives.length) return;
20
+ render3DDebugPrimitives = render3DDebugPrimitives.filter(p=> p.clearCount === debugClearCount);
21
+ if (!debugVideoCaptureIsActive()) // hidden from a video capture like the 2D ones, but they still expire
22
+ {
23
+ render3DWithState({lighting: false, depthTest: false, receiveShadow: false, additive: false, shader: undefined}, ()=>
24
+ {
25
+ for (const p of render3DDebugPrimitives)
26
+ p.draw();
27
+ });
28
+ }
29
+ render3DDebugPrimitives = render3DDebugPrimitives.filter(p=> p.timer < 0); // a Timer compares as negative until it elapses
30
+ }
31
+
32
+ // record a debug draw for a time
33
+ function render3DDebugPush(duration, draw)
34
+ {
35
+ ASSERT(isNumber(duration), 'duration must be a number');
36
+ debug && glEnable && render3D?.program &&
37
+ render3DDebugPrimitives.push({timer: new Timer(duration, true), draw, clearCount: debugClearCount}); // real time, like 2D
38
+ }
39
+
40
+ /** Draw a debug wireframe box
41
+ * @param {Vector3} pos - Center
42
+ * @param {Vector3|number} [size] - Full size, a number for a cube
43
+ * @param {Color} [color]
44
+ * @param {number} [time] - How long to show it, 0 is one frame
45
+ * @param {Vector3} [rotation] - vec3(pitch, yaw, roll)
46
+ * @memberof Render3D */
47
+ function debugBox3D(pos, size=1, color=WHITE, time=0, rotation)
48
+ {
49
+ const matrix = buildMatrix(pos, rotation, render3DSize3(size));
50
+ const corner = (i)=> matrix.transformPoint(vec3(i & 1 ? .5 : -.5, i & 2 ? .5 : -.5, i & 4 ? .5 : -.5));
51
+ render3DDebugPush(time, ()=>
52
+ {
53
+ for (let i = 0; i < 8; ++i)
54
+ for (const bit of [1, 2, 4])
55
+ if (!(i & bit))
56
+ render3D.drawLine(corner(i), corner(i | bit), RENDER3D_DEBUG_WIDTH, color);
57
+ });
58
+ }
59
+
60
+ /** Draw a debug wireframe sphere as three rings
61
+ * @param {Vector3} pos - Center
62
+ * @param {number} [size] - Diameter
63
+ * @param {Color} [color]
64
+ * @param {number} [time] - How long to show it, 0 is one frame
65
+ * @memberof Render3D */
66
+ function debugSphere3D(pos, size=1, color=WHITE, time=0)
67
+ {
68
+ pos = pos.copy(); // where it is now, a timed one stays put when the object moves
69
+ const circle = render3DCircle(24), r = size / 2;
70
+ render3DDebugPush(time, ()=>
71
+ {
72
+ for (const ring of [(c, s)=> vec3(c, s, 0), (c, s)=> vec3(c, 0, s), (c, s)=> vec3(0, c, s)])
73
+ {
74
+ const points = [];
75
+ for (let i = 0; i <= 24; ++i)
76
+ points.push(pos.add(ring(circle[i*2], circle[i*2 + 1]).scale(r)));
77
+ render3D.drawRibbon(points, RENDER3D_DEBUG_WIDTH, undefined, color);
78
+ }
79
+ });
80
+ }
81
+
82
+ /** Draw a debug line
83
+ * @param {Vector3} posA
84
+ * @param {Vector3} posB
85
+ * @param {Color} [color]
86
+ * @param {number} [width]
87
+ * @param {number} [time] - How long to show it, 0 is one frame
88
+ * @memberof Render3D */
89
+ function debugLine3D(posA, posB, color=WHITE, width=RENDER3D_DEBUG_WIDTH, time=0)
90
+ {
91
+ posA = posA.copy(), posB = posB.copy(); // where they are now, a timed one stays put when the ends move
92
+ render3DDebugPush(time, ()=> render3D.drawLine(posA, posB, width, color));
93
+ }
94
+
95
+ /** Draw a debug point as a small cross of three lines
96
+ * @param {Vector3} pos
97
+ * @param {Color} [color]
98
+ * @param {number} [time] - How long to show it, 0 is one frame
99
+ * @param {number} [size] - Length of the cross
100
+ * @memberof Render3D */
101
+ function debugPoint3D(pos, color=WHITE, time=0, size=.2)
102
+ {
103
+ pos = pos.copy(); // where it is now, a timed one stays put when the object moves
104
+ render3DDebugPush(time, ()=>
105
+ {
106
+ for (const axis of [vec3(size / 2, 0, 0), vec3(0, size / 2, 0), vec3(0, 0, size / 2)])
107
+ render3D.drawLine(pos.subtract(axis), pos.add(axis), RENDER3D_DEBUG_WIDTH, color);
108
+ });
109
+ }