@margoengine/voxel 0.0.0-stage → 0.1.0
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 +201 -0
- package/NOTICE +4 -0
- package/README.md +1671 -3
- package/dist/bevel.d.ts +79 -0
- package/dist/bevel.js +453 -0
- package/dist/blocks-BabtpQT-.js +179 -0
- package/dist/blocks.d.ts +220 -0
- package/dist/border.d.ts +9 -0
- package/dist/chunk-BCoaKSn4.js +158 -0
- package/dist/chunk.d.ts +112 -0
- package/dist/codec-ZZFj1xvt.js +410 -0
- package/dist/codec.d.ts +125 -0
- package/dist/codec.js +1 -0
- package/dist/debris.d.ts +114 -0
- package/dist/debris.js +387 -0
- package/dist/faces-DUR7LhrN.js +146 -0
- package/dist/faces.d.ts +7 -0
- package/dist/fluids.d.ts +74 -0
- package/dist/fluids.js +226 -0
- package/dist/generate.d.ts +78 -0
- package/dist/generate.js +99 -0
- package/dist/gi.d.ts +76 -0
- package/dist/gi.js +264 -0
- package/dist/gpu-mesher.d.ts +77 -0
- package/dist/gpu-mesher.js +461 -0
- package/dist/granular-mpm.d.ts +32 -0
- package/dist/granular-mpm.js +46 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/light-rgb.d.ts +71 -0
- package/dist/light-rgb.js +287 -0
- package/dist/light-worker.d.ts +84 -0
- package/dist/light-worker.js +110 -0
- package/dist/light.d.ts +108 -0
- package/dist/light.js +332 -0
- package/dist/light.worker.d.ts +1 -0
- package/dist/lightmap.d.ts +50 -0
- package/dist/lightmap.js +68 -0
- package/dist/lod.d.ts +87 -0
- package/dist/lod.js +182 -0
- package/dist/mesher.d.ts +214 -0
- package/dist/mesher.js +539 -0
- package/dist/mesher.worker.d.ts +1 -0
- package/dist/model-data-D_rIKJCQ.js +41 -0
- package/dist/model-data.d.ts +21 -0
- package/dist/model-mesh-C4Gi6bMM.js +122 -0
- package/dist/model-mesh.d.ts +21 -0
- package/dist/model-surface.d.ts +5 -0
- package/dist/models.d.ts +74 -0
- package/dist/models.js +308 -0
- package/dist/objects.d.ts +73 -0
- package/dist/objects.js +152 -0
- package/dist/octants-C_Ic7gdn.js +10 -0
- package/dist/octants.d.ts +16 -0
- package/dist/origin-DsMelUxs.js +23 -0
- package/dist/origin.d.ts +7 -0
- package/dist/physics.d.ts +147 -0
- package/dist/physics.js +486 -0
- package/dist/query.d.ts +166 -0
- package/dist/query.js +305 -0
- package/dist/render-post.d.ts +6 -0
- package/dist/render.d.ts +296 -0
- package/dist/render.js +1613 -0
- package/dist/shared/borrowed.d.ts +44 -0
- package/dist/smooth-CEwHkXli.js +968 -0
- package/dist/smooth-clip.d.ts +24 -0
- package/dist/smooth-lod.d.ts +118 -0
- package/dist/smooth-lod.js +244 -0
- package/dist/smooth.d.ts +171 -0
- package/dist/smooth.js +1 -0
- package/dist/stream.d.ts +201 -0
- package/dist/stream.js +402 -0
- package/dist/terrain.worker.d.ts +1 -0
- package/dist/textures.d.ts +86 -0
- package/dist/ticks.d.ts +126 -0
- package/dist/ticks.js +239 -0
- package/dist/unit-light-Ch7roJgB.js +7 -0
- package/dist/vox.d.ts +237 -0
- package/dist/vox.js +780 -0
- package/dist/wind-data.d.ts +13 -0
- package/dist/wind.d.ts +68 -0
- package/dist/wind.js +170 -0
- package/dist/worker-DlGRxlc4.js +44 -0
- package/dist/worker-pool-sPyC6jCE.js +93 -0
- package/dist/workers/light.js +1 -0
- package/dist/workers/mesher.js +1 -0
- package/dist/workers/terrain.js +1 -0
- package/dist/world-CelTlft2.js +153 -0
- package/dist/world.d.ts +117 -0
- package/package.json +175 -6
package/dist/vox.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { Vec3 } from '@margoengine/math';
|
|
2
|
+
import type { BlockTypeOptions } from './blocks.js';
|
|
3
|
+
import { VoxelWorld } from './world.js';
|
|
4
|
+
/** One model of a {@link VoxScene}: a SIZE chunk and the XYZI chunk after it. */
|
|
5
|
+
export interface VoxModel {
|
|
6
|
+
/** Size in voxels along MagicaVoxel's x, y and z (z points up), each 1-256. */
|
|
7
|
+
size: Vec3;
|
|
8
|
+
/**
|
|
9
|
+
* The voxels as stored, 4 bytes each: x, y, z (each below `size` on its axis) and a palette index 1-255. Order is
|
|
10
|
+
* kept; parseVox copies them out of the file.
|
|
11
|
+
*/
|
|
12
|
+
voxels: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A material (MATL chunk): the render properties of one palette colour. Typed fields are decoded from `attributes`;
|
|
16
|
+
* writeVox writes `attributes` with each typed field over its own key (the stored text is kept when it decodes to
|
|
17
|
+
* the same value, a key is added when missing and removed when its field is undefined).
|
|
18
|
+
*/
|
|
19
|
+
export interface VoxMaterial {
|
|
20
|
+
/** Material id: the palette index (1-255) it describes. */
|
|
21
|
+
id: number;
|
|
22
|
+
/** `_type` without its underscore: `'diffuse'`, `'metal'`, `'glass'`, `'emit'`, `'blend'` or `'media'`. */
|
|
23
|
+
type?: string;
|
|
24
|
+
/** `_weight`, 0-1: how much of `type` (metalness, transparency, emission). */
|
|
25
|
+
weight?: number;
|
|
26
|
+
/** `_rough`: roughness. */
|
|
27
|
+
rough?: number;
|
|
28
|
+
/** `_spec`: specular. */
|
|
29
|
+
spec?: number;
|
|
30
|
+
/** `_ior`: index of refraction. */
|
|
31
|
+
ior?: number;
|
|
32
|
+
/** `_att`: attenuation. */
|
|
33
|
+
att?: number;
|
|
34
|
+
/** `_flux`: emission power. */
|
|
35
|
+
flux?: number;
|
|
36
|
+
/** `_plastic`. */
|
|
37
|
+
plastic?: number;
|
|
38
|
+
/** Every property as stored, in file order: keys with their underscore, string values. Always set by parseVox. */
|
|
39
|
+
attributes?: Map<string, string>;
|
|
40
|
+
}
|
|
41
|
+
/** A layer (LAYR chunk). Typed fields work as on {@link VoxMaterial}. */
|
|
42
|
+
export interface VoxLayer {
|
|
43
|
+
/** Layer id: what transform nodes' `layer` refers to. */
|
|
44
|
+
id: number;
|
|
45
|
+
/** `_name`. */
|
|
46
|
+
name?: string;
|
|
47
|
+
/** `_hidden` (any value but `'0'` is true): pasteVoxModel skips the nodes of a hidden layer. */
|
|
48
|
+
hidden?: boolean;
|
|
49
|
+
/** The layer attributes as stored, in file order. Always set by parseVox. */
|
|
50
|
+
attributes?: Map<string, string>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A scene-graph node: a transform (nTRN) places its one child, a group (nGRP) holds transforms, a shape (nSHP) shows
|
|
54
|
+
* a model. MagicaVoxel's root is transform 0 over group 1. Typed fields work as on {@link VoxMaterial}.
|
|
55
|
+
*/
|
|
56
|
+
export type VoxNode = {
|
|
57
|
+
/** Node id, unique in the scene. */
|
|
58
|
+
id: number;
|
|
59
|
+
/** `_name`. */
|
|
60
|
+
name?: string;
|
|
61
|
+
/** `_hidden` (any value but `'0'` is true): pasteVoxModel skips hidden nodes. */
|
|
62
|
+
hidden?: boolean;
|
|
63
|
+
/** The node attributes as stored, in file order. Always set by parseVox. */
|
|
64
|
+
attributes?: Map<string, string>;
|
|
65
|
+
} & ({
|
|
66
|
+
/** A transform node (nTRN). */
|
|
67
|
+
type: 'transform';
|
|
68
|
+
/** Id of the group or shape node it places. */
|
|
69
|
+
child: number;
|
|
70
|
+
/** Id of its {@link VoxLayer}; -1 for none. */
|
|
71
|
+
layer: number;
|
|
72
|
+
/** Its keyframes (at least one); frame 0 is the still pose. */
|
|
73
|
+
frames: {
|
|
74
|
+
/**
|
|
75
|
+
* `_r`: a row-major 3 x 3 signed permutation matrix (9 entries; `p' = R p`), stored as the packed rotation
|
|
76
|
+
* byte. Undefined means identity.
|
|
77
|
+
*/
|
|
78
|
+
rotation?: readonly number[];
|
|
79
|
+
/** `_t`: integer translation of the child's centre. Undefined means 0. */
|
|
80
|
+
translation?: Vec3;
|
|
81
|
+
/** `_f`: the animation frame index of this keyframe, from 0. */
|
|
82
|
+
frame?: number;
|
|
83
|
+
/** The frame attributes as stored, in file order. Always set by parseVox. */
|
|
84
|
+
attributes?: Map<string, string>;
|
|
85
|
+
}[];
|
|
86
|
+
} | {
|
|
87
|
+
/** A group node (nGRP). */
|
|
88
|
+
type: 'group';
|
|
89
|
+
/** Ids of its transform nodes. */
|
|
90
|
+
children: number[];
|
|
91
|
+
} | {
|
|
92
|
+
/** A shape node (nSHP). */
|
|
93
|
+
type: 'shape';
|
|
94
|
+
/** Its models per keyframe (at least one). */
|
|
95
|
+
models: {
|
|
96
|
+
/** Index into {@link VoxScene.models}. */
|
|
97
|
+
model: number;
|
|
98
|
+
/** `_f`: the animation frame index from which this model shows. */
|
|
99
|
+
frame?: number;
|
|
100
|
+
/** The model attributes as stored, in file order. Always set by parseVox. */
|
|
101
|
+
attributes?: Map<string, string>;
|
|
102
|
+
}[];
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* A top-level chunk of a {@link VoxScene}, in file order. A chunk writeVox encodes from the scene's typed fields
|
|
106
|
+
* (`PACK`, `SIZE` with its `XYZI`, `nTRN`, `nGRP`, `nSHP`, `LAYR`, `RGBA`, `MATL`) has no bytes: it marks where the
|
|
107
|
+
* next item of that kind goes. Any other chunk (rOBJ, rCAM, NOTE, IMAP, META, MATT, a future one) keeps its bytes.
|
|
108
|
+
*/
|
|
109
|
+
export interface VoxChunk {
|
|
110
|
+
/** Four-character chunk id, such as `'rOBJ'`. */
|
|
111
|
+
id: string;
|
|
112
|
+
/** Content bytes of a kept chunk. */
|
|
113
|
+
content?: Uint8Array;
|
|
114
|
+
/** Child-chunk bytes of a kept chunk, as stored. */
|
|
115
|
+
children?: Uint8Array;
|
|
116
|
+
}
|
|
117
|
+
/** A MagicaVoxel `.vox` file: {@link parseVox} returns one and {@link writeVox} writes one. */
|
|
118
|
+
export interface VoxScene {
|
|
119
|
+
/** File version: 150 or 200 (MagicaVoxel 0.99.7 and later). */
|
|
120
|
+
version: number;
|
|
121
|
+
/** Models in file order; shape nodes refer to them by index. */
|
|
122
|
+
models: VoxModel[];
|
|
123
|
+
/**
|
|
124
|
+
* 256 RGBA8 colours, 4 bytes per palette index: index i at `4 * i`. Voxels use 1-255; index 0 holds the file's last
|
|
125
|
+
* (unused) colour. The file stores colour k as index k + 1 (the format's off-by-one). MagicaVoxel's default palette
|
|
126
|
+
* when the file has no RGBA chunk.
|
|
127
|
+
*/
|
|
128
|
+
palette: Uint8Array;
|
|
129
|
+
/** Materials (MATL chunks) in file order. */
|
|
130
|
+
materials: VoxMaterial[];
|
|
131
|
+
/** Scene-graph nodes in file order; empty in a version-150 file. */
|
|
132
|
+
nodes: VoxNode[];
|
|
133
|
+
/** Layers in file order. */
|
|
134
|
+
layers: VoxLayer[];
|
|
135
|
+
/**
|
|
136
|
+
* Every top-level chunk in file order, so writeVox reproduces the file byte for byte (items added past the last
|
|
137
|
+
* marker of their kind follow it). Omit it for a new scene: models, nodes, layers, palette, then materials.
|
|
138
|
+
*/
|
|
139
|
+
chunks?: VoxChunk[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Parses a MagicaVoxel `.vox` file (version 150 or 200). Models, palette, materials, scene graph and layers are
|
|
143
|
+
* decoded; every other chunk is kept as bytes in `chunks`, so {@link writeVox} gives the same bytes back (dictionary
|
|
144
|
+
* text that is not UTF-8 reads as windows-1252 and is written back in it while unchanged). The result
|
|
145
|
+
* shares no memory with `bytes`.
|
|
146
|
+
* @throws TypeError when `bytes` is not a Uint8Array or ArrayBuffer, or does not start with `VOX ` and a MAIN chunk.
|
|
147
|
+
* @throws RangeError for a truncated, oversized or inconsistent file: a chunk past its parent, trailing bytes, a SIZE
|
|
148
|
+
* outside 1-256 or without its XYZI, a voxel outside its SIZE or with palette index 0, a PACK count that does not
|
|
149
|
+
* match, a duplicate RGBA or PACK, an invalid rotation byte or attribute, or a scene graph with a missing, mistyped,
|
|
150
|
+
* shared or cyclic node reference.
|
|
151
|
+
*/
|
|
152
|
+
export declare function parseVox(bytes: Uint8Array | ArrayBuffer): VoxScene;
|
|
153
|
+
/** One problem {@link readVoxRenderDictionaries} found in a render chunk. The chunk itself is never changed. */
|
|
154
|
+
export interface VoxRenderDiagnostic {
|
|
155
|
+
/**
|
|
156
|
+
* `'malformed'`: the content does not follow the format's encoding (truncated, a count or string past the content,
|
|
157
|
+
* trailing bytes, a repeated key), so the chunk gives no dictionary. `'unsupported'`: well-formed data this reader
|
|
158
|
+
* leaves alone: a chunk over `maxBytes`, a dictionary over `maxEntries` (neither read), or child chunks (the content
|
|
159
|
+
* is still read; the children are kept, not interpreted).
|
|
160
|
+
*/
|
|
161
|
+
kind: 'malformed' | 'unsupported';
|
|
162
|
+
/** The chunk id. */
|
|
163
|
+
id: 'rOBJ' | 'rCAM';
|
|
164
|
+
/** The chunk's index in {@link VoxScene.chunks}. */
|
|
165
|
+
chunk: number;
|
|
166
|
+
/** What is wrong, with the byte offset inside the content where it applies. */
|
|
167
|
+
message: string;
|
|
168
|
+
}
|
|
169
|
+
/** The render settings a parsed scene keeps as bytes, decoded by {@link readVoxRenderDictionaries}. */
|
|
170
|
+
export interface VoxRenderDictionaries {
|
|
171
|
+
/** Each readable `rOBJ` (render object: one group of renderer settings, keyed by its `_type`), in file order. */
|
|
172
|
+
objects: Map<string, string>[];
|
|
173
|
+
/** Each readable `rCAM` (render camera) with its camera id, in file order. */
|
|
174
|
+
cameras: {
|
|
175
|
+
id: number;
|
|
176
|
+
attributes: Map<string, string>;
|
|
177
|
+
}[];
|
|
178
|
+
/** Every chunk that gave no dictionary, or gave one with a caveat, in file order. */
|
|
179
|
+
diagnostics: VoxRenderDiagnostic[];
|
|
180
|
+
}
|
|
181
|
+
/** Bounds for {@link readVoxRenderDictionaries}. */
|
|
182
|
+
export interface VoxRenderLimits {
|
|
183
|
+
/** Largest chunk content read, in bytes; default 1,048,576 (MagicaVoxel writes well under 1 KiB). */
|
|
184
|
+
maxBytes?: number;
|
|
185
|
+
/** Most key/value pairs read from one dictionary; default 4096. */
|
|
186
|
+
maxEntries?: number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Decodes the render settings a parsed scene keeps as raw chunks: each `rOBJ` is a DICT and each `rCAM` an int32
|
|
190
|
+
* camera id then a DICT, per the published format notes. Strings decode as {@link parseVox} decodes the dictionaries it
|
|
191
|
+
* types (UTF-8, else windows-1252) and a repeated key is malformed, as there. A chunk that cannot be read is reported
|
|
192
|
+
* in `diagnostics` and skipped, never thrown; `scene` is not modified, so {@link writeVox} still writes every chunk back
|
|
193
|
+
* byte for byte. The result is the input the voxel path tracer's `magicaVoxelLighting(objects)` and
|
|
194
|
+
* `magicaVoxelCamera(camera.attributes, objects)` take.
|
|
195
|
+
* @throws TypeError when `scene` is not an object, or `scene.chunks` is present but not an array.
|
|
196
|
+
* @throws RangeError when a limit is not an integer >= 0.
|
|
197
|
+
*/
|
|
198
|
+
export declare function readVoxRenderDictionaries(scene: VoxScene, limits?: VoxRenderLimits): VoxRenderDictionaries;
|
|
199
|
+
/**
|
|
200
|
+
* Writes `scene` as a `.vox` file. A parsed scene gives its file back byte for byte (except non-UTF-8 text and the
|
|
201
|
+
* reserved ids, written as -1); edits land where their chunks were. Anything writeVox writes, parseVox reads.
|
|
202
|
+
* @throws TypeError when a field has the wrong type, or `chunks` gives bytes for a chunk the typed fields encode.
|
|
203
|
+
* @throws RangeError for a value out of range (version, ids, sizes, voxels outside their size, rotations that are not
|
|
204
|
+
* signed permutations, non-integer translations), a scene graph parseVox would reject, or a file over 2 GiB.
|
|
205
|
+
*/
|
|
206
|
+
export declare function writeVox(scene: VoxScene): Uint8Array;
|
|
207
|
+
/**
|
|
208
|
+
* Writes voxels into `world` and returns how many cells changed. `model` is a {@link VoxModel}, pasted unrotated, or
|
|
209
|
+
* a whole {@link VoxScene}: every visible shape (hidden nodes and layers skipped) at frame 0 through its transforms,
|
|
210
|
+
* each model centred on its translation (a scene without nodes pastes its first model). MagicaVoxel's z (up) becomes
|
|
211
|
+
* world y and its y becomes world -z, and the pasted box (the models' sizes) has its minimum corner at cell `at`.
|
|
212
|
+
* `mapping[i]` is the block state for palette index i (0 skips those voxels). Without a mapping a scene's colours
|
|
213
|
+
* become block types named `vox:rrggbb` with that colour, defined in `world.blocks` unless already there; a colour
|
|
214
|
+
* with a metal, glass, blend, emit or media material gets {@link voxBlockOptions} and its options in the name
|
|
215
|
+
* (`vox:rrggbb:metalness=1`). A bare model
|
|
216
|
+
* has no palette, so it needs a mapping. Empty cells of a model leave the world as it was. Nothing is written when a
|
|
217
|
+
* check fails. Voxels are written chunk by chunk (each chunk's in file order), with the results of one
|
|
218
|
+
* {@link VoxelWorld.setBlock} per voxel: the same cells, dirty keys and count, and `onChange` once per changed cell
|
|
219
|
+
* right after it is written; only the order across chunks differs.
|
|
220
|
+
* @throws TypeError for a world that is not a VoxelWorld, a bare model without a mapping, or fields of the wrong type.
|
|
221
|
+
* @throws RangeError when `at` is not 3 integers, the pasted box leaves the world's y range or 32-bit x and z, a used
|
|
222
|
+
* mapping entry is not a defined block state, or the model or scene is invalid as for {@link writeVox}.
|
|
223
|
+
*/
|
|
224
|
+
export declare function pasteVoxModel(world: VoxelWorld, model: VoxModel | VoxScene, at: Vec3, mapping?: ArrayLike<number>): number;
|
|
225
|
+
/**
|
|
226
|
+
* Block-type options for a MagicaVoxel material, as {@link pasteVoxModel} defines its `vox:` types:
|
|
227
|
+
* - `metal` and `blend`: `metalness` = `_metal` if stored, else `_weight`.
|
|
228
|
+
* - `glass` (and `blend` with `_trans` or `_alpha`): a translucent block, `transmission` = `_trans`, else `_alpha`,
|
|
229
|
+
* else `_weight` for glass.
|
|
230
|
+
* - `emit`: `emissive` = `_weight * (1 + _flux)`. MagicaVoxel's power steps are not linear, so this is a starting
|
|
231
|
+
* point to tune.
|
|
232
|
+
* - `media`: a translucent block with `scatter` = `_weight`.
|
|
233
|
+
* - `metal`, `glass` and `blend`: `roughness` = `_rough` when stored.
|
|
234
|
+
* Key meanings follow the MagicaVoxel .vox MATL chunk notes (ephtracy/voxel-model, file-format semantics).
|
|
235
|
+
* A plain diffuse material gives `{}`.
|
|
236
|
+
*/
|
|
237
|
+
export declare function voxBlockOptions(material: VoxMaterial): BlockTypeOptions;
|