voxljs 0.1.0 → 0.1.1
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/dist/audio/SpatialAudioEngine.d.ts +10 -0
- package/dist/audio/SpatialAudioEngine.js +80 -0
- package/dist/audio/SpatialAudioEngine.js.map +1 -1
- package/dist/core/VoxelEngine.d.ts +99 -0
- package/dist/core/VoxelEngine.js +181 -0
- package/dist/core/VoxelEngine.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/input/InputManager.d.ts +45 -6
- package/dist/input/InputManager.js +178 -31
- package/dist/input/InputManager.js.map +1 -1
- package/dist/input/index.d.ts +1 -1
- package/dist/input/index.js +1 -1
- package/dist/input/index.js.map +1 -1
- package/dist/materials/Material.d.ts +6 -0
- package/dist/materials/Material.js +12 -0
- package/dist/materials/Material.js.map +1 -1
- package/dist/perf/EntityTickScheduler.d.ts +71 -0
- package/dist/perf/EntityTickScheduler.js +202 -0
- package/dist/perf/EntityTickScheduler.js.map +1 -0
- package/dist/perf/SpatialEntityGrid.d.ts +47 -0
- package/dist/perf/SpatialEntityGrid.js +200 -0
- package/dist/perf/SpatialEntityGrid.js.map +1 -0
- package/dist/perf/index.d.ts +2 -0
- package/dist/perf/index.js +2 -0
- package/dist/perf/index.js.map +1 -1
- package/dist/physics/VoxelPhysicsWorld.d.ts +308 -0
- package/dist/physics/VoxelPhysicsWorld.js +1020 -0
- package/dist/physics/VoxelPhysicsWorld.js.map +1 -0
- package/dist/physics/index.d.ts +1 -0
- package/dist/physics/index.js +1 -0
- package/dist/physics/index.js.map +1 -1
- package/dist/renderers/WebGLRenderer.js +1 -0
- package/dist/renderers/WebGLRenderer.js.map +1 -1
- package/dist/renderers/webgl/WebGLProgram.js +18 -19
- package/dist/renderers/webgl/WebGLProgram.js.map +1 -1
- package/dist/renderers/webgl/WebGLState.d.ts +17 -0
- package/dist/renderers/webgl/WebGLState.js +115 -1
- package/dist/renderers/webgl/WebGLState.js.map +1 -1
- package/dist/voxel/GrassFieldSystem.d.ts +186 -0
- package/dist/voxel/GrassFieldSystem.js +723 -0
- package/dist/voxel/GrassFieldSystem.js.map +1 -0
- package/dist/voxel/SilhouetteLightVolumes.d.ts +13 -2
- package/dist/voxel/SilhouetteLightVolumes.js +384 -78
- package/dist/voxel/SilhouetteLightVolumes.js.map +1 -1
- package/dist/voxel/VoxImporter.d.ts +32 -0
- package/dist/voxel/VoxImporter.js +228 -0
- package/dist/voxel/VoxImporter.js.map +1 -1
- package/dist/voxel/VoxelBrushes.d.ts +110 -0
- package/dist/voxel/VoxelBrushes.js +248 -0
- package/dist/voxel/VoxelBrushes.js.map +1 -0
- package/dist/voxel/VoxelPotatoShader.d.ts +8 -2
- package/dist/voxel/VoxelPotatoShader.js +68 -4
- package/dist/voxel/VoxelPotatoShader.js.map +1 -1
- package/dist/voxel/VoxelSilhouetteShadows.d.ts +69 -11
- package/dist/voxel/VoxelSilhouetteShadows.js +653 -32
- package/dist/voxel/VoxelSilhouetteShadows.js.map +1 -1
- package/dist/voxel/index.d.ts +4 -2
- package/dist/voxel/index.js +4 -2
- package/dist/voxel/index.js.map +1 -1
- package/dist/world/VoxelMobAISystem.d.ts +183 -0
- package/dist/world/VoxelMobAISystem.js +492 -0
- package/dist/world/VoxelMobAISystem.js.map +1 -0
- package/dist/world/index.d.ts +1 -0
- package/dist/world/index.js +1 -0
- package/dist/world/index.js.map +1 -1
- package/llms.txt +301 -0
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector3, type ColorRepresentation, type Vector3Like } from '../math/index.js';
|
|
1
|
+
import { Color, Vector3, type ColorRepresentation, type Vector3Like } from '../math/index.js';
|
|
2
2
|
import { BufferGeometry } from '../core/BufferGeometry.js';
|
|
3
3
|
import { ShaderMaterial } from '../materials/ShaderMaterial.js';
|
|
4
4
|
import { Mesh } from '../core/Mesh.js';
|
|
@@ -19,8 +19,10 @@ export interface VoxelGraphicsPreset {
|
|
|
19
19
|
sunAngleThreshold: number;
|
|
20
20
|
}
|
|
21
21
|
export declare const VOXEL_GRAPHICS_PRESETS: Record<VoxelGraphicsPresetId, VoxelGraphicsPreset>;
|
|
22
|
-
export declare const VOXEL_SILHOUETTE_SHADOW_VERTEX_SHADER = "\nattribute float extrudeDist;\n\nvarying float vExtrudeDist;\nvarying float vFogDepth;\n\nvoid main() {\n vExtrudeDist = extrudeDist;\n vec4 worldPosition = modelMatrix * vec4(position, 1.0);\n vec4 mvPosition = viewMatrix * worldPosition;\n vFogDepth = -mvPosition.z;\n
|
|
23
|
-
export declare const VOXEL_SILHOUETTE_SHADOW_FRAGMENT_SHADER = "\nuniform vec3 uShadowColor;\nuniform float uBaseOpacity;\nuniform float uMaxExtrudeDist;\nuniform float uPenumbraSoftness;\nuniform float uFogEnabled;\nuniform float uFogNear;\nuniform float uFogFar;\n\nvarying float vExtrudeDist;\nvarying float vFogDepth;\n\nvoid main() {\n float normDist = clamp(vExtrudeDist / max(0.001, uMaxExtrudeDist), 0.0, 1.0);\n // Fake penumbra: crisp near the caster (extrudeDist ~ 0), softly fading further from the caster\n float fadeStart = 1.0 - clamp(uPenumbraSoftness, 0.05, 0.95);\n float penumbraFade = 1.0 - smoothstep(fadeStart, 1.0, normDist);\n float distFalloff = mix(1.0, 0.28, normDist) * penumbraFade;\n float alpha = uBaseOpacity * distFalloff;\n\n if (uFogEnabled > 0.5) {\n float fogFactor = clamp((vFogDepth - uFogNear) / max(1.0, uFogFar - uFogNear), 0.0, 1.0);\n alpha *= (1.0 - fogFactor);\n }\n\n if (alpha < 0.003) discard;\n gl_FragColor = vec4(uShadowColor, alpha);\n}\n";
|
|
22
|
+
export declare const VOXEL_SILHOUETTE_SHADOW_VERTEX_SHADER = "\nattribute float extrudeDist;\n\nuniform float uDepthClamp;\n\nvarying float vExtrudeDist;\nvarying float vFogDepth;\n\nvoid main() {\n vExtrudeDist = extrudeDist;\n vec4 worldPosition = modelMatrix * vec4(position, 1.0);\n vec4 mvPosition = viewMatrix * worldPosition;\n vFogDepth = -mvPosition.z;\n vec4 clipPos = projectionMatrix * mvPosition;\n if (uDepthClamp > 0.5 && clipPos.w > 0.0 && clipPos.z > clipPos.w * 0.99999) {\n clipPos.z = clipPos.w * 0.99999;\n }\n gl_Position = clipPos;\n}\n";
|
|
23
|
+
export declare const VOXEL_SILHOUETTE_SHADOW_FRAGMENT_SHADER = "\nuniform vec3 uShadowColor;\nuniform float uBaseOpacity;\nuniform float uMaxExtrudeDist;\nuniform float uPenumbraSoftness;\nuniform float uFogEnabled;\nuniform float uFogNear;\nuniform float uFogFar;\nuniform float uStencilPass;\n\nvarying float vExtrudeDist;\nvarying float vFogDepth;\n\nvoid main() {\n // Hardware stencil shadow volume pass must never discard back caps or far side walls,\n // otherwise Z-fail front/back parity breaks and creates camera-dependent shadow inversion.\n if (uStencilPass > 0.5) {\n gl_FragColor = vec4(0.0);\n return;\n }\n\n float normDist = clamp(vExtrudeDist / max(0.001, uMaxExtrudeDist), 0.0, 1.0);\n // Fake penumbra: crisp near the caster (extrudeDist ~ 0), softly fading further from the caster\n float fadeStart = 1.0 - clamp(uPenumbraSoftness, 0.05, 0.95);\n float penumbraFade = 1.0 - smoothstep(fadeStart, 1.0, normDist);\n float distFalloff = mix(1.0, 0.28, normDist) * penumbraFade;\n float alpha = uBaseOpacity * distFalloff;\n\n if (uFogEnabled > 0.5) {\n float fogFactor = clamp((vFogDepth - uFogNear) / max(1.0, uFogFar - uFogNear), 0.0, 1.0);\n alpha *= (1.0 - fogFactor);\n }\n\n if (alpha < 0.003) discard;\n gl_FragColor = vec4(uShadowColor, alpha);\n}\n";
|
|
24
|
+
export declare const VOXEL_SILHOUETTE_SHADOW_OVERLAY_VERTEX_SHADER = "\nvoid main() {\n gl_Position = vec4(position.xy, 0.0, 1.0);\n}\n";
|
|
25
|
+
export declare const VOXEL_SILHOUETTE_SHADOW_OVERLAY_FRAGMENT_SHADER = "\nuniform vec3 uShadowColor;\nuniform float uBaseOpacity;\n\nvoid main() {\n if (uBaseOpacity < 0.003) discard;\n gl_FragColor = vec4(uShadowColor, uBaseOpacity);\n}\n";
|
|
24
26
|
export interface VoxelSilhouetteShadowMaterialOptions {
|
|
25
27
|
shadowColor?: ColorRepresentation;
|
|
26
28
|
baseOpacity?: number;
|
|
@@ -31,8 +33,18 @@ export interface VoxelSilhouetteShadowMaterialOptions {
|
|
|
31
33
|
fogFar?: number;
|
|
32
34
|
polygonOffsetFactor?: number;
|
|
33
35
|
polygonOffsetUnits?: number;
|
|
36
|
+
/** Enables hardware two-sided Z-fail stencil shadow volume mode (`colorWrite: false`). */
|
|
37
|
+
stencilVolumePass?: boolean;
|
|
34
38
|
}
|
|
35
39
|
export declare function createVoxelSilhouetteShadowMaterial(options?: VoxelSilhouetteShadowMaterialOptions): ShaderMaterial;
|
|
40
|
+
export declare function createVoxelSilhouetteShadowOverlayMaterial(sharedUniforms: {
|
|
41
|
+
uShadowColor: {
|
|
42
|
+
value: Color;
|
|
43
|
+
};
|
|
44
|
+
uBaseOpacity: {
|
|
45
|
+
value: number;
|
|
46
|
+
};
|
|
47
|
+
}): ShaderMaterial;
|
|
36
48
|
export interface ShadowSliceBounds {
|
|
37
49
|
originX: number;
|
|
38
50
|
originY: number;
|
|
@@ -102,6 +114,39 @@ export interface ProjectSilhouetteEdgesOptions {
|
|
|
102
114
|
* projected shadow quads with ray travel distance (`extrudeDist`).
|
|
103
115
|
*/
|
|
104
116
|
export declare function projectSilhouetteEdges(options: ProjectSilhouetteEdgesOptions): ProjectedShadowQuad[];
|
|
117
|
+
export type VoxelSilhouetteShadowRenderMode = 'stencil-volume' | 'quad-projection';
|
|
118
|
+
export interface BuildClosedShadowVolumeOptions extends ShadowSliceBounds {
|
|
119
|
+
getVoxel: (vx: number, vy: number, vz: number) => number;
|
|
120
|
+
sunDirection: Vector3Like;
|
|
121
|
+
isSolid?: (blockId: number) => boolean;
|
|
122
|
+
/** Minimum caster grid Y coordinate to scan (default: originY). */
|
|
123
|
+
minCasterY?: number;
|
|
124
|
+
/** Extrusion distance along `-sunDirection` in voxel grid units (default: `28`). */
|
|
125
|
+
extrudeDistance?: number;
|
|
126
|
+
/** Inward bias along `-sunDirection` in voxel grid units to eliminate front-face self-shadowing (default: `0.045`). */
|
|
127
|
+
frontBias?: number;
|
|
128
|
+
/** World units per voxel grid unit (default: `1.0`). */
|
|
129
|
+
voxelScale?: number;
|
|
130
|
+
/** Optional world-space origin offset added after scaling by `voxelScale`. */
|
|
131
|
+
worldOffset?: Vector3Like;
|
|
132
|
+
}
|
|
133
|
+
export interface ClosedShadowVolumeData {
|
|
134
|
+
positions: Float32Array;
|
|
135
|
+
normals: Float32Array;
|
|
136
|
+
extrudeDists: Float32Array;
|
|
137
|
+
indices: Uint32Array;
|
|
138
|
+
frontCapQuadCount: number;
|
|
139
|
+
silhouetteEdgeCount: number;
|
|
140
|
+
volumeQuadCount: number;
|
|
141
|
+
vertexCount: number;
|
|
142
|
+
indexCount: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Builds a 100% mathematically watertight, T-junction-free closed 3D shadow volume `∂(F × [frontBias, extrudeDistance])`
|
|
146
|
+
* directly from exposed sun-facing voxel faces `F` and their exact oriented silhouette boundary chain `∂F`,
|
|
147
|
+
* extruded along `-sunDirection` with outward CCW winding for two-sided Z-fail hardware stencil shadows.
|
|
148
|
+
*/
|
|
149
|
+
export declare function buildClosedSilhouetteShadowVolume(options: BuildClosedShadowVolumeOptions): ClosedShadowVolumeData;
|
|
105
150
|
export interface VoxelSilhouetteShadowsOptions {
|
|
106
151
|
/** Voxel sampler returning block/material ID at integer grid coordinates `(vx, vy, vz)`. */
|
|
107
152
|
getVoxel: (vx: number, vy: number, vz: number) => number;
|
|
@@ -125,22 +170,30 @@ export interface VoxelSilhouetteShadowsOptions {
|
|
|
125
170
|
minCasterY?: number;
|
|
126
171
|
/** Optional maximum dirty slices to rebuild per `update()` call (default: `64`). */
|
|
127
172
|
maxSlicesPerUpdate?: number;
|
|
128
|
-
/** Project caster edges directly onto the ground plane
|
|
173
|
+
/** Project caster edges directly onto the ground plane in `quad-projection` mode (default: `false`). */
|
|
129
174
|
flattenCasterToGround?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Shadow rendering pipeline:
|
|
177
|
+
* - `'stencil-volume'` (default): Closed silhouette shadow volumes extruded along `-sunDirection`
|
|
178
|
+
* rendered via hardware two-sided Z-fail stencil + single-pass darkening quad (real, zero-overlap shadows
|
|
179
|
+
* across flat ground, stepped terraces, overhangs, and vertical walls).
|
|
180
|
+
* - `'quad-projection'`: Legacy direct alpha-blended projected shadow quads.
|
|
181
|
+
*/
|
|
182
|
+
renderMode?: VoxelSilhouetteShadowRenderMode;
|
|
183
|
+
/** Front-cap inward bias along `-sunDirection` in voxel grid units for `'stencil-volume'` mode (default: `0.045`). */
|
|
184
|
+
frontBias?: number;
|
|
130
185
|
/** Initial graphics quality preset (`'low' | 'balanced' | 'high'`, default: `'balanced'`). */
|
|
131
186
|
preset?: VoxelGraphicsPresetId;
|
|
132
187
|
/** Custom shadow material options. */
|
|
133
188
|
materialOptions?: VoxelSilhouetteShadowMaterialOptions;
|
|
134
189
|
}
|
|
135
190
|
/**
|
|
136
|
-
* VoxelSilhouetteShadows — Lightweight, event-driven silhouette & sun-ray
|
|
137
|
-
*
|
|
191
|
+
* VoxelSilhouetteShadows — Lightweight, event-driven silhouette & sun-ray shadow volume
|
|
192
|
+
* system for @voxl optimized for older integrated GPUs (no shadow maps or per-pixel raytracing).
|
|
138
193
|
*
|
|
139
|
-
* -
|
|
140
|
-
* -
|
|
141
|
-
*
|
|
142
|
-
* - Batches all shadow quads into a single merged `Mesh` with `polygonOffset`, `depthWrite: false`,
|
|
143
|
-
* and an `extrudeDist` penumbra-fading shader.
|
|
194
|
+
* - Extracts exposed sun-facing voxel surfaces and their exact oriented silhouette boundary edges.
|
|
195
|
+
* - Extrudes watertight silhouette shadow volumes along `-sunDirection` for hardware two-sided
|
|
196
|
+
* Z-fail stencil shadow rendering (zero overlap, crisp architectural shadows on terraces & walls).
|
|
144
197
|
* - Event-driven deferred updates: zero per-frame CPU/GPU work when voxels and sun angle are static.
|
|
145
198
|
*/
|
|
146
199
|
export declare class VoxelSilhouetteShadows {
|
|
@@ -156,9 +209,14 @@ export declare class VoxelSilhouetteShadows {
|
|
|
156
209
|
minCasterY: number | undefined;
|
|
157
210
|
maxSlicesPerUpdate: number;
|
|
158
211
|
flattenCasterToGround: boolean;
|
|
212
|
+
readonly renderMode: VoxelSilhouetteShadowRenderMode;
|
|
213
|
+
frontBias: number;
|
|
159
214
|
readonly material: ShaderMaterial;
|
|
160
215
|
readonly geometry: BufferGeometry;
|
|
161
216
|
readonly mesh: Mesh;
|
|
217
|
+
readonly overlayMaterial: ShaderMaterial | null;
|
|
218
|
+
readonly overlayGeometry: BufferGeometry | null;
|
|
219
|
+
readonly overlayMesh: Mesh | null;
|
|
162
220
|
private _enabled;
|
|
163
221
|
private _presetId;
|
|
164
222
|
private readonly _lastBuiltSunDir;
|