Remove colour space

This commit is contained in:
Lucas Dower 2023-09-14 00:58:18 +01:00
parent 544a2433e5
commit 4cf0a64cb1
6 changed files with 14 additions and 20 deletions

View File

@ -11,7 +11,7 @@ import { MouseManager } from './mouse';
import { MeshType, Renderer } from './renderer/renderer'; import { MeshType, Renderer } from './renderer/renderer';
import { AppConsole, TMessage } from './ui/console'; import { AppConsole, TMessage } from './ui/console';
import { UI } from './ui/layout'; import { UI } from './ui/layout';
import { ColourSpace, EAction } from '../runtime/util'; import { EAction } from '../runtime/util';
import { ASSERT } from '../runtime/util/error_util'; import { ASSERT } from '../runtime/util/error_util';
import { download, downloadAsZip } from '../runtime/util/file_util'; import { download, downloadAsZip } from '../runtime/util/file_util';
import { LOG_ERROR, Logger } from '../runtime/util/log_util'; import { LOG_ERROR, Logger } from '../runtime/util/log_util';
@ -266,7 +266,6 @@ export class AppContext {
blockPalette: components.blockPalette.getValue().getBlocks(), blockPalette: components.blockPalette.getValue().getBlocks(),
dithering: components.dithering.getValue(), dithering: components.dithering.getValue(),
ditheringMagnitude: components.ditheringMagnitude.getValue(), ditheringMagnitude: components.ditheringMagnitude.getValue(),
colourSpace: ColourSpace.RGB,
fallable: components.fallable.getValue() as FallableBehaviour, fallable: components.fallable.getValue() as FallableBehaviour,
resolution: Math.pow(2, components.colourAccuracy.getValue()), resolution: Math.pow(2, components.colourAccuracy.getValue()),
calculateLighting: components.calculateLighting.getValue(), calculateLighting: components.calculateLighting.getValue(),

View File

@ -1,14 +1,11 @@
import { BlockMeshParams, FallableBehaviour } from '../../runtime/block_mesh'; import { BlockMeshParams } from '../../runtime/block_mesh';
import { Bounds } from '../../runtime/bounds'; import { Bounds } from '../../runtime/bounds';
import { TBlockMeshBufferDescription, TMeshBufferDescription, TVoxelMeshBufferDescription } from '../buffer'; import { TBlockMeshBufferDescription, TMeshBufferDescription, TVoxelMeshBufferDescription } from '../buffer';
import { RGBAUtil } from '../../runtime/colour';
import { TStructureExport } from '../../runtime/exporters/base_exporter'; import { TStructureExport } from '../../runtime/exporters/base_exporter';
import { TExporters } from '../../runtime/exporters/exporters'; import { TExporters } from '../../runtime/exporters/exporters';
import { MaterialMap } from '../../runtime/mesh'; import { MaterialMap } from '../../runtime/mesh';
import { TMessage } from '../ui/console'; import { TMessage } from '../ui/console';
import { ColourSpace } from '../../runtime/util';
import { TAxis } from '../../runtime/util/type_util'; import { TAxis } from '../../runtime/util/type_util';
import { TDithering } from '../../runtime/util/type_util';
import { Vector3 } from '../../runtime/vector'; import { Vector3 } from '../../runtime/vector';
import { TVoxelisers } from '../../runtime/voxelisers/voxelisers'; import { TVoxelisers } from '../../runtime/voxelisers/voxelisers';
import { AppError } from '../util/editor_util'; import { AppError } from '../util/editor_util';

View File

@ -6,7 +6,7 @@ import { AppRuntimeConstants } from './constants';
import { Ditherer } from './dither'; import { Ditherer } from './dither';
import { BlockMeshLighting } from './lighting'; import { BlockMeshLighting } from './lighting';
import { Palette } from './palette'; import { Palette } from './palette';
import { ColourSpace, TOptional } from './util'; import { TOptional } from './util';
import { ASSERT } from './util/error_util'; import { ASSERT } from './util/error_util';
import { Vector3 } from './vector'; import { Vector3 } from './vector';
import { TDithering } from './util/type_util'; import { TDithering } from './util/type_util';
@ -31,7 +31,6 @@ export interface BlockMeshParams {
blockPalette: string[], blockPalette: string[],
dithering: TDithering, dithering: TDithering,
ditheringMagnitude: number, ditheringMagnitude: number,
colourSpace: ColourSpace,
fallable: FallableBehaviour, fallable: FallableBehaviour,
resolution: RGBAUtil.TColourAccuracy, resolution: RGBAUtil.TColourAccuracy,
calculateLighting: boolean, calculateLighting: boolean,

View File

@ -18,14 +18,22 @@ export class OtS_VoxelMesh {
private _voxels: Map<number, Ots_Voxel_Internal>; private _voxels: Map<number, Ots_Voxel_Internal>;
private _isBoundsDirty: boolean; private _isBoundsDirty: boolean;
private _bounds: Bounds; private _bounds: Bounds;
private _replaceMode: OtS_ReplaceMode;
public constructor() { public constructor() {
this._voxels = new Map(); this._voxels = new Map();
this._bounds = Bounds.getEmptyBounds(); this._bounds = Bounds.getEmptyBounds();
this._isBoundsDirty = false; this._isBoundsDirty = false;
this._replaceMode = 'average';
} }
public addVoxel(x: number, y: number, z: number, colour: RGBA, replaceMode: OtS_ReplaceMode) { public setReplaceMode(replaceMode: OtS_ReplaceMode) {
this._replaceMode = replaceMode;
}
public addVoxel(x: number, y: number, z: number, colour: RGBA, replaceMode?: OtS_ReplaceMode) {
const useReplaceMode = replaceMode ?? this._replaceMode;
const key = Vector3.Hash(x, y, z); const key = Vector3.Hash(x, y, z);
let voxel: (Ots_Voxel_Internal | undefined) = this._voxels.get(key); let voxel: (Ots_Voxel_Internal | undefined) = this._voxels.get(key);
@ -39,13 +47,13 @@ export class OtS_VoxelMesh {
this._voxels.set(key, voxel); this._voxels.set(key, voxel);
this._bounds.extendByPoint(position); this._bounds.extendByPoint(position);
} else { } else {
if (replaceMode === 'average') { if (useReplaceMode === 'average') {
voxel.colour.r = ((voxel.colour.r * voxel.collisions) + colour.r) / (voxel.collisions + 1); voxel.colour.r = ((voxel.colour.r * voxel.collisions) + colour.r) / (voxel.collisions + 1);
voxel.colour.g = ((voxel.colour.g * voxel.collisions) + colour.g) / (voxel.collisions + 1); voxel.colour.g = ((voxel.colour.g * voxel.collisions) + colour.g) / (voxel.collisions + 1);
voxel.colour.b = ((voxel.colour.b * voxel.collisions) + colour.b) / (voxel.collisions + 1); voxel.colour.b = ((voxel.colour.b * voxel.collisions) + colour.b) / (voxel.collisions + 1);
voxel.colour.a = ((voxel.colour.a * voxel.collisions) + colour.a) / (voxel.collisions + 1); voxel.colour.a = ((voxel.colour.a * voxel.collisions) + colour.a) / (voxel.collisions + 1);
++voxel.collisions; ++voxel.collisions;
} else if (replaceMode === 'replace') { } else if (useReplaceMode === 'replace') {
voxel.colour = RGBAUtil.copy(colour); voxel.colour = RGBAUtil.copy(colour);
voxel.collisions = 1; voxel.collisions = 1;
} }

View File

@ -71,13 +71,6 @@ export class UV {
} }
} }
/* eslint-disable */
export enum ColourSpace {
RGB,
LAB
}
/* eslint-enable */
export type TOptional<T> = T | undefined; export type TOptional<T> = T | undefined;
export function getRandomID(): string { export function getRandomID(): string {

View File

@ -1,5 +1,4 @@
import { PALETTE_ALL_RELEASE } from '../res/palettes/all'; import { PALETTE_ALL_RELEASE } from '../res/palettes/all';
import { ColourSpace } from '../src/runtime/util';
import { Vector3 } from '../src/runtime/vector'; import { Vector3 } from '../src/runtime/vector';
import { THeadlessConfig } from './headless'; import { THeadlessConfig } from './headless';
@ -20,7 +19,6 @@ export const headlessConfig: THeadlessConfig = {
blockPalette: PALETTE_ALL_RELEASE, // Must be a palette name that exists in /resources/palettes blockPalette: PALETTE_ALL_RELEASE, // Must be a palette name that exists in /resources/palettes
dithering: 'ordered', dithering: 'ordered',
ditheringMagnitude: 32, ditheringMagnitude: 32,
colourSpace: ColourSpace.RGB,
fallable: 'replace-falling', fallable: 'replace-falling',
resolution: 32, resolution: 32,
calculateLighting: false, calculateLighting: false,