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

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 (198) hide show
  1. package/LICENSE +21 -0
  2. package/NayanEngine.podspec +28 -0
  3. package/README.md +308 -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 +249 -0
  10. package/lib/module/assets/font.js +139 -0
  11. package/lib/module/assets/loft.js +142 -0
  12. package/lib/module/assets/model.js +96 -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 +38 -0
  19. package/lib/module/assets/storage.web.js +38 -0
  20. package/lib/module/assets/surface.js +47 -0
  21. package/lib/module/assets/texture.js +69 -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 +39 -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 +97 -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 +568 -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 +317 -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/light.js +24 -0
  48. package/lib/module/render/meshes.js +159 -0
  49. package/lib/module/render/quality.js +119 -0
  50. package/lib/module/render/responder.js +4 -0
  51. package/lib/module/render/responder.web.js +97 -0
  52. package/lib/module/render/touch.js +185 -0
  53. package/lib/module/render/useWorld.js +72 -0
  54. package/lib/module/types.js +30 -0
  55. package/lib/module/world/Scoreboard.js +161 -0
  56. package/lib/module/world/TransformBatch.js +128 -0
  57. package/lib/module/world/World.js +704 -0
  58. package/lib/module/world/color.js +80 -0
  59. package/lib/module/world/desc.js +187 -0
  60. package/lib/module/world/effects.js +463 -0
  61. package/lib/module/world/quat.js +86 -0
  62. package/lib/module/world/types.js +4 -0
  63. package/lib/typescript/package.json +1 -0
  64. package/lib/typescript/src/assets/AssetBytesCache.d.ts +7 -0
  65. package/lib/typescript/src/assets/AssetCache.d.ts +9 -0
  66. package/lib/typescript/src/assets/AssetLoader.d.ts +11 -0
  67. package/lib/typescript/src/assets/CacheGeneration.d.ts +3 -0
  68. package/lib/typescript/src/assets/IndexedDbCache.web.d.ts +20 -0
  69. package/lib/typescript/src/assets/ProceduralCache.d.ts +45 -0
  70. package/lib/typescript/src/assets/font.d.ts +53 -0
  71. package/lib/typescript/src/assets/loft.d.ts +31 -0
  72. package/lib/typescript/src/assets/model.d.ts +58 -0
  73. package/lib/typescript/src/assets/modelling.d.ts +157 -0
  74. package/lib/typescript/src/assets/shape.d.ts +203 -0
  75. package/lib/typescript/src/assets/source.d.ts +10 -0
  76. package/lib/typescript/src/assets/source.web.d.ts +8 -0
  77. package/lib/typescript/src/assets/storage.d.ts +2 -0
  78. package/lib/typescript/src/assets/storage.shared.d.ts +7 -0
  79. package/lib/typescript/src/assets/storage.web.d.ts +7 -0
  80. package/lib/typescript/src/assets/surface.d.ts +17 -0
  81. package/lib/typescript/src/assets/texture.d.ts +30 -0
  82. package/lib/typescript/src/drawing/DrawingCanvas.d.ts +5 -0
  83. package/lib/typescript/src/drawing/DrawingCanvas.web.d.ts +4 -0
  84. package/lib/typescript/src/drawing/DrawingDocument.d.ts +210 -0
  85. package/lib/typescript/src/drawing/types.d.ts +12 -0
  86. package/lib/typescript/src/index.d.ts +45 -0
  87. package/lib/typescript/src/input/Joystick.d.ts +20 -0
  88. package/lib/typescript/src/input/Joystick.web.d.ts +13 -0
  89. package/lib/typescript/src/input/keyboard.d.ts +17 -0
  90. package/lib/typescript/src/media/audio.d.ts +46 -0
  91. package/lib/typescript/src/media/haptics.d.ts +22 -0
  92. package/lib/typescript/src/media/output.web.d.ts +4 -0
  93. package/lib/typescript/src/native/BrowserEngine.d.ts +8 -0
  94. package/lib/typescript/src/native/EngineBridge.d.ts +26 -0
  95. package/lib/typescript/src/native/NativeNayanEngine.d.ts +5 -0
  96. package/lib/typescript/src/native/NativeNayanEngine.web.d.ts +10 -0
  97. package/lib/typescript/src/native/prepare.d.ts +3 -0
  98. package/lib/typescript/src/native/prepare.web.d.ts +2 -0
  99. package/lib/typescript/src/native/spec/NativeNayanEngine.d.ts +211 -0
  100. package/lib/typescript/src/render/GameView.d.ts +107 -0
  101. package/lib/typescript/src/render/camera.d.ts +6 -0
  102. package/lib/typescript/src/render/host.d.ts +29 -0
  103. package/lib/typescript/src/render/host.web.d.ts +16 -0
  104. package/lib/typescript/src/render/light.d.ts +12 -0
  105. package/lib/typescript/src/render/meshes.d.ts +45 -0
  106. package/lib/typescript/src/render/quality.d.ts +48 -0
  107. package/lib/typescript/src/render/responder.d.ts +2 -0
  108. package/lib/typescript/src/render/responder.web.d.ts +40 -0
  109. package/lib/typescript/src/render/touch.d.ts +26 -0
  110. package/lib/typescript/src/render/useWorld.d.ts +20 -0
  111. package/lib/typescript/src/types.d.ts +81 -0
  112. package/lib/typescript/src/world/Scoreboard.d.ts +75 -0
  113. package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
  114. package/lib/typescript/src/world/World.d.ts +207 -0
  115. package/lib/typescript/src/world/color.d.ts +18 -0
  116. package/lib/typescript/src/world/desc.d.ts +17 -0
  117. package/lib/typescript/src/world/effects.d.ts +157 -0
  118. package/lib/typescript/src/world/quat.d.ts +31 -0
  119. package/lib/typescript/src/world/types.d.ts +238 -0
  120. package/lib/web/audio-worklet.js +29 -0
  121. package/lib/web/engine_core_bg.wasm +0 -0
  122. package/lib/web/index.js +8240 -0
  123. package/lib/web/types/src/assets/AssetBytesCache.d.ts +6 -0
  124. package/lib/web/types/src/assets/AssetCache.d.ts +8 -0
  125. package/lib/web/types/src/assets/AssetLoader.d.ts +10 -0
  126. package/lib/web/types/src/assets/CacheGeneration.d.ts +2 -0
  127. package/lib/web/types/src/assets/IndexedDbCache.d.ts +19 -0
  128. package/lib/web/types/src/assets/ProceduralCache.d.ts +44 -0
  129. package/lib/web/types/src/assets/font.d.ts +52 -0
  130. package/lib/web/types/src/assets/loft.d.ts +30 -0
  131. package/lib/web/types/src/assets/model.d.ts +57 -0
  132. package/lib/web/types/src/assets/modelling.d.ts +156 -0
  133. package/lib/web/types/src/assets/shape.d.ts +202 -0
  134. package/lib/web/types/src/assets/source.d.ts +7 -0
  135. package/lib/web/types/src/assets/storage.d.ts +6 -0
  136. package/lib/web/types/src/assets/storage.shared.d.ts +6 -0
  137. package/lib/web/types/src/assets/surface.d.ts +16 -0
  138. package/lib/web/types/src/assets/texture.d.ts +29 -0
  139. package/lib/web/types/src/drawing/DrawingCanvas.d.ts +3 -0
  140. package/lib/web/types/src/drawing/DrawingDocument.d.ts +209 -0
  141. package/lib/web/types/src/drawing/types.d.ts +11 -0
  142. package/lib/web/types/src/index.d.ts +44 -0
  143. package/lib/web/types/src/input/Joystick.d.ts +12 -0
  144. package/lib/web/types/src/input/keyboard.d.ts +16 -0
  145. package/lib/web/types/src/media/audio.d.ts +45 -0
  146. package/lib/web/types/src/media/haptics.d.ts +21 -0
  147. package/lib/web/types/src/media/output.d.ts +3 -0
  148. package/lib/web/types/src/native/BrowserEngine.d.ts +7 -0
  149. package/lib/web/types/src/native/EngineBridge.d.ts +25 -0
  150. package/lib/web/types/src/native/NativeNayanEngine.d.ts +9 -0
  151. package/lib/web/types/src/native/prepare.d.ts +1 -0
  152. package/lib/web/types/src/native/spec/NativeNayanEngine.d.ts +210 -0
  153. package/lib/web/types/src/render/GameView.d.ts +106 -0
  154. package/lib/web/types/src/render/camera.d.ts +5 -0
  155. package/lib/web/types/src/render/host.d.ts +15 -0
  156. package/lib/web/types/src/render/light.d.ts +11 -0
  157. package/lib/web/types/src/render/meshes.d.ts +44 -0
  158. package/lib/web/types/src/render/quality.d.ts +47 -0
  159. package/lib/web/types/src/render/responder.d.ts +39 -0
  160. package/lib/web/types/src/render/touch.d.ts +25 -0
  161. package/lib/web/types/src/render/useWorld.d.ts +19 -0
  162. package/lib/web/types/src/types.d.ts +80 -0
  163. package/lib/web/types/src/world/Scoreboard.d.ts +74 -0
  164. package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
  165. package/lib/web/types/src/world/World.d.ts +206 -0
  166. package/lib/web/types/src/world/color.d.ts +17 -0
  167. package/lib/web/types/src/world/desc.d.ts +16 -0
  168. package/lib/web/types/src/world/effects.d.ts +156 -0
  169. package/lib/web/types/src/world/quat.d.ts +30 -0
  170. package/lib/web/types/src/world/types.d.ts +237 -0
  171. package/native/android/CMakeLists.txt +34 -0
  172. package/native/android/NayanEngineSpec.h +15 -0
  173. package/native/android/build.gradle +26 -0
  174. package/native/android/codegen/CMakeLists.txt +3 -0
  175. package/native/android/proguard-rules.pro +2 -0
  176. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceView.java +295 -0
  177. package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceViewManager.java +45 -0
  178. package/native/android/src/main/java/com/nayanui/engine/NayanEnginePackage.java +24 -0
  179. package/native/core/build/EngineCore.xcframework/Info.plist +43 -0
  180. package/native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a +0 -0
  181. package/native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a +0 -0
  182. package/native/core/build/android/arm64-v8a/libengine_core.a +0 -0
  183. package/native/core/build/android/armeabi-v7a/libengine_core.a +0 -0
  184. package/native/core/build/android/x86/libengine_core.a +0 -0
  185. package/native/core/build/android/x86_64/libengine_core.a +0 -0
  186. package/native/core/include/drawing-licenses.txt +58 -0
  187. package/native/core/include/engine_core.h +331 -0
  188. package/native/cpp/NayanEngineModule.cpp +998 -0
  189. package/native/cpp/NayanEngineModule.h +174 -0
  190. package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
  191. package/native/cpp/generated/NayanEngineSpecJSI.h +1026 -0
  192. package/native/ios/NayanEngineProvider.h +5 -0
  193. package/native/ios/NayanEngineProvider.mm +21 -0
  194. package/native/ios/NayanEngineSurface.mm +252 -0
  195. package/native/scripts/check-package.mjs +39 -0
  196. package/package.json +162 -4
  197. package/react-native.config.js +18 -0
  198. package/src/native/spec/NativeNayanEngine.ts +265 -0
@@ -0,0 +1,53 @@
1
+ import type { AssetSource } from './source';
2
+ /** Printable ASCII plus common arithmetic and typography, prewarmed for ordinary labels. */
3
+ export declare const DEFAULT_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\u00D7\u00F7\u00B1\u2212\u00B0\u00B7\u2022\u2013\u2014\u2026\u2018\u2019\u201C\u201D";
4
+ export type FontOptions = {
5
+ /** How deep letters are extruded, as a fraction of the font size. 0 = flat. Default 0.2. */
6
+ depth?: number;
7
+ /** Characters to prewarm (space and ? are always included). Other font-supported characters load
8
+ * once when text is measured or laid out. Fewer = faster startup and fewer unused meshes. Default: DEFAULT_CHARS. */
9
+ chars?: string;
10
+ /** Weight (e.g. 400, 600) for a variable font, such as the device's system font. Default: the font's own. */
11
+ weight?: number;
12
+ };
13
+ type Glyph = {
14
+ mesh: number;
15
+ advance: number;
16
+ };
17
+ /** A loaded font. Use it on an entity with `text`: `{ text: "2048", font }`. */
18
+ export type Font = {
19
+ readonly id: number;
20
+ /** Height of capital letters at scale 1. */
21
+ readonly capHeight: number;
22
+ /** Cached mesh (-1 = nothing drawn, e.g. space) and advance per character. Grows as text is used. */
23
+ readonly glyphs: ReadonlyMap<string, Glyph>;
24
+ };
25
+ /**
26
+ * Initializes the engine automatically. Loads a TrueType / OpenType font (.ttf / .otf) for 3D text. The source/depth/weight are cached independently of the requested prewarm characters. Letters are real meshes: lit, shadowed,
27
+ * and every copy of a letter on screen is drawn in one call. At scale 1, letters are 1 unit tall (em).
28
+ * Additional Unicode glyphs are built on demand from the same font and cached. The font must contain
29
+ * an outline for the character; missing characters still use ?, including unsupported emoji.
30
+ *
31
+ * ```ts
32
+ * const font = await loadFont(require("./assets/Inter-Bold.ttf"), { chars: "0123456789" });
33
+ * world.spawn({ text: "2048", font, scale: 0.5, color: [1, 1, 1] });
34
+ * ```
35
+ */
36
+ export declare function loadFont(source: AssetSource, options?: FontOptions): Promise<Font>;
37
+ export type TextAlign = 'left' | 'center' | 'right';
38
+ export type TextLayout = {
39
+ /** Extra space between letters, in ems (at scale 1, letters are 1 em tall). Default 0. */
40
+ letterSpacing?: number;
41
+ /** Digits all as wide as the widest, so changing numbers (scores, timers) don't shift. Default false. */
42
+ tabular?: boolean;
43
+ };
44
+ /** A line's advance in ems, with the same Unicode glyph loading, spacing and fallbacks as rendering. */
45
+ export declare function measureText(font: Font, text: string, options?: TextLayout): number;
46
+ /** Glyph placements for a line of text: centered vertically on capitals, aligned horizontally. */
47
+ export declare function layoutText(font: Font, text: string, align: TextAlign, options?: TextLayout): {
48
+ mesh: number;
49
+ x: number;
50
+ y: number;
51
+ }[];
52
+ export {};
53
+ //# sourceMappingURL=font.d.ts.map
@@ -0,0 +1,31 @@
1
+ import type { Vec3 } from '../types.js';
2
+ import type { Color } from '../world/types.js';
3
+ import { type Geometry } from './shape.js';
4
+ export interface LoftSection {
5
+ z: number;
6
+ bottom: number;
7
+ top: number;
8
+ /** Half the width at the lower corners. */
9
+ width: number;
10
+ topWidth?: number;
11
+ /** Superellipse exponent, 2 = oval, larger values = boxier corners. Default 4. */
12
+ square?: number;
13
+ }
14
+ export interface LoftOptions {
15
+ around?: number;
16
+ smoothness?: number;
17
+ color?: Color | ((position: Vec3, normal: Vec3) => Color);
18
+ }
19
+ /**
20
+ * Smooth closed body through rounded rectangular cross sections along Z. Useful for vehicle
21
+ * shells, cabins, shoes and fairings. Caps have separate flat normals and planar UVs; sides have
22
+ * continuous longitudinal UVs and a welded seam. Input sections may increase or decrease in Z.
23
+ */
24
+ export declare function loft(sections: readonly LoftSection[], options?: LoftOptions): Geometry;
25
+ /** A rounded rectangular cross-section with flat front/back caps, centered at the origin. */
26
+ export declare function block(w: number, h: number, d: number, square?: number, color?: LoftOptions['color']): Geometry;
27
+ /** An exact ellipsoid with analytic normals, rather than capped/truncated poles. */
28
+ export declare function ellipsoid(radii: Vec3, color?: LoftOptions['color'], around?: number): Geometry;
29
+ /** Smooth Hermite interpolation through increasing [x,value] points; clamped beyond the ends. */
30
+ export declare function smoothCurve(points: readonly (readonly [number, number])[]): (x: number) => number;
31
+ //# sourceMappingURL=loft.d.ts.map
@@ -0,0 +1,58 @@
1
+ import { type MeshGeometry } from '../render/meshes.js';
2
+ import type { Vec3 } from '../types.js';
3
+ import type { AssetSource } from './source';
4
+ export type ModelOptions = {
5
+ /** Move the model's bounding box center to the origin, so `position` is its middle. Default true. */
6
+ center?: boolean;
7
+ /** Scale it so its largest side is this long (e.g. 1 to match the built-in shapes). Default: keep its size. */
8
+ fit?: number;
9
+ /**
10
+ * How glossy, 0..1: a sharp sun highlight and a reflection of the sky that grows at grazing angles.
11
+ * 0 is matte; around 0.8 reads as car paint or glass. Default 0.
12
+ */
13
+ shine?: number;
14
+ };
15
+ /** A loaded model: pass it as an entity's `mesh`. Colliders sized from the mesh fit its bounding box. */
16
+ export type Model = {
17
+ /** Bounding box size [x, y, z] at scale 1 (after `fit`). */
18
+ readonly size: Vec3;
19
+ /** Mesh id in the core. */
20
+ readonly id: number;
21
+ };
22
+ /** An animation embedded in a loaded GLB. */
23
+ export type ModelClip = {
24
+ readonly name: string;
25
+ readonly duration: number;
26
+ };
27
+ export type LoadedModel = Model & {
28
+ readonly animations: readonly ModelClip[];
29
+ readonly jointCount: number;
30
+ };
31
+ /** A registered mesh's geometry, aliasing native memory. */
32
+ export declare function nativeGeometry(mesh: number): {
33
+ vertices: Float32Array<ArrayBuffer>;
34
+ indices: Uint32Array<ArrayBuffer>;
35
+ };
36
+ /**
37
+ * Registers a mesh the core already holds (a created, cached or loaded model, a glyph, an alias):
38
+ * the renderer copies it inside Rust, and JS reads its geometry only if something asks for it
39
+ * (merging, caching). Apps built before `renderModel` upload it through JS as before.
40
+ */
41
+ export declare function registerCoreMesh(mesh: number, info?: {
42
+ texture?: number;
43
+ shine?: number;
44
+ }, geometry?: () => MeshGeometry): void;
45
+ /** Independent materials share core geometry without overwriting an existing model's appearance. */
46
+ export declare function registerModelMesh(mesh: number, shine: number): number;
47
+ /**
48
+ * Initializes the engine automatically. Loads a glTF model once; pass it as an entity's `mesh`. Meshes, node transforms, material colors
49
+ * and the base color texture are kept (one texture per model); skeletal animation clips are available through `animations` and `World.playClip`.
50
+ * Every entity using the model is drawn in one instanced draw call.
51
+ *
52
+ * ```ts
53
+ * const tree = await loadModel(require("./assets/tree.glb"), { fit: 2 });
54
+ * world.spawn({ mesh: tree, position: [0, 1, 0], physics: "fixed" });
55
+ * ```
56
+ */
57
+ export declare function loadModel(source: AssetSource, options?: ModelOptions): Promise<LoadedModel>;
58
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1,157 @@
1
+ import type { Vec3 } from '../types.js';
2
+ import type { Color, Quat } from '../world/types.js';
3
+ import type { Model } from './model.js';
4
+ import { type Geometry, type ShapeOptions } from './shape.js';
5
+ type Node = {
6
+ readonly kind: 'sphere';
7
+ readonly radius: number;
8
+ } | {
9
+ readonly kind: 'ellipsoid';
10
+ readonly radii: Vec3;
11
+ } | {
12
+ readonly kind: 'box';
13
+ readonly size: Vec3;
14
+ readonly radius: number;
15
+ } | {
16
+ readonly kind: 'capsule';
17
+ readonly start: Vec3;
18
+ readonly end: Vec3;
19
+ readonly radius: number;
20
+ } | {
21
+ readonly kind: 'cylinder';
22
+ readonly radius: number;
23
+ readonly height: number;
24
+ } | {
25
+ readonly kind: 'torus';
26
+ readonly radius: number;
27
+ readonly tube: number;
28
+ } | {
29
+ readonly kind: 'union';
30
+ readonly a: Node;
31
+ readonly b: Node;
32
+ readonly blend: number;
33
+ } | {
34
+ readonly kind: 'subtract' | 'intersect';
35
+ readonly a: Node;
36
+ readonly b: Node;
37
+ } | {
38
+ readonly kind: 'transform';
39
+ readonly child: Node;
40
+ readonly position: Vec3;
41
+ readonly rotation: Quat;
42
+ readonly scale: Vec3;
43
+ } | {
44
+ readonly kind: 'paint';
45
+ readonly child: Node;
46
+ readonly color: Color;
47
+ } | {
48
+ readonly kind: 'shell';
49
+ readonly child: Node;
50
+ readonly thickness: number;
51
+ } | {
52
+ readonly kind: 'displace';
53
+ readonly child: Node;
54
+ readonly amplitude: number;
55
+ readonly frequency: number;
56
+ readonly seed: number;
57
+ readonly octaves: number;
58
+ };
59
+ /**
60
+ * An immutable, code-authored solid. Join primitives into a single surface, blend organic forms,
61
+ * drill holes, hollow shells and add reproducible rock/terrain detail before tessellating once.
62
+ * Distances use world units; primitives are centered at the origin, cylinders/tori use the Y axis.
63
+ *
64
+ * const torso = Solid.ellipsoid([0.5, 0.7, 0.3]).paint([0.5, 0.1, 0.9]);
65
+ * const neck = Solid.capsule([0, 0.5, 0], [0, 0.9, 0], 0.15);
66
+ * const geometry = solidGeometry(torso.blend(neck, 0.15), { resolution: 48 });
67
+ */
68
+ export declare class Solid {
69
+ private readonly node;
70
+ private constructor();
71
+ static sphere(radius?: number): Solid;
72
+ static ellipsoid(radii: Vec3): Solid;
73
+ /** Full width/height/depth. Rounding stays inside these dimensions. */
74
+ static box(size: Vec3, radius?: number): Solid;
75
+ static capsule(start: Vec3, end: Vec3, radius: number): Solid;
76
+ static cylinder(radius: number, height: number): Solid;
77
+ /** Major radius to the tube center; minor radius of the tube itself. */
78
+ static torus(radius: number, tube: number): Solid;
79
+ /** Balanced union for many parts; avoids building a deeply nested operation chain. */
80
+ static union(...solids: readonly Solid[]): Solid;
81
+ union(other: Solid): Solid;
82
+ /** Smoothly weld overlapping forms; blend controls the transition width in world units. */
83
+ blend(other: Solid, blend: number): Solid;
84
+ subtract(other: Solid): Solid;
85
+ intersect(other: Solid): Solid;
86
+ translate(position: Vec3): Solid;
87
+ rotate(rotation: Quat): Solid;
88
+ scale(scale: number | Vec3): Solid;
89
+ private transform;
90
+ /** Vertex colors blend with the surface at smooth joins. Apply after subtract() to color cut walls. */
91
+ paint(color: Color): Solid;
92
+ /** A shell centered on the original surface; thickness is its full wall thickness. */
93
+ shell(thickness: number): Solid;
94
+ /** Seeded fractal value noise. Use a resolution fine enough to sample its smallest features. */
95
+ displace(options: DisplacementOptions): Solid;
96
+ /** Serializable recipe for caching or inspecting a generated asset. */
97
+ toJSON(): Node;
98
+ }
99
+ export interface DisplacementOptions {
100
+ amplitude: number;
101
+ frequency?: number;
102
+ seed?: number;
103
+ /** 1..6 octaves. Default 3. */
104
+ octaves?: number;
105
+ }
106
+ export interface SolidOptions {
107
+ /** Cells across the longest dimension, 8..128. Default 48. Higher costs cubic sampling work. */
108
+ resolution?: number;
109
+ /** Planar UV projection. Use parametricSurface/loft for explicitly authored UVs. Default xy. */
110
+ uv?: 'xy' | 'xz' | 'yz';
111
+ }
112
+ /** Tessellates into editable, unregistered geometry. Prefer createSolid() for automatic model reuse. */
113
+ export declare function solidGeometry(solid: Solid, options?: SolidOptions): Geometry;
114
+ /**
115
+ * Tessellates, cleans and registers a solid once, then returns its cached model on later calls
116
+ * with the same recipe/options. White vertex colors can be tinted per spawned entity. Temporary
117
+ * intermediate meshes consume no IDs. Prepared solids persist automatically when platform storage
118
+ * is available; storage failure falls back to building. Call after warmUpEngine(), before spawning a run.
119
+ */
120
+ export declare function createSolid(solid: Solid, options?: SolidOptions & ShapeOptions): Model;
121
+ export interface OptimizeOptions {
122
+ /** Target triangle fraction in (0,1]. Default 1: lossless cleanup, welding and GPU cache ordering. */
123
+ ratio?: number;
124
+ /** Maximum relative error, 0..1, against the largest dimension, with attribute error included. Default 0.001. */
125
+ error?: number;
126
+ /** Keep open borders fixed, useful for separately generated terrain chunks. Default true. */
127
+ lockBorders?: boolean;
128
+ }
129
+ /**
130
+ * Returns new geometry, preserving the input and its normal/color/UV seams. Removes degenerate
131
+ * triangles and unused/identical vertices, simplifies within the error bound, then orders buffers
132
+ * for GPU reuse. The error bound may prevent reaching the requested ratio. Opaque static meshes only:
133
+ * do not use on skinning buffers or meshes whose vertex indices are used by external code.
134
+ */
135
+ export declare function optimizeGeometry(geometry: Geometry, options?: OptimizeOptions): Geometry;
136
+ /**
137
+ * Independently simplifies the original at each requested ratio, avoiding accumulated error.
138
+ * Cache/register the results once. The caller selects a level when camera distance changes.
139
+ */
140
+ export declare function createGeometryLods(geometry: Geometry, ratios?: readonly number[], options?: Omit<OptimizeOptions, 'ratio'>): Geometry[];
141
+ export interface GeometryStats {
142
+ vertices: number;
143
+ triangles: number;
144
+ /** CPU geometry bytes, excluding registration/driver copies. */
145
+ bytes: number;
146
+ bounds: {
147
+ min: Vec3;
148
+ max: Vec3;
149
+ size: Vec3;
150
+ } | null;
151
+ }
152
+ /** Cheap counts and bounds without registering a mesh. */
153
+ export declare function getGeometryStats(geometry: Geometry): GeometryStats;
154
+ /** Copies/sculpts one smooth surface and updates its normals. Deform hard-edged parts separately. */
155
+ export declare function deformGeometry(geometry: Geometry, deform: (position: Vec3, uv: readonly [number, number]) => Vec3): Geometry;
156
+ export {};
157
+ //# sourceMappingURL=modelling.d.ts.map
@@ -0,0 +1,203 @@
1
+ import { type MeshGeometry } from '../render/meshes.js';
2
+ import { type Shape, type Vec3 } from '../types.js';
3
+ import type { Color, Quat } from '../world/types.js';
4
+ import { type Model } from './model.js';
5
+ import type { OptimizeOptions } from './modelling.js';
6
+ type P2 = [number, number];
7
+ /**
8
+ * A 2D outline, built like an SVG path: x right, y down. Solids made from it
9
+ * (`extrude`, `lathe`) are flipped upright, so a path drawn the way it looks on screen stands the
10
+ * same way in the world. Coordinates are in world units: a 1 x 1 path makes a 1 unit wide shape.
11
+ *
12
+ * ```ts
13
+ * const heart = Path.fromSVG("M0.5 0.9 C0 0.5 0 0.1 0.25 0.1 C0.4 0.1 0.5 0.25 0.5 0.3 C0.5 0.25 0.6 0.1 0.75 0.1 C1 0.1 1 0.5 0.5 0.9 Z");
14
+ * const star = new Path().addStar(0, 0, 0.5, 0.22, 5);
15
+ * ```
16
+ */
17
+ export declare class Path {
18
+ private contours;
19
+ private start;
20
+ private last;
21
+ private get current();
22
+ private add;
23
+ /** Starts a new contour at (x, y). */
24
+ moveTo(x: number, y: number): this;
25
+ lineTo(x: number, y: number): this;
26
+ /** A quadratic Bézier through control point (cx, cy) to (x, y). */
27
+ quadraticTo(cx: number, cy: number, x: number, y: number): this;
28
+ /** A cubic Bézier through control points (c1x, c1y) and (c2x, c2y) to (x, y). */
29
+ cubicTo(c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): this;
30
+ /**
31
+ * An elliptical arc to (x, y), as in SVG's `A` command: radii rx, ry, the ellipse turned `rotation`
32
+ * radians, and the flags choosing which of the four possible arcs.
33
+ */
34
+ arcTo(rx: number, ry: number, rotation: number, largeArc: boolean, sweep: boolean, x: number, y: number): this;
35
+ /** Closes the current contour back to its first point. */
36
+ close(): this;
37
+ /** A closed polygon through `points`. */
38
+ addPolygon(points: readonly (readonly [number, number])[], close?: boolean): this;
39
+ addRect(x: number, y: number, width: number, height: number): this;
40
+ /** A rectangle with corners rounded by `radius` (or [rx, ry]). */
41
+ addRoundedRect(x: number, y: number, width: number, height: number, radius: number | readonly [number, number]): this;
42
+ /** An ellipse filling the box. */
43
+ addOval(x: number, y: number, width: number, height: number): this;
44
+ addCircle(cx: number, cy: number, radius: number): this;
45
+ /** A star with `points` tips at `outer` radius and notches at `inner`, the first tip pointing up. */
46
+ addStar(cx: number, cy: number, outer: number, inner: number, points?: number): this;
47
+ /** A regular polygon with `sides` corners, the first pointing up. */
48
+ addRegularPolygon(cx: number, cy: number, radius: number, sides: number): this;
49
+ /**
50
+ * Parses SVG path data (`d`): M L H V C S Q T A Z, absolute and relative. Paste paths from Figma,
51
+ * Illustrator or any icon set (scale them with `fit` on the shape, or `transform` here).
52
+ */
53
+ static fromSVG(d: string): Path;
54
+ /** A copy moved by (dx, dy) and scaled by sx, sy (about the origin, before moving). */
55
+ transform(sx: number, sy?: number, dx?: number, dy?: number): Path;
56
+ /** The flattened contours (curves turned into points), y down as drawn. */
57
+ toContours(): P2[][];
58
+ /** [minX, minY, maxX, maxY], or undefined for an empty path. */
59
+ bounds(): [number, number, number, number] | undefined;
60
+ }
61
+ /**
62
+ * Shape geometry, before it's registered: 11 floats per vertex (position, normal, color, uv) and
63
+ * triangle indices. Builders return it; `merge` combines it; `createShape` turns it into a mesh.
64
+ */
65
+ export type Geometry = MeshGeometry;
66
+ /** A built-in shape's geometry (unit-sized, centered), to `merge` with others. */
67
+ export declare function shapeGeometry(shape: Exclude<Shape, 'none' | 'puff' | 'flame'>, options?: {
68
+ color?: Color;
69
+ }): Geometry;
70
+ export type ExtrudeOptions = {
71
+ /** How deep, in the path's units. 0 = a flat, one-sided face (facing +Z). Default 0.2. */
72
+ depth?: number;
73
+ /** SVG fill rules: "nonzero" (the default winding rule) or "evenodd" (every inner contour is a hole). */
74
+ fillRule?: 'nonzero' | 'evenodd';
75
+ /** Vertex color (multiplies the entity's color). Default white. */
76
+ color?: Color;
77
+ };
78
+ /**
79
+ * A 2D path filled and pushed into a solid, facing +Z: badges, coins, leaves, hearts, stars, logos,
80
+ * fruit slices. Holes follow the fill rule. Textures map across the front face.
81
+ */
82
+ export declare function extrude(path: Path, options?: ExtrudeOptions): Geometry;
83
+ /** Where a color function is asked about: `u` around (0..1), `v` along (0..1), and the surface there. */
84
+ export type SurfacePoint = {
85
+ u: number;
86
+ v: number;
87
+ position: Vec3;
88
+ normal: Vec3;
89
+ };
90
+ /** A flat color, or one per point of the surface: blushes, stripes, speckles, spots. */
91
+ export type SurfaceColor = Color | ((p: SurfacePoint) => Color);
92
+ /** A flat color, or one per point of a round face: `r` from its center (0) to its rim (1), `angle` around it. */
93
+ export type FaceColor = Color | ((r: number, angle: number) => Color);
94
+ export type LatheOptions = {
95
+ /** Steps around the axis. Default 32. */
96
+ segments?: number;
97
+ /** How far around, in radians: TAU (default) is a full turn; Math.PI a half, for a cut fruit. */
98
+ sweep?: number;
99
+ /** Color of the outside: one color, or a function of the surface point (u around, v down the profile). Default white. */
100
+ color?: SurfaceColor;
101
+ /**
102
+ * Pushes the surface out (or in, if negative) along its normal by this much at (u, v): peel dimples,
103
+ * ribs, ridges, bumps. Normals are recomputed so the bumps catch the light. Make it repeat in u
104
+ * (equal at u = 0 and 1) to avoid a seam.
105
+ */
106
+ displace?: (u: number, v: number) => number;
107
+ /** Color of the flat ends where the profile stops away from the axis (the face of a fruit cut across). Default `color`. */
108
+ capColor?: FaceColor;
109
+ /** Rings across each end cap, for patterned `capColor`. Default 1, or 12 for a function. */
110
+ capRings?: number;
111
+ /**
112
+ * Color of the faces where a partial sweep is cut open (the flesh of a fruit cut through its core).
113
+ * As a function: `r` from the axis (0) to the skin (1) at that height, and the height `y`. Default `color`.
114
+ */
115
+ cutColor?: Color | ((r: number, y: number) => Color);
116
+ /** Steps from the axis to the skin across each cut face, for a detailed `cutColor`. Default 12 for a function. */
117
+ cutSteps?: number;
118
+ };
119
+ /**
120
+ * Recolors geometry point by point (in place, and returned): two-tone leaves, painted tips, stripes on
121
+ * an extrusion. `u` and `v` are the texture coordinates there.
122
+ */
123
+ export declare function recolor(geometry: Geometry, color: (p: SurfacePoint) => Color): Geometry;
124
+ /**
125
+ * Recomputes corner-angle-weighted normals in place, welding UV seams and poles at 1e-5 units.
126
+ * Uses Rust when available. Call on a sculpted surface before merging caps or other hard edges:
127
+ * coincident vertices share a normal. Degenerate faces leave the original normals intact.
128
+ */
129
+ export declare function smoothNormals(g: Geometry): Geometry;
130
+ /**
131
+ * Spins a profile around the vertical axis, like a potter's wheel: fruit (apples, oranges, lemons,
132
+ * pears, cherries), vases, bottles, bowls, chess pieces, spinning tops. The profile is a `Path`
133
+ * (x = distance from the axis, y down, as drawn) or [radius, height] points (y up), top to bottom.
134
+ * Open ends away from the axis are capped. With `sweep` < TAU the cut faces are closed too.
135
+ */
136
+ export declare function lathe(profile: Path | readonly (readonly [number, number])[], options?: LatheOptions): Geometry;
137
+ export type TubeOptions = {
138
+ /** Radius, or a function of t (0 at the first point, 1 at the last) for tapering: bananas, horns, tails. Default 0.1. */
139
+ radius?: number | ((t: number) => number);
140
+ /**
141
+ * The cross-section: a radius multiplier at each point around (0..1, repeating), e.g. ridges for a
142
+ * banana or a star for a churro. Default round.
143
+ */
144
+ shape?: (around: number) => number;
145
+ /** Steps around the tube. Default 12. */
146
+ sides?: number;
147
+ /** Steps between each pair of points (the path is smoothed through them). Default 8. */
148
+ smoothness?: number;
149
+ /** Cap the ends (where the radius isn't 0). Default true. */
150
+ caps?: boolean;
151
+ /** Join the last point to the first with a smooth, untwisted seam; no end caps. Default false. */
152
+ closed?: boolean;
153
+ /** Color: one, or a function of the surface point (u around, v = t along). Default white. */
154
+ color?: SurfaceColor;
155
+ /** Color of the end caps (the face of a cut banana). Default `color`. */
156
+ capColor?: FaceColor;
157
+ };
158
+ /**
159
+ * A tube along a smooth curve through `points`: bananas, stems, chillies, worms, snakes, ropes,
160
+ * pipes, tentacles, candy canes.
161
+ */
162
+ export declare function tube(points: readonly Vec3[], options?: TubeOptions): Geometry;
163
+ export type GeometryPart = {
164
+ geometry: Geometry;
165
+ position?: Vec3;
166
+ /** A quaternion [x, y, z, w], as entities use. */
167
+ rotation?: Quat;
168
+ scale?: Vec3 | number;
169
+ /** Multiplies the part's vertex colors: an apple's red body, brown stem and green leaf in one mesh. */
170
+ color?: Color;
171
+ };
172
+ /**
173
+ * Bakes parts into one geometry, each scaled, rotated, moved and colored. One mesh draws in one
174
+ * instanced call and moves, spins and slices as one entity.
175
+ */
176
+ export declare function merge(parts: readonly GeometryPart[]): Geometry;
177
+ export type ShapeOptions = {
178
+ /** Clean/optimize before upload, or simplify within an error bound. Built once, then shared. Default false. */
179
+ optimize?: boolean | OptimizeOptions;
180
+ /** Move the bounding box's center to the origin, so `position` is the middle. Default true. */
181
+ center?: boolean;
182
+ /** Scale so the largest side is this long (1 matches the built-in shapes). Default: keep the size. */
183
+ fit?: number;
184
+ /** How glossy, 0..1 (as for models): around 0.6 for a waxy apple, 0.85 for glass. Default 0. */
185
+ shine?: number;
186
+ };
187
+ /**
188
+ * Registers geometry as a mesh: pass the result as an entity's `mesh` (or a burst's), with any
189
+ * `texture`, physics and picking. Colliders default to a box holding the shape. Mesh ids are
190
+ * shared by models, fonts and shapes (about 4,080) and live for the whole app. Equal geometry/options
191
+ * automatically reuse preparation and registration; input buffers may still be edited for a later
192
+ * call. Material variants remain independent. Build geometry during scene setup, outside onUpdate.
193
+ *
194
+ * ```ts
195
+ * const orange = createShape(lathe(orangeProfile, { color: [1, 0.55, 0.1] }), { fit: 1, shine: 0.3 });
196
+ * world.spawn({ mesh: orange, position: [0, 2, 0], physics: "dynamic" });
197
+ * ```
198
+ */
199
+ export declare function createShape(geometry: Geometry, options?: ShapeOptions): Model;
200
+ export declare function preparedModel(mesh: number, shine: number): Model;
201
+ export declare function prepareOptions(options: ShapeOptions): string;
202
+ export {};
203
+ //# sourceMappingURL=shape.d.ts.map
@@ -0,0 +1,10 @@
1
+ /** A `require("./file.ext")` asset, or a URI (http(s):// or file://). */
2
+ export type AssetSource = number | string;
3
+ /** The URI an asset resolves to (a Metro dev-server URL in development, a bundle path in release). */
4
+ export declare function assetUri(source: AssetSource): string | undefined;
5
+ /** Fetches an asset's bytes. */
6
+ export declare function loadAssetBytes(source: AssetSource): Promise<{
7
+ uri: string;
8
+ bytes: ArrayBuffer;
9
+ }>;
10
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1,8 @@
1
+ /** Browser assets use URLs (including URLs emitted by Vite/webpack imports). */
2
+ export type AssetSource = number | string;
3
+ export declare function assetUri(source: AssetSource): string | undefined;
4
+ export declare function loadAssetBytes(source: AssetSource): Promise<{
5
+ uri: string;
6
+ bytes: ArrayBuffer;
7
+ }>;
8
+ //# sourceMappingURL=source.web.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { proceduralStorage, readPersistentAsset, writePersistentAsset, removePersistentAsset, clearPersistentStorage } from './storage.shared.js';
2
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { ProceduralStorage } from './ProceduralCache.js';
2
+ export declare function proceduralStorage(revision: string): ProceduralStorage | undefined;
3
+ export declare function readPersistentAsset(key: string): Promise<ArrayBuffer | null>;
4
+ export declare function writePersistentAsset(key: string, bytes: ArrayBuffer): Promise<void>;
5
+ export declare function removePersistentAsset(key: string): Promise<void>;
6
+ export declare function clearPersistentStorage(): Promise<void>;
7
+ //# sourceMappingURL=storage.shared.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { ProceduralStorage } from './ProceduralCache.js';
2
+ export declare function proceduralStorage(revision: string): ProceduralStorage | undefined;
3
+ export declare function readPersistentAsset(key: string): Promise<ArrayBuffer | null>;
4
+ export declare function writePersistentAsset(key: string, bytes: ArrayBuffer): Promise<void>;
5
+ export declare function removePersistentAsset(key: string): Promise<void>;
6
+ export declare function clearPersistentStorage(): Promise<void>;
7
+ //# sourceMappingURL=storage.web.d.ts.map
@@ -0,0 +1,17 @@
1
+ import type { Vec3 } from '../types.js';
2
+ import type { Geometry, SurfaceColor } from './shape.js';
3
+ export interface ParametricSurfaceOptions {
4
+ uSegments?: number;
5
+ vSegments?: number;
6
+ /** Match the first/last positions and smooth their normals, keeping separate 0/1 UVs. */
7
+ wrapU?: boolean;
8
+ wrapV?: boolean;
9
+ color?: SurfaceColor;
10
+ }
11
+ /**
12
+ * Samples an arbitrary surface on u/v in [0,1]. Winding follows dP/du cross dP/dv.
13
+ * Use for terrain, cloth, wings, twisted ribbons and custom mathematical forms. Wrapped edges
14
+ * retain texture seams; coincident pole vertices share normals. Degenerate triangles are omitted.
15
+ */
16
+ export declare function parametricSurface(sample: (u: number, v: number) => Vec3, options?: ParametricSurfaceOptions): Geometry;
17
+ //# sourceMappingURL=surface.d.ts.map
@@ -0,0 +1,30 @@
1
+ import type { AssetSource } from './source';
2
+ /** A loaded image. Pass it as an entity's `texture`. */
3
+ export type Texture = {
4
+ readonly id: number;
5
+ readonly width: number;
6
+ readonly height: number;
7
+ };
8
+ export type TextureImage = {
9
+ width: number;
10
+ height: number;
11
+ pixels: Uint8Array;
12
+ };
13
+ /**
14
+ * Initializes the engine automatically. Loads a PNG or JPEG once (up to 4096 x 4096). Use it on any entity: `{ mesh: "cube", texture }`.
15
+ * The entity's `color` tints it; `textureRegion` shows part of it (sprite sheets, card atlases).
16
+ *
17
+ * ```ts
18
+ * const crate = await loadTexture(require("./assets/crate.png"));
19
+ * world.spawn({ mesh: "cube", texture: crate });
20
+ * ```
21
+ */
22
+ export declare function loadTexture(source: AssetSource): Promise<Texture>;
23
+ /** Pixels of a texture id (aliasing native memory), for the renderer. */
24
+ export declare function textureImage(id: number): TextureImage;
25
+ /**
26
+ * The mesh id that draws `mesh`'s geometry with `texture`: a textured variant made on first use
27
+ * (it shares the geometry, colliders and picking of the original).
28
+ */
29
+ export declare function texturedMesh(mesh: number, texture: Texture): number;
30
+ //# sourceMappingURL=texture.d.ts.map
@@ -0,0 +1,5 @@
1
+ export type { DrawingCanvasProps } from './types.js';
2
+ import type { DrawingCanvasProps } from './types.js';
3
+ /** Native coalesced finger/Pencil/stylus input, with pinch zoom and pan, bypasses the JS thread. */
4
+ export declare const DrawingCanvas: import("react").MemoExoticComponent<({ document, mode, background, active, onChange, onError, style }: DrawingCanvasProps) => import("react").JSX.Element>;
5
+ //# sourceMappingURL=DrawingCanvas.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { DrawingCanvasProps } from './types.js';
2
+ export type { DrawingCanvasProps } from './types.js';
3
+ export declare const DrawingCanvas: import("react").MemoExoticComponent<({ document: drawing, mode, background, active, onError, onChange, style }: DrawingCanvasProps) => import("react").JSX.Element>;
4
+ //# sourceMappingURL=DrawingCanvas.web.d.ts.map