@dayme/bunraylib 0.1.0 → 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 (67) hide show
  1. package/README.md +60 -11
  2. package/package.json +11 -3
  3. package/src/Raylib.ts +58 -3678
  4. package/src/c/common.h +0 -2
  5. package/src/constants.ts +2 -2
  6. package/src/index.ts +6 -6
  7. package/src/main.c +0 -1
  8. package/src/main.d.ts +1 -1
  9. package/src/modules/audio/AudioModule.ts +197 -0
  10. package/src/modules/audio/symbols.ts +70 -0
  11. package/src/{c/audio.c → modules/audio/wrapper.c} +40 -80
  12. package/src/modules/camera/CameraModule.ts +239 -0
  13. package/src/modules/camera/symbols.ts +49 -0
  14. package/src/modules/camera/wrapper.c +141 -0
  15. package/src/modules/collision/CollisionModule.ts +363 -0
  16. package/src/modules/collision/symbols.ts +149 -0
  17. package/src/modules/collision/wrapper.c +176 -0
  18. package/src/modules/color/ColorModule.ts +65 -0
  19. package/src/modules/color/symbols.ts +26 -0
  20. package/src/modules/color/wrapper.c +16 -0
  21. package/src/modules/draw3d/Draw3DModule.ts +441 -0
  22. package/src/modules/draw3d/symbols.ts +199 -0
  23. package/src/modules/draw3d/wrapper.c +202 -0
  24. package/src/modules/font/FontModule.ts +250 -0
  25. package/src/modules/font/symbols.ts +46 -0
  26. package/src/{c/font.c → modules/font/wrapper.c} +50 -70
  27. package/src/modules/image/ImageModule.ts +451 -0
  28. package/src/{symbols/image.ts → modules/image/symbols.ts} +15 -12
  29. package/src/{c/image.c → modules/image/wrapper.c} +23 -45
  30. package/src/modules/input/InputModule.ts +160 -0
  31. package/src/modules/input/symbols.ts +54 -0
  32. package/src/modules/input/wrapper.c +31 -0
  33. package/src/modules/model/ModelModule.ts +228 -0
  34. package/src/{symbols/model.ts → modules/model/symbols.ts} +17 -14
  35. package/src/{c/model.c → modules/model/wrapper.c} +30 -30
  36. package/src/modules/shader/ShaderModule.ts +78 -0
  37. package/src/{symbols/shader.ts → modules/shader/symbols.ts} +3 -1
  38. package/src/{c/shader.c → modules/shader/wrapper.c} +11 -1
  39. package/src/modules/shapes/ShapesModule.ts +687 -0
  40. package/src/modules/shapes/symbols.ts +161 -0
  41. package/src/modules/shapes/wrapper.c +183 -0
  42. package/src/modules/texture/TextureModule.ts +190 -0
  43. package/src/{symbols/texture.ts → modules/texture/symbols.ts} +15 -9
  44. package/src/{c/texture.c → modules/texture/wrapper.c} +7 -22
  45. package/src/modules/window/WindowModule.ts +248 -0
  46. package/src/modules/window/symbols.ts +85 -0
  47. package/src/modules/window/wrapper.c +39 -0
  48. package/src/symbols.ts +87 -47
  49. package/src/utils.ts +63 -15
  50. package/src/c/camera.c +0 -161
  51. package/src/c/collision.c +0 -176
  52. package/src/c/color.c +0 -100
  53. package/src/c/draw3d.c +0 -222
  54. package/src/c/filesystem.c +0 -36
  55. package/src/c/input.c +0 -85
  56. package/src/c/shapes.c +0 -283
  57. package/src/c/window.c +0 -150
  58. package/src/symbols/audio.ts +0 -64
  59. package/src/symbols/camera.ts +0 -46
  60. package/src/symbols/collision.ts +0 -116
  61. package/src/symbols/color.ts +0 -22
  62. package/src/symbols/draw3d.ts +0 -137
  63. package/src/symbols/filesystem.ts +0 -30
  64. package/src/symbols/font.ts +0 -40
  65. package/src/symbols/input.ts +0 -51
  66. package/src/symbols/shapes.ts +0 -92
  67. package/src/symbols/window.ts +0 -83
@@ -1,4 +1,4 @@
1
- #include "common.h"
1
+ #include "../../c/common.h"
2
2
 
3
3
  int LoadImageW(const char* fileName) {
4
4
  int slot = imageAlloc();
@@ -78,21 +78,17 @@ int GenImageGradientLinearW(int width, int height, int direction, Color start, C
78
78
  return slot;
79
79
  }
80
80
 
81
- int GenImageGradientRadialW(int width, int height, int density, Color inner, Color outer) {
82
- float d;
83
- memcpy(&d, &density, sizeof(float));
81
+ int GenImageGradientRadialW(int width, int height, float density, Color inner, Color outer) {
84
82
  int slot = imageAlloc();
85
83
  if (slot < 0) return -1;
86
- imageRegistry[slot] = GenImageGradientRadial(width, height, d, inner, outer);
84
+ imageRegistry[slot] = GenImageGradientRadial(width, height, density, inner, outer);
87
85
  return slot;
88
86
  }
89
87
 
90
- int GenImageGradientSquareW(int width, int height, int density, Color inner, Color outer) {
91
- float d;
92
- memcpy(&d, &density, sizeof(float));
88
+ int GenImageGradientSquareW(int width, int height, float density, Color inner, Color outer) {
93
89
  int slot = imageAlloc();
94
90
  if (slot < 0) return -1;
95
- imageRegistry[slot] = GenImageGradientSquare(width, height, d, inner, outer);
91
+ imageRegistry[slot] = GenImageGradientSquare(width, height, density, inner, outer);
96
92
  return slot;
97
93
  }
98
94
 
@@ -103,21 +99,17 @@ int GenImageCheckedW(int width, int height, int checksX, int checksY, Color col1
103
99
  return slot;
104
100
  }
105
101
 
106
- int GenImageWhiteNoiseW(int width, int height, int factor) {
107
- float f;
108
- memcpy(&f, &factor, sizeof(float));
102
+ int GenImageWhiteNoiseW(int width, int height, float factor) {
109
103
  int slot = imageAlloc();
110
104
  if (slot < 0) return -1;
111
- imageRegistry[slot] = GenImageWhiteNoise(width, height, f);
105
+ imageRegistry[slot] = GenImageWhiteNoise(width, height, factor);
112
106
  return slot;
113
107
  }
114
108
 
115
- int GenImagePerlinNoiseW(int width, int height, int offsetX, int offsetY, int scale) {
116
- float s;
117
- memcpy(&s, &scale, sizeof(float));
109
+ int GenImagePerlinNoiseW(int width, int height, int offsetX, int offsetY, float scale) {
118
110
  int slot = imageAlloc();
119
111
  if (slot < 0) return -1;
120
- imageRegistry[slot] = GenImagePerlinNoise(width, height, offsetX, offsetY, s);
112
+ imageRegistry[slot] = GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
121
113
  return slot;
122
114
  }
123
115
 
@@ -167,12 +159,10 @@ int ImageTextW(const char* text, int fontSize, Color color) {
167
159
  return slot;
168
160
  }
169
161
 
170
- int ImageTextExW(int fontId, const char* text, int fontSize, int spacing, Color tint) {
171
- float sp;
172
- memcpy(&sp, &spacing, sizeof(float));
162
+ int ImageTextExW(int fontId, const char* text, int fontSize, float spacing, Color tint) {
173
163
  int slot = imageAlloc();
174
164
  if (slot < 0) return -1;
175
- imageRegistry[slot] = ImageTextEx(fontRegistry[fontId], text, fontSize, sp, tint);
165
+ imageRegistry[slot] = ImageTextEx(fontRegistry[fontId], text, fontSize, spacing, tint);
176
166
  return slot;
177
167
  }
178
168
 
@@ -187,18 +177,14 @@ void ImageCropW(int id, int rx, int ry, int rw, int rh) {
187
177
  ImageCrop(&imageRegistry[id], rec);
188
178
  }
189
179
 
190
- void ImageAlphaCropW(int id, int threshold) {
180
+ void ImageAlphaCropW(int id, float threshold) {
191
181
  if (id < 0 || id >= MAX_IMAGES || !imageUsed[id]) return;
192
- float t;
193
- memcpy(&t, &threshold, sizeof(float));
194
- ImageAlphaCrop(&imageRegistry[id], t);
182
+ ImageAlphaCrop(&imageRegistry[id], threshold);
195
183
  }
196
184
 
197
- void ImageAlphaClearW(int id, Color color, int threshold) {
185
+ void ImageAlphaClearW(int id, Color color, float threshold) {
198
186
  if (id < 0 || id >= MAX_IMAGES || !imageUsed[id]) return;
199
- float t;
200
- memcpy(&t, &threshold, sizeof(float));
201
- ImageAlphaClear(&imageRegistry[id], color, t);
187
+ ImageAlphaClear(&imageRegistry[id], color, threshold);
202
188
  }
203
189
 
204
190
  void ImageAlphaMaskW(int id, int alphaMaskId) {
@@ -252,11 +238,9 @@ void ImageFlipHorizontalW(int id) {
252
238
  ImageFlipHorizontal(&imageRegistry[id]);
253
239
  }
254
240
 
255
- void ImageRotateW(int id, int degrees) {
241
+ void ImageRotateW(int id, float degrees) {
256
242
  if (id < 0 || id >= MAX_IMAGES || !imageUsed[id]) return;
257
- float d;
258
- memcpy(&d, &degrees, sizeof(float));
259
- ImageRotate(&imageRegistry[id], d);
243
+ ImageRotate(&imageRegistry[id], degrees);
260
244
  }
261
245
 
262
246
  void ImageRotateCWW(int id) {
@@ -284,11 +268,9 @@ void ImageColorGrayscaleW(int id) {
284
268
  ImageColorGrayscale(&imageRegistry[id]);
285
269
  }
286
270
 
287
- void ImageColorContrastW(int id, int contrast) {
271
+ void ImageColorContrastW(int id, float contrast) {
288
272
  if (id < 0 || id >= MAX_IMAGES || !imageUsed[id]) return;
289
- float c;
290
- memcpy(&c, &contrast, sizeof(float));
291
- ImageColorContrast(&imageRegistry[id], c);
273
+ ImageColorContrast(&imageRegistry[id], contrast);
292
274
  }
293
275
 
294
276
  void ImageColorBrightnessW(int id, int brightness) {
@@ -301,12 +283,10 @@ void ImageColorReplaceW(int id, Color color, Color replace) {
301
283
  ImageColorReplace(&imageRegistry[id], color, replace);
302
284
  }
303
285
 
304
- void GetImageAlphaBorderW(float* out, int id, int threshold) {
286
+ void GetImageAlphaBorderW(float* out, int id, float threshold) {
305
287
  Rectangle rec = {0};
306
288
  if (id >= 0 && id < MAX_IMAGES && imageUsed[id]) {
307
- float t;
308
- memcpy(&t, &threshold, sizeof(float));
309
- rec = GetImageAlphaBorder(imageRegistry[id], t);
289
+ rec = GetImageAlphaBorder(imageRegistry[id], threshold);
310
290
  }
311
291
  out[0] = rec.x; out[1] = rec.y; out[2] = rec.width; out[3] = rec.height;
312
292
  }
@@ -427,11 +407,9 @@ void ImageDrawTextW(int dstId, const char* text, int posX, int posY, int fontSiz
427
407
  ImageDrawText(&imageRegistry[dstId], text, posX, posY, fontSize, color);
428
408
  }
429
409
 
430
- void ImageDrawTextExW(int dstId, int fontId, const char* text, int posX, int posY, int fontSize, int spacing, Color tint) {
410
+ void ImageDrawTextExW(int dstId, int fontId, const char* text, int posX, int posY, int fontSize, float spacing, Color tint) {
431
411
  if (dstId < 0 || dstId >= MAX_IMAGES || !imageUsed[dstId]) return;
432
- float sp;
433
- memcpy(&sp, &spacing, sizeof(float));
434
- ImageDrawTextEx(&imageRegistry[dstId], fontRegistry[fontId], text, (Vector2){posX, posY}, fontSize, sp, tint);
412
+ ImageDrawTextEx(&imageRegistry[dstId], fontRegistry[fontId], text, (Vector2){posX, posY}, fontSize, spacing, tint);
435
413
  }
436
414
 
437
415
  void ImageToPOTW(int id, int fill) {
@@ -0,0 +1,160 @@
1
+ import { getSymbols } from '../../symbols';
2
+ import { bufs as b, cstr, f, i } from '../../utils';
3
+ import { CString } from 'bun:ffi';
4
+ import type { Vec2 } from '../../types';
5
+
6
+ const r = () => getSymbols();
7
+
8
+ export class InputModule {
9
+ static isKeyPressed(key: number): boolean {
10
+ return r().symbols.IsKeyPressed(i(key));
11
+ }
12
+ static isKeyPressedRepeat(key: number): boolean {
13
+ return r().symbols.IsKeyPressedRepeat(i(key));
14
+ }
15
+ static isKeyDown(key: number): boolean {
16
+ return r().symbols.IsKeyDown(i(key));
17
+ }
18
+ static isKeyReleased(key: number): boolean {
19
+ return r().symbols.IsKeyReleased(i(key));
20
+ }
21
+ static isKeyUp(key: number): boolean {
22
+ return r().symbols.IsKeyUp(i(key));
23
+ }
24
+ static getKeyPressed(): number {
25
+ return r().symbols.GetKeyPressed();
26
+ }
27
+ static getCharPressed(): number {
28
+ return r().symbols.GetCharPressed();
29
+ }
30
+ static setExitKey(key: number): void {
31
+ r().symbols.SetExitKey(i(key));
32
+ }
33
+ static isGamepadAvailable(gamepad: number): boolean {
34
+ return r().symbols.IsGamepadAvailable(i(gamepad));
35
+ }
36
+ static getGamepadName(gamepad: number): string {
37
+ const ptr = r().symbols.GetGamepadName(i(gamepad));
38
+ if (!ptr) return '';
39
+ return new CString(ptr).toString();
40
+ }
41
+ static isGamepadButtonPressed(gamepad: number, button: number): boolean {
42
+ return r().symbols.IsGamepadButtonPressed(i(gamepad), i(button));
43
+ }
44
+ static isGamepadButtonDown(gamepad: number, button: number): boolean {
45
+ return r().symbols.IsGamepadButtonDown(i(gamepad), i(button));
46
+ }
47
+ static isGamepadButtonReleased(gamepad: number, button: number): boolean {
48
+ return r().symbols.IsGamepadButtonReleased(i(gamepad), i(button));
49
+ }
50
+ static isGamepadButtonUp(gamepad: number, button: number): boolean {
51
+ return r().symbols.IsGamepadButtonUp(i(gamepad), i(button));
52
+ }
53
+ static getGamepadButtonPressed(): number {
54
+ return r().symbols.GetGamepadButtonPressed();
55
+ }
56
+ static getGamepadAxisCount(gamepad: number): number {
57
+ return r().symbols.GetGamepadAxisCount(i(gamepad));
58
+ }
59
+ static getGamepadAxisMovement(gamepad: number, axis: number): number {
60
+ return r().symbols.GetGamepadAxisMovement(i(gamepad), i(axis));
61
+ }
62
+ static setGamepadMappings(mappings: string): number {
63
+ return r().symbols.SetGamepadMappings(cstr(mappings));
64
+ }
65
+ static isMouseButtonPressed(button: number): boolean {
66
+ return r().symbols.IsMouseButtonPressed(i(button));
67
+ }
68
+ static isMouseButtonDown(button: number): boolean {
69
+ return r().symbols.IsMouseButtonDown(i(button));
70
+ }
71
+ static isMouseButtonReleased(button: number): boolean {
72
+ return r().symbols.IsMouseButtonReleased(i(button));
73
+ }
74
+ static isMouseButtonUp(button: number): boolean {
75
+ return r().symbols.IsMouseButtonUp(i(button));
76
+ }
77
+ static getMouseX(): number {
78
+ return r().symbols.GetMouseX();
79
+ }
80
+ static getMouseY(): number {
81
+ return r().symbols.GetMouseY();
82
+ }
83
+ static getMousePosition(): Vec2 {
84
+ r().symbols.GetMousePositionW(b._vec2Buf);
85
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
86
+ }
87
+ static getMouseDelta(): Vec2 {
88
+ r().symbols.GetMouseDeltaW(b._vec2Buf);
89
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
90
+ }
91
+ static setMousePosition(x: number, y: number): void {
92
+ r().symbols.SetMousePosition(i(x), i(y));
93
+ }
94
+ static setMouseOffset(x: number, y: number): void {
95
+ r().symbols.SetMouseOffset(i(x), i(y));
96
+ }
97
+ static setMouseScale(scaleX: number, scaleY: number): void {
98
+ r().symbols.SetMouseScale(f(scaleX), f(scaleY));
99
+ }
100
+ static getMouseWheelMove(): number {
101
+ return r().symbols.GetMouseWheelMove();
102
+ }
103
+ static getMouseWheelMoveV(): Vec2 {
104
+ r().symbols.GetMouseWheelMoveVW(b._vec2Buf);
105
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
106
+ }
107
+ static setMouseCursor(cursor: number): void {
108
+ r().symbols.SetMouseCursor(i(cursor));
109
+ }
110
+ static getTouchX(): number {
111
+ return r().symbols.GetTouchX();
112
+ }
113
+ static getTouchY(): number {
114
+ return r().symbols.GetTouchY();
115
+ }
116
+ static getTouchPosition(index: number): Vec2 {
117
+ r().symbols.GetTouchPositionW(b._vec2Buf, i(index));
118
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
119
+ }
120
+ static getTouchPointId(index: number): number {
121
+ return r().symbols.GetTouchPointId(i(index));
122
+ }
123
+ static getTouchPointCount(): number {
124
+ return r().symbols.GetTouchPointCount();
125
+ }
126
+ static setGesturesEnabled(flags: number): void {
127
+ r().symbols.SetGesturesEnabled(i(flags));
128
+ }
129
+ static isGestureDetected(gesture: number): boolean {
130
+ return r().symbols.IsGestureDetected(i(gesture));
131
+ }
132
+ static getGestureDetected(): number {
133
+ return r().symbols.GetGestureDetected();
134
+ }
135
+ static getGestureHoldDuration(): number {
136
+ return r().symbols.GetGestureHoldDuration();
137
+ }
138
+ static getGestureDragVector(): Vec2 {
139
+ r().symbols.GetGestureDragVectorW(b._vec2Buf);
140
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
141
+ }
142
+ static getGestureDragAngle(): number {
143
+ return r().symbols.GetGestureDragAngle();
144
+ }
145
+ static getGesturePinchVector(): Vec2 {
146
+ r().symbols.GetGesturePinchVectorW(b._vec2Buf);
147
+ return { x: b._vec2Buf[0]!, y: b._vec2Buf[1]! };
148
+ }
149
+ static getGesturePinchAngle(): number {
150
+ return r().symbols.GetGesturePinchAngle();
151
+ }
152
+ static setGamepadVibration(
153
+ gamepad: number,
154
+ leftMotor: number,
155
+ rightMotor: number,
156
+ duration: number,
157
+ ): void {
158
+ r().symbols.SetGamepadVibration(i(gamepad), f(leftMotor), f(rightMotor), f(duration));
159
+ }
160
+ }
@@ -0,0 +1,54 @@
1
+ import { FFIType } from 'bun:ffi';
2
+ const { i32, cstring, bool, f32, ptr } = FFIType;
3
+
4
+ export const inputDirectSymbols = {
5
+ IsKeyPressed: { args: [i32], returns: bool },
6
+ IsKeyPressedRepeat: { args: [i32], returns: bool },
7
+ IsKeyDown: { args: [i32], returns: bool },
8
+ IsKeyReleased: { args: [i32], returns: bool },
9
+ IsKeyUp: { args: [i32], returns: bool },
10
+ GetKeyPressed: { args: [], returns: i32 },
11
+ GetCharPressed: { args: [], returns: i32 },
12
+ SetExitKey: { args: [i32], returns: FFIType.void },
13
+ IsGamepadAvailable: { args: [i32], returns: bool },
14
+ GetGamepadName: { args: [i32], returns: ptr },
15
+ IsGamepadButtonPressed: { args: [i32, i32], returns: bool },
16
+ IsGamepadButtonDown: { args: [i32, i32], returns: bool },
17
+ IsGamepadButtonReleased: { args: [i32, i32], returns: bool },
18
+ IsGamepadButtonUp: { args: [i32, i32], returns: bool },
19
+ GetGamepadButtonPressed: { args: [], returns: i32 },
20
+ GetGamepadAxisCount: { args: [i32], returns: i32 },
21
+ GetGamepadAxisMovement: { args: [i32, i32], returns: f32 },
22
+ SetGamepadMappings: { args: [cstring], returns: i32 },
23
+ SetGamepadVibration: { args: [i32, f32, f32, f32], returns: FFIType.void },
24
+ IsMouseButtonPressed: { args: [i32], returns: bool },
25
+ IsMouseButtonDown: { args: [i32], returns: bool },
26
+ IsMouseButtonReleased: { args: [i32], returns: bool },
27
+ IsMouseButtonUp: { args: [i32], returns: bool },
28
+ GetMouseX: { args: [], returns: i32 },
29
+ GetMouseY: { args: [], returns: i32 },
30
+ SetMousePosition: { args: [i32, i32], returns: FFIType.void },
31
+ SetMouseOffset: { args: [i32, i32], returns: FFIType.void },
32
+ SetMouseScale: { args: [f32, f32], returns: FFIType.void },
33
+ GetMouseWheelMove: { args: [], returns: f32 },
34
+ SetMouseCursor: { args: [i32], returns: FFIType.void },
35
+ GetTouchX: { args: [], returns: i32 },
36
+ GetTouchY: { args: [], returns: i32 },
37
+ GetTouchPointId: { args: [i32], returns: i32 },
38
+ GetTouchPointCount: { args: [], returns: i32 },
39
+ SetGesturesEnabled: { args: [i32], returns: FFIType.void },
40
+ IsGestureDetected: { args: [i32], returns: bool },
41
+ GetGestureDetected: { args: [], returns: i32 },
42
+ GetGestureHoldDuration: { args: [], returns: f32 },
43
+ GetGestureDragAngle: { args: [], returns: f32 },
44
+ GetGesturePinchAngle: { args: [], returns: f32 },
45
+ } as const;
46
+
47
+ export const inputWrapperSymbols = {
48
+ GetMousePositionW: { args: [ptr], returns: FFIType.void },
49
+ GetMouseDeltaW: { args: [ptr], returns: FFIType.void },
50
+ GetMouseWheelMoveVW: { args: [ptr], returns: FFIType.void },
51
+ GetTouchPositionW: { args: [ptr, i32], returns: FFIType.void },
52
+ GetGestureDragVectorW: { args: [ptr], returns: FFIType.void },
53
+ GetGesturePinchVectorW: { args: [ptr], returns: FFIType.void },
54
+ } as const;
@@ -0,0 +1,31 @@
1
+ #include <raylib.h>
2
+
3
+ void GetMousePositionW(float* out) {
4
+ Vector2 v = GetMousePosition();
5
+ out[0] = v.x; out[1] = v.y;
6
+ }
7
+
8
+ void GetMouseDeltaW(float* out) {
9
+ Vector2 v = GetMouseDelta();
10
+ out[0] = v.x; out[1] = v.y;
11
+ }
12
+
13
+ void GetMouseWheelMoveVW(float* out) {
14
+ Vector2 v = GetMouseWheelMoveV();
15
+ out[0] = v.x; out[1] = v.y;
16
+ }
17
+
18
+ void GetTouchPositionW(float* out, int index) {
19
+ Vector2 v = GetTouchPosition(index);
20
+ out[0] = v.x; out[1] = v.y;
21
+ }
22
+
23
+ void GetGestureDragVectorW(float* out) {
24
+ Vector2 v = GetGestureDragVector();
25
+ out[0] = v.x; out[1] = v.y;
26
+ }
27
+
28
+ void GetGesturePinchVectorW(float* out) {
29
+ Vector2 v = GetGesturePinchVector();
30
+ out[0] = v.x; out[1] = v.y;
31
+ }
@@ -0,0 +1,228 @@
1
+ import { getSymbols } from '../../symbols';
2
+ import { bufs as b, cstr, f, i } from '../../utils';
3
+ import type {
4
+ Vec3,
5
+ Texture2D,
6
+ Model,
7
+ BoundingBox,
8
+ Image,
9
+ Material,
10
+ Mesh,
11
+ ModelAnimation,
12
+ Color,
13
+ } from '../../types';
14
+
15
+ const r = () => getSymbols();
16
+
17
+ export class ModelModule {
18
+ static loadModel(fileName: string): Model {
19
+ return r().symbols.LoadModelW(cstr(fileName));
20
+ }
21
+ static unloadModel(model: Model): void {
22
+ r().symbols.UnloadModelW(i(model));
23
+ }
24
+ static isModelValid(model: Model): boolean {
25
+ return r().symbols.IsModelValidW(i(model));
26
+ }
27
+ static getModelBoundingBox(model: Model): BoundingBox {
28
+ r().symbols.GetModelBoundingBoxW(b._bbMin, b._bbMax, i(model));
29
+ return {
30
+ min: { x: b._bbMin[0]!, y: b._bbMin[1]!, z: b._bbMin[2]! },
31
+ max: { x: b._bbMax[0]!, y: b._bbMax[1]!, z: b._bbMax[2]! },
32
+ };
33
+ }
34
+ static drawModel(model: Model, position: Vec3, scale: number, tint: Color): void {
35
+ r().symbols.DrawModelW(
36
+ i(model),
37
+ f(position.x),
38
+ f(position.y),
39
+ f(position.z),
40
+ f(scale),
41
+ i(tint),
42
+ );
43
+ }
44
+ static drawModelEx(
45
+ model: Model,
46
+ position: Vec3,
47
+ rotationAxis: Vec3,
48
+ rotationAngle: number,
49
+ scale: Vec3,
50
+ tint: Color,
51
+ ): void {
52
+ r().symbols.DrawModelExW(
53
+ i(model),
54
+ f(position.x),
55
+ f(position.y),
56
+ f(position.z),
57
+ f(rotationAxis.x),
58
+ f(rotationAxis.y),
59
+ f(rotationAxis.z),
60
+ f(rotationAngle),
61
+ f(scale.x),
62
+ f(scale.y),
63
+ f(scale.z),
64
+ i(tint),
65
+ );
66
+ }
67
+ static drawModelWires(model: Model, position: Vec3, scale: number, tint: Color): void {
68
+ r().symbols.DrawModelWiresW(
69
+ i(model),
70
+ f(position.x),
71
+ f(position.y),
72
+ f(position.z),
73
+ f(scale),
74
+ i(tint),
75
+ );
76
+ }
77
+ static drawModelWiresEx(
78
+ model: Model,
79
+ position: Vec3,
80
+ rotationAxis: Vec3,
81
+ rotationAngle: number,
82
+ scale: Vec3,
83
+ tint: Color,
84
+ ): void {
85
+ r().symbols.DrawModelWiresExW(
86
+ i(model),
87
+ f(position.x),
88
+ f(position.y),
89
+ f(position.z),
90
+ f(rotationAxis.x),
91
+ f(rotationAxis.y),
92
+ f(rotationAxis.z),
93
+ f(rotationAngle),
94
+ f(scale.x),
95
+ f(scale.y),
96
+ f(scale.z),
97
+ i(tint),
98
+ );
99
+ }
100
+ static drawMesh(mesh: Mesh, material: Material, transform: Float32Array): void {
101
+ r().symbols.DrawMeshW(i(mesh), i(material), transform);
102
+ }
103
+ static drawMeshInstanced(
104
+ mesh: Mesh,
105
+ material: Material,
106
+ transforms: Float32Array,
107
+ instances: number,
108
+ ): void {
109
+ r().symbols.DrawMeshInstancedW(i(mesh), i(material), transforms, i(instances));
110
+ }
111
+ static loadModelFromMesh(mesh: Mesh): Model {
112
+ return r().symbols.LoadModelFromMeshW(i(mesh));
113
+ }
114
+ static unloadMesh(mesh: Mesh): void {
115
+ r().symbols.UnloadMeshW(i(mesh));
116
+ }
117
+ static uploadMesh(mesh: Mesh, dynamic: boolean): void {
118
+ r().symbols.UploadMeshW(i(mesh), dynamic);
119
+ }
120
+ static getMeshBoundingBox(mesh: Mesh): BoundingBox {
121
+ r().symbols.GetMeshBoundingBoxW(b._bbMin, b._bbMax, i(mesh));
122
+ return {
123
+ min: { x: b._bbMin[0]!, y: b._bbMin[1]!, z: b._bbMin[2]! },
124
+ max: { x: b._bbMax[0]!, y: b._bbMax[1]!, z: b._bbMax[2]! },
125
+ };
126
+ }
127
+ static genMeshTangents(mesh: Mesh): void {
128
+ r().symbols.GenMeshTangentsW(i(mesh));
129
+ }
130
+ static exportMesh(mesh: Mesh, fileName: string): boolean {
131
+ return r().symbols.ExportMeshW(i(mesh), cstr(fileName));
132
+ }
133
+ static exportMeshAsCode(mesh: Mesh, fileName: string): boolean {
134
+ return r().symbols.ExportMeshAsCodeW(i(mesh), cstr(fileName));
135
+ }
136
+ static genMeshPoly(sides: number, radius: number): Mesh {
137
+ return r().symbols.GenMeshPolyW(i(sides), f(radius));
138
+ }
139
+ static genMeshPlane(width: number, length: number, resX: number, resZ: number): Mesh {
140
+ return r().symbols.GenMeshPlaneW(f(width), f(length), i(resX), i(resZ));
141
+ }
142
+ static genMeshCube(width: number, height: number, length: number): Mesh {
143
+ return r().symbols.GenMeshCubeW(f(width), f(height), f(length));
144
+ }
145
+ static genMeshSphere(radius: number, rings: number, slices: number): Mesh {
146
+ return r().symbols.GenMeshSphereW(f(radius), i(rings), i(slices));
147
+ }
148
+ static genMeshHemiSphere(radius: number, rings: number, slices: number): Mesh {
149
+ return r().symbols.GenMeshHemiSphereW(f(radius), i(rings), i(slices));
150
+ }
151
+ static genMeshCylinder(radius: number, height: number, slices: number): Mesh {
152
+ return r().symbols.GenMeshCylinderW(f(radius), f(height), i(slices));
153
+ }
154
+ static genMeshCone(radius: number, height: number, slices: number): Mesh {
155
+ return r().symbols.GenMeshConeW(f(radius), f(height), i(slices));
156
+ }
157
+ static genMeshTorus(radius: number, size: number, radSeg: number, sides: number): Mesh {
158
+ return r().symbols.GenMeshTorusW(f(radius), f(size), i(radSeg), i(sides));
159
+ }
160
+ static genMeshKnot(radius: number, size: number, radSeg: number, sides: number): Mesh {
161
+ return r().symbols.GenMeshKnotW(f(radius), f(size), i(radSeg), i(sides));
162
+ }
163
+ static genMeshHeightmap(heightmap: Image, size: Vec3): Mesh {
164
+ return r().symbols.GenMeshHeightmapW(i(heightmap), f(size.x), f(size.y), f(size.z));
165
+ }
166
+ static genMeshCubicmap(cubicmap: Image, cubeSize: Vec3): Mesh {
167
+ return r().symbols.GenMeshCubicmapW(i(cubicmap), f(cubeSize.x), f(cubeSize.y), f(cubeSize.z));
168
+ }
169
+ static loadMaterialDefault(): Material {
170
+ return r().symbols.LoadMaterialDefaultW();
171
+ }
172
+ static isMaterialValid(material: Material): boolean {
173
+ return r().symbols.IsMaterialValidW(i(material));
174
+ }
175
+ static unloadMaterial(material: Material): void {
176
+ r().symbols.UnloadMaterialW(i(material));
177
+ }
178
+ static setMaterialTexture(material: Material, mapType: number, texture: Texture2D): void {
179
+ r().symbols.SetMaterialTextureW(
180
+ i(material),
181
+ i(mapType),
182
+ i(texture.id),
183
+ i(texture.width),
184
+ i(texture.height),
185
+ );
186
+ }
187
+ static setModelMeshMaterial(model: Model, meshId: number, materialId: number): void {
188
+ r().symbols.SetModelMeshMaterialW(i(model), i(meshId), i(materialId));
189
+ }
190
+ static loadModelAnimations(fileName: string): { startSlot: number; count: number } {
191
+ r().symbols.LoadModelAnimationsW(b._animSlotStart, b._animCount, cstr(fileName));
192
+ return { startSlot: b._animSlotStart[0]!, count: b._animCount[0]! };
193
+ }
194
+ static updateModelAnimation(model: Model, anim: ModelAnimation, frame: number): void {
195
+ r().symbols.UpdateModelAnimationW(i(model), i(anim), f(frame));
196
+ }
197
+ static updateModelAnimationEx(
198
+ model: Model,
199
+ animA: ModelAnimation,
200
+ frameA: number,
201
+ animB: ModelAnimation,
202
+ frameB: number,
203
+ blend: number,
204
+ ): void {
205
+ r().symbols.UpdateModelAnimationExW(
206
+ i(model),
207
+ i(animA),
208
+ f(frameA),
209
+ i(animB),
210
+ f(frameB),
211
+ f(blend),
212
+ );
213
+ }
214
+ static unloadModelAnimations(startSlot: number, count: number): void {
215
+ r().symbols.UnloadModelAnimationsW(i(startSlot), i(count));
216
+ }
217
+ static isModelAnimationValid(model: Model, anim: ModelAnimation): boolean {
218
+ return r().symbols.IsModelAnimationValidW(i(model), i(anim));
219
+ }
220
+ static updateMeshBuffer(
221
+ mesh: Mesh,
222
+ index: number,
223
+ data: Buffer | Uint8Array,
224
+ offset: number,
225
+ ): void {
226
+ r().symbols.UpdateMeshBufferW(i(mesh), i(index), data, i(data.length), i(offset));
227
+ }
228
+ }
@@ -1,4 +1,4 @@
1
- import { FFIType } from "bun:ffi";
1
+ import { FFIType } from 'bun:ffi';
2
2
  const { i32, cstring, bool, ptr } = FFIType;
3
3
 
4
4
  export const modelSymbols = {
@@ -13,17 +13,17 @@ export const modelSymbols = {
13
13
  GenMeshTangentsW: { args: [i32], returns: FFIType.void },
14
14
  ExportMeshW: { args: [i32, cstring], returns: bool },
15
15
  ExportMeshAsCodeW: { args: [i32, cstring], returns: bool },
16
- GenMeshPolyW: { args: [i32, i32], returns: i32 },
17
- GenMeshPlaneW: { args: [i32, i32, i32, i32], returns: i32 },
18
- GenMeshCubeW: { args: [i32, i32, i32], returns: i32 },
19
- GenMeshSphereW: { args: [i32, i32, i32], returns: i32 },
20
- GenMeshHemiSphereW: { args: [i32, i32, i32], returns: i32 },
21
- GenMeshCylinderW: { args: [i32, i32, i32], returns: i32 },
22
- GenMeshConeW: { args: [i32, i32, i32], returns: i32 },
23
- GenMeshTorusW: { args: [i32, i32, i32, i32], returns: i32 },
24
- GenMeshKnotW: { args: [i32, i32, i32, i32], returns: i32 },
25
- GenMeshHeightmapW: { args: [i32, i32, i32, i32], returns: i32 },
26
- GenMeshCubicmapW: { args: [i32, i32, i32, i32], returns: i32 },
16
+ GenMeshPolyW: { args: [i32, FFIType.f32], returns: i32 },
17
+ GenMeshPlaneW: { args: [FFIType.f32, FFIType.f32, i32, i32], returns: i32 },
18
+ GenMeshCubeW: { args: [FFIType.f32, FFIType.f32, FFIType.f32], returns: i32 },
19
+ GenMeshSphereW: { args: [FFIType.f32, i32, i32], returns: i32 },
20
+ GenMeshHemiSphereW: { args: [FFIType.f32, i32, i32], returns: i32 },
21
+ GenMeshCylinderW: { args: [FFIType.f32, FFIType.f32, i32], returns: i32 },
22
+ GenMeshConeW: { args: [FFIType.f32, FFIType.f32, i32], returns: i32 },
23
+ GenMeshTorusW: { args: [FFIType.f32, FFIType.f32, i32, i32], returns: i32 },
24
+ GenMeshKnotW: { args: [FFIType.f32, FFIType.f32, i32, i32], returns: i32 },
25
+ GenMeshHeightmapW: { args: [i32, FFIType.f32, FFIType.f32, FFIType.f32], returns: i32 },
26
+ GenMeshCubicmapW: { args: [i32, FFIType.f32, FFIType.f32, FFIType.f32], returns: i32 },
27
27
  UpdateMeshBufferW: { args: [i32, i32, ptr, i32, i32], returns: FFIType.void },
28
28
  LoadMaterialDefaultW: { args: [], returns: i32 },
29
29
  IsMaterialValidW: { args: [i32], returns: bool },
@@ -31,8 +31,11 @@ export const modelSymbols = {
31
31
  SetMaterialTextureW: { args: [i32, i32, i32, i32, i32], returns: FFIType.void },
32
32
  SetModelMeshMaterialW: { args: [i32, i32, i32], returns: FFIType.void },
33
33
  LoadModelAnimationsW: { args: [ptr, ptr, cstring], returns: FFIType.void },
34
- UpdateModelAnimationW: { args: [i32, i32, i32], returns: FFIType.void },
35
- UpdateModelAnimationExW: { args: [i32, i32, i32, i32, i32, i32], returns: FFIType.void },
34
+ UpdateModelAnimationW: { args: [i32, i32, FFIType.f32], returns: FFIType.void },
35
+ UpdateModelAnimationExW: {
36
+ args: [i32, i32, FFIType.f32, i32, FFIType.f32, FFIType.f32],
37
+ returns: FFIType.void,
38
+ },
36
39
  UnloadModelAnimationsW: { args: [i32, i32], returns: FFIType.void },
37
40
  IsModelAnimationValidW: { args: [i32, i32], returns: bool },
38
41
  } as const;