diff --git a/src/editor/renderer/renderer.ts b/src/editor/renderer/renderer.ts index 0fa6e11..059f5d9 100644 --- a/src/editor/renderer/renderer.ts +++ b/src/editor/renderer/renderer.ts @@ -16,7 +16,7 @@ import { RenderMeshParams, RenderNextBlockMeshChunkParams, RenderNextVoxelMeshCh import { UIUtil } from '../../runtime/util/ui_util'; import { TAxis } from '../../runtime/util/type_util'; import { Atlas } from '../../runtime/atlas'; -import { Material, MaterialType } from '../../runtime/materials'; +import { Material } from '../../runtime/materials'; /* eslint-disable */ export enum MeshType { @@ -41,7 +41,7 @@ enum EDebugBufferComponents { * Dedicated type for passing to shaders for solid materials */ type InternalSolidMaterial = { - type: MaterialType.solid, + type: 'solid', colourArray: number[], } @@ -49,7 +49,7 @@ type InternalSolidMaterial = { * Dedicated type for passing to shaders for textured materials */ type InternalTextureMaterial = { - type: MaterialType.textured, + type: 'textured', diffuseTexture: WebGLTexture, // The texture to sample alpha values from (if is using a texture map) alphaTexture: WebGLTexture, @@ -328,9 +328,9 @@ export class Renderer { } private _createInternalMaterial(material: Material): (InternalSolidMaterial | InternalTextureMaterial) { - if (material.type === MaterialType.solid) { + if (material.type === 'solid') { return { - type: MaterialType.solid, + type: 'solid', colourArray: RGBAUtil.toArray(material.colour), }; } else { @@ -389,7 +389,7 @@ export class Renderer { } return { - type: MaterialType.textured, + type: 'textured', diffuseTexture: diffuseTexture, alphaTexture: alphaTexture, alphaValue: alphaValue, @@ -565,7 +565,7 @@ export class Renderer { private _drawMesh() { this._materialBuffers.forEach((materialBuffer, materialName) => { - if (materialBuffer.material.type === MaterialType.textured) { + if (materialBuffer.material.type === 'textured') { this._drawMeshBuffer(materialBuffer.buffer, materialBuffer.numElements, ShaderManager.Get.textureTriProgram!, { u_lightWorldPos: ArcballCamera.Get.getCameraPosition(-Math.PI/4, 0.0).toArray(), u_worldViewProjection: ArcballCamera.Get.getWorldViewProjection(), diff --git a/src/editor/ui/components/material_type.ts b/src/editor/ui/components/material_type.ts index 0487920..941f3c1 100644 --- a/src/editor/ui/components/material_type.ts +++ b/src/editor/ui/components/material_type.ts @@ -2,9 +2,9 @@ import { LOC } from '../../localiser'; import { AppIcons } from '../../../editor/ui/icons'; import { ConfigComponent } from './config'; import { ToolbarItemComponent } from './toolbar_item'; -import { Material, MaterialType } from '../../../runtime/materials'; +import { Material, OtS_MaterialType } from '../../../runtime/materials'; -export class MaterialTypeComponent extends ConfigComponent { +export class MaterialTypeComponent extends ConfigComponent { private _solidButton: ToolbarItemComponent; private _texturedButton: ToolbarItemComponent; private _material: Material; @@ -17,7 +17,7 @@ export class MaterialTypeComponent extends ConfigComponent { - if (this._material.type === MaterialType.textured) { + if (this._material.type === 'textured') { this._onClickChangeTypeDelegate?.(); } }); @@ -26,7 +26,7 @@ export class MaterialTypeComponent extends ConfigComponent { - if (this._material.type === MaterialType.solid) { + if (this._material.type === 'solid') { this._onClickChangeTypeDelegate?.(); } }); @@ -45,8 +45,8 @@ export class MaterialTypeComponent extends ConfigComponent { - if (material.type === MaterialType.solid) { + if (material.type === 'solid') { this.layoutDull['materials'].components[`mat_${material.name}`] = new SolidMaterialComponent(material.name, material) .setUnlocalisedLabel(material.name) .onChangeTypeDelegate(() => { - materialManager.changeMaterialType(material.name, MaterialType.textured); + materialManager.changeMaterialType(material.name, 'textured'); this.updateMaterialsAction(materialManager); }); } else { this.layoutDull['materials'].components[`mat_${material.name}`] = new TexturedMaterialComponent(material.name, material) .setUnlocalisedLabel(material.name) .onChangeTypeDelegate(() => { - materialManager.changeMaterialType(material.name, MaterialType.solid); + materialManager.changeMaterialType(material.name, 'solid'); this.updateMaterialsAction(materialManager); }) .onChangeTransparencyTypeDelegate((newTransparency) => { diff --git a/src/runtime/importers/gltf_loader.ts b/src/runtime/importers/gltf_loader.ts index 82b85e0..6e7178c 100644 --- a/src/runtime/importers/gltf_loader.ts +++ b/src/runtime/importers/gltf_loader.ts @@ -6,7 +6,7 @@ import { UV } from '../util'; import { Vector3 } from '../vector'; import { IImporter } from './base_importer'; import { OtS_Mesh, TEMP_CONVERT_MESH, Tri } from '../ots_mesh'; -import { Material, MaterialType } from '../materials'; +import { Material } from '../materials'; export type TGltfImporterError = | { type: 'failed-to-parse' } @@ -44,9 +44,8 @@ export class GltfLoader extends IImporter { const meshMaterials: Map = new Map(); meshMaterials.set('NONE', { name: 'NONE', - type: MaterialType.solid, + type: 'solid', colour: RGBAUtil.copy(RGBAColours.WHITE), - needsAttention: false, canBeTextured: false, }); let maxIndex = 0; @@ -111,22 +110,20 @@ export class GltfLoader extends IImporter { meshMaterials.set(materialName, { name: materialName, - type: MaterialType.textured, + type: 'textured', diffuse: { filetype: mimeType === 'image/jpeg' ? 'jpg' : 'png', raw: (mimeType === 'image/jpeg' ? 'data:image/jpeg;base64,' : 'data:image/png;base64,') + base64, }, extension: 'clamp', interpolation: 'linear', - needsAttention: false, transparency: { type: 'None' }, }); } catch { meshMaterials.set(materialName, { name: materialName, - type: MaterialType.solid, + type: 'solid', colour: RGBAUtil.copy(RGBAColours.WHITE), - needsAttention: false, canBeTextured: true, }); } @@ -144,14 +141,13 @@ export class GltfLoader extends IImporter { if (diffuseColour !== undefined) { meshMaterials.set(materialName, { name: materialName, - type: MaterialType.solid, + type: 'solid', colour: { r: diffuseColour[0], g: diffuseColour[1], b: diffuseColour[2], a: diffuseColour[3], }, - needsAttention: false, canBeTextured: false, }); } @@ -165,14 +161,13 @@ export class GltfLoader extends IImporter { if (!materialMade && emissiveColour !== undefined) { meshMaterials.set(materialName, { name: materialName, - type: MaterialType.solid, + type: 'solid', colour: { r: emissiveColour[0], g: emissiveColour[1], b: emissiveColour[2], a: 1.0, }, - needsAttention: false, canBeTextured: false, }); diff --git a/src/runtime/materials.ts b/src/runtime/materials.ts index 2ae1ebf..d4a3792 100644 --- a/src/runtime/materials.ts +++ b/src/runtime/materials.ts @@ -3,20 +3,19 @@ import { EImageChannel, TImageRawWrap, TTransparencyOptions, TTransparencyTypes import { ASSERT } from './util/error_util'; import { TTexelExtension, TTexelInterpolation } from './util/type_util'; -export enum MaterialType { solid, textured } +export type OtS_MaterialType = 'solid' | 'textured'; type BaseMaterial = { name: string, - needsAttention: boolean, // True if the user should make edits to this material } export type SolidMaterial = BaseMaterial & { - type: MaterialType.solid, + type: 'solid' colour: RGBA, canBeTextured: boolean, } export type TexturedMaterial = BaseMaterial & { - type: MaterialType.textured, + type: 'textured', diffuse?: TImageRawWrap, interpolation: TTexelInterpolation, extension: TTexelExtension, @@ -57,7 +56,7 @@ export class MaterialMapManager { public changeTransparencyType(materialName: string, newTransparencyType: TTransparencyTypes) { const currentMaterial = this.getMaterial(materialName); ASSERT(currentMaterial !== undefined, 'Cannot change transparency type of non-existent material'); - ASSERT(currentMaterial.type === MaterialType.textured); + ASSERT(currentMaterial.type === 'textured'); switch (newTransparencyType) { case 'None': @@ -90,7 +89,7 @@ export class MaterialMapManager { * Convert a material to a new type, i.e. textured to solid. * Will return if the material is already the given type. */ - public changeMaterialType(materialName: string, newMaterialType: MaterialType) { + public changeMaterialType(materialName: string, newMaterialType: OtS_MaterialType) { const currentMaterial = this.getMaterial(materialName); ASSERT(currentMaterial !== undefined, 'Cannot change material type of non-existent material'); @@ -99,27 +98,25 @@ export class MaterialMapManager { } switch (newMaterialType) { - case MaterialType.solid: - ASSERT(currentMaterial.type === MaterialType.textured, 'Old material expect to be texture'); + case 'solid': + ASSERT(currentMaterial.type === 'textured', 'Old material expect to be texture'); this._setMaterial(materialName, { name: materialName, - type: MaterialType.solid, + type: 'solid', colour: RGBAUtil.randomPretty(), canBeTextured: true, - needsAttention: true, }); break; - case MaterialType.textured: - ASSERT(currentMaterial.type === MaterialType.solid, 'Old material expect to be solid'); + case 'textured': + ASSERT(currentMaterial.type === 'solid', 'Old material expect to be solid'); this._setMaterial(materialName, { name: materialName, - type: MaterialType.textured, + type: 'textured', transparency: { type: 'None', }, extension: 'repeat', interpolation: 'linear', - needsAttention: true, diffuse: undefined, }); break; diff --git a/src/runtime/ots_mesh.ts b/src/runtime/ots_mesh.ts index 7830ec8..edb01a9 100644 --- a/src/runtime/ots_mesh.ts +++ b/src/runtime/ots_mesh.ts @@ -1,6 +1,6 @@ import { Bounds } from './bounds'; import { RGBAColours, RGBAUtil } from './colour'; -import { Material, MaterialMapManager, MaterialType, SolidMaterial } from './materials'; +import { Material, MaterialMapManager, SolidMaterial } from './materials'; import { degreesToRadians } from './math'; import { UV } from "./util"; import { Vector3 } from "./vector"; @@ -121,7 +121,7 @@ export class OtS_Mesh { for (let i = 0; i < this._materials.length; ++i) { const oldMaterial = this._materials[i]; if (oldMaterial.name === newMaterial.name) { - if (oldMaterial.type === MaterialType.solid && newMaterial.type === MaterialType.textured && !oldMaterial.canBeTextured) { + if (oldMaterial.type === 'solid' && newMaterial.type === 'textured' && !oldMaterial.canBeTextured) { return false; // Assigning a texture material to a non-textureable material } @@ -255,8 +255,7 @@ export function TEMP_CONVERT_MESH(vertices: Vector3[], uvs: UV[], tris: Tri[]): name: materialName, canBeTextured: hasTexcoords, colour: RGBAUtil.copy(RGBAColours.WHITE), - needsAttention: false, - type: MaterialType.solid, + type: 'solid', } materials.push(material); diff --git a/src/runtime/ots_mesh_texture_loader.ts b/src/runtime/ots_mesh_texture_loader.ts index 84a6ed1..d5b2b59 100644 --- a/src/runtime/ots_mesh_texture_loader.ts +++ b/src/runtime/ots_mesh_texture_loader.ts @@ -1,4 +1,3 @@ -import { MaterialType } from "./materials"; import { OtS_Mesh } from "./ots_mesh"; import { Texture } from "./texture"; @@ -13,7 +12,7 @@ export class OtS_Mesh_TextureLoader { this._textures.clear(); mesh.getMaterials().forEach((material) => { - if (material.type === MaterialType.textured) { + if (material.type === 'textured') { this._textures.set( material.name, new Texture({ diff --git a/src/runtime/ots_voxel_mesh_converter.ts b/src/runtime/ots_voxel_mesh_converter.ts index 98c7eea..dd99571 100644 --- a/src/runtime/ots_voxel_mesh_converter.ts +++ b/src/runtime/ots_voxel_mesh_converter.ts @@ -9,7 +9,6 @@ import { RGBA, RGBAColours, RGBAUtil } from './colour'; import { OtS_Mesh, OtS_Triangle } from './ots_mesh'; import { ASSERT } from './util/error_util'; import { OtS_Mesh_TextureLoader } from './ots_mesh_texture_loader'; -import { MaterialType } from './materials'; export type OtS_VoxelMesh_ConverterConfig = { constraintAxis: TAxis, @@ -128,7 +127,7 @@ export class OtS_VoxelMesh_Converter { } private _getVoxelColour(mesh: OtS_Mesh, triangle: OtS_Triangle, location: Vector3): RGBA { - if (triangle.material.type === MaterialType.solid) { + if (triangle.material.type === 'solid') { return RGBAUtil.copy(triangle.material.colour); } @@ -150,7 +149,7 @@ export class OtS_VoxelMesh_Converter { RGBAUtil.copy(RGBAColours.MAGENTA); } - ASSERT(triangle.material.type === MaterialType.textured); + ASSERT(triangle.material.type === 'textured'); const texture = this._textureLoader.getTexture(triangle.material.name); if (texture !== undefined) { return texture.getRGBA(uv, triangle.material.interpolation, triangle.material.extension);