From de01b895550563f6f6767eb842b7d1e10ae94f37 Mon Sep 17 00:00:00 2001 From: etienne Date: Fri, 20 Dec 2024 00:14:28 +0000 Subject: [PATCH] fix: formatting --- src/api/WorldComputeProxy.ts | 9 +- src/api/WorldProcessing.ts | 41 ++-- src/api/world-compute-worker.ts | 4 +- src/api/world-compute.ts | 16 +- src/datacontainers/BlocksBatch.ts | 216 +++++++++---------- src/datacontainers/BoardContainer.ts | 38 ++-- src/datacontainers/ChunkContainer.ts | 1 + src/datacontainers/ChunksIndexer.ts | 8 +- src/datacontainers/GroundPatch.ts | 15 +- src/datacontainers/PatchBase.ts | 17 +- src/demo-samples/configs/world_dev_setup.ts | 11 +- src/misc/ItemsInventory.ts | 12 +- src/misc/WorldEnv.ts | 18 +- src/procgen/Biome.ts | 19 +- src/procgen/NoiseSampler.ts | 1 + src/tools/SchematicLoader.ts | 8 +- src/utils/convert.ts | 6 +- src/utils/data.ts | 62 +++--- src/utils/index.ts | 2 +- src/utils/math.ts | 3 +- src/utils/misc.ts | 43 ++-- src/utils/process.ts | 44 ++-- src/utils/spatial.ts | 217 ++++++++++---------- src/utils/types.ts | 2 +- 24 files changed, 432 insertions(+), 381 deletions(-) diff --git a/src/api/WorldComputeProxy.ts b/src/api/WorldComputeProxy.ts index 240a5ce..5766e00 100644 --- a/src/api/WorldComputeProxy.ts +++ b/src/api/WorldComputeProxy.ts @@ -4,12 +4,7 @@ import workerpool, { Pool } from 'workerpool' import { ChunkContainer, ChunkStub } from '../datacontainers/ChunkContainer' import { WorldEnv } from '../index' import { SpawnedItems } from '../misc/ItemsInventory' -import { - ChunkId, - ChunkKey, - PatchId, - PatchKey, -} from '../utils/types' +import { ChunkId, ChunkKey, PatchId, PatchKey } from '../utils/types' import { ComputeTask } from './world-compute' @@ -73,7 +68,7 @@ export class WorldComputeProxy { this.customProxy = customProxy } - isReady(){ + isReady() { return !!WorldComputeProxy.workerPool } diff --git a/src/api/WorldProcessing.ts b/src/api/WorldProcessing.ts index 1e85333..a8b2c95 100644 --- a/src/api/WorldProcessing.ts +++ b/src/api/WorldProcessing.ts @@ -1,27 +1,28 @@ -import { BlocksBatch } from "../datacontainers/BlocksBatch" -import { WorldUtils } from "../index" -import { ProcessType, WorldProcess } from "../utils/types" +import { BlocksBatch } from '../datacontainers/BlocksBatch' +import { WorldUtils } from '../index' +import { ProcessType, WorldProcess } from '../utils/types' -type WorldProcessImpl = new (args: any) => WorldProcess //typeof WorldProcess +type WorldProcessImpl = new (args: any) => WorldProcess // typeof WorldProcess export const ProcessMapping: Record = { - [ProcessType.BlocksBatch]: BlocksBatch + [ProcessType.BlocksBatch]: BlocksBatch, } export class WorldProcessing { - static parseArgs(rawArgs: any) { - const args = rawArgs.map((arg: any) => - arg instanceof Array - ? arg.map(item => WorldUtils.convert.parseThreeStub(item)) - : WorldUtils.convert.parseThreeStub(arg), - ) - return args - } - static async process(processType: ProcessType, processArgs: any) { - processArgs = WorldProcessing.parseArgs(processArgs) - const processClass = ProcessMapping[processType] - const processInstance = new processClass(processArgs) - await processInstance.process() - return processInstance.toStub() - } + static parseArgs(rawArgs: any) { + const args = rawArgs.map((arg: any) => + arg instanceof Array + ? arg.map(item => WorldUtils.convert.parseThreeStub(item)) + : WorldUtils.convert.parseThreeStub(arg), + ) + return args + } + + static async process(processType: ProcessType, processArgs: any) { + processArgs = WorldProcessing.parseArgs(processArgs) + const ProcessClass = ProcessMapping[processType] + const processInstance = new ProcessClass(processArgs) + await processInstance.process() + return processInstance.toStub() + } } diff --git a/src/api/world-compute-worker.ts b/src/api/world-compute-worker.ts index 548085c..c769fe1 100644 --- a/src/api/world-compute-worker.ts +++ b/src/api/world-compute-worker.ts @@ -1,5 +1,6 @@ import { WorldUtils } from '../index' import { ProcessType } from '../utils/types' + import { WorldComputeApi } from './world-compute' import { WorldProcessing } from './WorldProcessing' @@ -32,6 +33,7 @@ export const WorldWorkerInit = (workerPool: any) => { workerPool.worker({ ...worldComputeApiWrap, - [ProcessType.BlocksBatch]: async (...rawArgs: any) => WorldProcessing.process(ProcessType.BlocksBatch, rawArgs[0]) + [ProcessType.BlocksBatch]: async (...rawArgs: any) => + WorldProcessing.process(ProcessType.BlocksBatch, rawArgs[0]), }) } diff --git a/src/api/world-compute.ts b/src/api/world-compute.ts index f1de8ef..2e7f6f6 100644 --- a/src/api/world-compute.ts +++ b/src/api/world-compute.ts @@ -40,8 +40,6 @@ import { import { PatchBase } from '../datacontainers/PatchBase' import { GroundChunk } from '../datacontainers/ChunkFactory' - - const defaultDistribution: DistributionParams = { ...DistributionProfiles[DistributionProfile.MEDIUM], minDistance: 10, @@ -140,7 +138,9 @@ export const bakePatch = (boundsOrPatchKey: PatchKey | Box2) => { export const bakeGroundLayer = (boundsOrPatchKey: PatchKey | Box2) => { const groundPatch = new GroundPatch(boundsOrPatchKey) const { valueRange } = groundPatch - const biomeBoundsInfluences = Biome.instance.getBoundsInfluences(groundPatch.bounds) + const biomeBoundsInfluences = Biome.instance.getBoundsInfluences( + groundPatch.bounds, + ) const blocks = groundPatch.iterBlocksQuery(undefined, false) let blockIndex = 0 for (const block of blocks) { @@ -174,7 +174,11 @@ export const retrieveOvergroundItems = async (bounds: Box2) => { asVect2(defaultItemDims), ) for (const pos of spawnPlaces) { - const blockBiome = WorldUtils.process.getBlockBiome(pos, bounds, boundsBiomeInfluences) + const blockBiome = WorldUtils.process.getBlockBiome( + pos, + bounds, + boundsBiomeInfluences, + ) const { level, biome, landscapeIndex } = computeGroundBlock( asVect3(pos), blockBiome, @@ -216,7 +220,9 @@ export const queryLastBlockData = async (queriedLoc: Vector2) => { getPatchId(spawnOrigin, WorldEnv.current.patchDimensions), ) const groundPatch = new GroundPatch(patchKey) - const biomeBoundsInfluences = Biome.instance.getBoundsInfluences(groundPatch.bounds) + const biomeBoundsInfluences = Biome.instance.getBoundsInfluences( + groundPatch.bounds, + ) const blockBiome = WorldUtils.process.getBlockBiome( spawnOrigin, groundPatch.bounds, diff --git a/src/datacontainers/BlocksBatch.ts b/src/datacontainers/BlocksBatch.ts index 296921a..d7a503b 100644 --- a/src/datacontainers/BlocksBatch.ts +++ b/src/datacontainers/BlocksBatch.ts @@ -1,118 +1,126 @@ -import { Vector2 } from "three" -import { computeGroundBlock } from "../api/world-compute" -import { WorldEnv, Biome, WorldUtils, WorldComputeProxy } from "../index" -import { serializePatchId, getPatchId, asVect3 } from "../utils/convert" -import { PatchKey, GroundBlock, WorldProcess, ProcessType } from "../utils/types" -import { GroundPatch } from "./GroundPatch" +import { Vector2 } from 'three' + +import { computeGroundBlock } from '../api/world-compute' +import { WorldEnv, Biome, WorldUtils, WorldComputeProxy } from '../index' +import { serializePatchId, getPatchId, asVect3 } from '../utils/convert' +import { + PatchKey, + GroundBlock, + WorldProcess, + ProcessType, +} from '../utils/types' + +import { GroundPatch } from './GroundPatch' export type BlocksBatchArgs = { - posBatch: Vector2[] + posBatch: Vector2[] } export class BlocksBatch implements WorldProcess { - patchIndex: Record = {} - blocks: any[] = [] - constructor(posBatch: Vector2[]) { - // sort input blocks by patch - // const blocksByPatch: Record = {} - for (const pos of posBatch) { - const patchId = getPatchId(pos, WorldEnv.current.patchDimensions) - const patchKey = serializePatchId(patchId) - this.patchIndex[patchKey] = this.patchIndex[patchKey] || [] - this.patchIndex[patchKey]?.push(pos) - } + patchIndex: Record = {} + blocks: any[] = [] + constructor(posBatch: Vector2[]) { + // sort input blocks by patch + // const blocksByPatch: Record = {} + for (const pos of posBatch) { + const patchId = getPatchId(pos, WorldEnv.current.patchDimensions) + const patchKey = serializePatchId(patchId) + this.patchIndex[patchKey] = this.patchIndex[patchKey] || [] + this.patchIndex[patchKey]?.push(pos) } + } - bake() { - - } + bake() {} - async process() { - // const blocksBatch = posBatch.map(pos => { + async process() { + // const blocksBatch = posBatch.map(pos => { - // const data: BlockData = { - // level: 0, - // type: BlockType.NONE, - // } - // const block: Block = { - // pos: asVect3(pos), - // data, - // } + // const data: BlockData = { + // level: 0, + // type: BlockType.NONE, + // } + // const block: Block = { + // pos: asVect3(pos), + // data, + // } - // return block - // }) - const blocksBatch = [] - for (const [patchKey, posBatch] of Object.entries(this.patchIndex)) { - const groundPatch = new GroundPatch(patchKey) - const biomeBoundsInfluences = Biome.instance.getBoundsInfluences(groundPatch.bounds) - for (const blockPos of posBatch) { - - - const blockBiome = WorldUtils.process.getBlockBiome( - blockPos, - groundPatch.bounds, - biomeBoundsInfluences, - ) - const blockData = computeGroundBlock(asVect3(blockPos), blockBiome) - // const {level, type } = - // override with last block if specified - // if (params.includeEntitiesBlocks) { - // const lastBlockData = await queryLastBlockData(blockPos) - // block.data = - // lastBlockData.level > 0 && lastBlockData.type - // ? lastBlockData - // : (block.data as any) - // } - blockPos.y = blockData.level - const block = { - pos: asVect3(blockPos), - data: blockData - } - blocksBatch.push(block) - } + // return block + // }) + const blocksBatch = [] + for (const [patchKey, posBatch] of Object.entries(this.patchIndex)) { + const groundPatch = new GroundPatch(patchKey) + const biomeBoundsInfluences = Biome.instance.getBoundsInfluences( + groundPatch.bounds, + ) + for (const blockPos of posBatch) { + const blockBiome = WorldUtils.process.getBlockBiome( + blockPos, + groundPatch.bounds, + biomeBoundsInfluences, + ) + const blockData = computeGroundBlock(asVect3(blockPos), blockBiome) + // const {level, type } = + // override with last block if specified + // if (params.includeEntitiesBlocks) { + // const lastBlockData = await queryLastBlockData(blockPos) + // block.data = + // lastBlockData.level > 0 && lastBlockData.type + // ? lastBlockData + // : (block.data as any) + // } + blockPos.y = blockData.level + const block = { + pos: asVect3(blockPos), + data: blockData, } - this.blocks = blocksBatch - // return blocksBatch - // const blocksBatch = blockPosBatch.map((pos) => { - // const blockPos = asVect3(pos) - // const blockData = computeGroundBlock(blockPos) - // const { spawnableItems } = blockData - // const queriedLoc = new Box2().setFromPoints([asVect2(blockPos)]) - // queriedLoc.max.addScalar(1) - // false && includeEntitiesBlocks && spawnableItems.forEach(itemType => { - // // several (overlapping) objects may be found at queried position - // const [spawnedEntity] = ItemsInventory.querySpawnedEntities(itemType, queriedLoc) - // const lastBlockIndex = blocksBuffer?.findLastIndex(elt => elt) - // if (blocksBuffer && lastBlockIndex && lastBlockIndex >= 0) { - // blockData.level += lastBlockIndex - // blockData.type = blocksBuffer[lastBlockIndex] as BlockType - // } - // }) - // blockPos.y = blockData.level - // const block: Block = { - // pos: blockPos, - // data: blockData, - // } - // return block - // }) + blocksBatch.push(block) + } } + this.blocks = blocksBatch + // return blocksBatch + // const blocksBatch = blockPosBatch.map((pos) => { + // const blockPos = asVect3(pos) + // const blockData = computeGroundBlock(blockPos) + // const { spawnableItems } = blockData + // const queriedLoc = new Box2().setFromPoints([asVect2(blockPos)]) + // queriedLoc.max.addScalar(1) + // false && includeEntitiesBlocks && spawnableItems.forEach(itemType => { + // // several (overlapping) objects may be found at queried position + // const [spawnedEntity] = ItemsInventory.querySpawnedEntities(itemType, queriedLoc) + // const lastBlockIndex = blocksBuffer?.findLastIndex(elt => elt) + // if (blocksBuffer && lastBlockIndex && lastBlockIndex >= 0) { + // blockData.level += lastBlockIndex + // blockData.type = blocksBuffer[lastBlockIndex] as BlockType + // } + // }) + // blockPos.y = blockData.level + // const block: Block = { + // pos: blockPos, + // data: blockData, + // } + // return block + // }) + } - toStub() { - return this.blocks - } + toStub() { + return this.blocks + } - // byProxy - static async proxyGen(posBatch: Vector2[], processingUnit = WorldComputeProxy.workerPool) { - const res = await processingUnit - .exec(ProcessType.BlocksBatch, [posBatch]) - .then((blocksStubs: GroundBlock[]) => { - // parse worker's data to recreate original objects - const blocks = blocksStubs.map(blockStub => { - blockStub.pos = WorldUtils.convert.parseThreeStub(blockStub.pos) - return blockStub - }) as GroundBlock[] - return blocks - }) as GroundBlock[] - return res - } -} \ No newline at end of file + // byProxy + static async proxyGen( + posBatch: Vector2[], + processingUnit = WorldComputeProxy.workerPool, + ) { + const res = (await processingUnit + .exec(ProcessType.BlocksBatch, [posBatch]) + .then((blocksStubs: GroundBlock[]) => { + // parse worker's data to recreate original objects + const blocks = blocksStubs.map(blockStub => { + blockStub.pos = WorldUtils.convert.parseThreeStub(blockStub.pos) + return blockStub + }) as GroundBlock[] + return blocks + })) as GroundBlock[] + return res + } +} diff --git a/src/datacontainers/BoardContainer.ts b/src/datacontainers/BoardContainer.ts index 5f4d358..a52bd26 100644 --- a/src/datacontainers/BoardContainer.ts +++ b/src/datacontainers/BoardContainer.ts @@ -46,11 +46,6 @@ export type BoardStub = { content: Uint8Array } -type BoardContent = { - chunk: ChunkContainer, - patch: BoardPatch -} - type ChunkIndex = Record type BoardCacheData = { itemsLayer: ItemsChunkLayer @@ -73,11 +68,15 @@ class BoardPatch extends PatchBase implements DataContainer { return { bounds, // elevation: 0, - content: rawData + content: rawData, } } - override *iterDataQuery(iterBounds?: Box2 | Vector2 | undefined, skipMargin?: boolean, skipEmpty = true) { + override *iterDataQuery( + iterBounds?: Box2 | Vector2 | undefined, + skipMargin?: boolean, + skipEmpty = true, + ) { const elements = super.iterDataQuery(iterBounds, skipMargin) for (const element of elements) { const { index } = element @@ -98,7 +97,11 @@ class BoardPatch extends PatchBase implements DataContainer { const val = this.rawData[index] return !!val } +} +type BoardContent = { + chunk: ChunkContainer + patch: BoardPatch } export class BoardCache extends PatchIndexer { @@ -147,7 +150,9 @@ export class BoardCache extends PatchIndexer { this.center = center const indexChanges = super.getIndexingChanges(asVect2(center), radius) // insert new keys in index - await Promise.all(indexChanges.map(patchKey => this.initCacheIndex(patchKey))) + await Promise.all( + indexChanges.map(patchKey => this.initCacheIndex(patchKey)), + ) const indexEntries = Object.entries(this.patchLookup) // refresh chunks required for board construction for await (const [patchKey, cacheData] of indexEntries) { @@ -214,6 +219,7 @@ export class BoardContainer { radius: 0, thickness: 0, } + finalBounds = new Box2() boardData!: BoardPatch @@ -266,9 +272,8 @@ export class BoardContainer { overlapsBoard(bounds: Box2) { if (this.boardData) { - for (const _boardIter of this.boardData.iterDataQuery(bounds, true)) { - return true - } + const boardIter = this.boardData.iterDataQuery(bounds, true) + return !!boardIter.next() } return false } @@ -296,10 +301,7 @@ export class BoardContainer { heightBuff[0] = marginBlock // chunkBuff.data.fill(33,0,2) // find last empty block - const surfaceIndex = Math.max( - heightBuff.findIndex(val => !val) - 1, - 0, - ) + const surfaceIndex = Math.max(heightBuff.findIndex(val => !val) - 1, 0) const surfaceBlock = ChunkContainer.dataEncoder( heightBuff[surfaceIndex] || BlockType.NONE, BlockMode.CHECKERBOARD, @@ -330,7 +332,7 @@ export class BoardContainer { finalChunkBounds.max.y = boardChunk.bounds.max.y const boardContent: BoardContent = { patch: new BoardPatch(this.finalBounds), - chunk: new ChunkContainer(finalChunkBounds, 1) + chunk: new ChunkContainer(finalChunkBounds, 1), } WorldUtils.data.copySourceToTargetPatch(boardPatch, boardContent.patch) ChunkContainer.copySourceToTarget(boardChunk, boardContent.chunk) @@ -341,7 +343,9 @@ export class BoardContainer { // trim items spawning inside board addTrimmedItems(boardPatch: BoardPatch, boardChunk: ChunkContainer) { - const boardSpawnedItems = this.localCache.querySpawnedItems(boardChunk.bounds) + const boardSpawnedItems = this.localCache.querySpawnedItems( + boardChunk.bounds, + ) for (const itemChunk of boardSpawnedItems) { const itemOffset = this.boardElevation - itemChunk.bounds.min.y + 1 // iter slice from item which is at same level as the board diff --git a/src/datacontainers/ChunkContainer.ts b/src/datacontainers/ChunkContainer.ts index d802eff..d8000fa 100644 --- a/src/datacontainers/ChunkContainer.ts +++ b/src/datacontainers/ChunkContainer.ts @@ -1,4 +1,5 @@ import { Vector2, Box3, Vector3 } from 'three' + import { BlockMode, ChunkId, ChunkKey } from '../utils/types' import { asVect3, diff --git a/src/datacontainers/ChunksIndexer.ts b/src/datacontainers/ChunksIndexer.ts index d8c1f61..e4039fd 100644 --- a/src/datacontainers/ChunksIndexer.ts +++ b/src/datacontainers/ChunksIndexer.ts @@ -1,7 +1,9 @@ import { Box2, Vector2 } from 'three' + import { WorldUtils } from '../index' import { WorldEnv } from '../misc/WorldEnv' import { PatchKey } from '../utils/types' + import { GroundChunk, CaveChunkMask } from './ChunkFactory' import { ChunkSetProcessor } from './ChunksProcessing' @@ -53,9 +55,9 @@ export class PatchIndexer { const dims = new Vector2(rad, rad).multiplyScalar(2) // const sphere = new Sphere(center, rad) const bounds = new Box2().setFromCenterAndSize(center, dims) - const patchKeys = WorldUtils.convert.getPatchIds(bounds, WorldEnv.current.patchDimensions).map( - patchId => WorldUtils.convert.serializePatchId(patchId), - ) + const patchKeys = WorldUtils.convert + .getPatchIds(bounds, WorldEnv.current.patchDimensions) + .map(patchId => WorldUtils.convert.serializePatchId(patchId)) const newPatchKeys = patchKeys.filter( patchKey => !this.patchLookup[patchKey], ) diff --git a/src/datacontainers/GroundPatch.ts b/src/datacontainers/GroundPatch.ts index a086e82..46f6ad8 100644 --- a/src/datacontainers/GroundPatch.ts +++ b/src/datacontainers/GroundPatch.ts @@ -1,10 +1,7 @@ import { Box2, Vector2, Vector3 } from 'three' import { GroundBlock, PatchBlock, PatchKey } from '../utils/types' -import { - asVect3, - asVect2, -} from '../utils/convert' +import { asVect3, asVect2 } from '../utils/convert' import { BlockMode, WorldComputeProxy } from '../index' import { BiomeNumericType, @@ -53,7 +50,10 @@ export const parseGroundFlags = (rawFlags: number) => { * overgroundIndex | 16 | support for 65536 different configurations * */ -export class GroundPatch extends PatchBase implements PatchDataContainer { +export class GroundPatch + extends PatchBase + implements PatchDataContainer +{ rawData: Uint32Array valueRange = { min: 512, max: 0 } // here elevation isEmpty = true @@ -205,9 +205,8 @@ export class GroundPatch extends PatchBase implements PatchDataContainer } async bake() { - const stub: GroundPatchStub = await WorldComputeProxy.current.bakeGroundPatch( - this.key || this.bounds, - ) + const stub: GroundPatchStub = + await WorldComputeProxy.current.bakeGroundPatch(this.key || this.bounds) this.valueRange = stub.valueRange || this.valueRange this.rawData.set(stub.rawData) this.isEmpty = false diff --git a/src/datacontainers/PatchBase.ts b/src/datacontainers/PatchBase.ts index e7de86d..82681b8 100644 --- a/src/datacontainers/PatchBase.ts +++ b/src/datacontainers/PatchBase.ts @@ -1,6 +1,13 @@ import { Vector2, Box2, Vector3 } from 'three' + import { PatchKey } from '../utils/types' -import { parsePatchKey, asPatchBounds, serializePatchId, asVect2, parseThreeStub } from '../utils/convert' +import { + parsePatchKey, + asPatchBounds, + serializePatchId, + asVect2, + parseThreeStub, +} from '../utils/convert' import { WorldEnv } from '../index' // export class PatchChunkCommon { @@ -8,9 +15,9 @@ import { WorldEnv } from '../index' // } export type PatchElement = { - pos: Vector2, - index: number, - localPos: Vector2, + pos: Vector2 + index: number + localPos: Vector2 data: T } @@ -201,7 +208,7 @@ export class PatchBase { index, pos: this.toWorldPos(localPos), localPos, - data: undefined + data: undefined, } yield patchElem } diff --git a/src/demo-samples/configs/world_dev_setup.ts b/src/demo-samples/configs/world_dev_setup.ts index 38b7053..e7bf2cc 100644 --- a/src/demo-samples/configs/world_dev_setup.ts +++ b/src/demo-samples/configs/world_dev_setup.ts @@ -15,9 +15,12 @@ import { export const EnvOverride = (worldEnv = WorldEnv.current) => { worldEnv.biomes.rawConf = BIOMES_LANDSCAPES_CONFIG // populate inventory with schematics and procedural objects - worldEnv.schematics.globalBlocksMapping = { ...worldEnv.schematics.globalBlocksMapping, ...SCHEMATICS_BLOCKS_MAPPING } + worldEnv.schematics.globalBlocksMapping = { + ...worldEnv.schematics.globalBlocksMapping, + ...SCHEMATICS_BLOCKS_MAPPING, + } // override schematics blocks mapping here - // worldEnv.schematics.localBlocksMapping['trees/palmtree_big_1'] = { + // worldEnv.schematics.localBlocksMapping['trees/palmtree_big_1'] = { // jungle_leaves: BlockType.SNOW, // jungle_wood: BlockType.SAND, // } @@ -30,7 +33,9 @@ export const EnvOverride = (worldEnv = WorldEnv.current) => { WorldEnv.current.debug.schematics.missingBlockType = ExtBlock.DBG_DARK } -export const BlocksColorOverride = (blocksColorMapping: Record) => ({ ...blocksColorMapping, ...BLOCKS_COLOR_MAPPING }) +export const BlocksColorOverride = ( + blocksColorMapping: Record, +) => ({ ...blocksColorMapping, ...BLOCKS_COLOR_MAPPING }) /** * Unified world setup to ensure having same settings everywhere (workers, main thread) diff --git a/src/misc/ItemsInventory.ts b/src/misc/ItemsInventory.ts index 985cd69..28c1238 100644 --- a/src/misc/ItemsInventory.ts +++ b/src/misc/ItemsInventory.ts @@ -43,8 +43,12 @@ export class ItemsInventory { const fileUrl = ItemsInventory.schematicFilesIndex[id] let chunk if (fileUrl) { - const customBlocksMapping = WorldEnv.current.schematics.localBlocksMapping[id] - chunk = await SchematicLoader.createChunkContainer(fileUrl, customBlocksMapping) + const customBlocksMapping = + WorldEnv.current.schematics.localBlocksMapping[id] + chunk = await SchematicLoader.createChunkContainer( + fileUrl, + customBlocksMapping, + ) // const spawner = new PseudoDistributionMap() ItemsInventory.catalog[id] = chunk } @@ -147,7 +151,9 @@ export class ItemsChunkLayer { } // compute blocks batch to find lower element const blocksBatch = await BlocksBatch.proxyGen(chunkBottomBlocks) - const lowestBlock = blocksBatch.sort((b1, b2) => b1.data.level - b2.data.level)[0] + const [lowestBlock] = blocksBatch.sort( + (b1, b2) => b1.data.level - b2.data.level, + ) const lowestLevel = lowestBlock?.data.level || 0 const yOffset = itemChunk.bounds.min.y - lowestLevel const offset = new Vector3(0, yOffset, 0) diff --git a/src/misc/WorldEnv.ts b/src/misc/WorldEnv.ts index af738cb..c96ab9c 100644 --- a/src/misc/WorldEnv.ts +++ b/src/misc/WorldEnv.ts @@ -88,16 +88,16 @@ export class WorldEnv { localBlocksMapping: Record filesIndex: Record } = { - globalBlocksMapping: {}, - localBlocksMapping: {}, - filesIndex: {}, - } + globalBlocksMapping: {}, + localBlocksMapping: {}, + filesIndex: {}, + } proceduralItems: { configs: Record } = { - configs: {}, - } + configs: {}, + } workerPool = { count: 4, @@ -114,9 +114,9 @@ export class WorldEnv { rawConf: BiomesRawConf seaLevel: number } = { - rawConf: {} as any, - seaLevel: 0, - } + rawConf: {} as any, + seaLevel: 0, + } get seaLevel() { return this.biomes.seaLevel diff --git a/src/procgen/Biome.ts b/src/procgen/Biome.ts index 2464983..abde798 100644 --- a/src/procgen/Biome.ts +++ b/src/procgen/Biome.ts @@ -3,7 +3,6 @@ import { Box2, Vector2, Vector3 } from 'three' import { smoothstep } from 'three/src/math/MathUtils' import { LinkedList } from '../datacontainers/LinkedList' - import { BiomeLandscapeKey, BiomesConf, @@ -298,7 +297,9 @@ export class Biome { const boundsInfluences = {} as PatchBoundingBiomes ;[xMyM, xMyP, xPyM, xPyP].map(key => { const boundPos = boundsPoints[key] as Vector2 - const biomeInfluence = this.getBiomeInfluence(WorldUtils.convert.asVect3(boundPos)) + const biomeInfluence = this.getBiomeInfluence( + WorldUtils.convert.asVect3(boundPos), + ) boundsInfluences[key] = biomeInfluence // const block = computeGroundBlock(asVect3(pos), biomeInfluence) return biomeInfluence @@ -340,7 +341,9 @@ export class Biome { ) => { const period = 0.005 * Math.pow(2, 2) const mapCoords = groundPos.clone().multiplyScalar(period) - const posRandomizerVal = this.posRandomizer.eval(WorldUtils.convert.asVect3(mapCoords)) + const posRandomizerVal = this.posRandomizer.eval( + WorldUtils.convert.asVect3(mapCoords), + ) // add some height variations to break painting monotony const { amplitude }: any = landscapeConf.data const bounds = { @@ -385,7 +388,10 @@ export class Biome { rawVal = includeSea ? Math.max(rawVal, seaLevel) : rawVal rawVal = WorldUtils.math.clamp(rawVal, 0, 1) const firstItem = this.mappings[biomeType] - const confId = WorldUtils.misc.findMatchingRange(rawVal as number, firstItem) + const confId = WorldUtils.misc.findMatchingRange( + rawVal as number, + firstItem, + ) const current = firstItem.nth(confId) const upper = current?.next || current const min = new Vector2(current.data.x, current.data.y) @@ -410,7 +416,10 @@ export class Biome { getBiomeConf = (rawVal: number, biomeType: BiomeType) => { const firstItem = this.mappings[biomeType] - const confId = WorldUtils.misc.findMatchingRange(rawVal as number, firstItem) + const confId = WorldUtils.misc.findMatchingRange( + rawVal as number, + firstItem, + ) let currentItem = firstItem.nth(confId) while (!currentItem?.data.type && currentItem?.prev) { currentItem = currentItem.prev diff --git a/src/procgen/NoiseSampler.ts b/src/procgen/NoiseSampler.ts index 63ed70d..0128cfb 100644 --- a/src/procgen/NoiseSampler.ts +++ b/src/procgen/NoiseSampler.ts @@ -1,6 +1,7 @@ import { createNoise2D, createNoise3D, createNoise4D } from 'simplex-noise' import alea from 'alea' import { Vector2, Vector3 } from 'three' + import { clamp } from '../utils/math' export type InputType = Vector2 | Vector3 diff --git a/src/tools/SchematicLoader.ts b/src/tools/SchematicLoader.ts index 74f6d7a..4597606 100644 --- a/src/tools/SchematicLoader.ts +++ b/src/tools/SchematicLoader.ts @@ -41,7 +41,10 @@ export class SchematicLoader { * @param schemBlocks * @returns */ - static async createChunkContainer(fileUrl: string, localBlocksMapping?: SchematicsBlocksMapping) { + static async createChunkContainer( + fileUrl: string, + localBlocksMapping?: SchematicsBlocksMapping, + ) { const rawData = await SchematicLoader.load(fileUrl) const parsedSchematic = await SchematicLoader.parse(rawData) const schemBlocks: any = SchematicLoader.getBlocks(parsedSchematic) @@ -61,7 +64,8 @@ export class SchematicLoader { for (let x = 0; x < schemBlocks[y].length; x++) { for (let z = 0; z < schemBlocks[y][x].length; z++) { const [, rawType] = schemBlocks[y][x][z].name.split(':') - let blockType = localBlocksMapping?.[rawType] || globalBlocksMapping[rawType] + let blockType = + localBlocksMapping?.[rawType] || globalBlocksMapping[rawType] if (blockType === undefined) { console.warn(`missing schematic block type ${rawType}`) blockType = WorldEnv.current.debug.schematics.missingBlockType diff --git a/src/utils/convert.ts b/src/utils/convert.ts index d4df50e..c7f2e1b 100644 --- a/src/utils/convert.ts +++ b/src/utils/convert.ts @@ -1,10 +1,6 @@ import { Box2, Box3, Vector2, Vector2Like, Vector3, Vector3Like } from 'three' -import { - ChunkKey, - PatchId, - PatchKey, -} from './types' +import { ChunkKey, PatchId, PatchKey } from './types' const asVect2 = (v3: Vector3) => { return new Vector2(v3.x, v3.z) diff --git a/src/utils/data.ts b/src/utils/data.ts index a22b97f..c1dc1c6 100644 --- a/src/utils/data.ts +++ b/src/utils/data.ts @@ -2,37 +2,41 @@ * Low level data operations over data containers */ -import { Box2, Vector2 } from "three" -import { PatchDataContainer } from "../datacontainers/PatchBase" +import { Box2, Vector2 } from 'three' + +import { PatchDataContainer } from '../datacontainers/PatchBase' // copy occurs only on the overlapping global pos region of both containers -export const copySourceToTargetPatch = (source: PatchDataContainer, target: PatchDataContainer) => { - const adjustOverlapMargins = (overlap: Box2) => { - const margin = Math.min(target.margin, source.margin) || 0 - overlap.min.x -= target.bounds.min.x === overlap.min.x ? margin : 0 - overlap.min.y -= target.bounds.min.y === overlap.min.y ? margin : 0 - overlap.max.x += target.bounds.max.x === overlap.max.x ? margin : 0 - overlap.max.y += target.bounds.max.y === overlap.max.y ? margin : 0 - } +export const copySourceToTargetPatch = ( + source: PatchDataContainer, + target: PatchDataContainer, +) => { + const adjustOverlapMargins = (overlap: Box2) => { + const margin = Math.min(target.margin, source.margin) || 0 + overlap.min.x -= target.bounds.min.x === overlap.min.x ? margin : 0 + overlap.min.y -= target.bounds.min.y === overlap.min.y ? margin : 0 + overlap.max.x += target.bounds.max.x === overlap.max.x ? margin : 0 + overlap.max.y += target.bounds.max.y === overlap.max.y ? margin : 0 + } - if (source.bounds.intersectsBox(target.bounds)) { - const overlap = target.bounds.clone().intersect(source.bounds) - adjustOverlapMargins(overlap) - for (let { y } = overlap.min; y < overlap.max.y; y++) { - // const globalStartPos = new Vector3(x, 0, overlap.min.y) - const globalStartPos = new Vector2(overlap.min.x, y) - const targetLocalStartPos = target.toLocalPos(globalStartPos) - const sourceLocalStartPos = source.toLocalPos(globalStartPos) - let targetIndex = target.getIndex(targetLocalStartPos) - let sourceIndex = source.getIndex(sourceLocalStartPos) - for (let { x } = overlap.min; x < overlap.max.x; x++) { - const sourceVal = source.rawData[sourceIndex] - if (sourceVal) { - target.rawData[targetIndex] = sourceVal - } - sourceIndex++ - targetIndex++ - } + if (source.bounds.intersectsBox(target.bounds)) { + const overlap = target.bounds.clone().intersect(source.bounds) + adjustOverlapMargins(overlap) + for (let { y } = overlap.min; y < overlap.max.y; y++) { + // const globalStartPos = new Vector3(x, 0, overlap.min.y) + const globalStartPos = new Vector2(overlap.min.x, y) + const targetLocalStartPos = target.toLocalPos(globalStartPos) + const sourceLocalStartPos = source.toLocalPos(globalStartPos) + let targetIndex = target.getIndex(targetLocalStartPos) + let sourceIndex = source.getIndex(sourceLocalStartPos) + for (let { x } = overlap.min; x < overlap.max.x; x++) { + const sourceVal = source.rawData[sourceIndex] + if (sourceVal) { + target.rawData[targetIndex] = sourceVal } + sourceIndex++ + targetIndex++ + } } -} \ No newline at end of file + } +} diff --git a/src/utils/index.ts b/src/utils/index.ts index c69d88c..8c2fef6 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -3,4 +3,4 @@ export * as math from './math' export * as process from './process' export * as data from './data' export * as misc from './misc' -export * as spatial from './spatial' \ No newline at end of file +export * as spatial from './spatial' diff --git a/src/utils/math.ts b/src/utils/math.ts index b8bee5c..6047fc7 100644 --- a/src/utils/math.ts +++ b/src/utils/math.ts @@ -1,10 +1,11 @@ import { Box2, Box3, Vector2, Vector3 } from 'three' + import { PatchBoundId } from './types' /** * @param point input point inside bounding box * @param points surrounding points which must remain outside bounding box - * @param bounds + * @param bounds * @returns largest bounding box including input point while excluding surrounding points */ export const findBoundingBox = ( diff --git a/src/utils/misc.ts b/src/utils/misc.ts index a56c720..39a6896 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,25 +1,28 @@ -import { LandscapeFields, LandscapesConf } from "./types" +import { LandscapeFields, LandscapesConf } from './types' // const MappingRangeFinder = (item: LinkedList, inputVal: number) => item.next && inputVal > (item.next.data as MappingData).x export const MappingRangeSorter = ( - item1: LandscapeFields, - item2: LandscapeFields, - ) => item1.x - item2.x - - /** - * find element with inputVal withing interpolation range - * @param inputVal - * @returns - */ - export const findMatchingRange = (inputVal: number, noiseMappings: LandscapesConf) => { - let match = noiseMappings.first() - let i = 1 - while (match.next && inputVal > match.next.data.x) { - match = match.next - i++ - } - return i + item1: LandscapeFields, + item2: LandscapeFields, +) => item1.x - item2.x + +/** + * find element with inputVal withing interpolation range + * @param inputVal + * @returns + */ +export const findMatchingRange = ( + inputVal: number, + noiseMappings: LandscapesConf, +) => { + let match = noiseMappings.first() + let i = 1 + while (match.next && inputVal > match.next.data.x) { + match = match.next + i++ } + return i +} - export const typesNumbering = (types: Record, offset = 0) => - Object.keys(types).forEach((key, i) => (types[key] = offset + i)) \ No newline at end of file +export const typesNumbering = (types: Record, offset = 0) => + Object.keys(types).forEach((key, i) => (types[key] = offset + i)) diff --git a/src/utils/process.ts b/src/utils/process.ts index d579178..605aa46 100644 --- a/src/utils/process.ts +++ b/src/utils/process.ts @@ -1,23 +1,25 @@ -import { Vector2, Box2 } from "three" -import { WorldEnv } from "../index" -import { BiomeInfluence, PatchBoundingBiomes } from "../procgen/Biome" -import { bilinearInterpolation } from "./math" -import { PatchBoundId } from "./types" +import { Vector2, Box2 } from 'three' + +import { WorldEnv } from '../index' +import { BiomeInfluence, PatchBoundingBiomes } from '../procgen/Biome' + +import { bilinearInterpolation } from './math' +import { PatchBoundId } from './types' export const getBlockBiome = ( - blockPos: Vector2, - patchBounds: Box2, - boundingBiomes: BiomeInfluence | PatchBoundingBiomes, - ) => { - if ( - (boundingBiomes as PatchBoundingBiomes)[PatchBoundId.xMyM] && - WorldEnv.current.settings.useBiomeBilinearInterpolation - ) { - return bilinearInterpolation( - blockPos, - patchBounds, - boundingBiomes as PatchBoundingBiomes, - ) as BiomeInfluence - } - return boundingBiomes as BiomeInfluence - } \ No newline at end of file + blockPos: Vector2, + patchBounds: Box2, + boundingBiomes: BiomeInfluence | PatchBoundingBiomes, +) => { + if ( + (boundingBiomes as PatchBoundingBiomes)[PatchBoundId.xMyM] && + WorldEnv.current.settings.useBiomeBilinearInterpolation + ) { + return bilinearInterpolation( + blockPos, + patchBounds, + boundingBiomes as PatchBoundingBiomes, + ) as BiomeInfluence + } + return boundingBiomes as BiomeInfluence +} diff --git a/src/utils/spatial.ts b/src/utils/spatial.ts index 956ba88..b0ef2ab 100644 --- a/src/utils/spatial.ts +++ b/src/utils/spatial.ts @@ -1,10 +1,6 @@ -import { Box2, Vector2, Vector3, } from 'three' +import { Box2, Vector2, Vector3 } from 'three' -import { - PatchBoundingPoints, - SurfaceNeighbour, - VolumeNeighbour, -} from './types' +import { PatchBoundingPoints, SurfaceNeighbour, VolumeNeighbour } from './types' /** * Orthogonal or direct 2D neighbours e.g. @@ -12,10 +8,10 @@ import { * - LEFT/RIGHT */ const directNeighbours2D = [ - SurfaceNeighbour.left, - SurfaceNeighbour.right, - SurfaceNeighbour.top, - SurfaceNeighbour.bottom, + SurfaceNeighbour.left, + SurfaceNeighbour.right, + SurfaceNeighbour.top, + SurfaceNeighbour.bottom, ] /** @@ -25,35 +21,35 @@ const directNeighbours2D = [ * - LEFT/RIGHT */ const directNeighbours3D = [ - VolumeNeighbour.xPy0z0, - VolumeNeighbour.xMy0z0, // right, left - VolumeNeighbour.x0yPz0, - VolumeNeighbour.x0yMz0, // top, bottom - VolumeNeighbour.x0y0zP, - VolumeNeighbour.x0y0zM, // front, back + VolumeNeighbour.xPy0z0, + VolumeNeighbour.xMy0z0, // right, left + VolumeNeighbour.x0yPz0, + VolumeNeighbour.x0yMz0, // top, bottom + VolumeNeighbour.x0y0zP, + VolumeNeighbour.x0y0zM, // front, back ] const getAdjacent2dCoords = (pos: Vector2, dir: SurfaceNeighbour): Vector2 => { - switch (dir) { - case SurfaceNeighbour.center: - return pos.clone() - case SurfaceNeighbour.left: - return pos.clone().add(new Vector2(-1, 0)) - case SurfaceNeighbour.right: - return pos.clone().add(new Vector2(1, 0)) - case SurfaceNeighbour.top: - return pos.clone().add(new Vector2(0, 1)) - case SurfaceNeighbour.bottom: - return pos.clone().add(new Vector2(0, -1)) - case SurfaceNeighbour.topleft: - return pos.clone().add(new Vector2(-1, 1)) - case SurfaceNeighbour.topright: - return pos.clone().add(new Vector2(1, 1)) - case SurfaceNeighbour.bottomright: - return pos.clone().add(new Vector2(-1, -1)) - case SurfaceNeighbour.bottomleft: - return pos.clone().add(new Vector2(1, -1)) - } + switch (dir) { + case SurfaceNeighbour.center: + return pos.clone() + case SurfaceNeighbour.left: + return pos.clone().add(new Vector2(-1, 0)) + case SurfaceNeighbour.right: + return pos.clone().add(new Vector2(1, 0)) + case SurfaceNeighbour.top: + return pos.clone().add(new Vector2(0, 1)) + case SurfaceNeighbour.bottom: + return pos.clone().add(new Vector2(0, -1)) + case SurfaceNeighbour.topleft: + return pos.clone().add(new Vector2(-1, 1)) + case SurfaceNeighbour.topright: + return pos.clone().add(new Vector2(1, 1)) + case SurfaceNeighbour.bottomright: + return pos.clone().add(new Vector2(-1, -1)) + case SurfaceNeighbour.bottomleft: + return pos.clone().add(new Vector2(1, -1)) + } } /** @@ -63,89 +59,88 @@ const getAdjacent2dCoords = (pos: Vector2, dir: SurfaceNeighbour): Vector2 => { * @returns */ const getAdjacent3dCoords = (pos: Vector3, dir: VolumeNeighbour): Vector3 => { - switch (dir) { - case VolumeNeighbour.xMyMzM: - return pos.clone().add(new Vector3(-1, -1, -1)) - case VolumeNeighbour.xMyMz0: - return pos.clone().add(new Vector3(-1, -1, 0)) - case VolumeNeighbour.xMyMzP: - return pos.clone().add(new Vector3(-1, -1, 1)) - case VolumeNeighbour.xMy0zM: - return pos.clone().add(new Vector3(-1, 0, -1)) - case VolumeNeighbour.xMy0z0: - return pos.clone().add(new Vector3(-1, 0, 0)) - case VolumeNeighbour.xMy0zP: - return pos.clone().add(new Vector3(-1, 0, 1)) - case VolumeNeighbour.xMyPzM: - return pos.clone().add(new Vector3(-1, 1, -1)) - case VolumeNeighbour.xMyPz0: - return pos.clone().add(new Vector3(-1, 1, 0)) - case VolumeNeighbour.xMyPzP: - return pos.clone().add(new Vector3(-1, 1, 1)) - case VolumeNeighbour.x0yMzM: - return pos.clone().add(new Vector3(0, -1, -1)) - case VolumeNeighbour.x0yMz0: - return pos.clone().add(new Vector3(0, -1, 0)) - case VolumeNeighbour.x0yMzP: - return pos.clone().add(new Vector3(0, -1, 1)) - case VolumeNeighbour.x0y0zM: - return pos.clone().add(new Vector3(0, 0, -1)) - case VolumeNeighbour.x0y0zP: - return pos.clone().add(new Vector3(0, 0, 1)) - case VolumeNeighbour.x0yPzM: - return pos.clone().add(new Vector3(0, 1, -1)) - case VolumeNeighbour.x0yPz0: - return pos.clone().add(new Vector3(0, 1, 0)) - case VolumeNeighbour.x0yPzP: - return pos.clone().add(new Vector3(0, 1, 1)) - case VolumeNeighbour.xPyMzM: - return pos.clone().add(new Vector3(1, -1, -1)) - case VolumeNeighbour.xPyMz0: - return pos.clone().add(new Vector3(1, -1, 0)) - case VolumeNeighbour.xPyMzP: - return pos.clone().add(new Vector3(1, -1, 1)) - case VolumeNeighbour.xPy0zM: - return pos.clone().add(new Vector3(1, 0, -1)) - case VolumeNeighbour.xPy0z0: - return pos.clone().add(new Vector3(1, 0, 0)) - case VolumeNeighbour.xPy0zP: - return pos.clone().add(new Vector3(1, 0, 1)) - case VolumeNeighbour.xPyPzM: - return pos.clone().add(new Vector3(1, 1, -1)) - case VolumeNeighbour.xPyPz0: - return pos.clone().add(new Vector3(1, 1, 0)) - case VolumeNeighbour.xPyPzP: - return pos.clone().add(new Vector3(1, 1, 1)) - } + switch (dir) { + case VolumeNeighbour.xMyMzM: + return pos.clone().add(new Vector3(-1, -1, -1)) + case VolumeNeighbour.xMyMz0: + return pos.clone().add(new Vector3(-1, -1, 0)) + case VolumeNeighbour.xMyMzP: + return pos.clone().add(new Vector3(-1, -1, 1)) + case VolumeNeighbour.xMy0zM: + return pos.clone().add(new Vector3(-1, 0, -1)) + case VolumeNeighbour.xMy0z0: + return pos.clone().add(new Vector3(-1, 0, 0)) + case VolumeNeighbour.xMy0zP: + return pos.clone().add(new Vector3(-1, 0, 1)) + case VolumeNeighbour.xMyPzM: + return pos.clone().add(new Vector3(-1, 1, -1)) + case VolumeNeighbour.xMyPz0: + return pos.clone().add(new Vector3(-1, 1, 0)) + case VolumeNeighbour.xMyPzP: + return pos.clone().add(new Vector3(-1, 1, 1)) + case VolumeNeighbour.x0yMzM: + return pos.clone().add(new Vector3(0, -1, -1)) + case VolumeNeighbour.x0yMz0: + return pos.clone().add(new Vector3(0, -1, 0)) + case VolumeNeighbour.x0yMzP: + return pos.clone().add(new Vector3(0, -1, 1)) + case VolumeNeighbour.x0y0zM: + return pos.clone().add(new Vector3(0, 0, -1)) + case VolumeNeighbour.x0y0zP: + return pos.clone().add(new Vector3(0, 0, 1)) + case VolumeNeighbour.x0yPzM: + return pos.clone().add(new Vector3(0, 1, -1)) + case VolumeNeighbour.x0yPz0: + return pos.clone().add(new Vector3(0, 1, 0)) + case VolumeNeighbour.x0yPzP: + return pos.clone().add(new Vector3(0, 1, 1)) + case VolumeNeighbour.xPyMzM: + return pos.clone().add(new Vector3(1, -1, -1)) + case VolumeNeighbour.xPyMz0: + return pos.clone().add(new Vector3(1, -1, 0)) + case VolumeNeighbour.xPyMzP: + return pos.clone().add(new Vector3(1, -1, 1)) + case VolumeNeighbour.xPy0zM: + return pos.clone().add(new Vector3(1, 0, -1)) + case VolumeNeighbour.xPy0z0: + return pos.clone().add(new Vector3(1, 0, 0)) + case VolumeNeighbour.xPy0zP: + return pos.clone().add(new Vector3(1, 0, 1)) + case VolumeNeighbour.xPyPzM: + return pos.clone().add(new Vector3(1, 1, -1)) + case VolumeNeighbour.xPyPz0: + return pos.clone().add(new Vector3(1, 1, 0)) + case VolumeNeighbour.xPyPzP: + return pos.clone().add(new Vector3(1, 1, 1)) + } } export const getNeighbours2D = ( - pos: Vector2, - directNeighboursOnly = false, + pos: Vector2, + directNeighboursOnly = false, ): Vector2[] => { - const neighbours = directNeighboursOnly - ? directNeighbours2D - : Object.values(SurfaceNeighbour).filter(v => !isNaN(Number(v))) - return neighbours.map(type => getAdjacent2dCoords(pos, type as number)) + const neighbours = directNeighboursOnly + ? directNeighbours2D + : Object.values(SurfaceNeighbour).filter(v => !isNaN(Number(v))) + return neighbours.map(type => getAdjacent2dCoords(pos, type as number)) } export const getNeighbours3D = ( - pos: Vector3, - directNeighboursOnly = false, + pos: Vector3, + directNeighboursOnly = false, ): Vector3[] => { - const neighbours = directNeighboursOnly - ? directNeighbours3D - : Object.values(VolumeNeighbour).filter(v => !isNaN(Number(v))) - return neighbours.map(type => getAdjacent3dCoords(pos, type as number)) + const neighbours = directNeighboursOnly + ? directNeighbours3D + : Object.values(VolumeNeighbour).filter(v => !isNaN(Number(v))) + return neighbours.map(type => getAdjacent3dCoords(pos, type as number)) } - export const getPatchBoundingPoints = (bounds: Box2) => { - const { min: xMyM, max: xPyP } = bounds - const xMyP = xMyM.clone() - xMyP.y = xPyP.y - const xPyM = xMyM.clone() - xPyM.x = xPyP.x - const points: PatchBoundingPoints = { xMyM, xMyP, xPyM, xPyP } - return points -} \ No newline at end of file + const { min: xMyM, max: xPyP } = bounds + const xMyP = xMyM.clone() + xMyP.y = xPyP.y + const xPyM = xMyM.clone() + xPyM.x = xPyP.x + const points: PatchBoundingPoints = { xMyM, xMyP, xPyM, xPyP } + return points +} diff --git a/src/utils/types.ts b/src/utils/types.ts index 296cbb9..7d4e6f9 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -176,5 +176,5 @@ export interface WorldProcess { } export enum ProcessType { - BlocksBatch = 'BlocksBatch' + BlocksBatch = 'BlocksBatch', }