@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
@@ -0,0 +1,65 @@
1
+ import { getSymbols } from '../../symbols';
2
+ import { bufs as b, f, i } from '../../utils';
3
+ import type { Color } from '../../types';
4
+
5
+ const r = () => getSymbols();
6
+
7
+ export class ColorModule {
8
+ static colorToInt(c: Color): number {
9
+ return r().symbols.ColorToInt(i(c));
10
+ }
11
+ static colorNormalize(c: Color): { x: number; y: number; z: number; w: number } {
12
+ r().symbols.ColorNormalizeW(b._vec4Buf, i(c));
13
+ return {
14
+ x: b._vec4Buf[0]!,
15
+ y: b._vec4Buf[1]!,
16
+ z: b._vec4Buf[2]!,
17
+ w: b._vec4Buf[3]!,
18
+ };
19
+ }
20
+ static colorFromNormalized(normalized: { x: number; y: number; z: number; w: number }): Color {
21
+ return r().symbols.ColorFromNormalizedW(
22
+ f(normalized.x),
23
+ f(normalized.y),
24
+ f(normalized.z),
25
+ f(normalized.w),
26
+ );
27
+ }
28
+ static colorToHSV(c: Color): { h: number; s: number; v: number } {
29
+ r().symbols.ColorToHSVW(b._vec3Buf2, i(c));
30
+ return { h: b._vec3Buf2[0]!, s: b._vec3Buf2[1]!, v: b._vec3Buf2[2]! };
31
+ }
32
+ static colorFromHSV(hue: number, saturation: number, value: number): Color {
33
+ return r().symbols.ColorFromHSV(f(hue), f(saturation), f(value));
34
+ }
35
+ static colorTint(color: Color, tint: Color): Color {
36
+ return r().symbols.ColorTint(i(color), i(tint));
37
+ }
38
+ static colorBrightness(color: Color, factor: number): Color {
39
+ return r().symbols.ColorBrightness(i(color), f(factor));
40
+ }
41
+ static colorContrast(color: Color, contrast: number): Color {
42
+ return r().symbols.ColorContrast(i(color), f(contrast));
43
+ }
44
+ static colorAlpha(color: Color, alpha: number): Color {
45
+ return r().symbols.ColorAlpha(i(color), f(alpha));
46
+ }
47
+ static colorAlphaBlend(dst: Color, src: Color, tint: Color): Color {
48
+ return r().symbols.ColorAlphaBlend(i(dst), i(src), i(tint));
49
+ }
50
+ static colorLerp(color1: Color, color2: Color, factor: number): Color {
51
+ return r().symbols.ColorLerp(i(color1), i(color2), f(factor));
52
+ }
53
+ static getColor(hexValue: number): Color {
54
+ return r().symbols.GetColor(i(hexValue));
55
+ }
56
+ static fade(color: Color, alpha: number): Color {
57
+ return r().symbols.Fade(i(color), f(alpha));
58
+ }
59
+ static colorIsEqual(col1: Color, col2: Color): boolean {
60
+ return r().symbols.ColorIsEqual(i(col1), i(col2));
61
+ }
62
+ static getPixelDataSize(width: number, height: number, format: number): number {
63
+ return r().symbols.GetPixelDataSize(i(width), i(height), i(format));
64
+ }
65
+ }
@@ -0,0 +1,26 @@
1
+ import { FFIType } from 'bun:ffi';
2
+ const { i32, bool, ptr } = FFIType;
3
+
4
+ export const colorSymbols = {
5
+ ColorNormalizeW: { args: [ptr, i32], returns: FFIType.void },
6
+ ColorToHSVW: { args: [ptr, i32], returns: FFIType.void },
7
+ ColorFromNormalizedW: {
8
+ args: [FFIType.f32, FFIType.f32, FFIType.f32, FFIType.f32],
9
+ returns: i32,
10
+ },
11
+ } as const;
12
+
13
+ export const colorDirectSymbols = {
14
+ ColorIsEqual: { args: [i32, i32], returns: bool },
15
+ ColorToInt: { args: [i32], returns: i32 },
16
+ GetPixelDataSize: { args: [i32, i32, i32], returns: i32 },
17
+ ColorTint: { args: [i32, i32], returns: i32 },
18
+ ColorBrightness: { args: [i32, FFIType.f32], returns: i32 },
19
+ ColorContrast: { args: [i32, FFIType.f32], returns: i32 },
20
+ ColorAlpha: { args: [i32, FFIType.f32], returns: i32 },
21
+ ColorAlphaBlend: { args: [i32, i32, i32], returns: i32 },
22
+ ColorLerp: { args: [i32, i32, FFIType.f32], returns: i32 },
23
+ GetColor: { args: [i32], returns: i32 },
24
+ Fade: { args: [i32, FFIType.f32], returns: i32 },
25
+ ColorFromHSV: { args: [FFIType.f32, FFIType.f32, FFIType.f32], returns: i32 },
26
+ } as const;
@@ -0,0 +1,16 @@
1
+ #include <raylib.h>
2
+
3
+ void ColorNormalizeW(float* out, Color color) {
4
+ Vector4 v = ColorNormalize(color);
5
+ out[0] = v.x; out[1] = v.y; out[2] = v.z; out[3] = v.w;
6
+ }
7
+
8
+ int ColorFromNormalizedW(float x, float y, float z, float w) {
9
+ Color c = ColorFromNormalized((Vector4){x, y, z, w});
10
+ return *((int*)&c);
11
+ }
12
+
13
+ void ColorToHSVW(float* out, Color color) {
14
+ Vector3 v = ColorToHSV(color);
15
+ out[0] = v.x; out[1] = v.y; out[2] = v.z;
16
+ }
@@ -0,0 +1,441 @@
1
+ import { getSymbols } from '../../symbols';
2
+ import { f, i, validatePoints } from '../../utils';
3
+ import type {
4
+ Vec2,
5
+ Vec3,
6
+ Rectangle,
7
+ Camera3D,
8
+ Ray,
9
+ Texture2D,
10
+ BoundingBox,
11
+ Color,
12
+ } from '../../types';
13
+
14
+ const r = () => getSymbols();
15
+
16
+ export class Draw3DModule {
17
+ /** Draw a line in 3D world space */
18
+ static drawLine3D(startPos: Vec3, endPos: Vec3, col: Color): void {
19
+ r().symbols.DrawLine3DW(
20
+ f(startPos.x),
21
+ f(startPos.y),
22
+ f(startPos.z),
23
+ f(endPos.x),
24
+ f(endPos.y),
25
+ f(endPos.z),
26
+ i(col),
27
+ );
28
+ }
29
+ /** Draw a point in 3D space */
30
+ static drawPoint3D(position: Vec3, col: Color): void {
31
+ r().symbols.DrawPoint3DW(f(position.x), f(position.y), f(position.z), i(col));
32
+ }
33
+ /** Draw a circle in 3D world space */
34
+ static drawCircle3D(
35
+ center: Vec3,
36
+ radius: number,
37
+ rotationAxis: Vec3,
38
+ rotationAngle: number,
39
+ col: Color,
40
+ ): void {
41
+ r().symbols.DrawCircle3DW(
42
+ f(center.x),
43
+ f(center.y),
44
+ f(center.z),
45
+ f(radius),
46
+ f(rotationAxis.x),
47
+ f(rotationAxis.y),
48
+ f(rotationAxis.z),
49
+ f(rotationAngle),
50
+ i(col),
51
+ );
52
+ }
53
+ /** Draw a color-filled triangle (vertex in counter-clockwise order!) */
54
+ static drawTriangle3D(v1: Vec3, v2: Vec3, v3: Vec3, col: Color): void {
55
+ r().symbols.DrawTriangle3DW(
56
+ f(v1.x),
57
+ f(v1.y),
58
+ f(v1.z),
59
+ f(v2.x),
60
+ f(v2.y),
61
+ f(v2.z),
62
+ f(v3.x),
63
+ f(v3.y),
64
+ f(v3.z),
65
+ i(col),
66
+ );
67
+ }
68
+ /** Draw a triangle strip defined by points. Points packed as [x0,y0,z0, x1,y1,z1, ...] in Float32Array */
69
+ static drawTriangleStrip3D(points: Float32Array, col: Color): void {
70
+ validatePoints('drawTriangleStrip3D', points, 3, 2);
71
+ r().symbols.DrawTriangleStrip3D(points, i(points.length / 3), i(col));
72
+ }
73
+ /** Draw cube */
74
+ static drawCube(position: Vec3, width: number, height: number, length: number, col: Color): void {
75
+ r().symbols.DrawCubeW(
76
+ f(position.x),
77
+ f(position.y),
78
+ f(position.z),
79
+ f(width),
80
+ f(height),
81
+ f(length),
82
+ i(col),
83
+ );
84
+ }
85
+ /** Draw cube (Vector version) */
86
+ static drawCubeV(position: Vec3, size: Vec3, col: Color): void {
87
+ r().symbols.DrawCubeVW(
88
+ f(position.x),
89
+ f(position.y),
90
+ f(position.z),
91
+ f(size.x),
92
+ f(size.y),
93
+ f(size.z),
94
+ i(col),
95
+ );
96
+ }
97
+ /** Draw cube wires */
98
+ static drawCubeWires(
99
+ position: Vec3,
100
+ width: number,
101
+ height: number,
102
+ length: number,
103
+ col: Color,
104
+ ): void {
105
+ r().symbols.DrawCubeWiresW(
106
+ f(position.x),
107
+ f(position.y),
108
+ f(position.z),
109
+ f(width),
110
+ f(height),
111
+ f(length),
112
+ i(col),
113
+ );
114
+ }
115
+ /** Draw cube wires (Vector version) */
116
+ static drawCubeWiresV(position: Vec3, size: Vec3, col: Color): void {
117
+ r().symbols.DrawCubeWiresVW(
118
+ f(position.x),
119
+ f(position.y),
120
+ f(position.z),
121
+ f(size.x),
122
+ f(size.y),
123
+ f(size.z),
124
+ i(col),
125
+ );
126
+ }
127
+ /** Draw sphere */
128
+ static drawSphere(centerPos: Vec3, radius: number, col: Color): void {
129
+ r().symbols.DrawSphereW(f(centerPos.x), f(centerPos.y), f(centerPos.z), f(radius), i(col));
130
+ }
131
+ /** Draw sphere with extended parameters */
132
+ static drawSphereEx(
133
+ centerPos: Vec3,
134
+ radius: number,
135
+ rings: number,
136
+ slices: number,
137
+ col: Color,
138
+ ): void {
139
+ r().symbols.DrawSphereExW(
140
+ f(centerPos.x),
141
+ f(centerPos.y),
142
+ f(centerPos.z),
143
+ f(radius),
144
+ i(rings),
145
+ i(slices),
146
+ i(col),
147
+ );
148
+ }
149
+ /** Draw sphere wires */
150
+ static drawSphereWires(
151
+ centerPos: Vec3,
152
+ radius: number,
153
+ rings: number,
154
+ slices: number,
155
+ col: Color,
156
+ ): void {
157
+ r().symbols.DrawSphereWiresW(
158
+ f(centerPos.x),
159
+ f(centerPos.y),
160
+ f(centerPos.z),
161
+ f(radius),
162
+ i(rings),
163
+ i(slices),
164
+ i(col),
165
+ );
166
+ }
167
+ /** Draw a cylinder/cone */
168
+ static drawCylinder(
169
+ position: Vec3,
170
+ radiusTop: number,
171
+ radiusBottom: number,
172
+ height: number,
173
+ slices: number,
174
+ col: Color,
175
+ ): void {
176
+ r().symbols.DrawCylinderW(
177
+ f(position.x),
178
+ f(position.y),
179
+ f(position.z),
180
+ f(radiusTop),
181
+ f(radiusBottom),
182
+ f(height),
183
+ i(slices),
184
+ i(col),
185
+ );
186
+ }
187
+ /** Draw a cylinder with base at startPos and top at endPos */
188
+ static drawCylinderEx(
189
+ startPos: Vec3,
190
+ endPos: Vec3,
191
+ startRadius: number,
192
+ endRadius: number,
193
+ sides: number,
194
+ col: Color,
195
+ ): void {
196
+ r().symbols.DrawCylinderExW(
197
+ f(startPos.x),
198
+ f(startPos.y),
199
+ f(startPos.z),
200
+ f(endPos.x),
201
+ f(endPos.y),
202
+ f(endPos.z),
203
+ f(startRadius),
204
+ f(endRadius),
205
+ i(sides),
206
+ i(col),
207
+ );
208
+ }
209
+ /** Draw a cylinder/cone wires */
210
+ static drawCylinderWires(
211
+ position: Vec3,
212
+ radiusTop: number,
213
+ radiusBottom: number,
214
+ height: number,
215
+ slices: number,
216
+ col: Color,
217
+ ): void {
218
+ r().symbols.DrawCylinderWiresW(
219
+ f(position.x),
220
+ f(position.y),
221
+ f(position.z),
222
+ f(radiusTop),
223
+ f(radiusBottom),
224
+ f(height),
225
+ i(slices),
226
+ i(col),
227
+ );
228
+ }
229
+ /** Draw a cylinder wires with base at startPos and top at endPos */
230
+ static drawCylinderWiresEx(
231
+ startPos: Vec3,
232
+ endPos: Vec3,
233
+ startRadius: number,
234
+ endRadius: number,
235
+ sides: number,
236
+ col: Color,
237
+ ): void {
238
+ r().symbols.DrawCylinderWiresExW(
239
+ f(startPos.x),
240
+ f(startPos.y),
241
+ f(startPos.z),
242
+ f(endPos.x),
243
+ f(endPos.y),
244
+ f(endPos.z),
245
+ f(startRadius),
246
+ f(endRadius),
247
+ i(sides),
248
+ i(col),
249
+ );
250
+ }
251
+ /** Draw a capsule with the center of its sphere caps at startPos and endPos */
252
+ static drawCapsule(
253
+ startPos: Vec3,
254
+ endPos: Vec3,
255
+ radius: number,
256
+ slices: number,
257
+ rings: number,
258
+ col: Color,
259
+ ): void {
260
+ r().symbols.DrawCapsuleW(
261
+ f(startPos.x),
262
+ f(startPos.y),
263
+ f(startPos.z),
264
+ f(endPos.x),
265
+ f(endPos.y),
266
+ f(endPos.z),
267
+ f(radius),
268
+ i(slices),
269
+ i(rings),
270
+ i(col),
271
+ );
272
+ }
273
+ /** Draw capsule wireframe */
274
+ static drawCapsuleWires(
275
+ startPos: Vec3,
276
+ endPos: Vec3,
277
+ radius: number,
278
+ slices: number,
279
+ rings: number,
280
+ col: Color,
281
+ ): void {
282
+ r().symbols.DrawCapsuleWiresW(
283
+ f(startPos.x),
284
+ f(startPos.y),
285
+ f(startPos.z),
286
+ f(endPos.x),
287
+ f(endPos.y),
288
+ f(endPos.z),
289
+ f(radius),
290
+ i(slices),
291
+ i(rings),
292
+ i(col),
293
+ );
294
+ }
295
+ /** Draw a plane XZ */
296
+ static drawPlane(centerPos: Vec3, size: Vec2, col: Color): void {
297
+ r().symbols.DrawPlaneW(
298
+ f(centerPos.x),
299
+ f(centerPos.y),
300
+ f(centerPos.z),
301
+ f(size.x),
302
+ f(size.y),
303
+ i(col),
304
+ );
305
+ }
306
+ /** Draw a ray line */
307
+ static drawRay(ray: Ray, col: Color): void {
308
+ r().symbols.DrawRayW(
309
+ f(ray.position.x),
310
+ f(ray.position.y),
311
+ f(ray.position.z),
312
+ f(ray.direction.x),
313
+ f(ray.direction.y),
314
+ f(ray.direction.z),
315
+ i(col),
316
+ );
317
+ }
318
+ /** Draw a grid */
319
+ static drawGrid(slices: number, spacing: number): void {
320
+ r().symbols.DrawGrid(i(slices), f(spacing));
321
+ }
322
+ static drawBoundingBox(box: BoundingBox, color: Color): void {
323
+ r().symbols.DrawBoundingBoxW(
324
+ f(box.min.x),
325
+ f(box.min.y),
326
+ f(box.min.z),
327
+ f(box.max.x),
328
+ f(box.max.y),
329
+ f(box.max.z),
330
+ i(color),
331
+ );
332
+ }
333
+ static drawBillboard(
334
+ camera: Camera3D,
335
+ texture: Texture2D,
336
+ position: Vec3,
337
+ scale: number,
338
+ tint: Color,
339
+ ): void {
340
+ r().symbols.DrawBillboardW(
341
+ f(camera.position.x),
342
+ f(camera.position.y),
343
+ f(camera.position.z),
344
+ f(camera.target.x),
345
+ f(camera.target.y),
346
+ f(camera.target.z),
347
+ f(camera.up.x),
348
+ f(camera.up.y),
349
+ f(camera.up.z),
350
+ f(camera.fovy),
351
+ i(camera.projection),
352
+ i(texture.id),
353
+ i(texture.width),
354
+ i(texture.height),
355
+ f(position.x),
356
+ f(position.y),
357
+ f(position.z),
358
+ f(scale),
359
+ i(tint),
360
+ );
361
+ }
362
+ static drawBillboardRec(
363
+ camera: Camera3D,
364
+ texture: Texture2D,
365
+ source: Rectangle,
366
+ position: Vec3,
367
+ size: Vec2,
368
+ tint: Color,
369
+ ): void {
370
+ r().symbols.DrawBillboardRecW(
371
+ f(camera.position.x),
372
+ f(camera.position.y),
373
+ f(camera.position.z),
374
+ f(camera.target.x),
375
+ f(camera.target.y),
376
+ f(camera.target.z),
377
+ f(camera.up.x),
378
+ f(camera.up.y),
379
+ f(camera.up.z),
380
+ f(camera.fovy),
381
+ i(camera.projection),
382
+ i(texture.id),
383
+ i(texture.width),
384
+ i(texture.height),
385
+ i(source.x),
386
+ i(source.y),
387
+ i(source.width),
388
+ i(source.height),
389
+ f(position.x),
390
+ f(position.y),
391
+ f(position.z),
392
+ f(size.x),
393
+ f(size.y),
394
+ i(tint),
395
+ );
396
+ }
397
+ static drawBillboardPro(
398
+ camera: Camera3D,
399
+ texture: Texture2D,
400
+ source: Rectangle,
401
+ position: Vec3,
402
+ up: Vec3,
403
+ size: Vec2,
404
+ origin: Vec2,
405
+ rotation: number,
406
+ tint: Color,
407
+ ): void {
408
+ r().symbols.DrawBillboardProW(
409
+ f(camera.position.x),
410
+ f(camera.position.y),
411
+ f(camera.position.z),
412
+ f(camera.target.x),
413
+ f(camera.target.y),
414
+ f(camera.target.z),
415
+ f(camera.up.x),
416
+ f(camera.up.y),
417
+ f(camera.up.z),
418
+ f(camera.fovy),
419
+ i(camera.projection),
420
+ i(texture.id),
421
+ i(texture.width),
422
+ i(texture.height),
423
+ i(source.x),
424
+ i(source.y),
425
+ i(source.width),
426
+ i(source.height),
427
+ f(position.x),
428
+ f(position.y),
429
+ f(position.z),
430
+ f(up.x),
431
+ f(up.y),
432
+ f(up.z),
433
+ f(size.x),
434
+ f(size.y),
435
+ f(origin.x),
436
+ f(origin.y),
437
+ f(rotation),
438
+ i(tint),
439
+ );
440
+ }
441
+ }