import * as THREE from "three"; import { Actor, ActorComponent, Systems } from "@jolly-pixel/engine"; import { BlockRegistry } from "./blocks/BlockRegistry.ts"; import type { BlockDefinition } from "./blocks/BlockDefinition.ts"; import { BlockShapeRegistry } from "./blocks/BlockShapeRegistry.ts"; import type { BlockShape } from "./blocks/BlockShape.ts"; import { type RapierAPI, type RapierWorld } from "./collision/VoxelColliderBuilder.ts"; import { VoxelSerializer, type VoxelWorldJSON, type VoxelObjectLayerJSON, type VoxelObjectJSON } from "./serialization/VoxelSerializer.ts"; import { TilesetManager, type TilesetDefinition } from "./tileset/TilesetManager.ts"; import { VoxelWorld } from "./world/VoxelWorld.ts"; import { VoxelLayer, type VoxelLayerConfigurableOptions } from "./world/VoxelLayer.ts"; import type { VoxelEntry, VoxelCoord } from "./world/types.ts"; import { type FACE } from "./utils/math.ts"; import type { VoxelLayerHookListener } from "./hooks.ts"; type MaterialCustomizerFn = (material: THREE.MeshLambertMaterial | THREE.MeshStandardMaterial, tilesetId: string) => void; export declare const VoxelRotation: { /** No rotation (default). */ readonly None: 0; /** 90° counter-clockwise around the Y axis. */ readonly CCW90: 1; /** 180° around the Y axis. */ readonly Deg180: 2; /** 270° counter-clockwise (= 90° clockwise) around the Y axis. */ readonly CW90: 3; }; export interface VoxelSetOptions { position: THREE.Vector3Like; blockId: number; /** Y-axis rotation. Use the `VoxelRotation` constants. Default: `VoxelRotation.None` */ rotation?: typeof VoxelRotation[keyof typeof VoxelRotation]; /** Mirror the block around x = 0.5. Default: false */ flipX?: boolean; /** Mirror the block around z = 0.5. Default: false */ flipZ?: boolean; /** Mirror the block around y = 0.5. Default: false */ flipY?: boolean; } export interface VoxelRemoveOptions { position: THREE.Vector3Like; } export interface VoxelRendererOptions { /** * @default 16 */ chunkSize?: number; /** * Enables collision shapes when provided. * disabled by default to avoid forcing Rapier as a dependency for users who don't need physics. */ rapier?: { /** Rapier3D module (static API) */ api: RapierAPI; /** Rapier3D world instance */ world: RapierWorld; }; /** * @default "lambert" * The type of material to use for rendering chunks. "standard" supports * roughness and metalness maps but is more expensive to render; "lambert" * is faster but only supports a simple diffuse map. */ material?: "lambert" | "standard"; /** * Optional callback to customize each material after it is created. * Called with the material instance and the tileset ID it corresponds to */ materialCustomizer?: MaterialCustomizerFn; /** * Optional list of layer names to create on initialization. */ layers?: string[]; /** * Optional initial block definitions to register. * Block ID 0 is reserved for air */ blocks?: BlockDefinition[]; /** * Optional block shapes to register in addition to the default * shapes provided by BlockShapeRegistry.createDefault(). */ shapes?: BlockShape[]; /** * Alpha value below which fragments are discarded (cutout transparency). * Set to 0 to disable alpha testing entirely (useful when your tileset tiles * have no transparency, or during debugging to confirm geometry is present). * @default 0.1 */ alphaTest?: number; /** * Optional logger instance for debug output. * Uses the engine's default logger if not provided. */ logger?: Systems.Logger; /** * Optional callback that is called whenever a layer is added, removed, or updated. * Useful for synchronizing external systems with changes to the voxel world. */ onLayerUpdated?: VoxelLayerHookListener; } /** * ActorComponent that renders a layered voxel world as chunked THREE.js meshes. * * Usage: * const vr = actor.addComponentAndGet(VoxelRenderer, { chunkSize: 16 }); * await vr.loadTileset({ id: "default", src: "tileset.png", tileSize: 16, cols: 16, rows: 16 }); * vr.blockRegistry.register({ id: 1, name: "Grass", shapeId: "fullCube", ... }); * const layer = vr.addLayer("Ground"); * vr.setVoxel(layer.id, 0, 0, 0, 1); */ export declare class VoxelRenderer extends ActorComponent { #private; readonly world: VoxelWorld; readonly blockRegistry: BlockRegistry; readonly shapeRegistry: BlockShapeRegistry; readonly tilesetManager: TilesetManager; readonly serializer: VoxelSerializer; constructor(actor: Actor, options?: VoxelRendererOptions); awake(): void; update(_deltaTime: number): void; destroy(): void; /** * Places a voxel in the specified layer. * Rotation is expressed as Y-axis steps (0–3 × 90°); flipX/flipZ mirror the block. */ setVoxel(layerName: string, options: VoxelSetOptions): void; removeVoxel(layerName: string, options: VoxelRemoveOptions): void; setVoxelBulk(layerName: string, entries: VoxelSetOptions[]): void; removeVoxelBulk(layerName: string, entries: VoxelRemoveOptions[]): void; getVoxel(position: THREE.Vector3Like): VoxelEntry | undefined; getVoxel(layerName: string, position: THREE.Vector3Like): VoxelEntry | undefined; getVoxelNeighbour(position: THREE.Vector3Like, face: FACE): VoxelEntry | undefined; getVoxelNeighbour(layerName: string, position: THREE.Vector3Like, face: FACE): VoxelEntry | undefined; getLayer(name: string): VoxelLayer | undefined; addLayer(name: string, options?: VoxelLayerConfigurableOptions): VoxelLayer; updateLayer(name: string, options: Partial): boolean; removeLayer(name: string): boolean; setLayerOffset(name: string, offset: VoxelCoord): void; translateLayer(name: string, delta: VoxelCoord): void; moveLayer(name: string, direction: "up" | "down"): void; getLayerCenter(name: string): THREE.Vector3 | null; addObjectLayer(name: string, options?: Partial>): VoxelObjectLayerJSON; removeObjectLayer(name: string): boolean; getObjectLayer(name: string): VoxelObjectLayerJSON | undefined; getObjectLayers(): readonly VoxelObjectLayerJSON[]; updateObjectLayer(name: string, patch: Partial>): boolean; addObject(layerName: string, object: VoxelObjectJSON): boolean; removeObject(layerName: string, objectId: string): boolean; updateObject(layerName: string, objectId: string, patch: Partial): boolean; loadTileset(def: TilesetDefinition): Promise; save(): VoxelWorldJSON; load(data: VoxelWorldJSON): Promise; markAllChunksDirty(source?: string): void; } export {}; //# sourceMappingURL=VoxelRenderer.d.ts.map