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,97 @@
1
+ // actionengine/math/geometry/modelcodegenerator.js
2
+
3
+ /**
4
+ * ModelCodeGenerator converts GLB models into ActionEngine Triangle-based code.
5
+ * This outputs ActionEngine Model Format - clean Triangle[] code instead of base64.
6
+ */
7
+ class ModelCodeGenerator {
8
+
9
+ /**
10
+ * Generate ActionEngine Triangle code from GLB file
11
+ * @param {string} base64Data - GLB file as base64 string
12
+ * @param {string} modelName - Name for the generated function
13
+ * @param {Object} options - Generation options
14
+ * @returns {string} Complete JavaScript code for the model
15
+ */
16
+ static generateFromGLB(base64Data, modelName = null, options = {}) {
17
+ // Generate generic name if none provided
18
+ if (!modelName) {
19
+ const timestamp = Date.now().toString(36);
20
+ modelName = `Model_${timestamp}`;
21
+ }
22
+
23
+ try {
24
+ // Load GLB model using ActionEngine GLBLoader
25
+ const glbModel = GLBLoader.loadModel(base64Data);
26
+
27
+ // Generate Triangle-based code directly from GLB triangles
28
+ return ModelCodeGenerator.generateTriangleCode(glbModel.triangles, modelName, options);
29
+ } catch (error) {
30
+ console.error('ActionEngine model code generation failed:', error);
31
+ throw error;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Generate ActionEngine Triangle code from Triangle array
37
+ * @param {Triangle[]} triangles - Array of Triangle objects
38
+ * @param {string} modelName - Function name for the model
39
+ * @param {Object} options - Code generation options
40
+ * @returns {string} Complete JavaScript function code
41
+ */
42
+ static generateTriangleCode(triangles, modelName, options = {}) {
43
+ const timestamp = new Date().toISOString();
44
+
45
+ let code = `// Generated ActionEngine Model: ${modelName}\n`;
46
+ code += `// Created: ${timestamp}\n`;
47
+ code += `createTriangles() {\n`;
48
+ code += ` return [\n`;
49
+
50
+ triangles.forEach((triangle, i) => {
51
+ const v1 = triangle.vertices[0];
52
+ const v2 = triangle.vertices[1];
53
+ const v3 = triangle.vertices[2];
54
+ const color = triangle.color || "#808080";
55
+
56
+ code += ` new Triangle(\n`;
57
+ code += ` new Vector3(${v1.x.toFixed(6)}, ${v1.y.toFixed(6)}, ${v1.z.toFixed(6)}),\n`;
58
+ code += ` new Vector3(${v2.x.toFixed(6)}, ${v2.y.toFixed(6)}, ${v2.z.toFixed(6)}),\n`;
59
+ code += ` new Vector3(${v3.x.toFixed(6)}, ${v3.y.toFixed(6)}, ${v3.z.toFixed(6)}),\n`;
60
+ code += ` "${color}"\n`;
61
+ code += ` )${i < triangles.length - 1 ? ',' : ''}\n`;
62
+ });
63
+
64
+ code += ` ];\n`;
65
+ code += `}\n`;
66
+
67
+ return code;
68
+ }
69
+
70
+ /**
71
+ * Export Triangle code as downloadable file
72
+ * @param {Triangle[]} triangles - Array of Triangle objects
73
+ * @param {string} modelName - Name for the model
74
+ */
75
+ static exportTriangleCode(triangles, modelName) {
76
+ const code = ModelCodeGenerator.generateTriangleCode(triangles, modelName);
77
+
78
+ // Download the file
79
+ const blob = new Blob([code], { type: 'text/javascript' });
80
+ const url = URL.createObjectURL(blob);
81
+ const a = document.createElement('a');
82
+ a.href = url;
83
+ a.download = `${modelName}.js`;
84
+ a.click();
85
+ URL.revokeObjectURL(url);
86
+ }
87
+
88
+ /**
89
+ * Export GLB model as ActionEngine Triangle code
90
+ * @param {string} base64Data - GLB file as base64 string
91
+ * @param {string} modelName - Name for the model
92
+ */
93
+ static exportGLBAsCode(base64Data, modelName) {
94
+ const glbModel = GLBLoader.loadModel(base64Data);
95
+ ModelCodeGenerator.exportTriangleCode(glbModel.triangles, modelName);
96
+ }
97
+ }
@@ -0,0 +1,33 @@
1
+ // actionengine/math/geometry/triangle.js
2
+ class Triangle {
3
+ constructor(v1, v2, v3, color = "#FF00FF", texture = null, uvs = null) {
4
+ this.vertices = [v1, v2, v3];
5
+ this.normal = this.calculateNormal();
6
+ this.color = color; // Default to magenta
7
+ this.texture = texture;
8
+ this.uvs = uvs;
9
+ }
10
+
11
+ calculateNormal() {
12
+ const edge1 = this.vertices[1].sub(this.vertices[0]);
13
+ const edge2 = this.vertices[2].sub(this.vertices[0]);
14
+ return edge1.cross(edge2).normalize();
15
+ }
16
+
17
+ getVertexArray() {
18
+ return this.vertices.flatMap((v) => [v.x, v.y, v.z]);
19
+ }
20
+
21
+ getNormalArray() {
22
+ return [...this.normal.toArray(), ...this.normal.toArray(), ...this.normal.toArray()];
23
+ }
24
+
25
+ getColorArray() {
26
+ // Convert hex color to RGB array
27
+ const r = parseInt(this.color.substr(1, 2), 16) / 255;
28
+ const g = parseInt(this.color.substr(3, 2), 16) / 255;
29
+ const b = parseInt(this.color.substr(5, 2), 16) / 255;
30
+ // Return color for all three vertices
31
+ return [r, g, b, r, g, b, r, g, b];
32
+ }
33
+ }
@@ -0,0 +1,34 @@
1
+ // actionengine/math/geometry/triangleutils.js
2
+ class TriangleUtils {
3
+ static interpolateZ(x, y, p1, p2, p3) {
4
+ const denominator = (p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y);
5
+ if (Math.abs(denominator) < 0.0001) {
6
+ return (p1.z + p2.z + p3.z) / 3;
7
+ }
8
+ const w1 = ((p2.y - p3.y) * (x - p3.x) + (p3.x - p2.x) * (y - p3.y)) / denominator;
9
+ const w2 = ((p3.y - p1.y) * (x - p3.x) + (p1.x - p3.x) * (y - p3.y)) / denominator;
10
+ const w3 = 1 - w1 - w2;
11
+ return w1 * p1.z + w2 * p2.z + w3 * p3.z;
12
+ }
13
+
14
+ static pointInTriangle(p, v1, v2, v3) {
15
+ const d1 = (p.x - v2.x) * (v1.y - v2.y) - (v1.x - v2.x) * (p.y - v2.y);
16
+ const d2 = (p.x - v3.x) * (v2.y - v3.y) - (v2.x - v3.x) * (p.y - v3.y);
17
+ const d3 = (p.x - v1.x) * (v3.y - v1.y) - (v3.x - v1.x) * (p.y - v1.y);
18
+ const hasNeg = d1 < 0 || d2 < 0 || d3 < 0;
19
+ const hasPos = d1 > 0 || d2 > 0 || d3 > 0;
20
+ return !(hasNeg && hasPos);
21
+ }
22
+
23
+ static isFrontFacing(p1, p2, p3) {
24
+ return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y) < 0;
25
+ }
26
+
27
+ static getBarycentricCoords(x, y, p1, p2, p3) {
28
+ const denominator = (p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y);
29
+ const w1 = ((p2.y - p3.y) * (x - p3.x) + (p3.x - p2.x) * (y - p3.y)) / denominator;
30
+ const w2 = ((p3.y - p1.y) * (x - p3.x) + (p1.x - p3.x) * (y - p3.y)) / denominator;
31
+ const w3 = 1 - w1 - w2;
32
+ return { w1, w2, w3 };
33
+ }
34
+ }
@@ -0,0 +1,25 @@
1
+ // actionengine/math/mathutils.js
2
+ class MathUtils {
3
+ static clamp(value, min, max) {
4
+ return Math.min(Math.max(value, min), max);
5
+ }
6
+
7
+ static lerp(start, end, t) {
8
+ return start + (end - start) * t;
9
+ }
10
+
11
+ static sign(p, v1, v2) {
12
+ return (p.x - v2.x) * (v1.z - v2.z) - (v1.x - v2.x) * (p.z - v2.z);
13
+ }
14
+ }
15
+
16
+ class SeededRandom {
17
+ constructor(seed) {
18
+ this.seed = seed;
19
+ }
20
+
21
+ next() {
22
+ this.seed = (this.seed * 16807) % 2147483647;
23
+ return (this.seed - 1) / 2147483646;
24
+ }
25
+ }