mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-12-11 20:15:30 +01:00
Change MaterialType enum to OtS_MaterialType type
This commit is contained in:
parent
9fae5a4336
commit
4d77a58d17
@ -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(),
|
||||
|
||||
@ -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<MaterialType, HTMLDivElement> {
|
||||
export class MaterialTypeComponent extends ConfigComponent<OtS_MaterialType, HTMLDivElement> {
|
||||
private _solidButton: ToolbarItemComponent;
|
||||
private _texturedButton: ToolbarItemComponent;
|
||||
private _material: Material;
|
||||
@ -17,7 +17,7 @@ export class MaterialTypeComponent extends ConfigComponent<MaterialType, HTMLDiv
|
||||
.setLabel(LOC('materials.components.solid'))
|
||||
.setGrow()
|
||||
.onClick(() => {
|
||||
if (this._material.type === MaterialType.textured) {
|
||||
if (this._material.type === 'textured') {
|
||||
this._onClickChangeTypeDelegate?.();
|
||||
}
|
||||
});
|
||||
@ -26,7 +26,7 @@ export class MaterialTypeComponent extends ConfigComponent<MaterialType, HTMLDiv
|
||||
.setLabel(LOC('materials.components.textured'))
|
||||
.setGrow()
|
||||
.onClick(() => {
|
||||
if (this._material.type === MaterialType.solid) {
|
||||
if (this._material.type === 'solid') {
|
||||
this._onClickChangeTypeDelegate?.();
|
||||
}
|
||||
});
|
||||
@ -45,8 +45,8 @@ export class MaterialTypeComponent extends ConfigComponent<MaterialType, HTMLDiv
|
||||
this._solidButton.finalise();
|
||||
this._texturedButton.finalise();
|
||||
|
||||
this._solidButton.setActive(this._material.type === MaterialType.solid);
|
||||
this._texturedButton.setActive(this._material.type === MaterialType.textured);
|
||||
this._solidButton.setActive(this._material.type === 'solid');
|
||||
this._texturedButton.setActive(this._material.type === 'textured');
|
||||
}
|
||||
|
||||
public override registerEvents(): void {
|
||||
@ -58,7 +58,7 @@ export class MaterialTypeComponent extends ConfigComponent<MaterialType, HTMLDiv
|
||||
super._onEnabledChanged();
|
||||
|
||||
this._solidButton.setEnabled(this.enabled);
|
||||
this._texturedButton.setEnabled(this.enabled && (this._material.type === MaterialType.textured || this._material.canBeTextured));
|
||||
this._texturedButton.setEnabled(this.enabled && (this._material.type === 'textured' || this._material.canBeTextured));
|
||||
}
|
||||
|
||||
protected override _onValueChanged(): void {
|
||||
|
||||
@ -7,7 +7,7 @@ import { ArcballCamera } from '../renderer/camera';
|
||||
import { EAppEvent, EventManager } from '../event';
|
||||
import { TExporters } from '../../runtime/exporters/exporters';
|
||||
import { LOC, Localiser, TLocalisedString } from '../localiser';
|
||||
import { MaterialMapManager, MaterialType } from '../../runtime/materials';
|
||||
import { MaterialMapManager } from '../../runtime/materials';
|
||||
import { MeshType, Renderer } from '../renderer/renderer';
|
||||
import { EAction } from '../../runtime/util';
|
||||
import { ASSERT } from '../../runtime/util/error_util';
|
||||
@ -872,18 +872,18 @@ export class UI {
|
||||
this.layoutDull['materials'].componentOrder.push(`placeholder_element`);
|
||||
} else {
|
||||
materialManager.toMaterialArray().forEach((material) => {
|
||||
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) => {
|
||||
|
||||
@ -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<string, Material> = 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,
|
||||
});
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user