action-engine-js 1.0.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 (93) hide show
  1. package/LICENSE +45 -0
  2. package/README.md +348 -0
  3. package/actionengine/3rdparty/goblin/goblin.js +9609 -0
  4. package/actionengine/3rdparty/goblin/goblin.min.js +5 -0
  5. package/actionengine/camera/actioncamera.js +90 -0
  6. package/actionengine/camera/cameracollisionhandler.js +69 -0
  7. package/actionengine/character/actioncharacter.js +360 -0
  8. package/actionengine/character/actioncharacter3D.js +61 -0
  9. package/actionengine/core/app.js +430 -0
  10. package/actionengine/debug/basedebugpanel.js +858 -0
  11. package/actionengine/display/canvasmanager.js +75 -0
  12. package/actionengine/display/gl/programmanager.js +570 -0
  13. package/actionengine/display/gl/shaders/lineshader.js +118 -0
  14. package/actionengine/display/gl/shaders/objectshader.js +1756 -0
  15. package/actionengine/display/gl/shaders/particleshader.js +43 -0
  16. package/actionengine/display/gl/shaders/shadowshader.js +319 -0
  17. package/actionengine/display/gl/shaders/spriteshader.js +100 -0
  18. package/actionengine/display/gl/shaders/watershader.js +67 -0
  19. package/actionengine/display/graphics/actionmodel3D.js +191 -0
  20. package/actionengine/display/graphics/actionsprite3D.js +230 -0
  21. package/actionengine/display/graphics/lighting/actiondirectionalshadowlight.js +864 -0
  22. package/actionengine/display/graphics/lighting/actionlight.js +211 -0
  23. package/actionengine/display/graphics/lighting/actionomnidirectionalshadowlight.js +862 -0
  24. package/actionengine/display/graphics/lighting/lightingconstants.js +263 -0
  25. package/actionengine/display/graphics/lighting/lightmanager.js +789 -0
  26. package/actionengine/display/graphics/renderableobject.js +44 -0
  27. package/actionengine/display/graphics/renderers/actionrenderer2D.js +341 -0
  28. package/actionengine/display/graphics/renderers/actionrenderer3D/actionrenderer3D.js +655 -0
  29. package/actionengine/display/graphics/renderers/actionrenderer3D/canvasmanager3D.js +82 -0
  30. package/actionengine/display/graphics/renderers/actionrenderer3D/debugrenderer3D.js +493 -0
  31. package/actionengine/display/graphics/renderers/actionrenderer3D/objectrenderer3D.js +790 -0
  32. package/actionengine/display/graphics/renderers/actionrenderer3D/spriteRenderer3D.js +266 -0
  33. package/actionengine/display/graphics/renderers/actionrenderer3D/sunrenderer3D.js +140 -0
  34. package/actionengine/display/graphics/renderers/actionrenderer3D/waterrenderer3D.js +173 -0
  35. package/actionengine/display/graphics/renderers/actionrenderer3D/weatherrenderer3D.js +87 -0
  36. package/actionengine/display/graphics/texture/proceduraltexture.js +192 -0
  37. package/actionengine/display/graphics/texture/texturemanager.js +242 -0
  38. package/actionengine/display/graphics/texture/textureregistry.js +177 -0
  39. package/actionengine/input/actionscrollablearea.js +1405 -0
  40. package/actionengine/input/inputhandler.js +1647 -0
  41. package/actionengine/math/geometry/geometrybuilder.js +161 -0
  42. package/actionengine/math/geometry/glbexporter.js +364 -0
  43. package/actionengine/math/geometry/glbloader.js +722 -0
  44. package/actionengine/math/geometry/modelcodegenerator.js +97 -0
  45. package/actionengine/math/geometry/triangle.js +33 -0
  46. package/actionengine/math/geometry/triangleutils.js +34 -0
  47. package/actionengine/math/mathutils.js +25 -0
  48. package/actionengine/math/matrix4.js +785 -0
  49. package/actionengine/math/physics/actionphysics.js +108 -0
  50. package/actionengine/math/physics/actionphysicsobject3D.js +164 -0
  51. package/actionengine/math/physics/actionphysicsworld3D.js +238 -0
  52. package/actionengine/math/physics/actionraycast.js +129 -0
  53. package/actionengine/math/physics/shapes/actionphysicsbox3D.js +158 -0
  54. package/actionengine/math/physics/shapes/actionphysicscapsule3D.js +200 -0
  55. package/actionengine/math/physics/shapes/actionphysicscompoundshape3D.js +147 -0
  56. package/actionengine/math/physics/shapes/actionphysicscone3D.js +126 -0
  57. package/actionengine/math/physics/shapes/actionphysicsconvexshape3D.js +72 -0
  58. package/actionengine/math/physics/shapes/actionphysicscylinder3D.js +117 -0
  59. package/actionengine/math/physics/shapes/actionphysicsmesh3D.js +74 -0
  60. package/actionengine/math/physics/shapes/actionphysicsplane3D.js +100 -0
  61. package/actionengine/math/physics/shapes/actionphysicssphere3D.js +95 -0
  62. package/actionengine/math/quaternion.js +61 -0
  63. package/actionengine/math/vector2.js +277 -0
  64. package/actionengine/math/vector3.js +318 -0
  65. package/actionengine/math/viewfrustum.js +136 -0
  66. package/actionengine/network/ACTIONNETREADME.md +810 -0
  67. package/actionengine/network/client/ActionNetManager.js +802 -0
  68. package/actionengine/network/client/ActionNetManagerGUI.js +1709 -0
  69. package/actionengine/network/client/ActionNetManagerP2P.js +1537 -0
  70. package/actionengine/network/client/SyncSystem.js +422 -0
  71. package/actionengine/network/p2p/ActionNetPeer.js +142 -0
  72. package/actionengine/network/p2p/ActionNetTrackerClient.js +623 -0
  73. package/actionengine/network/p2p/DataConnection.js +282 -0
  74. package/actionengine/network/p2p/README.md +510 -0
  75. package/actionengine/network/p2p/example.html +502 -0
  76. package/actionengine/network/server/ActionNetServer.js +577 -0
  77. package/actionengine/network/server/ActionNetServerSSL.js +579 -0
  78. package/actionengine/network/server/ActionNetServerUtils.js +458 -0
  79. package/actionengine/network/server/SERVERREADME.md +314 -0
  80. package/actionengine/network/server/package-lock.json +35 -0
  81. package/actionengine/network/server/package.json +13 -0
  82. package/actionengine/network/server/start.bat +27 -0
  83. package/actionengine/network/server/start.sh +25 -0
  84. package/actionengine/network/server/startwss.bat +27 -0
  85. package/actionengine/sound/audiomanager.js +1589 -0
  86. package/actionengine/sound/soundfont/ACTIONSOUNDFONT_README.md +205 -0
  87. package/actionengine/sound/soundfont/actionparser.js +718 -0
  88. package/actionengine/sound/soundfont/actionreverb.js +252 -0
  89. package/actionengine/sound/soundfont/actionsoundfont.js +543 -0
  90. package/actionengine/sound/soundfont/sf2playerlicence.txt +29 -0
  91. package/actionengine/sound/soundfont/soundfont.js +2 -0
  92. package/dist/action-engine.min.js +328 -0
  93. package/package.json +35 -0
@@ -0,0 +1,136 @@
1
+ // actionengine/math/ViewFrustum.js
2
+ class ViewFrustum {
3
+ constructor() {
4
+ // Create the 6 frustum planes
5
+ this.planes = [
6
+ new Float32Array(4), // Left
7
+ new Float32Array(4), // Right
8
+ new Float32Array(4), // Bottom
9
+ new Float32Array(4), // Top
10
+ new Float32Array(4), // Near
11
+ new Float32Array(4) // Far
12
+ ];
13
+ }
14
+
15
+ // Extract frustum planes from the combined projection-view matrix
16
+ updateFromMatrix(projViewMatrix) {
17
+ // Left plane
18
+ this.planes[0][0] = projViewMatrix[3] + projViewMatrix[0];
19
+ this.planes[0][1] = projViewMatrix[7] + projViewMatrix[4];
20
+ this.planes[0][2] = projViewMatrix[11] + projViewMatrix[8];
21
+ this.planes[0][3] = projViewMatrix[15] + projViewMatrix[12];
22
+
23
+ // Right plane
24
+ this.planes[1][0] = projViewMatrix[3] - projViewMatrix[0];
25
+ this.planes[1][1] = projViewMatrix[7] - projViewMatrix[4];
26
+ this.planes[1][2] = projViewMatrix[11] - projViewMatrix[8];
27
+ this.planes[1][3] = projViewMatrix[15] - projViewMatrix[12];
28
+
29
+ // Bottom plane
30
+ this.planes[2][0] = projViewMatrix[3] + projViewMatrix[1];
31
+ this.planes[2][1] = projViewMatrix[7] + projViewMatrix[5];
32
+ this.planes[2][2] = projViewMatrix[11] + projViewMatrix[9];
33
+ this.planes[2][3] = projViewMatrix[15] + projViewMatrix[13];
34
+
35
+ // Top plane
36
+ this.planes[3][0] = projViewMatrix[3] - projViewMatrix[1];
37
+ this.planes[3][1] = projViewMatrix[7] - projViewMatrix[5];
38
+ this.planes[3][2] = projViewMatrix[11] - projViewMatrix[9];
39
+ this.planes[3][3] = projViewMatrix[15] - projViewMatrix[13];
40
+
41
+ // Near plane
42
+ this.planes[4][0] = projViewMatrix[3] + projViewMatrix[2];
43
+ this.planes[4][1] = projViewMatrix[7] + projViewMatrix[6];
44
+ this.planes[4][2] = projViewMatrix[11] + projViewMatrix[10];
45
+ this.planes[4][3] = projViewMatrix[15] + projViewMatrix[14];
46
+
47
+ // Far plane
48
+ this.planes[5][0] = projViewMatrix[3] - projViewMatrix[2];
49
+ this.planes[5][1] = projViewMatrix[7] - projViewMatrix[6];
50
+ this.planes[5][2] = projViewMatrix[11] - projViewMatrix[10];
51
+ this.planes[5][3] = projViewMatrix[15] - projViewMatrix[14];
52
+
53
+ // Normalize the planes
54
+ this.normalizePlanes();
55
+ }
56
+
57
+ // Normalize all the planes for more efficient checks
58
+ normalizePlanes() {
59
+ for (let i = 0; i < 6; i++) {
60
+ const plane = this.planes[i];
61
+ const length = Math.sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
62
+ if (length !== 0) {
63
+ plane[0] /= length;
64
+ plane[1] /= length;
65
+ plane[2] /= length;
66
+ plane[3] /= length;
67
+ }
68
+ }
69
+ }
70
+
71
+ // Update the frustum using camera parameters
72
+ updateFromCamera(camera) {
73
+ const projMatrix = Matrix4.create();
74
+ Matrix4.perspective(
75
+ projMatrix,
76
+ camera.fov,
77
+ Game.WIDTH / Game.HEIGHT,
78
+ 0.1,
79
+ camera.far || 10000.0
80
+ );
81
+
82
+ const viewMatrix = Matrix4.create();
83
+ Matrix4.lookAt(
84
+ viewMatrix,
85
+ camera.position.toArray(),
86
+ camera.target.toArray(),
87
+ camera.up.toArray()
88
+ );
89
+
90
+ const projViewMatrix = Matrix4.create();
91
+ Matrix4.multiply(projViewMatrix, projMatrix, viewMatrix);
92
+
93
+ this.updateFromMatrix(projViewMatrix);
94
+ }
95
+
96
+ // Check if a sphere is inside or intersects the frustum
97
+ containsSphere(center, radius) {
98
+ for (let i = 0; i < 6; i++) {
99
+ const plane = this.planes[i];
100
+ const distance = plane[0] * center.x + plane[1] * center.y + plane[2] * center.z + plane[3];
101
+ if (distance < -radius) {
102
+ return false; // Completely outside
103
+ }
104
+ }
105
+ return true; // Inside or intersecting
106
+ }
107
+
108
+ // Test if an object is visible based on its bounding volume
109
+ isVisible(object) {
110
+ // If the object has no position, we can't test it
111
+ if (!object || !object.position) {
112
+ return false;
113
+ }
114
+
115
+ // Check if the object has opted out of frustum culling
116
+ if (object.excludeFromFrustumCulling === true) {
117
+ return true;
118
+ }
119
+
120
+ // If the object has a bounding sphere radius, use that
121
+ if (object.boundingSphereRadius !== undefined) {
122
+ return this.containsSphere(object.position, object.boundingSphereRadius);
123
+ }
124
+
125
+ // If the object is terrain-like (large grid), use a larger radius
126
+ if (object.gridResolution && object.baseWorldScale) {
127
+ // For terrain, use a size proportional to its scale
128
+ const terrainSize = object.baseWorldScale * object.gridResolution / 2;
129
+ return this.containsSphere(object.position, terrainSize);
130
+ }
131
+
132
+ // Default to a larger radius than before to be more conservative
133
+ const defaultRadius = object.radius || 20; // Default to 20 units instead of 5
134
+ return this.containsSphere(object.position, defaultRadius);
135
+ }
136
+ }