Missing materials given random colours

This commit is contained in:
Lucas Dower 2022-11-13 01:57:04 +00:00
parent 74a2964808
commit 897f49c5f8
No known key found for this signature in database
GPG Key ID: B3EE6B8499593605
5 changed files with 38 additions and 12 deletions

View File

@ -234,9 +234,10 @@ export class AppContext {
if (oldMaterial.type == MaterialType.textured) {
this._materialMap[materialName] = {
type: MaterialType.solid,
colour: RGBAUtil.copy(RGBAColours.WHITE),
colour: RGBAUtil.random(),
edited: true,
canBeTextured: oldMaterial.canBeTextured,
set: false,
};
} else {
this._materialMap[materialName] = {
@ -280,6 +281,7 @@ export class AppContext {
colour: newColour,
edited: true,
canBeTextured: oldMaterial.canBeTextured,
set: true,
};
this._sendMaterialsToWorker((result: SetMaterialsParams.Output) => {

View File

@ -12,8 +12,20 @@ export namespace RGBAUtil {
return `(${a.r}, ${a.g}, ${a.b}, ${a.a})`;
}
export function random(): RGBA {
return {
r: Math.random(),
g: Math.random(),
b: Math.random(),
a: 1.0,
};
}
export function toHexString(a: RGBA) {
return `#${Math.floor(255 * a.r).toString(16)}${Math.floor(255 * a.g).toString(16)}${Math.floor(255 * a.b).toString(16)}`;
const r = Math.floor(255 * a.r).toString(16).padStart(2, '0');
const g = Math.floor(255 * a.g).toString(16).padStart(2, '0');
const b = Math.floor(255 * a.b).toString(16).padStart(2, '0');
return `#${r}${g}${b}`;
}
export function fromHexString(str: string) {

View File

@ -22,7 +22,7 @@ export class ObjImporter extends IImporter {
private _tris: Tri[] = [];
private _materials: { [key: string]: (SolidMaterial | TexturedMaterial) } = {
'DEFAULT_UNASSIGNED': { type: MaterialType.solid, colour: RGBAColours.WHITE, edited: true, canBeTextured: false },
'DEFAULT_UNASSIGNED': { type: MaterialType.solid, colour: RGBAColours.WHITE, edited: true, canBeTextured: false, set: true },
};
private _mtlLibs: string[] = [];
private _currentMaterialName: string = 'DEFAULT_UNASSIGNED';
@ -411,6 +411,7 @@ export class ObjImporter extends IImporter {
},
edited: false,
canBeTextured: false,
set: true,
};
}
this._currentAlpha = 1.0;

View File

@ -33,12 +33,16 @@ type BaseMaterial = {
canBeTextured: boolean,
}
export type SolidMaterial = BaseMaterial & { colour: RGBA; type: MaterialType.solid }
export type SolidMaterial = BaseMaterial & {
type: MaterialType.solid,
colour: RGBA,
set: boolean,
}
export type TexturedMaterial = BaseMaterial & {
path: string;
type: MaterialType.textured;
alphaPath?: string;
alphaFactor: number;
type: MaterialType.textured,
path: string,
alphaPath?: string,
alphaFactor: number,
}
export type MaterialMap = { [key: string]: (SolidMaterial | TexturedMaterial) };
@ -166,15 +170,16 @@ export class Mesh {
colour: RGBAColours.MAGENTA,
edited: true,
canBeTextured: false,
set: false,
};
} else {
// Texcoords exist, therefore make a texture material
// Texcoords exist
this._materials[tri.material] = {
type: MaterialType.textured,
path: PathUtil.join(AppPaths.Get.static, 'debug.png'),
alphaFactor: 1.0,
type: MaterialType.solid,
colour: RGBAUtil.random(),
edited: true,
canBeTextured: true,
set: false,
};
}
@ -215,6 +220,7 @@ export class Mesh {
colour: RGBAColours.WHITE,
edited: true,
canBeTextured: true,
set: false,
};
}
}
@ -388,6 +394,7 @@ export class Mesh {
colour: RGBAUtil.copy(material.colour),
edited: material.edited,
canBeTextured: material.canBeTextured,
set: material.set,
};
} else {
materials[materialName] = {

View File

@ -181,6 +181,10 @@ export class SolidMaterialUIElement extends MaterialUIElement {
return `<input class="colour-swatch" type="color" id="${this._colourId}" value="${RGBAUtil.toHexString(this._material.colour)}">`;
}
public hasWarning(): boolean {
return !this._material.set;
}
public registerEvents(): void {
super.registerEvents();