Finished up initial round of runtime editor dependency split

This commit is contained in:
Lucas Dower 2023-09-07 23:31:10 +01:00
parent 66d9619b9b
commit 4e8f3680e5
No known key found for this signature in database
GPG Key ID: B3EE6B8499593605
9 changed files with 45 additions and 42 deletions

View File

@ -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';

View File

@ -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";

View File

@ -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";

View File

@ -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);

View File

@ -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';

View File

@ -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 {

View File

@ -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<string>;
private _blocks: Map<number, Block>;
//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 }

View File

@ -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;
}

View File

@ -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 = {