@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.
- package/LICENSE +21 -0
- package/NayanEngine.podspec +28 -0
- package/README.md +210 -2
- package/lib/module/assets/AssetBytesCache.js +76 -0
- package/lib/module/assets/AssetCache.js +19 -0
- package/lib/module/assets/AssetLoader.js +52 -0
- package/lib/module/assets/CacheGeneration.js +7 -0
- package/lib/module/assets/IndexedDbCache.web.js +149 -0
- package/lib/module/assets/ProceduralCache.js +222 -0
- package/lib/module/assets/font.js +136 -0
- package/lib/module/assets/loft.js +142 -0
- package/lib/module/assets/model.js +74 -0
- package/lib/module/assets/modelling.js +254 -0
- package/lib/module/assets/shape.js +926 -0
- package/lib/module/assets/source.js +58 -0
- package/lib/module/assets/source.web.js +22 -0
- package/lib/module/assets/storage.js +4 -0
- package/lib/module/assets/storage.shared.js +36 -0
- package/lib/module/assets/storage.web.js +37 -0
- package/lib/module/assets/surface.js +47 -0
- package/lib/module/assets/texture.js +66 -0
- package/lib/module/drawing/DrawingCanvas.js +38 -0
- package/lib/module/drawing/DrawingCanvas.web.js +206 -0
- package/lib/module/drawing/DrawingDocument.js +256 -0
- package/lib/module/drawing/types.js +4 -0
- package/lib/module/globals.d.ts +12 -0
- package/lib/module/index.js +36 -0
- package/lib/module/input/Joystick.js +84 -0
- package/lib/module/input/Joystick.web.js +93 -0
- package/lib/module/input/keyboard.js +250 -0
- package/lib/module/media/audio-worklet.js +34 -0
- package/lib/module/media/audio.js +94 -0
- package/lib/module/media/haptics.js +82 -0
- package/lib/module/media/output.web.js +66 -0
- package/lib/module/native/BrowserEngine.js +551 -0
- package/lib/module/native/EngineBridge.js +4 -0
- package/lib/module/native/NativeNayanEngine.js +7 -0
- package/lib/module/native/NativeNayanEngine.web.js +62 -0
- package/lib/module/native/prepare.js +7 -0
- package/lib/module/native/prepare.web.js +17 -0
- package/lib/module/native/spec/NativeNayanEngine.js +17 -0
- package/lib/module/package.json +1 -0
- package/lib/module/render/GameView.js +249 -0
- package/lib/module/render/camera.js +34 -0
- package/lib/module/render/host.js +39 -0
- package/lib/module/render/host.web.js +104 -0
- package/lib/module/render/meshes.js +159 -0
- package/lib/module/render/quality.js +112 -0
- package/lib/module/render/responder.js +4 -0
- package/lib/module/render/responder.web.js +97 -0
- package/lib/module/render/touch.js +185 -0
- package/lib/module/types.js +30 -0
- package/lib/module/world/Scoreboard.js +143 -0
- package/lib/module/world/TransformBatch.js +126 -0
- package/lib/module/world/World.js +690 -0
- package/lib/module/world/desc.js +186 -0
- package/lib/module/world/effects.js +451 -0
- package/lib/module/world/quat.js +86 -0
- package/lib/module/world/types.js +4 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/assets/AssetBytesCache.d.ts +7 -0
- package/lib/typescript/src/assets/AssetCache.d.ts +9 -0
- package/lib/typescript/src/assets/AssetLoader.d.ts +11 -0
- package/lib/typescript/src/assets/CacheGeneration.d.ts +3 -0
- package/lib/typescript/src/assets/IndexedDbCache.web.d.ts +20 -0
- package/lib/typescript/src/assets/ProceduralCache.d.ts +33 -0
- package/lib/typescript/src/assets/font.d.ts +53 -0
- package/lib/typescript/src/assets/loft.d.ts +31 -0
- package/lib/typescript/src/assets/model.d.ts +48 -0
- package/lib/typescript/src/assets/modelling.d.ts +157 -0
- package/lib/typescript/src/assets/shape.d.ts +203 -0
- package/lib/typescript/src/assets/source.d.ts +10 -0
- package/lib/typescript/src/assets/source.web.d.ts +8 -0
- package/lib/typescript/src/assets/storage.d.ts +2 -0
- package/lib/typescript/src/assets/storage.shared.d.ts +7 -0
- package/lib/typescript/src/assets/storage.web.d.ts +7 -0
- package/lib/typescript/src/assets/surface.d.ts +17 -0
- package/lib/typescript/src/assets/texture.d.ts +30 -0
- package/lib/typescript/src/drawing/DrawingCanvas.d.ts +5 -0
- package/lib/typescript/src/drawing/DrawingCanvas.web.d.ts +4 -0
- package/lib/typescript/src/drawing/DrawingDocument.d.ts +210 -0
- package/lib/typescript/src/drawing/types.d.ts +12 -0
- package/lib/typescript/src/index.d.ts +42 -0
- package/lib/typescript/src/input/Joystick.d.ts +20 -0
- package/lib/typescript/src/input/Joystick.web.d.ts +13 -0
- package/lib/typescript/src/input/keyboard.d.ts +17 -0
- package/lib/typescript/src/media/audio.d.ts +46 -0
- package/lib/typescript/src/media/haptics.d.ts +22 -0
- package/lib/typescript/src/media/output.web.d.ts +4 -0
- package/lib/typescript/src/native/BrowserEngine.d.ts +8 -0
- package/lib/typescript/src/native/EngineBridge.d.ts +22 -0
- package/lib/typescript/src/native/NativeNayanEngine.d.ts +5 -0
- package/lib/typescript/src/native/NativeNayanEngine.web.d.ts +10 -0
- package/lib/typescript/src/native/prepare.d.ts +3 -0
- package/lib/typescript/src/native/prepare.web.d.ts +2 -0
- package/lib/typescript/src/native/spec/NativeNayanEngine.d.ts +182 -0
- package/lib/typescript/src/render/GameView.d.ts +95 -0
- package/lib/typescript/src/render/camera.d.ts +6 -0
- package/lib/typescript/src/render/host.d.ts +29 -0
- package/lib/typescript/src/render/host.web.d.ts +16 -0
- package/lib/typescript/src/render/meshes.d.ts +45 -0
- package/lib/typescript/src/render/quality.d.ts +46 -0
- package/lib/typescript/src/render/responder.d.ts +2 -0
- package/lib/typescript/src/render/responder.web.d.ts +40 -0
- package/lib/typescript/src/render/touch.d.ts +26 -0
- package/lib/typescript/src/types.d.ts +72 -0
- package/lib/typescript/src/world/Scoreboard.d.ts +65 -0
- package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
- package/lib/typescript/src/world/World.d.ts +199 -0
- package/lib/typescript/src/world/desc.d.ts +17 -0
- package/lib/typescript/src/world/effects.d.ts +156 -0
- package/lib/typescript/src/world/quat.d.ts +31 -0
- package/lib/typescript/src/world/types.d.ts +233 -0
- package/lib/web/audio-worklet.js +29 -0
- package/lib/web/engine_core_bg.wasm +0 -0
- package/lib/web/index.js +7974 -0
- package/lib/web/types/src/assets/AssetBytesCache.d.ts +6 -0
- package/lib/web/types/src/assets/AssetCache.d.ts +8 -0
- package/lib/web/types/src/assets/AssetLoader.d.ts +10 -0
- package/lib/web/types/src/assets/CacheGeneration.d.ts +2 -0
- package/lib/web/types/src/assets/IndexedDbCache.d.ts +19 -0
- package/lib/web/types/src/assets/ProceduralCache.d.ts +32 -0
- package/lib/web/types/src/assets/font.d.ts +52 -0
- package/lib/web/types/src/assets/loft.d.ts +30 -0
- package/lib/web/types/src/assets/model.d.ts +47 -0
- package/lib/web/types/src/assets/modelling.d.ts +156 -0
- package/lib/web/types/src/assets/shape.d.ts +202 -0
- package/lib/web/types/src/assets/source.d.ts +7 -0
- package/lib/web/types/src/assets/storage.d.ts +6 -0
- package/lib/web/types/src/assets/storage.shared.d.ts +6 -0
- package/lib/web/types/src/assets/surface.d.ts +16 -0
- package/lib/web/types/src/assets/texture.d.ts +29 -0
- package/lib/web/types/src/drawing/DrawingCanvas.d.ts +3 -0
- package/lib/web/types/src/drawing/DrawingDocument.d.ts +209 -0
- package/lib/web/types/src/drawing/types.d.ts +11 -0
- package/lib/web/types/src/index.d.ts +41 -0
- package/lib/web/types/src/input/Joystick.d.ts +12 -0
- package/lib/web/types/src/input/keyboard.d.ts +16 -0
- package/lib/web/types/src/media/audio.d.ts +45 -0
- package/lib/web/types/src/media/haptics.d.ts +21 -0
- package/lib/web/types/src/media/output.d.ts +3 -0
- package/lib/web/types/src/native/BrowserEngine.d.ts +7 -0
- package/lib/web/types/src/native/EngineBridge.d.ts +21 -0
- package/lib/web/types/src/native/NativeNayanEngine.d.ts +9 -0
- package/lib/web/types/src/native/prepare.d.ts +1 -0
- package/lib/web/types/src/native/spec/NativeNayanEngine.d.ts +181 -0
- package/lib/web/types/src/render/GameView.d.ts +94 -0
- package/lib/web/types/src/render/camera.d.ts +5 -0
- package/lib/web/types/src/render/host.d.ts +15 -0
- package/lib/web/types/src/render/meshes.d.ts +44 -0
- package/lib/web/types/src/render/quality.d.ts +45 -0
- package/lib/web/types/src/render/responder.d.ts +39 -0
- package/lib/web/types/src/render/touch.d.ts +25 -0
- package/lib/web/types/src/types.d.ts +71 -0
- package/lib/web/types/src/world/Scoreboard.d.ts +64 -0
- package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
- package/lib/web/types/src/world/World.d.ts +198 -0
- package/lib/web/types/src/world/desc.d.ts +16 -0
- package/lib/web/types/src/world/effects.d.ts +155 -0
- package/lib/web/types/src/world/quat.d.ts +30 -0
- package/lib/web/types/src/world/types.d.ts +232 -0
- package/native/android/CMakeLists.txt +34 -0
- package/native/android/NayanEngineSpec.h +15 -0
- package/native/android/build.gradle +26 -0
- package/native/android/codegen/CMakeLists.txt +3 -0
- package/native/android/proguard-rules.pro +2 -0
- package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceView.java +234 -0
- package/native/android/src/main/java/com/nayanui/engine/EngineSurfaceViewManager.java +45 -0
- package/native/android/src/main/java/com/nayanui/engine/NayanEnginePackage.java +24 -0
- package/native/core/build/EngineCore.xcframework/Info.plist +43 -0
- package/native/core/build/EngineCore.xcframework/ios-arm64/libengine_core.a +0 -0
- package/native/core/build/EngineCore.xcframework/ios-arm64-simulator/libengine_core.a +0 -0
- package/native/core/build/android/arm64-v8a/libengine_core.a +0 -0
- package/native/core/build/android/armeabi-v7a/libengine_core.a +0 -0
- package/native/core/build/android/x86/libengine_core.a +0 -0
- package/native/core/build/android/x86_64/libengine_core.a +0 -0
- package/native/core/include/drawing-licenses.txt +58 -0
- package/native/core/include/engine_core.h +322 -0
- package/native/cpp/NayanEngineModule.cpp +827 -0
- package/native/cpp/NayanEngineModule.h +144 -0
- package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
- package/native/cpp/generated/NayanEngineSpecJSI.h +921 -0
- package/native/ios/NayanEngineProvider.h +5 -0
- package/native/ios/NayanEngineProvider.mm +21 -0
- package/native/ios/NayanEngineSurface.mm +223 -0
- package/native/scripts/check-package.mjs +39 -0
- package/package.json +162 -4
- package/react-native.config.js +18 -0
- package/src/native/spec/NativeNayanEngine.ts +226 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Share concurrent requests across loader variants; failed requests can always be retried. */
|
|
2
|
+
export declare function assetBytes(key: string, load: () => Promise<ArrayBuffer>): Promise<ArrayBuffer>;
|
|
3
|
+
/** A decoder rejected the payload: a later load must fetch fresh bytes, not replay bad data. */
|
|
4
|
+
export declare function forgetAssetBytes(key: string | undefined): void;
|
|
5
|
+
/** Clearing disk must also prevent an earlier request from retaining its old bytes. */
|
|
6
|
+
export declare function clearAssetBytes(): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explicitly removes the engine's saved geometry and original model/texture/font/audio files.
|
|
3
|
+
* Also clears temporary download bytes. Existing worlds and loaded handles remain usable;
|
|
4
|
+
* registrations are session resources and will be rebuilt/reloaded on a future app launch.
|
|
5
|
+
* Custom ProceduralStorage adapters belong to their host and are not cleared by this function.
|
|
6
|
+
* Rejects if storage cannot be cleared, allowing a settings screen to report the failure.
|
|
7
|
+
*/
|
|
8
|
+
export declare function clearAssetCache(): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EngineBridge } from '../native/EngineBridge';
|
|
2
|
+
import { type AssetSource } from './source';
|
|
3
|
+
/** Shared session handles; source-byte persistence stays in AssetBytesCache and Rust. */
|
|
4
|
+
export declare class AssetLoader<T> {
|
|
5
|
+
private readonly name;
|
|
6
|
+
private readonly loads;
|
|
7
|
+
constructor(name: string);
|
|
8
|
+
load(source: AssetSource, decode: (native: EngineBridge, bytes: ArrayBuffer) => T, variant?: readonly (string | number | boolean)[]): Promise<T>;
|
|
9
|
+
private error;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class IndexedDbCache {
|
|
2
|
+
private readonly database;
|
|
3
|
+
private tail;
|
|
4
|
+
private pending;
|
|
5
|
+
private generation;
|
|
6
|
+
private clearOperation;
|
|
7
|
+
private constructor();
|
|
8
|
+
static open(): Promise<IndexedDbCache>;
|
|
9
|
+
private enqueue;
|
|
10
|
+
/** The Uint8Array is an owned copy made by Rust, never a view into growable WASM memory. */
|
|
11
|
+
write(name: string, bytes: Uint8Array, geometry: boolean): Promise<void>;
|
|
12
|
+
read(name: string): Promise<Uint8Array | undefined>;
|
|
13
|
+
remove(name: string): Promise<void>;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
flush(): Promise<void>;
|
|
16
|
+
cleared(): Promise<void>;
|
|
17
|
+
/** Read recent geometry only. Large source files remain in IndexedDB until requested by a loader. */
|
|
18
|
+
warm(canFit: (size: number) => boolean, restore: (name: string, bytes: Uint8Array) => boolean): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Optional storage override. The engine selects a best-effort platform cache by default. */
|
|
2
|
+
export interface ProceduralStorage {
|
|
3
|
+
read(key: string): Uint8Array | null;
|
|
4
|
+
write(key: string, bytes: Uint8Array): void | Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Persists the output of a deterministic model factory, including nested model arrays/objects.
|
|
8
|
+
* Hits register saved vertices directly: no procedural tessellation, painting or optimization.
|
|
9
|
+
* Imported/skinned/textured models are intentionally excluded; their own loaders retain their rigs.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ProceduralCache {
|
|
12
|
+
readonly revision: string;
|
|
13
|
+
private storage;
|
|
14
|
+
private memory;
|
|
15
|
+
private hits;
|
|
16
|
+
private builds;
|
|
17
|
+
private invalid;
|
|
18
|
+
private failures;
|
|
19
|
+
private writes;
|
|
20
|
+
constructor(revision: string, storage?: ProceduralStorage | undefined);
|
|
21
|
+
get stats(): {
|
|
22
|
+
hits: number;
|
|
23
|
+
builds: number;
|
|
24
|
+
invalid: number;
|
|
25
|
+
failures: number;
|
|
26
|
+
pendingWrites: number;
|
|
27
|
+
};
|
|
28
|
+
flush(): Promise<void>;
|
|
29
|
+
get<T>(key: string, build: () => T): T;
|
|
30
|
+
private encode;
|
|
31
|
+
private restore;
|
|
32
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Vec3 } from '../types';
|
|
2
|
+
import type { Color } from '../world/types';
|
|
3
|
+
import { type Geometry } from './shape';
|
|
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;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Vec3 } from '../types';
|
|
2
|
+
import type { AssetSource } from './source';
|
|
3
|
+
export type ModelOptions = {
|
|
4
|
+
/** Move the model's bounding box center to the origin, so `position` is its middle. Default true. */
|
|
5
|
+
center?: boolean;
|
|
6
|
+
/** Scale it so its largest side is this long (e.g. 1 to match the built-in shapes). Default: keep its size. */
|
|
7
|
+
fit?: number;
|
|
8
|
+
/**
|
|
9
|
+
* How glossy, 0..1: a sharp sun highlight and a reflection of the sky that grows at grazing angles.
|
|
10
|
+
* 0 is matte; around 0.8 reads as car paint or glass. Default 0.
|
|
11
|
+
*/
|
|
12
|
+
shine?: number;
|
|
13
|
+
};
|
|
14
|
+
/** A loaded model: pass it as an entity's `mesh`. Colliders sized from the mesh fit its bounding box. */
|
|
15
|
+
export type Model = {
|
|
16
|
+
/** Bounding box size [x, y, z] at scale 1 (after `fit`). */
|
|
17
|
+
readonly size: Vec3;
|
|
18
|
+
/** Mesh id in the core. */
|
|
19
|
+
readonly id: number;
|
|
20
|
+
};
|
|
21
|
+
/** An animation embedded in a loaded GLB. */
|
|
22
|
+
export type ModelClip = {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly duration: number;
|
|
25
|
+
};
|
|
26
|
+
export type LoadedModel = Model & {
|
|
27
|
+
readonly animations: readonly ModelClip[];
|
|
28
|
+
readonly jointCount: number;
|
|
29
|
+
};
|
|
30
|
+
/** A registered mesh's geometry, aliasing native memory. */
|
|
31
|
+
export declare function nativeGeometry(mesh: number): {
|
|
32
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
33
|
+
indices: Uint32Array<ArrayBuffer>;
|
|
34
|
+
};
|
|
35
|
+
/** Independent materials share core geometry without overwriting an existing model's appearance. */
|
|
36
|
+
export declare function registerModelMesh(mesh: number, shine: number): number;
|
|
37
|
+
/**
|
|
38
|
+
* Initializes the engine automatically. Loads a glTF model once; pass it as an entity's `mesh`. Meshes, node transforms, material colors
|
|
39
|
+
* and the base color texture are kept (one texture per model); skeletal animation clips are available through `animations` and `World.playClip`.
|
|
40
|
+
* Every entity using the model is drawn in one instanced draw call.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const tree = await loadModel(require("./assets/tree.glb"), { fit: 2 });
|
|
44
|
+
* world.spawn({ mesh: tree, position: [0, 1, 0], physics: "fixed" });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function loadModel(source: AssetSource, options?: ModelOptions): Promise<LoadedModel>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { Vec3 } from '../types';
|
|
2
|
+
import type { Color, Quat } from '../world/types';
|
|
3
|
+
import type { Model } from './model';
|
|
4
|
+
import { type Geometry, type ShapeOptions } from './shape';
|
|
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 {};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { type MeshGeometry } from '../render/meshes';
|
|
2
|
+
import { type Shape, type Vec3 } from '../types';
|
|
3
|
+
import type { Color, Quat } from '../world/types';
|
|
4
|
+
import { type Model } from './model';
|
|
5
|
+
import type { OptimizeOptions } from './modelling';
|
|
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 {};
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProceduralStorage } from './ProceduralCache';
|
|
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>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProceduralStorage } from './ProceduralCache';
|
|
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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Vec3 } from '../types';
|
|
2
|
+
import type { Geometry, SurfaceColor } from './shape';
|
|
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;
|
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DrawingCanvasProps } from './types';
|
|
2
|
+
export type { DrawingCanvasProps } from './types';
|
|
3
|
+
export declare const DrawingCanvas: import("react").MemoExoticComponent<({ document: drawing, mode, background, active, onError, onChange, style }: DrawingCanvasProps) => import("react").JSX.Element>;
|