forked from mirror/ObjToSchematic
Missing materials given random colours
This commit is contained in:
parent
74a2964808
commit
897f49c5f8
@ -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) => {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
25
src/mesh.ts
25
src/mesh.ts
@ -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] = {
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user