forked from mirror/ObjToSchematic
Added choice of colour space for colour matching
This commit is contained in:
parent
4f1975ccfe
commit
1818ab383a
@ -45,6 +45,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@popperjs/core": "^2.9.3",
|
"@popperjs/core": "^2.9.3",
|
||||||
|
"color-convert": "^2.0.1",
|
||||||
"eslint-config-google": "^0.14.0",
|
"eslint-config-google": "^0.14.0",
|
||||||
"expand-vertex-data": "^1.1.2",
|
"expand-vertex-data": "^1.1.2",
|
||||||
"jpeg-js": "^0.4.3",
|
"jpeg-js": "^0.4.3",
|
||||||
|
@ -75,8 +75,12 @@ export class UI {
|
|||||||
{ id: 'on', displayText: 'On (recommended)' },
|
{ id: 'on', displayText: 'On (recommended)' },
|
||||||
{ id: 'off', displayText: 'Off' },
|
{ id: 'off', displayText: 'Off' },
|
||||||
]),
|
]),
|
||||||
|
'colourSpace': new ComboBoxElement('Colour space', [
|
||||||
|
{ id: 'lab', displayText: 'LAB (recommended)' },
|
||||||
|
{ id: 'rgb', displayText: 'RGB' },
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
elementsOrder: ['textureAtlas', 'blockPalette', 'dithering'],
|
elementsOrder: ['textureAtlas', 'blockPalette', 'dithering', 'colourSpace'],
|
||||||
submitButton: new ButtonElement('Assign blocks', () => {
|
submitButton: new ButtonElement('Assign blocks', () => {
|
||||||
AppContext.Get.do(Action.Palette);
|
AppContext.Get.do(Action.Palette);
|
||||||
}),
|
}),
|
||||||
|
18
src/util.ts
18
src/util.ts
@ -1,7 +1,10 @@
|
|||||||
import { AppConfig } from './config';
|
import { AppConfig } from './config';
|
||||||
import { Vector3 } from './vector';
|
import { Vector3 } from './vector';
|
||||||
|
|
||||||
|
const convert = require('color-convert');
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { UI } from './ui/layout';
|
||||||
|
|
||||||
export class UV {
|
export class UV {
|
||||||
public u: number;
|
public u: number;
|
||||||
@ -47,9 +50,18 @@ export class RGB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static distance(a: RGB, b: RGB): number {
|
public static distance(a: RGB, b: RGB): number {
|
||||||
const _a = a.toVector3();
|
const useLAB = UI.Get.layout.palette.elements.colourSpace.getCachedValue() === 'lab';
|
||||||
const _b = b.toVector3();
|
if (useLAB) {
|
||||||
return _a.sub(_b).magnitude();
|
const aLAB = convert.rgb.lab(a.r * 255, a.g * 255, a.b * 255);
|
||||||
|
const bLAB = convert.rgb.lab(b.r * 255, b.g * 255, b.b * 255);
|
||||||
|
const _a = Vector3.fromArray(aLAB);
|
||||||
|
const _b = Vector3.fromArray(bLAB);
|
||||||
|
return _a.sub(_b).magnitude();
|
||||||
|
} else {
|
||||||
|
const _a = a.toVector3();
|
||||||
|
const _b = b.toVector3();
|
||||||
|
return _a.sub(_b).magnitude();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get white(): RGB {
|
public static get white(): RGB {
|
||||||
|
Loading…
Reference in New Issue
Block a user