@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,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Declarative solid modelling and native mesh preparation. These produce ordinary Geometry,
|
|
4
|
+
// so solids, lathes, lofts, imported geometry and hand-authored parts compose through merge().
|
|
5
|
+
import NativeEngine from '../native/NativeNayanEngine';
|
|
6
|
+
import { preparedModel, prepareOptions, smoothNormals } from "./shape.js";
|
|
7
|
+
const vector = v => [v[0], v[1], v[2]];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An immutable, code-authored solid. Join primitives into a single surface, blend organic forms,
|
|
11
|
+
* drill holes, hollow shells and add reproducible rock/terrain detail before tessellating once.
|
|
12
|
+
* Distances use world units; primitives are centered at the origin, cylinders/tori use the Y axis.
|
|
13
|
+
*
|
|
14
|
+
* const torso = Solid.ellipsoid([0.5, 0.7, 0.3]).paint([0.5, 0.1, 0.9]);
|
|
15
|
+
* const neck = Solid.capsule([0, 0.5, 0], [0, 0.9, 0], 0.15);
|
|
16
|
+
* const geometry = solidGeometry(torso.blend(neck, 0.15), { resolution: 48 });
|
|
17
|
+
*/
|
|
18
|
+
export class Solid {
|
|
19
|
+
constructor(node) {
|
|
20
|
+
this.node = node;
|
|
21
|
+
}
|
|
22
|
+
static sphere(radius = 0.5) {
|
|
23
|
+
return new Solid({
|
|
24
|
+
kind: 'sphere',
|
|
25
|
+
radius
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
static ellipsoid(radii) {
|
|
29
|
+
return new Solid({
|
|
30
|
+
kind: 'ellipsoid',
|
|
31
|
+
radii: vector(radii)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Full width/height/depth. Rounding stays inside these dimensions. */
|
|
35
|
+
static box(size, radius = 0) {
|
|
36
|
+
return new Solid({
|
|
37
|
+
kind: 'box',
|
|
38
|
+
size: vector(size),
|
|
39
|
+
radius
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
static capsule(start, end, radius) {
|
|
43
|
+
return new Solid({
|
|
44
|
+
kind: 'capsule',
|
|
45
|
+
start: vector(start),
|
|
46
|
+
end: vector(end),
|
|
47
|
+
radius
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
static cylinder(radius, height) {
|
|
51
|
+
return new Solid({
|
|
52
|
+
kind: 'cylinder',
|
|
53
|
+
radius,
|
|
54
|
+
height
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Major radius to the tube center; minor radius of the tube itself. */
|
|
58
|
+
static torus(radius, tube) {
|
|
59
|
+
return new Solid({
|
|
60
|
+
kind: 'torus',
|
|
61
|
+
radius,
|
|
62
|
+
tube
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Balanced union for many parts; avoids building a deeply nested operation chain. */
|
|
66
|
+
static union(...solids) {
|
|
67
|
+
if (solids.length === 0) throw new Error('Solid.union needs at least one solid');
|
|
68
|
+
if (solids.length === 1) return solids[0];
|
|
69
|
+
const middle = Math.floor(solids.length / 2);
|
|
70
|
+
return Solid.union(...solids.slice(0, middle)).union(Solid.union(...solids.slice(middle)));
|
|
71
|
+
}
|
|
72
|
+
union(other) {
|
|
73
|
+
return new Solid({
|
|
74
|
+
kind: 'union',
|
|
75
|
+
a: this.node,
|
|
76
|
+
b: other.node,
|
|
77
|
+
blend: 0
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Smoothly weld overlapping forms; blend controls the transition width in world units. */
|
|
81
|
+
blend(other, blend) {
|
|
82
|
+
return new Solid({
|
|
83
|
+
kind: 'union',
|
|
84
|
+
a: this.node,
|
|
85
|
+
b: other.node,
|
|
86
|
+
blend
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
subtract(other) {
|
|
90
|
+
return new Solid({
|
|
91
|
+
kind: 'subtract',
|
|
92
|
+
a: this.node,
|
|
93
|
+
b: other.node
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
intersect(other) {
|
|
97
|
+
return new Solid({
|
|
98
|
+
kind: 'intersect',
|
|
99
|
+
a: this.node,
|
|
100
|
+
b: other.node
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
translate(position) {
|
|
104
|
+
return this.transform(position, [0, 0, 0, 1], [1, 1, 1]);
|
|
105
|
+
}
|
|
106
|
+
rotate(rotation) {
|
|
107
|
+
return this.transform([0, 0, 0], rotation, [1, 1, 1]);
|
|
108
|
+
}
|
|
109
|
+
scale(scale) {
|
|
110
|
+
return this.transform([0, 0, 0], [0, 0, 0, 1], typeof scale === 'number' ? [scale, scale, scale] : scale);
|
|
111
|
+
}
|
|
112
|
+
transform(position, rotation, scale) {
|
|
113
|
+
return new Solid({
|
|
114
|
+
kind: 'transform',
|
|
115
|
+
child: this.node,
|
|
116
|
+
position: vector(position),
|
|
117
|
+
rotation: [...rotation],
|
|
118
|
+
scale: vector(scale)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/** Vertex colors blend with the surface at smooth joins. Apply after subtract() to color cut walls. */
|
|
122
|
+
paint(color) {
|
|
123
|
+
return new Solid({
|
|
124
|
+
kind: 'paint',
|
|
125
|
+
child: this.node,
|
|
126
|
+
color: [color[0], color[1], color[2]]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** A shell centered on the original surface; thickness is its full wall thickness. */
|
|
130
|
+
shell(thickness) {
|
|
131
|
+
return new Solid({
|
|
132
|
+
kind: 'shell',
|
|
133
|
+
child: this.node,
|
|
134
|
+
thickness
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Seeded fractal value noise. Use a resolution fine enough to sample its smallest features. */
|
|
138
|
+
displace(options) {
|
|
139
|
+
return new Solid({
|
|
140
|
+
kind: 'displace',
|
|
141
|
+
child: this.node,
|
|
142
|
+
amplitude: options.amplitude,
|
|
143
|
+
frequency: options.frequency ?? 2,
|
|
144
|
+
seed: options.seed ?? 0,
|
|
145
|
+
octaves: options.octaves ?? 3
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/** Serializable recipe for caching or inspecting a generated asset. */
|
|
149
|
+
toJSON() {
|
|
150
|
+
return this.node;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function unpack(buffers) {
|
|
154
|
+
if (!(buffers.vertices instanceof ArrayBuffer) || !(buffers.indices instanceof ArrayBuffer)) throw new Error('modelling: invalid native geometry result');
|
|
155
|
+
return {
|
|
156
|
+
vertices: new Float32Array(buffers.vertices),
|
|
157
|
+
indices: new Uint32Array(buffers.indices)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Tessellates into editable, unregistered geometry. Prefer createSolid() for automatic model reuse. */
|
|
162
|
+
export function solidGeometry(solid, options = {}) {
|
|
163
|
+
if (typeof NativeEngine?.geometrySolid !== 'function') throw new Error("solidGeometry: rebuild the app with the engine's native modelling tools");
|
|
164
|
+
return unpack(NativeEngine.geometrySolid(JSON.stringify({
|
|
165
|
+
solid,
|
|
166
|
+
resolution: options.resolution ?? 48,
|
|
167
|
+
uv: options.uv ?? 'xy'
|
|
168
|
+
})));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Tessellates, cleans and registers a solid once, then returns its cached model on later calls
|
|
173
|
+
* with the same recipe/options. White vertex colors can be tinted per spawned entity. Temporary
|
|
174
|
+
* intermediate meshes consume no IDs. Prepared solids persist automatically when platform storage
|
|
175
|
+
* is available; storage failure falls back to building. Call after warmUpEngine(), before spawning a run.
|
|
176
|
+
*/
|
|
177
|
+
export function createSolid(solid, options = {}) {
|
|
178
|
+
if (typeof NativeEngine?.solidPrepare !== 'function') throw new Error("createSolid: rebuild the app with the engine's Rust asset preparation");
|
|
179
|
+
const {
|
|
180
|
+
resolution = 48,
|
|
181
|
+
uv = 'xy',
|
|
182
|
+
shine = 0,
|
|
183
|
+
optimize = true
|
|
184
|
+
} = options;
|
|
185
|
+
const mesh = NativeEngine.solidPrepare(JSON.stringify({
|
|
186
|
+
solid,
|
|
187
|
+
resolution,
|
|
188
|
+
uv
|
|
189
|
+
}), prepareOptions({
|
|
190
|
+
...options,
|
|
191
|
+
optimize
|
|
192
|
+
}));
|
|
193
|
+
if (mesh < 0) throw new Error(`createSolid: ${NativeEngine.loadError()}`);
|
|
194
|
+
return preparedModel(mesh, shine);
|
|
195
|
+
}
|
|
196
|
+
const wholeBuffer = array => array.byteOffset === 0 && array.byteLength === array.buffer.byteLength ? array.buffer : array.slice().buffer;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Returns new geometry, preserving the input and its normal/color/UV seams. Removes degenerate
|
|
200
|
+
* triangles and unused/identical vertices, simplifies within the error bound, then orders buffers
|
|
201
|
+
* for GPU reuse. The error bound may prevent reaching the requested ratio. Opaque static meshes only:
|
|
202
|
+
* do not use on skinning buffers or meshes whose vertex indices are used by external code.
|
|
203
|
+
*/
|
|
204
|
+
export function optimizeGeometry(geometry, options = {}) {
|
|
205
|
+
if (typeof NativeEngine?.geometryOptimize !== 'function') throw new Error("optimizeGeometry: rebuild the app with the engine's native modelling tools");
|
|
206
|
+
return unpack(NativeEngine.geometryOptimize(wholeBuffer(geometry.vertices), wholeBuffer(geometry.indices), options.ratio ?? 1, options.error ?? 0.001, options.lockBorders ?? true));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Independently simplifies the original at each requested ratio, avoiding accumulated error.
|
|
211
|
+
* Cache/register the results once. The caller selects a level when camera distance changes.
|
|
212
|
+
*/
|
|
213
|
+
export function createGeometryLods(geometry, ratios = [1, 0.5, 0.25], options = {}) {
|
|
214
|
+
if (ratios.length === 0 || ratios.some((r, i) => !Number.isFinite(r) || r <= 0 || r > 1 || i > 0 && r >= ratios[i - 1])) throw new Error('createGeometryLods: ratios must strictly decrease within (0, 1]');
|
|
215
|
+
return ratios.map(ratio => optimizeGeometry(geometry, {
|
|
216
|
+
...options,
|
|
217
|
+
ratio
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
/** Cheap counts and bounds without registering a mesh. */
|
|
221
|
+
export function getGeometryStats(geometry) {
|
|
222
|
+
const v = geometry.vertices;
|
|
223
|
+
const min = [Infinity, Infinity, Infinity];
|
|
224
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
225
|
+
for (let i = 0; i < v.length; i += 11) for (let k = 0; k < 3; k++) {
|
|
226
|
+
min[k] = Math.min(min[k], v[i + k]);
|
|
227
|
+
max[k] = Math.max(max[k], v[i + k]);
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
vertices: v.length / 11,
|
|
231
|
+
triangles: geometry.indices.length / 3,
|
|
232
|
+
bytes: v.byteLength + geometry.indices.byteLength,
|
|
233
|
+
bounds: v.length ? {
|
|
234
|
+
min,
|
|
235
|
+
max,
|
|
236
|
+
size: [max[0] - min[0], max[1] - min[1], max[2] - min[2]]
|
|
237
|
+
} : null
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Copies/sculpts one smooth surface and updates its normals. Deform hard-edged parts separately. */
|
|
242
|
+
export function deformGeometry(geometry, deform) {
|
|
243
|
+
const vertices = geometry.vertices.slice();
|
|
244
|
+
for (let i = 0; i < vertices.length; i += 11) {
|
|
245
|
+
const point = deform([vertices[i], vertices[i + 1], vertices[i + 2]], [vertices[i + 9], vertices[i + 10]]);
|
|
246
|
+
if (point.some(v => !Number.isFinite(v))) throw new Error('deformGeometry: position must be finite');
|
|
247
|
+
vertices.set(point, i);
|
|
248
|
+
}
|
|
249
|
+
return smoothNormals({
|
|
250
|
+
vertices,
|
|
251
|
+
indices: geometry.indices.slice()
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=modelling.js.map
|