@nayan-ui/engine 0.0.0-stage → 1.0.0-beta.3

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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/NayanEngine.podspec +28 -0
  3. package/README.md +210 -2
  4. package/lib/module/assets/AssetBytesCache.js +76 -0
  5. package/lib/module/assets/AssetCache.js +19 -0
  6. package/lib/module/assets/AssetLoader.js +52 -0
  7. package/lib/module/assets/CacheGeneration.js +7 -0
  8. package/lib/module/assets/IndexedDbCache.web.js +149 -0
  9. package/lib/module/assets/ProceduralCache.js +222 -0
  10. package/lib/module/assets/font.js +136 -0
  11. package/lib/module/assets/loft.js +142 -0
  12. package/lib/module/assets/model.js +74 -0
  13. package/lib/module/assets/modelling.js +254 -0
  14. package/lib/module/assets/shape.js +926 -0
  15. package/lib/module/assets/source.js +58 -0
  16. package/lib/module/assets/source.web.js +22 -0
  17. package/lib/module/assets/storage.js +4 -0
  18. package/lib/module/assets/storage.shared.js +36 -0
  19. package/lib/module/assets/storage.web.js +37 -0
  20. package/lib/module/assets/surface.js +47 -0
  21. package/lib/module/assets/texture.js +66 -0
  22. package/lib/module/drawing/DrawingCanvas.js +38 -0
  23. package/lib/module/drawing/DrawingCanvas.web.js +206 -0
  24. package/lib/module/drawing/DrawingDocument.js +256 -0
  25. package/lib/module/drawing/types.js +4 -0
  26. package/lib/module/globals.d.ts +12 -0
  27. package/lib/module/index.js +36 -0
  28. package/lib/module/input/Joystick.js +84 -0
  29. package/lib/module/input/Joystick.web.js +93 -0
  30. package/lib/module/input/keyboard.js +250 -0
  31. package/lib/module/media/audio-worklet.js +34 -0
  32. package/lib/module/media/audio.js +94 -0
  33. package/lib/module/media/haptics.js +82 -0
  34. package/lib/module/media/output.web.js +66 -0
  35. package/lib/module/native/BrowserEngine.js +551 -0
  36. package/lib/module/native/EngineBridge.js +4 -0
  37. package/lib/module/native/NativeNayanEngine.js +7 -0
  38. package/lib/module/native/NativeNayanEngine.web.js +62 -0
  39. package/lib/module/native/prepare.js +7 -0
  40. package/lib/module/native/prepare.web.js +17 -0
  41. package/lib/module/native/spec/NativeNayanEngine.js +17 -0
  42. package/lib/module/package.json +1 -0
  43. package/lib/module/render/GameView.js +249 -0
  44. package/lib/module/render/camera.js +34 -0
  45. package/lib/module/render/host.js +39 -0
  46. package/lib/module/render/host.web.js +104 -0
  47. package/lib/module/render/meshes.js +159 -0
  48. package/lib/module/render/quality.js +112 -0
  49. package/lib/module/render/responder.js +4 -0
  50. package/lib/module/render/responder.web.js +97 -0
  51. package/lib/module/render/touch.js +185 -0
  52. package/lib/module/types.js +30 -0
  53. package/lib/module/world/Scoreboard.js +143 -0
  54. package/lib/module/world/TransformBatch.js +126 -0
  55. package/lib/module/world/World.js +690 -0
  56. package/lib/module/world/desc.js +186 -0
  57. package/lib/module/world/effects.js +451 -0
  58. package/lib/module/world/quat.js +86 -0
  59. package/lib/module/world/types.js +4 -0
  60. package/lib/typescript/package.json +1 -0
  61. package/lib/typescript/src/assets/AssetBytesCache.d.ts +7 -0
  62. package/lib/typescript/src/assets/AssetCache.d.ts +9 -0
  63. package/lib/typescript/src/assets/AssetLoader.d.ts +11 -0
  64. package/lib/typescript/src/assets/CacheGeneration.d.ts +3 -0
  65. package/lib/typescript/src/assets/IndexedDbCache.web.d.ts +20 -0
  66. package/lib/typescript/src/assets/ProceduralCache.d.ts +33 -0
  67. package/lib/typescript/src/assets/font.d.ts +53 -0
  68. package/lib/typescript/src/assets/loft.d.ts +31 -0
  69. package/lib/typescript/src/assets/model.d.ts +48 -0
  70. package/lib/typescript/src/assets/modelling.d.ts +157 -0
  71. package/lib/typescript/src/assets/shape.d.ts +203 -0
  72. package/lib/typescript/src/assets/source.d.ts +10 -0
  73. package/lib/typescript/src/assets/source.web.d.ts +8 -0
  74. package/lib/typescript/src/assets/storage.d.ts +2 -0
  75. package/lib/typescript/src/assets/storage.shared.d.ts +7 -0
  76. package/lib/typescript/src/assets/storage.web.d.ts +7 -0
  77. package/lib/typescript/src/assets/surface.d.ts +17 -0
  78. package/lib/typescript/src/assets/texture.d.ts +30 -0
  79. package/lib/typescript/src/drawing/DrawingCanvas.d.ts +5 -0
  80. package/lib/typescript/src/drawing/DrawingCanvas.web.d.ts +4 -0
  81. package/lib/typescript/src/drawing/DrawingDocument.d.ts +210 -0
  82. package/lib/typescript/src/drawing/types.d.ts +12 -0
  83. package/lib/typescript/src/index.d.ts +42 -0
  84. package/lib/typescript/src/input/Joystick.d.ts +20 -0
  85. package/lib/typescript/src/input/Joystick.web.d.ts +13 -0
  86. package/lib/typescript/src/input/keyboard.d.ts +17 -0
  87. package/lib/typescript/src/media/audio.d.ts +46 -0
  88. package/lib/typescript/src/media/haptics.d.ts +22 -0
  89. package/lib/typescript/src/media/output.web.d.ts +4 -0
  90. package/lib/typescript/src/native/BrowserEngine.d.ts +8 -0
  91. package/lib/typescript/src/native/EngineBridge.d.ts +22 -0
  92. package/lib/typescript/src/native/NativeNayanEngine.d.ts +5 -0
  93. package/lib/typescript/src/native/NativeNayanEngine.web.d.ts +10 -0
  94. package/lib/typescript/src/native/prepare.d.ts +3 -0
  95. package/lib/typescript/src/native/prepare.web.d.ts +2 -0
  96. package/lib/typescript/src/native/spec/NativeNayanEngine.d.ts +182 -0
  97. package/lib/typescript/src/render/GameView.d.ts +95 -0
  98. package/lib/typescript/src/render/camera.d.ts +6 -0
  99. package/lib/typescript/src/render/host.d.ts +29 -0
  100. package/lib/typescript/src/render/host.web.d.ts +16 -0
  101. package/lib/typescript/src/render/meshes.d.ts +45 -0
  102. package/lib/typescript/src/render/quality.d.ts +46 -0
  103. package/lib/typescript/src/render/responder.d.ts +2 -0
  104. package/lib/typescript/src/render/responder.web.d.ts +40 -0
  105. package/lib/typescript/src/render/touch.d.ts +26 -0
  106. package/lib/typescript/src/types.d.ts +72 -0
  107. package/lib/typescript/src/world/Scoreboard.d.ts +65 -0
  108. package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
  109. package/lib/typescript/src/world/World.d.ts +199 -0
  110. package/lib/typescript/src/world/desc.d.ts +17 -0
  111. package/lib/typescript/src/world/effects.d.ts +156 -0
  112. package/lib/typescript/src/world/quat.d.ts +31 -0
  113. package/lib/typescript/src/world/types.d.ts +233 -0
  114. package/lib/web/audio-worklet.js +29 -0
  115. package/lib/web/engine_core_bg.wasm +0 -0
  116. package/lib/web/index.js +7974 -0
  117. package/lib/web/types/src/assets/AssetBytesCache.d.ts +6 -0
  118. package/lib/web/types/src/assets/AssetCache.d.ts +8 -0
  119. package/lib/web/types/src/assets/AssetLoader.d.ts +10 -0
  120. package/lib/web/types/src/assets/CacheGeneration.d.ts +2 -0
  121. package/lib/web/types/src/assets/IndexedDbCache.d.ts +19 -0
  122. package/lib/web/types/src/assets/ProceduralCache.d.ts +32 -0
  123. package/lib/web/types/src/assets/font.d.ts +52 -0
  124. package/lib/web/types/src/assets/loft.d.ts +30 -0
  125. package/lib/web/types/src/assets/model.d.ts +47 -0
  126. package/lib/web/types/src/assets/modelling.d.ts +156 -0
  127. package/lib/web/types/src/assets/shape.d.ts +202 -0
  128. package/lib/web/types/src/assets/source.d.ts +7 -0
  129. package/lib/web/types/src/assets/storage.d.ts +6 -0
  130. package/lib/web/types/src/assets/storage.shared.d.ts +6 -0
  131. package/lib/web/types/src/assets/surface.d.ts +16 -0
  132. package/lib/web/types/src/assets/texture.d.ts +29 -0
  133. package/lib/web/types/src/drawing/DrawingCanvas.d.ts +3 -0
  134. package/lib/web/types/src/drawing/DrawingDocument.d.ts +209 -0
  135. package/lib/web/types/src/drawing/types.d.ts +11 -0
  136. package/lib/web/types/src/index.d.ts +41 -0
  137. package/lib/web/types/src/input/Joystick.d.ts +12 -0
  138. package/lib/web/types/src/input/keyboard.d.ts +16 -0
  139. package/lib/web/types/src/media/audio.d.ts +45 -0
  140. package/lib/web/types/src/media/haptics.d.ts +21 -0
  141. package/lib/web/types/src/media/output.d.ts +3 -0
  142. package/lib/web/types/src/native/BrowserEngine.d.ts +7 -0
  143. package/lib/web/types/src/native/EngineBridge.d.ts +21 -0
  144. package/lib/web/types/src/native/NativeNayanEngine.d.ts +9 -0
  145. package/lib/web/types/src/native/prepare.d.ts +1 -0
  146. package/lib/web/types/src/native/spec/NativeNayanEngine.d.ts +181 -0
  147. package/lib/web/types/src/render/GameView.d.ts +94 -0
  148. package/lib/web/types/src/render/camera.d.ts +5 -0
  149. package/lib/web/types/src/render/host.d.ts +15 -0
  150. package/lib/web/types/src/render/meshes.d.ts +44 -0
  151. package/lib/web/types/src/render/quality.d.ts +45 -0
  152. package/lib/web/types/src/render/responder.d.ts +39 -0
  153. package/lib/web/types/src/render/touch.d.ts +25 -0
  154. package/lib/web/types/src/types.d.ts +71 -0
  155. package/lib/web/types/src/world/Scoreboard.d.ts +64 -0
  156. package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
  157. package/lib/web/types/src/world/World.d.ts +198 -0
  158. package/lib/web/types/src/world/desc.d.ts +16 -0
  159. package/lib/web/types/src/world/effects.d.ts +155 -0
  160. package/lib/web/types/src/world/quat.d.ts +30 -0
  161. package/lib/web/types/src/world/types.d.ts +232 -0
  162. package/native/android/CMakeLists.txt +34 -0
  163. package/native/android/NayanEngineSpec.h +15 -0
  164. package/native/android/build.gradle +26 -0
  165. package/native/android/codegen/CMakeLists.txt +3 -0
  166. package/native/android/proguard-rules.pro +2 -0
  167. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceView.java +234 -0
  168. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceViewManager.java +45 -0
  169. package/native/android/src/main/java/com/nayanui/engine/NayanEnginePackage.java +24 -0
  170. package/native/core/build/EngineCore.xcframework/Info.plist +43 -0
  171. package/native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a +0 -0
  172. package/native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a +0 -0
  173. package/native/core/build/android/arm64-v8a/libengine_core.a +0 -0
  174. package/native/core/build/android/armeabi-v7a/libengine_core.a +0 -0
  175. package/native/core/build/android/x86/libengine_core.a +0 -0
  176. package/native/core/build/android/x86_64/libengine_core.a +0 -0
  177. package/native/core/include/drawing-licenses.txt +58 -0
  178. package/native/core/include/engine_core.h +322 -0
  179. package/native/cpp/NayanEngineModule.cpp +827 -0
  180. package/native/cpp/NayanEngineModule.h +144 -0
  181. package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
  182. package/native/cpp/generated/NayanEngineSpecJSI.h +921 -0
  183. package/native/ios/NayanEngineProvider.h +5 -0
  184. package/native/ios/NayanEngineProvider.mm +21 -0
  185. package/native/ios/NayanEngineSurface.mm +223 -0
  186. package/native/scripts/check-package.mjs +39 -0
  187. package/package.json +162 -4
  188. package/react-native.config.js +18 -0
  189. package/src/native/spec/NativeNayanEngine.ts +226 -0
@@ -0,0 +1,16 @@
1
+ import type { EntityOptions } from './types';
2
+ export declare const DESC_LEN = 64;
3
+ /** Writes `options` into `d`, with the mesh id already resolved. Only the fields present are flagged. */
4
+ export declare function encode(d: Float64Array, o: EntityOptions, mesh: number | undefined): void;
5
+ export declare const ANIM_HEADER = 12;
6
+ export declare const ANIM_KEY_LEN = 23;
7
+ export declare const BURST_LEN = 36;
8
+ export declare const EASING: {
9
+ readonly linear: 0;
10
+ readonly easeIn: 1;
11
+ readonly easeOut: 2;
12
+ readonly easeInOut: 3;
13
+ readonly back: 4;
14
+ readonly bounce: 5;
15
+ readonly elastic: 6;
16
+ };
@@ -0,0 +1,155 @@
1
+ import type { Vec3 } from '../types';
2
+ import type { BurstOptions, Color, Entity } from './types';
3
+ import type { World } from './World';
4
+ /** Shared options of the layered effects (confetti, sparkle, shatter, splash, sparks, explosion). */
5
+ export type EffectOptions = {
6
+ position: Vec3;
7
+ /** One color, or several to pick from at random. */
8
+ colors: Color | readonly Color[];
9
+ /** Typical particle size. */
10
+ size: number;
11
+ /** Top speed. */
12
+ speed: number;
13
+ /** About how many particles (a few extra go to the flash and puffs). */
14
+ count: number;
15
+ /** Seconds. */
16
+ lifetime: number;
17
+ /** Vertical acceleration (negative falls). Default 0. */
18
+ gravity?: number;
19
+ /** Main direction. Default up. */
20
+ direction?: Vec3;
21
+ /** Half-angle of the cone around `direction`. Default π (every direction). */
22
+ spread?: number;
23
+ /** A brief glow at the source. Default true. */
24
+ flash?: boolean;
25
+ };
26
+ /** A soft cloud of puffs that swell and fade: landing dust, kicked-up sand, sawdust, steam, muzzle smoke. */
27
+ export type DustOptions = {
28
+ position: Vec3;
29
+ /** Start color (alpha is how thick it looks), or several to pick from. */
30
+ color: Color | readonly Color[];
31
+ /** Puff size at the start. */
32
+ size: number;
33
+ /** Top speed. */
34
+ speed: number;
35
+ count: number;
36
+ /** Seconds. */
37
+ lifetime: number;
38
+ /** Default up. */
39
+ direction?: Vec3;
40
+ /** Half-angle around `direction`. Default π. */
41
+ spread?: number;
42
+ /** Default 0 (dust hangs; positive rises like smoke). */
43
+ gravity?: number;
44
+ /** How much each puff grows by the end. Default 2. */
45
+ endSize?: number;
46
+ /** Color at the end. Default: a single `color` faded to transparent; several colors keep theirs. */
47
+ endColor?: Color;
48
+ /** Default "puff" (blended); "flame" adds light instead. */
49
+ mesh?: BurstOptions['mesh'];
50
+ };
51
+ /** One glow that swells and fades at a point: a hit, a strike, a muzzle flash. */
52
+ export type FlashOptions = {
53
+ position: Vec3;
54
+ /** Use channels above 1 to glow (see `effects.hot`). */
55
+ color: Color;
56
+ size: number;
57
+ /** Seconds. Default 0.22. */
58
+ lifetime?: number;
59
+ /** How much it grows by the end. Default 2.2. */
60
+ endSize?: number;
61
+ /** Default: `color` faded to transparent. */
62
+ endColor?: Color;
63
+ /** Default "flame" (adds light); "sphere" or "puff" for a solid or soft flash. */
64
+ mesh?: BurstOptions['mesh'];
65
+ /** Glows drawn at once (slightly scattered when `speed` > 0). Default 1. */
66
+ count?: number;
67
+ /** Default 0. */
68
+ speed?: number;
69
+ };
70
+ /** The cleared-piece pop: swell, flash white, settle, shrink away. */
71
+ export type PopOptions = {
72
+ /** Its scale at rest (what it has now): one number, or per axis. */
73
+ scale: number | Vec3;
74
+ /** Its color at rest, to return to after the white flash. Omit to flash `flash` only (or nothing). */
75
+ color?: Color;
76
+ /** Parts to flash white as well (a group's visible children, whose rest color is white). */
77
+ flash?: readonly Entity[];
78
+ /** Seconds before it starts. Default 0. */
79
+ delay?: number;
80
+ /** Seconds it takes. Default `effects.POP_TIME`. */
81
+ duration?: number;
82
+ };
83
+ type Rgba = [number, number, number, number];
84
+ /** The same hue, self-lit: its brightest channel lifted to `peak` (above 1 glows, through light, shadow and fog). */
85
+ declare function hot(c: Color, peak?: number, alpha?: number): Rgba;
86
+ /** Part way (`t`, 0..1) to white, with `alpha`. */
87
+ declare function pale(c: Color, t: number, alpha?: number): Rgba;
88
+ declare function flash(world: World, o: FlashOptions): number;
89
+ declare function dust(world: World, o: DustOptions): number;
90
+ /** Celebration confetti: tumbling paper in two layers, a few glinting sparkles, and a pop of light. */
91
+ declare function confetti(world: World, e: EffectOptions): void;
92
+ /** Glitter for a reward: solid bright beads (seen on any background) with additive glints around them. */
93
+ declare function sparkle(world: World, e: EffectOptions): void;
94
+ /**
95
+ * Something breaking apart: big slow chunks, small fast crumbs, a glow at the break and a puff of
96
+ * its dust. `mesh` is the chunks' shape.
97
+ */
98
+ declare function shatter(world: World, e: EffectOptions & {
99
+ mesh?: BurstOptions['mesh'];
100
+ dust?: boolean;
101
+ }): void;
102
+ /** Liquid: droplets in two sizes thrown out of a fine mist of the same color. */
103
+ declare function splash(world: World, e: EffectOptions): void;
104
+ /** Hot metal sparks: additive streaks that burn out, with a few solid beads and a flash where they strike. */
105
+ declare function sparks(world: World, e: EffectOptions): void;
106
+ /**
107
+ * A fiery blast: a white-hot flash, a fireball that cools into smoke, embers thrown out and, given
108
+ * `debris` colors, chunks of whatever blew up. `size` is the fireball's puff size; `colors` its fire.
109
+ * The fire and smoke swell every way; `direction`, `spread` and `gravity` aim the embers and debris.
110
+ */
111
+ declare function explosion(world: World, e: Omit<EffectOptions, 'colors'> & {
112
+ colors?: EffectOptions['colors'];
113
+ debris?: readonly Color[];
114
+ smoke?: Color;
115
+ }): void;
116
+ /** The piece swells, flashes white, settles and shrinks away. Resolves when it's gone (despawning it is the caller's). */
117
+ declare function pop(world: World, entity: Entity, o: PopOptions): Promise<void>;
118
+ /**
119
+ * Ready-made effects. Each is one call; particles then live, fall, shrink and recolor in Rust.
120
+ *
121
+ * ```ts
122
+ * effects.confetti(world, { position, colors: [RED, GOLD], size: 0.12, speed: 6, count: 40, lifetime: 1.2, gravity: -6 });
123
+ * effects.dust(world, { position: feet, color: [0.8, 0.75, 0.65, 0.6], size: 0.3, speed: 1.5, count: 6, lifetime: 0.5 });
124
+ * effects.flash(world, { position: hit, color: effects.hot(ORANGE), size: 0.8 });
125
+ * await effects.pop(world, candy, { scale: 1, color: RED });
126
+ * world.despawn(candy);
127
+ * ```
128
+ */
129
+ export declare const effects: {
130
+ /** Celebration: tumbling paper, glints and a pop of light (wins, level-ups). */
131
+ confetti: typeof confetti;
132
+ /** Reward glitter: bright beads and glints (pickups, perfect moves). */
133
+ sparkle: typeof sparkle;
134
+ /** Breaking apart: chunks, crumbs, a glow and dust (bricks, crates, glass). `mesh` shapes the chunks. */
135
+ shatter: typeof shatter;
136
+ /** Liquid: droplets and mist (water, juice, paint). */
137
+ splash: typeof splash;
138
+ /** Hot metal: additive streaks and beads (scrapes, strikes, electricity). */
139
+ sparks: typeof sparks;
140
+ /** Fiery blast: flash, fireball cooling to smoke, embers and optional debris. */
141
+ explosion: typeof explosion;
142
+ /** Soft swelling puffs: dust, sand, sawdust, steam, smoke. */
143
+ dust: typeof dust;
144
+ /** One swelling glow: hits, strikes, muzzle flashes. */
145
+ flash: typeof flash;
146
+ /** The cleared-piece animation: swell, flash white, settle, shrink to nothing. */
147
+ pop: typeof pop;
148
+ /** Default `pop` duration in seconds. */
149
+ POP_TIME: number;
150
+ /** The same hue made self-lit (brightest channel lifted to `peak`), for glows. */
151
+ hot: typeof hot;
152
+ /** Part way (`t`, 0..1) to white. */
153
+ pale: typeof pale;
154
+ };
155
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { Quat } from './types';
2
+ /** A writable quaternion; pass one as `out` to reuse it instead of allocating. */
3
+ export type MutableQuat = [number, number, number, number];
4
+ /**
5
+ * Quaternion helpers for `rotation` options, keyframes and geometry parts ([x, y, z, w]). Every
6
+ * function takes an optional `out` so per-frame code can reuse one array instead of allocating.
7
+ *
8
+ * ```ts
9
+ * world.set(car, { rotation: quat.y(heading) });
10
+ * const spin = quat.multiply(quat.y(yaw), quat.x(pitch), scratch); // pitch first, then yaw
11
+ * ```
12
+ */
13
+ export declare const quat: {
14
+ /** No rotation. */
15
+ identity: Quat;
16
+ /** Rotation by `angle` radians around the unit axis (x, y, z). */
17
+ axisAngle(x: number, y: number, z: number, angle: number, out?: MutableQuat): MutableQuat;
18
+ /** Rotation around the x axis (pitch). */
19
+ x(angle: number, out?: MutableQuat): MutableQuat;
20
+ /** Rotation around the y axis (yaw, heading). */
21
+ y(angle: number, out?: MutableQuat): MutableQuat;
22
+ /** Rotation around the z axis (roll; spin for 2D games looking down -z). */
23
+ z(angle: number, out?: MutableQuat): MutableQuat;
24
+ /** `a` after `b`: `b` turns first. `out` may be `a` or `b`. */
25
+ multiply(a: Quat, b: Quat, out?: MutableQuat): MutableQuat;
26
+ /** Turns around x, then y, then z (radians): the same as `multiply(z(z), multiply(y(y), x(x)))`. */
27
+ fromEuler(x: number, y: number, z: number, out?: MutableQuat): MutableQuat;
28
+ /** Shortest-path interpolation from `a` (t = 0) to `b` (t = 1). */
29
+ slerp(a: Quat, b: Quat, t: number, out?: MutableQuat): MutableQuat;
30
+ };
@@ -0,0 +1,232 @@
1
+ import type { Font, TextAlign } from '../assets/font';
2
+ import type { Model } from '../assets/model';
3
+ import type { Texture } from '../assets/texture';
4
+ import type { Sound } from '../media/audio';
5
+ import type { Vec3 } from '../types';
6
+ /** Opaque entity handle. Handles of despawned entities are safely ignored. */
7
+ export type Entity = number & {
8
+ readonly __entity: unique symbol;
9
+ };
10
+ export type Color = readonly [number, number, number] | readonly [number, number, number, number];
11
+ export type Quat = readonly [number, number, number, number];
12
+ /** Playback for one entity using a skeletal animation embedded in a loaded model. */
13
+ export interface ClipOptions {
14
+ /** Repeat the clip. Default true. */
15
+ loop?: boolean;
16
+ /** Playback rate; zero holds a pose. Default 1. */
17
+ speed?: number;
18
+ /** Crossfade from the current pose, in seconds. Default 0.15. */
19
+ fade?: number;
20
+ /** Seek to this time in seconds. Omit to retain playback when reselecting a clip. */
21
+ time?: number;
22
+ }
23
+ /** Plane used by screenToWorld; defaults to the ground through the origin. */
24
+ export interface ScreenPlane {
25
+ point?: Vec3;
26
+ normal?: Vec3;
27
+ }
28
+ /**
29
+ * - `dynamic`: moved by physics (gravity, collisions, impulses).
30
+ * - `kinematic`: moved by you; pushes dynamic bodies out of the way.
31
+ * - `fixed`: never moves (floors, walls).
32
+ */
33
+ export type BodyType = 'dynamic' | 'kinematic' | 'fixed';
34
+ export type PhysicsOptions = {
35
+ type: BodyType;
36
+ /** Default: matches the mesh (spheres get a ball, cylinders a cylinder, ...; anything else a box). */
37
+ shape?: 'ball' | 'box' | 'cylinder' | 'capsule' | 'cone';
38
+ /** Ball, cylinder, capsule or cone radius. Default: from the entity's size. */
39
+ radius?: number;
40
+ /** Cylinder, capsule or cone height (total). Default: from the entity's size. */
41
+ height?: number;
42
+ /** Box size (full width, height, depth). Default: the entity's size. */
43
+ size?: Vec3;
44
+ /** Layer bits this collider is on. Default 1. */
45
+ layer?: number;
46
+ /** Layers it interacts with. Either side's mask is enough. Default: all. */
47
+ mask?: number;
48
+ /** Reports touches but doesn't push: pickups, trigger zones. */
49
+ sensor?: boolean;
50
+ /** How grippy, default 0.5. */
51
+ friction?: number;
52
+ /** Bounciness 0..1, default 0. */
53
+ bounce?: number;
54
+ /** Mass per volume, default 1. */
55
+ density?: number;
56
+ /** Slows movement over time (air resistance), default 0. */
57
+ drag?: number;
58
+ /** Slows spinning over time, default 0.05. */
59
+ angularDrag?: number;
60
+ /** Multiplier on world gravity, default 1. */
61
+ gravityScale?: number;
62
+ /** Stays upright: never tumbles. */
63
+ upright?: boolean;
64
+ /** Stops fast, small bodies passing through walls. */
65
+ ccd?: boolean;
66
+ /** 2D games: stays in its XY plane (moves in x/y, spins only around z). Keep the camera looking down -z. */
67
+ planar?: boolean;
68
+ };
69
+ /** Sound/haptic the core plays by itself when the entity hits something solid. */
70
+ export type ImpactFeedback = {
71
+ /** A loaded sound, e.g. `sfx.get("bump")`. Omit for haptics only. */
72
+ sound?: Sound;
73
+ /** Slower impacts are silent. Default 1. */
74
+ minSpeed?: number;
75
+ /** Full volume and strength at this speed. Default 10. */
76
+ maxSpeed?: number;
77
+ /** Volume at full strength, 0..2. Default 1. */
78
+ volume?: number;
79
+ /** Vibration at full strength, 0..1. Default 0 (none). */
80
+ haptic?: number;
81
+ };
82
+ /**
83
+ * Everything about an entity. `spawn` and `set` take the same options; in `set`, only what you
84
+ * pass changes, and `null` removes something (physics, parent, follow, bob, lifetime, impact).
85
+ */
86
+ export type EntityOptions = {
87
+ /** A built-in shape or a model from `loadModel`. Default "cube". */
88
+ mesh?: Shape | Model;
89
+ /** An image from `loadTexture`, drawn on the mesh (`null` = none). In `set`, pass `mesh` with it. */
90
+ texture?: Texture | null;
91
+ /** Part of the texture to show, [u0, v0, u1, v1] from 0..1 (sprite sheets, card atlases). */
92
+ textureRegion?: readonly [number, number, number, number];
93
+ /** 3D text instead of a mesh (needs `font`). Letters are 1 unit tall at scale 1. */
94
+ text?: string;
95
+ /** A font from `loadFont`, for `text`. */
96
+ font?: Font;
97
+ /** Text alignment around `position`. Default "center". */
98
+ align?: TextAlign;
99
+ /** Extra space between letters, in ems. Default 0. */
100
+ letterSpacing?: number;
101
+ /** Digits all as wide as the widest, so changing scores and timers don't shift. Default false. */
102
+ tabular?: boolean;
103
+ /** Relative to the parent when attached. */
104
+ position?: Vec3;
105
+ rotation?: Quat;
106
+ /** A number scales uniformly. Children scale with their parent. Visual only after the body exists. */
107
+ scale?: Vec3 | number;
108
+ /** Alpha below 1 makes it see-through. Channels above 1 glow: at 2 it's self-lit, ignoring light and shadow (fire, lamps). */
109
+ color?: Color;
110
+ /** Units per second. */
111
+ velocity?: Vec3;
112
+ /** Sets horizontal speed [x, z] and keeps the vertical one: steer a body and it still falls. */
113
+ groundVelocity?: readonly [number, number];
114
+ /** Units per second², for entities without a dynamic body (falling debris, thrown items). */
115
+ acceleration?: Vec3;
116
+ /** Radians per second around each axis. */
117
+ spin?: Vec3;
118
+ /** Visual bob: the drawn position moves by amplitude * sin(phase), phase advancing at `speed`. */
119
+ bob?: {
120
+ amplitude: Vec3;
121
+ speed: number;
122
+ phase?: number;
123
+ } | null;
124
+ /** Chase `target` along the ground at `speed`. */
125
+ follow?: {
126
+ target: Entity;
127
+ speed: number;
128
+ } | null;
129
+ /** Seconds until it shrinks away and is despawned. */
130
+ lifetime?: number | null;
131
+ /** Attach to another entity: it moves, turns and scales with the parent and is despawned with it. Visual only. */
132
+ parent?: Entity | null;
133
+ physics?: BodyType | PhysicsOptions | null;
134
+ impact?: ImpactFeedback | null;
135
+ /** Whether `pick` can hit it. Default true. */
136
+ pickable?: boolean;
137
+ };
138
+ export type Easing = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'back' | 'bounce' | 'elastic';
139
+ /** What `animate` changes. Anything left out stays as it is (and keeps any animation it already has). */
140
+ export type AnimateTarget = {
141
+ position?: Vec3;
142
+ rotation?: Quat;
143
+ scale?: Vec3 | number;
144
+ color?: Color;
145
+ /** Move by this offset from where the animation starts (instead of to a `position`). */
146
+ moveBy?: Vec3;
147
+ /** Turn by these angles (radians around x, y, z) from the starting rotation. 2π spins once; more spins more. */
148
+ turn?: Vec3;
149
+ /** Shake by up to this distance, fading out. Only the drawn position shakes (hits, wrong moves). */
150
+ shake?: number;
151
+ };
152
+ /** A step of a keyframed animation: values to pass through, and when (0..1 of the duration; default evenly spaced). */
153
+ export type Keyframe = AnimateTarget & {
154
+ at?: number;
155
+ };
156
+ export type SpringOptions = {
157
+ /** How strongly it pulls toward the target. Default 170. */
158
+ stiffness?: number;
159
+ /** How quickly it calms down. Lower bounces more. Default 26 (no overshoot). */
160
+ damping?: number;
161
+ /** Heavier moves slower and swings further. Default 1. */
162
+ mass?: number;
163
+ };
164
+ export type AnimateOptions = {
165
+ /** Seconds (ignored by springs). Default 0.3. */
166
+ duration?: number;
167
+ /** Seconds before it starts. Default 0. */
168
+ delay?: number;
169
+ /** Default "easeOut". "back" overshoots, "bounce" bounces, "elastic" springs. */
170
+ easing?: Easing;
171
+ /** Extra runs after the first, or "forever". Default 0. */
172
+ repeat?: number | 'forever';
173
+ /** Every other run plays backwards (pulses, ping-pong). */
174
+ yoyo?: boolean;
175
+ /** With several entities: extra delay for each next one, in seconds (waves, board reveals). */
176
+ stagger?: number;
177
+ /** "smooth" moves along a curve through the keyframes (arcs, hops) instead of straight lines. */
178
+ path?: 'linear' | 'smooth';
179
+ /**
180
+ * Physically simulated motion instead of a fixed duration: true (smooth), "bouncy", or your own
181
+ * settings. Interrupting a spring with another keeps its speed, so it never jerks.
182
+ */
183
+ spring?: boolean | 'bouncy' | SpringOptions;
184
+ };
185
+ export type BurstOptions = {
186
+ position: Vec3;
187
+ /** How many particles. Default 16. */
188
+ count?: number;
189
+ /** Main direction. Default up. */
190
+ direction?: Vec3;
191
+ /** Half-angle of the cone around `direction`, in radians. Default π (every direction). */
192
+ spread?: number;
193
+ /** Default "cube". */
194
+ mesh?: Shape | Model;
195
+ /** Particle size. Default 0.15. */
196
+ size?: number;
197
+ /** Top speed. Default 5. */
198
+ speed?: number;
199
+ /** Seconds. Default 0.8. */
200
+ lifetime?: number;
201
+ /** Vertical acceleration. Default -9.81 (falls); 0 floats. */
202
+ gravity?: number;
203
+ /** One color, or up to 4 to pick from at random. Default white. */
204
+ color?: Color | readonly Color[];
205
+ /** Size at the end of each particle's life, as a multiple of its start size: above 1 grows (smoke), below shrinks (embers). Default 1. */
206
+ endSize?: number;
207
+ /** Color every particle shifts to over its life, e.g. flame to dark red; an alpha below 1 fades it out. Default: keeps its color. */
208
+ endColor?: Color;
209
+ };
210
+ export type CollisionInfo = {
211
+ /** True when the touch started; false when it ended. */
212
+ started: boolean;
213
+ /** A sensor was involved. */
214
+ sensor: boolean;
215
+ /** Impact speed (0 when a touch ends). */
216
+ speed: number;
217
+ };
218
+ export type RaycastHit = {
219
+ entity: Entity;
220
+ distance: number;
221
+ normal: [number, number, number];
222
+ point: [number, number, number];
223
+ };
224
+ export type PickHit = {
225
+ entity: Entity;
226
+ /** Where the tap ray hit the entity's bounding box, in world space. */
227
+ point: [number, number, number];
228
+ distance: number;
229
+ };
230
+ export type Bounds = readonly [minX: number, minZ: number, maxX: number, maxZ: number];
231
+ import type { Shape } from '../types';
232
+ export type { Shape };
@@ -0,0 +1,34 @@
1
+ # Android build of the engine's native module. React Native's autolinking adds this directory to the
2
+ # app's native build (see react-native.config.js); there is no Gradle project, so this is a "pure C++"
3
+ # dependency and the codegen header ships in native/cpp/generated (regenerate with `bun run codegen`).
4
+ cmake_minimum_required(VERSION 3.13)
5
+ project(NayanEngine CXX)
6
+
7
+ get_filename_component(NATIVE_ROOT "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
8
+
9
+ # Rust core, prebuilt per ABI by native/core/scripts/build-android.sh.
10
+ add_library(engine_core STATIC IMPORTED)
11
+ set_target_properties(engine_core PROPERTIES
12
+ IMPORTED_LOCATION "${NATIVE_ROOT}/core/build/android/${ANDROID_ABI}/libengine_core.a")
13
+
14
+ # The codegen target autolinking expects (react_codegen_<codegenConfig.name>). It must be a real
15
+ # library: autolinking links `common_flags` into it with a plain target_link_libraries call.
16
+ add_library(react_codegen_NayanEngineSpec STATIC "${NATIVE_ROOT}/cpp/generated/NayanEngineSpecJSI.cpp")
17
+ # android/ holds NayanEngineSpec.h, the (empty) Java module provider autolinking includes.
18
+ target_include_directories(react_codegen_NayanEngineSpec PUBLIC "${NATIVE_ROOT}/cpp/generated" "${CMAKE_CURRENT_LIST_DIR}")
19
+ target_compile_features(react_codegen_NayanEngineSpec PUBLIC cxx_std_20)
20
+ target_link_libraries(react_codegen_NayanEngineSpec jsi reactnative)
21
+
22
+ # The TurboModule (shared with iOS) and the Rust core it calls.
23
+ add_library(NayanEngine STATIC "${NATIVE_ROOT}/cpp/NayanEngineModule.cpp")
24
+ target_include_directories(NayanEngine PUBLIC "${NATIVE_ROOT}/cpp" "${NATIVE_ROOT}/core/include")
25
+ target_compile_features(NayanEngine PUBLIC cxx_std_20)
26
+ target_link_libraries(NayanEngine
27
+ react_codegen_NayanEngineSpec
28
+ engine_core
29
+ fbjni
30
+ jsi
31
+ reactnative
32
+ aaudio # audio output (cpal's AAudio backend)
33
+ android
34
+ log)
@@ -0,0 +1,15 @@
1
+ // Autolinking includes <NayanEngineSpec.h> and calls this provider for every library with a codegen
2
+ // config. The engine has no Java module (it is registered through the C++ provider in
3
+ // NayanEngineModule.h), so this always declines.
4
+ #pragma once
5
+
6
+ #include <ReactCommon/JavaTurboModule.h>
7
+
8
+ namespace facebook::react {
9
+
10
+ inline std::shared_ptr<TurboModule> NayanEngineSpec_ModuleProvider(
11
+ const std::string&, const JavaTurboModule::InitParams&) {
12
+ return nullptr;
13
+ }
14
+
15
+ } // namespace facebook::react
@@ -0,0 +1,26 @@
1
+ // Java side of the engine: the EngineSurface view the renderer draws into. The native module itself is
2
+ // pure C++ (CMakeLists.txt, built into the app by autolinking).
3
+ apply plugin: "com.android.library"
4
+
5
+ def safeExtGet(prop, fallback) {
6
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
7
+ }
8
+
9
+ android {
10
+ namespace "com.nayanui.engine"
11
+ compileSdkVersion safeExtGet("compileSdkVersion", 35)
12
+
13
+ defaultConfig {
14
+ minSdkVersion safeExtGet("minSdkVersion", 24)
15
+ consumerProguardFiles "proguard-rules.pro"
16
+ }
17
+ }
18
+
19
+ repositories {
20
+ google()
21
+ mavenCentral()
22
+ }
23
+
24
+ dependencies {
25
+ implementation "com.facebook.react:react-android"
26
+ }
@@ -0,0 +1,3 @@
1
+ # Autolinking adds a codegen directory for every library with a Gradle project. The engine runs no
2
+ # Gradle codegen: ../CMakeLists.txt defines react_codegen_NayanEngineSpec from native/cpp/generated.
3
+ cmake_minimum_required(VERSION 3.13)
@@ -0,0 +1,2 @@
1
+ # The native methods are looked up by name from C++ (JNI).
2
+ -keep class com.nayanui.engine.** { *; }