diff --git a/src/common/misc.ts b/src/common/misc.ts deleted file mode 100644 index 92977bb..0000000 --- a/src/common/misc.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { BlockType } from '../common/types' -export const blockTypesColorMapping: Record = { - [BlockType.ROCK]: 0xABABAB, - [BlockType.GRASS]: 0x00B920, - [BlockType.SNOW]: 0xE5E5E5, - [BlockType.WATER]: 0x0055E2, - [BlockType.SAND]: 0xDCBE28 -} \ No newline at end of file diff --git a/src/common/types.ts b/src/common/types.ts index ab01dbd..ffdfdfb 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -10,7 +10,7 @@ export enum BlockType { } export type Block = { - pos: Vector3, + pos: Vector3 type: BlockType } diff --git a/src/common/utils.ts b/src/common/utils.ts index 6de8c45..db1e279 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -1,4 +1,5 @@ import { Vector2, Vector3 } from 'three' + import { GenStats } from './stats' import { BlockNeighbour } from './types' @@ -37,9 +38,9 @@ const interpolatePoints = (p1: Vector2, p2: Vector2, t: number) => { return p1.y + slope * (t - p1.x) } /** - * Direct neighbours e.g. - * - FRONT/BACK, - * - TOP/BOTTOM, + * Direct neighbours e.g. + * - FRONT/BACK, + * - TOP/BOTTOM, * - LEFT/RIGHT */ const AdjacentNeighbours = [ diff --git a/src/procgen/ProcGenLayer.ts b/src/procgen/ProcGenLayer.ts index a9fab75..4794855 100644 --- a/src/procgen/ProcGenLayer.ts +++ b/src/procgen/ProcGenLayer.ts @@ -189,7 +189,7 @@ export class ProcGenLayer extends GenLayer { return vals * 255 } - static layerIndex(index: number){ + static layerIndex(index: number) { return `layer#${index}` } diff --git a/src/procgen/WorldGen.ts b/src/procgen/WorldGen.ts index a81a462..b91aa79 100644 --- a/src/procgen/WorldGen.ts +++ b/src/procgen/WorldGen.ts @@ -1,10 +1,13 @@ import { Vector2, Vector3, Box3 } from 'three' + import { Block, BlockType } from '../common/types' -import { GenLayer } from './ProcGenLayer' import { GenStats } from '../common/stats' import * as Utils from '../common/utils' +import { GenLayer } from './ProcGenLayer' + export class WorldGenerator { + // eslint-disable-next-line no-use-before-define static singleton: WorldGenerator parent: any samplingScale: number = 1 / 8 // 8 blocks per unit of noise @@ -13,16 +16,6 @@ export class WorldGenerator { procLayers!: GenLayer layerSelection!: string - constructor() { - // blending map - // const transitionThreshold = 0.5 - // const transitionRange = 0.1 - // const transition = { - // lower: round2(transitionThreshold - transitionRange / 2), - // upper: round2(transitionThreshold + transitionRange / 2) - // } - } - static get instance() { WorldGenerator.singleton = WorldGenerator.singleton || new WorldGenerator() return WorldGenerator.singleton @@ -71,7 +64,7 @@ export class WorldGenerator { } /** - * Checking neighbours surrounding block's position + * Checking neighbours surrounding block's position * to determine if block is hidden or not */ hiddenBlock(position: Vector3) { @@ -119,9 +112,15 @@ export class WorldGenerator { // for (let y = bbox.max.y - 1; y >= bbox.min.y; y--) { while (!hidden && y >= bbox.min.y) { const blockPos = new Vector3(x, y, z) - const blockType = blockPos.y < groundLevel ? this.blockTypeMapper(blockPos.y) : BlockType.NONE + const blockType = + blockPos.y < groundLevel + ? this.blockTypeMapper(blockPos.y) + : BlockType.NONE const block: Block = { pos: blockPos, type: blockType } - hidden = pruning && block.type !== BlockType.NONE && this.hiddenBlock(block.pos) + hidden = + pruning && + block.type !== BlockType.NONE && + this.hiddenBlock(block.pos) // only existing and visible block, e.g with a face in contact with air if (block.type !== BlockType.NONE && !hidden) { yield block @@ -145,9 +144,10 @@ export class WorldGenerator { iterations: iterCount, } } + /** - * @param bbox - * @returns + * @param bbox + * @returns */ estimatedVoxelsCount(bbox: Box3): number { const range = bbox.getSize(new Vector3())