Fixed warnings

This commit is contained in:
Lucas Dower 2022-03-21 21:48:37 +00:00
parent d5ccda9fa9
commit cee9871bfa
2 changed files with 27 additions and 1 deletions

View File

@ -151,6 +151,8 @@ export class AppContext {
this._loadedMesh = importer.toMesh();
this._loadedMesh.processMesh();
Renderer.Get.useMesh(this._loadedMesh);
this._warnings = this._loadedMesh.getWarnings();
}
private _simplify() {
@ -201,6 +203,8 @@ export class AppContext {
if (filePath) {
exporter.export(this._loadedBlockMesh, filePath);
}
this._warnings = exporter.getWarnings();
}
public draw() {

View File

@ -85,12 +85,34 @@ export class Mesh extends Warnable {
// TODO: Check indices exist
if (this._vertices.length === 0) {
throw new CustomError('No verticies were loaded');
throw new CustomError('No vertices were loaded');
}
if (this._tris.length === 0) {
throw new CustomError('No triangles were loaded');
}
// Give warning if normals are not defined
let giveNormalsWarning = false;
for (let triIndex = 0; triIndex < this.getTriangleCount(); ++triIndex) {
const tri = this._tris[triIndex];
if (tri.normalIndices) {
const xWellDefined = tri.normalIndices.x < this._normals.length;
const yWellDefined = tri.normalIndices.y < this._normals.length;
const zWellDefined = tri.normalIndices.z < this._normals.length;
if (!xWellDefined || !yWellDefined || !zWellDefined) {
giveNormalsWarning = true;
break;
}
}
if (!tri.normalIndices) {
giveNormalsWarning = true;
break;
}
}
if (giveNormalsWarning) {
this.addWarning('Some vertices do not have their normals defined, this may cause voxels to be aligned incorrectly');
}
}
private _checkMaterials() {