@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.
- package/LICENSE +21 -0
- package/NayanEngine.podspec +28 -0
- package/README.md +308 -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 +249 -0
- package/lib/module/assets/font.js +139 -0
- package/lib/module/assets/loft.js +142 -0
- package/lib/module/assets/model.js +96 -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 +38 -0
- package/lib/module/assets/storage.web.js +38 -0
- package/lib/module/assets/surface.js +47 -0
- package/lib/module/assets/texture.js +69 -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 +39 -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 +97 -0
- package/lib/module/media/haptics.js +82 -0
- package/lib/module/media/output.web.js +66 -0
- package/lib/module/native/BrowserEngine.js +568 -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 +317 -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/light.js +24 -0
- package/lib/module/render/meshes.js +159 -0
- package/lib/module/render/quality.js +119 -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/render/useWorld.js +72 -0
- package/lib/module/types.js +30 -0
- package/lib/module/world/Scoreboard.js +161 -0
- package/lib/module/world/TransformBatch.js +128 -0
- package/lib/module/world/World.js +704 -0
- package/lib/module/world/color.js +80 -0
- package/lib/module/world/desc.js +187 -0
- package/lib/module/world/effects.js +463 -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 +45 -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 +58 -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 +45 -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 +26 -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 +211 -0
- package/lib/typescript/src/render/GameView.d.ts +107 -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/light.d.ts +12 -0
- package/lib/typescript/src/render/meshes.d.ts +45 -0
- package/lib/typescript/src/render/quality.d.ts +48 -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/render/useWorld.d.ts +20 -0
- package/lib/typescript/src/types.d.ts +81 -0
- package/lib/typescript/src/world/Scoreboard.d.ts +75 -0
- package/lib/typescript/src/world/TransformBatch.d.ts +39 -0
- package/lib/typescript/src/world/World.d.ts +207 -0
- package/lib/typescript/src/world/color.d.ts +18 -0
- package/lib/typescript/src/world/desc.d.ts +17 -0
- package/lib/typescript/src/world/effects.d.ts +157 -0
- package/lib/typescript/src/world/quat.d.ts +31 -0
- package/lib/typescript/src/world/types.d.ts +238 -0
- package/lib/web/audio-worklet.js +29 -0
- package/lib/web/engine_core_bg.wasm +0 -0
- package/lib/web/index.js +8240 -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 +44 -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 +57 -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 +44 -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 +25 -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 +210 -0
- package/lib/web/types/src/render/GameView.d.ts +106 -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/light.d.ts +11 -0
- package/lib/web/types/src/render/meshes.d.ts +44 -0
- package/lib/web/types/src/render/quality.d.ts +47 -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/render/useWorld.d.ts +19 -0
- package/lib/web/types/src/types.d.ts +80 -0
- package/lib/web/types/src/world/Scoreboard.d.ts +74 -0
- package/lib/web/types/src/world/TransformBatch.d.ts +38 -0
- package/lib/web/types/src/world/World.d.ts +206 -0
- package/lib/web/types/src/world/color.d.ts +17 -0
- package/lib/web/types/src/world/desc.d.ts +16 -0
- package/lib/web/types/src/world/effects.d.ts +156 -0
- package/lib/web/types/src/world/quat.d.ts +30 -0
- package/lib/web/types/src/world/types.d.ts +237 -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 +295 -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 +331 -0
- package/native/cpp/NayanEngineModule.cpp +998 -0
- package/native/cpp/NayanEngineModule.h +174 -0
- package/native/cpp/generated/NayanEngineSpecJSI.cpp +2 -0
- package/native/cpp/generated/NayanEngineSpecJSI.h +1026 -0
- package/native/ios/NayanEngineProvider.h +5 -0
- package/native/ios/NayanEngineProvider.mm +21 -0
- package/native/ios/NayanEngineSurface.mm +252 -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 +265 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { resolveColor } from "./color.js";
|
|
4
|
+
export const TRANSFORM_STRIDE = 16;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Explicit draw-only updates, applied in one native call by `flush()`. `world.update` flushes
|
|
8
|
+
* `world.transforms` before stepping; flush yourself before reading positions or animating. Records and scratch storage are reused; values are
|
|
9
|
+
* copied when queued, never retained by reference. The scalar methods (`position`, `rotation`,
|
|
10
|
+
* `scale`, `color`, `transform`) allocate nothing; consecutive calls for the same entity share one
|
|
11
|
+
* record.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const batch = world.transforms;
|
|
15
|
+
* for (const p of pieces) batch.transform(p.entity, p.x, 0, p.z, 0, p.qy, 0, p.qw);
|
|
16
|
+
* batch.flush();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class TransformBatch {
|
|
20
|
+
data = new Float64Array(TRANSFORM_STRIDE * 32);
|
|
21
|
+
count = 0;
|
|
22
|
+
constructor(commit) {
|
|
23
|
+
this.commit = commit;
|
|
24
|
+
}
|
|
25
|
+
record(entity, flags) {
|
|
26
|
+
// Merge into the previous record when it updates the same entity (the layout is fixed per field).
|
|
27
|
+
if (this.count > 0) {
|
|
28
|
+
const last = (this.count - 1) * TRANSFORM_STRIDE;
|
|
29
|
+
if (this.data[last] === entity) {
|
|
30
|
+
this.data[last + 1] = this.data[last + 1] | flags;
|
|
31
|
+
return last;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const offset = this.count * TRANSFORM_STRIDE;
|
|
35
|
+
if (offset + TRANSFORM_STRIDE > this.data.length) {
|
|
36
|
+
const grown = new Float64Array(this.data.length * 2);
|
|
37
|
+
grown.set(this.data);
|
|
38
|
+
this.data = grown;
|
|
39
|
+
}
|
|
40
|
+
this.count++;
|
|
41
|
+
this.data[offset] = entity;
|
|
42
|
+
this.data[offset + 1] = flags;
|
|
43
|
+
return offset;
|
|
44
|
+
}
|
|
45
|
+
position(entity, x, y, z) {
|
|
46
|
+
const offset = this.record(entity, 2);
|
|
47
|
+
this.data[offset + 2] = x;
|
|
48
|
+
this.data[offset + 3] = y;
|
|
49
|
+
this.data[offset + 4] = z;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Rotation quaternion [x, y, z, w]. */
|
|
53
|
+
rotation(entity, x, y, z, w) {
|
|
54
|
+
const offset = this.record(entity, 4);
|
|
55
|
+
this.data[offset + 5] = x;
|
|
56
|
+
this.data[offset + 6] = y;
|
|
57
|
+
this.data[offset + 7] = z;
|
|
58
|
+
this.data[offset + 8] = w;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Uniform scale, or per axis. */
|
|
62
|
+
scale(entity, x, y = x, z = x) {
|
|
63
|
+
const offset = this.record(entity, 8);
|
|
64
|
+
this.data[offset + 9] = x;
|
|
65
|
+
this.data[offset + 10] = y;
|
|
66
|
+
this.data[offset + 11] = z;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** RGBA color; alpha defaults to 1. */
|
|
70
|
+
color(entity, r, g, b, a = 1) {
|
|
71
|
+
const offset = this.record(entity, 16);
|
|
72
|
+
this.data[offset + 12] = r;
|
|
73
|
+
this.data[offset + 13] = g;
|
|
74
|
+
this.data[offset + 14] = b;
|
|
75
|
+
this.data[offset + 15] = a;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Position and rotation together (the common per-frame update for a moving piece). */
|
|
79
|
+
transform(entity, x, y, z, qx, qy, qz, qw) {
|
|
80
|
+
const offset = this.record(entity, 6);
|
|
81
|
+
this.data[offset + 2] = x;
|
|
82
|
+
this.data[offset + 3] = y;
|
|
83
|
+
this.data[offset + 4] = z;
|
|
84
|
+
this.data[offset + 5] = qx;
|
|
85
|
+
this.data[offset + 6] = qy;
|
|
86
|
+
this.data[offset + 7] = qz;
|
|
87
|
+
this.data[offset + 8] = qw;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Queued records (merged per entity). */
|
|
91
|
+
get size() {
|
|
92
|
+
return this.count;
|
|
93
|
+
}
|
|
94
|
+
set(entity, options) {
|
|
95
|
+
const {
|
|
96
|
+
position,
|
|
97
|
+
rotation,
|
|
98
|
+
scale,
|
|
99
|
+
color
|
|
100
|
+
} = options;
|
|
101
|
+
const flags = (position ? 2 : 0) | (rotation ? 4 : 0) | (scale !== undefined ? 8 : 0) | (color ? 16 : 0);
|
|
102
|
+
if (!flags) return;
|
|
103
|
+
const offset = this.record(entity, flags);
|
|
104
|
+
if (position) this.data.set(position, offset + 2);
|
|
105
|
+
if (rotation) this.data.set(rotation, offset + 5);
|
|
106
|
+
if (typeof scale === 'number') this.data.fill(scale, offset + 9, offset + 12);else if (scale) this.data.set(scale, offset + 9);
|
|
107
|
+
if (color) this.writeColor(offset, color);
|
|
108
|
+
}
|
|
109
|
+
writeColor(offset, input) {
|
|
110
|
+
const color = resolveColor(input);
|
|
111
|
+
this.data[offset + 12] = color[0];
|
|
112
|
+
this.data[offset + 13] = color[1];
|
|
113
|
+
this.data[offset + 14] = color[2];
|
|
114
|
+
this.data[offset + 15] = color[3] ?? 1;
|
|
115
|
+
}
|
|
116
|
+
flush() {
|
|
117
|
+
if (!this.count) return 0;
|
|
118
|
+
try {
|
|
119
|
+
return this.commit(this.data, this.count);
|
|
120
|
+
} finally {
|
|
121
|
+
this.count = 0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
clear() {
|
|
125
|
+
this.count = 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=TransformBatch.js.map
|