diff --git a/src/editor/buffer.ts b/src/editor/buffer.ts index a27ee3e..e4b0114 100644 --- a/src/editor/buffer.ts +++ b/src/editor/buffer.ts @@ -1,7 +1,7 @@ import { BlockMesh } from '../runtime/block_mesh'; import { AppConfig } from './config'; import { AppConstants } from '../runtime/constants'; -import { GeometryTemplates } from '../runtime/geometry'; +import { GeometryTemplates } from './renderer/geometry'; import { Mesh, SolidMaterial, TexturedMaterial } from '../runtime/mesh'; import { OcclusionManager } from '../runtime/occlusion'; import { ProgressManager } from './progress'; diff --git a/src/editor/renderer/buffer_block_mesh.ts b/src/editor/renderer/buffer_block_mesh.ts index 8fdd545..5ade641 100644 --- a/src/editor/renderer/buffer_block_mesh.ts +++ b/src/editor/renderer/buffer_block_mesh.ts @@ -3,7 +3,7 @@ import { Voxel, VoxelMesh } from '../../runtime/voxel_mesh'; import { AppConfig } from "../config"; import { ASSERT } from "../../runtime/util/error_util"; import { Vector3 } from "../../runtime/vector"; -import { GeometryTemplates } from "../../runtime/geometry"; +import { GeometryTemplates } from "./geometry"; import { AttributeData } from "./render_buffer"; import { AppUtil } from "../../runtime/util"; import { AppConstants } from "../../runtime/constants"; diff --git a/src/editor/renderer/buffer_voxel_mesh.ts b/src/editor/renderer/buffer_voxel_mesh.ts index 0d2e20e..85b37f8 100644 --- a/src/editor/renderer/buffer_voxel_mesh.ts +++ b/src/editor/renderer/buffer_voxel_mesh.ts @@ -3,7 +3,7 @@ import { Voxel, VoxelMesh } from '../../runtime/voxel_mesh'; import { AppConfig } from "../config"; import { ASSERT } from "../../runtime/util/error_util"; import { Vector3 } from "../../runtime/vector"; -import { GeometryTemplates } from "../../runtime/geometry"; +import { GeometryTemplates } from "./geometry"; import { AttributeData } from "./render_buffer"; import { AppUtil, TOptional } from "../../runtime/util"; import { AppConstants } from "../../runtime/constants"; diff --git a/src/runtime/geometry.ts b/src/editor/renderer/geometry.ts similarity index 97% rename from src/runtime/geometry.ts rename to src/editor/renderer/geometry.ts index 439e68f..3c6be83 100644 --- a/src/runtime/geometry.ts +++ b/src/editor/renderer/geometry.ts @@ -1,12 +1,13 @@ import * as twgl from 'twgl.js'; -import { Bounds } from './bounds'; -import { RGBA } from '../runtime/colour'; -import { Mesh } from './mesh'; -import { Triangle, UVTriangle } from './triangle'; -import { ASSERT } from './util/error_util'; -import { Vector3 } from './vector'; -import { VoxelMesh } from './voxel_mesh'; +import { Bounds } from '../../runtime/bounds'; +import { RGBA } from '../../runtime/colour'; +import { Mesh } from '../../runtime/mesh'; +import { AttributeData, MergeAttributeData, RenderBuffer } from './render_buffer'; +import { Triangle, UVTriangle } from '../../runtime/triangle'; +import { ASSERT } from '../../runtime/util/error_util'; +import { Vector3 } from '../../runtime/vector'; +import { VoxelMesh } from '../../runtime/voxel_mesh'; export class GeometryTemplates { private static readonly _default_cube = twgl.primitives.createCubeVertices(1.0); diff --git a/src/editor/renderer/renderer.ts b/src/editor/renderer/renderer.ts index 9f629ce..e3a4b2f 100644 --- a/src/editor/renderer/renderer.ts +++ b/src/editor/renderer/renderer.ts @@ -1,11 +1,11 @@ import * as twgl from 'twgl.js'; -import VANILLA_TEXTURE from '../../res/atlases/vanilla.png'; +import VANILLA_TEXTURE from '../../../res/atlases/vanilla.png'; import { Bounds } from '../../runtime/bounds'; import { ArcballCamera } from './camera'; import { RGBA, RGBAUtil } from '../../runtime/colour'; import { AppConfig } from '../config'; -import { DebugGeometryTemplates } from '../../runtime/geometry'; +import { DebugGeometryTemplates } from './geometry'; import { MaterialType, SolidMaterial, TexturedMaterial } from '../../runtime/mesh'; import { RenderBuffer } from './render_buffer'; import { ShaderManager } from './shaders'; diff --git a/src/editor/renderer/shaders.ts b/src/editor/renderer/shaders.ts index 63c5ee3..f46080b 100644 --- a/src/editor/renderer/shaders.ts +++ b/src/editor/renderer/shaders.ts @@ -1,15 +1,15 @@ import * as twgl from 'twgl.js'; -import FRAG_BLOCK from '../../res/shaders/block_fragment.fs'; -import VERT_BLOCK from '../../res/shaders/block_vertex.vs'; -import FRAG_DEBUG from '../../res/shaders/debug_fragment.fs'; -import VERT_DEBUG from '../../res/shaders/debug_vertex.vs'; -import FRAG_TRI_SOLID from '../../res/shaders/solid_tri_fragment.fs'; -import VERT_TRI_SOLID from '../../res/shaders/solid_tri_vertex.vs'; -import FRAG_TRI_TEXTURE from '../../res/shaders/texture_tri_fragment.fs'; -import VERT_TRI_TEXTURE from '../../res/shaders/texture_tri_vertex.vs'; -import FRAG_VOXEL from '../../res/shaders/voxel_fragment.fs'; -import VERT_VOXEL from '../../res/shaders/voxel_vertex.vs'; +import FRAG_BLOCK from '../../../res/shaders/block_fragment.fs'; +import VERT_BLOCK from '../../../res/shaders/block_vertex.vs'; +import FRAG_DEBUG from '../../../res/shaders/debug_fragment.fs'; +import VERT_DEBUG from '../../../res/shaders/debug_vertex.vs'; +import FRAG_TRI_SOLID from '../../../res/shaders/solid_tri_fragment.fs'; +import VERT_TRI_SOLID from '../../../res/shaders/solid_tri_vertex.vs'; +import FRAG_TRI_TEXTURE from '../../../res/shaders/texture_tri_fragment.fs'; +import VERT_TRI_TEXTURE from '../../../res/shaders/texture_tri_vertex.vs'; +import FRAG_VOXEL from '../../../res/shaders/voxel_fragment.fs'; +import VERT_VOXEL from '../../../res/shaders/voxel_vertex.vs'; import { Renderer } from './renderer'; export class ShaderManager { diff --git a/src/runtime/block_mesh.ts b/src/runtime/block_mesh.ts index e39a0b9..74bc310 100644 --- a/src/runtime/block_mesh.ts +++ b/src/runtime/block_mesh.ts @@ -6,12 +6,11 @@ import { AppRuntimeConstants } from './constants'; import { Ditherer } from './dither'; import { BlockMeshLighting } from './lighting'; import { Palette } from './palette'; -import { ProgressManager } from '../editor/progress'; import { ColourSpace, TOptional } from './util'; import { ASSERT } from './util/error_util'; import { Vector3 } from './vector'; import { Voxel, VoxelMesh } from './voxel_mesh'; -import { AssignParams } from '../editor/worker/worker_types'; +import { TDithering } from './util/type_util'; export interface Block { voxel: Voxel; @@ -28,10 +27,16 @@ interface GrassLikeBlock { export type FallableBehaviour = 'replace-falling' | 'replace-fallable' | 'place-string' | 'do-nothing'; export interface BlockMeshParams { - textureAtlas: Atlas, - blockPalette: Palette, + blockPalette: string[], + dithering: TDithering, + ditheringMagnitude: number, colourSpace: ColourSpace, fallable: FallableBehaviour, + resolution: RGBAUtil.TColourAccuracy, + calculateLighting: boolean, + lightThreshold: number, + contextualAveraging: boolean, + errorWeight: number, } export type TAssignBlocksWarning = @@ -40,12 +45,11 @@ export type TAssignBlocksWarning = export class BlockMesh { private _blocksUsed: Set; private _blocks: Map; - //private _blocks: Block[]; private _voxelMesh: VoxelMesh; private _atlas: Atlas; private _lighting: BlockMeshLighting; - public static createFromVoxelMesh(voxelMesh: VoxelMesh, blockMeshParams: AssignParams.Input) { + public static createFromVoxelMesh(voxelMesh: VoxelMesh, blockMeshParams: BlockMeshParams) { const blockMesh = new BlockMesh(voxelMesh); const warn = blockMesh._assignBlocks(blockMeshParams); @@ -73,7 +77,7 @@ export class BlockMesh { * Before we turn a voxel into a block we have the opportunity to alter the voxel's colour. * This is where the colour accuracy bands colours together and where dithering is calculated. */ - private _getFinalVoxelColour(voxel: Voxel, blockMeshParams: AssignParams.Input) { + private _getFinalVoxelColour(voxel: Voxel, blockMeshParams: BlockMeshParams) { const voxelColour = RGBAUtil.copy(voxel.colour); const binnedColour = RGBAUtil.bin(voxelColour, blockMeshParams.resolution); @@ -96,14 +100,13 @@ export class BlockMesh { return ditheredColour; } - private _assignBlocks(blockMeshParams: AssignParams.Input): (null | TAssignBlocksWarning) { - const atlas = Atlas.load(blockMeshParams.textureAtlas); + private _assignBlocks(blockMeshParams: BlockMeshParams): (null | TAssignBlocksWarning) { + const atlas = Atlas.load('vanilla'); // TODO: AtlasPaletteRework ASSERT(atlas !== undefined, 'Could not load atlas'); this._atlas = atlas; const palette = Palette.create(); palette.add(blockMeshParams.blockPalette); - ASSERT(palette !== undefined, 'Could not load palette'); const atlasPalette = new AtlasPalette(atlas, palette); const allBlockCollection = atlasPalette.createBlockCollection([]); @@ -111,10 +114,11 @@ export class BlockMesh { const grassLikeBlocksBuffer: GrassLikeBlock[] = []; let countFalling = 0; - const taskHandle = ProgressManager.Get.start('Assigning'); + // TODO: ProgressRework + //const taskHandle = ProgressManager.Get.start('Assigning'); const voxels = this._voxelMesh.getVoxels(); for (let voxelIndex = 0; voxelIndex < voxels.length; ++voxelIndex) { - ProgressManager.Get.progress(taskHandle, voxelIndex / voxels.length); + //ProgressManager.Get.progress(taskHandle, voxelIndex / voxels.length); // Convert the voxel into a block const voxel = voxels[voxelIndex]; @@ -160,7 +164,7 @@ export class BlockMesh { if (grassLikeBlocksBuffer.length > 0) { const nonGrassLikeBlockCollection = atlasPalette.createBlockCollection(Array.from(AppRuntimeConstants.Get.GRASS_LIKE_BLOCKS)); for (let index=0; index < grassLikeBlocksBuffer.length; index++) { - ProgressManager.Get.progress(taskHandle, index / grassLikeBlocksBuffer.length); + //ProgressManager.Get.progress(taskHandle, index / grassLikeBlocksBuffer.length); const examined = grassLikeBlocksBuffer[index]; const examinedBlock = this._blocks.get(examined.hash); ASSERT(examinedBlock, 'Missing examined block'); @@ -177,7 +181,7 @@ export class BlockMesh { } } } - ProgressManager.Get.end(taskHandle); + //ProgressManager.Get.end(taskHandle); if (blockMeshParams.fallable === 'do-nothing' && countFalling > 0) { return { type: 'falling-blocks', count: countFalling } diff --git a/src/runtime/colour.ts b/src/runtime/colour.ts index c7424b2..382d03c 100644 --- a/src/runtime/colour.ts +++ b/src/runtime/colour.ts @@ -1,4 +1,3 @@ -import { AppConfig } from '../editor/config'; import { TBrand } from './util/type_util'; const hsv_rgb = require('hsv-rgb'); @@ -120,7 +119,7 @@ export namespace RGBAUtil { squaredDistance += (a.r - b.r) * (a.r - b.r); squaredDistance += (a.g - b.g) * (a.g - b.g); squaredDistance += (a.b - b.b) * (a.b - b.b); - squaredDistance += (a.a - b.a) * (a.a - b.a) * AppConfig.Get.ALPHA_BIAS; + squaredDistance += (a.a - b.a) * (a.a - b.a); // * AppConfig.Get.ALPHA_BIAS; TODO: ConfigRework return squaredDistance; } diff --git a/src/runtime/exporters/schematic_exporter.ts b/src/runtime/exporters/schematic_exporter.ts index 718f20d..da5ba2f 100644 --- a/src/runtime/exporters/schematic_exporter.ts +++ b/src/runtime/exporters/schematic_exporter.ts @@ -1,11 +1,7 @@ -//import { NBT, TagType } from 'prismarine-nbt'; - import { NBT, TagType } from 'prismarine-nbt'; import { BLOCK_IDS } from '../../../res/block_ids'; import { BlockMesh } from '../block_mesh'; -import { LOC } from '../../editor/localiser'; -import { StatusHandler } from '../../editor/status'; import { LOG_WARN } from '../util/log_util'; import { saveNBT } from '../util/nbt_util'; import { Vector3 } from '../vector'; @@ -53,10 +49,13 @@ export class Schematic extends IExporter { } } + // TODO: StatusRework + /* if (unsupportedBlocks.size > 0) { StatusHandler.warning(LOC('export.schematic_unsupported_blocks', { count: numBlocksUnsupported, unique: unsupportedBlocks.size })); LOG_WARN(unsupportedBlocks); } + */ // TODO Unimplemented const nbt: NBT = {