Fixed #37, added triangle count warning

This commit is contained in:
Lucas Dower 2022-03-31 18:33:14 +01:00
parent acde66085f
commit 8e04c1eb00
3 changed files with 14 additions and 2 deletions

View File

@ -92,6 +92,10 @@ export class Mesh extends Warnable {
throw new CustomError('No triangles were loaded');
}
if (this._tris.length >= 100_000) {
this.addWarning(`The imported mesh has ${this._tris.length} triangles, consider simplifying it in a DDC such as Blender`);
}
// Give warning if normals are not defined
let giveNormalsWarning = false;
for (let triIndex = 0; triIndex < this.getTriangleCount(); ++triIndex) {

View File

@ -186,7 +186,7 @@ export const LOG_ERROR = console.error;
export const REGEX_NZ_WS = /[ \t]+/;
/** Regex for number */
export const REGEX_NUMBER = /[0-9\.\-]+/;
export const REGEX_NUMBER = /[0-9e+\.\-]+/;
export const REGEX_NZ_ANY = /.+/;
@ -280,7 +280,7 @@ export class Warnable {
}
public addWarning(warning: string) {
this._warnings.push(warning);
this._warnings.push('- ' + warning);
}
public getWarnings() {

View File

@ -10,6 +10,14 @@ test('Parse vertex #1', () => {
expect(mesh._vertices[0].equals(new Vector3(1, -2, 3))).toBe(true);
});
test('Parse vertex #2', () => {
const importer = new ObjImporter();
importer.parseOBJLine('v 4.467e+000 9.243e+000 9.869e+000');
const mesh = importer.toMesh();
expect(mesh._vertices.length).toEqual(1);
expect(mesh._vertices[0].equals(new Vector3(4.467e+000, 9.243e+000, 9.869e+000))).toBe(true);
});
test('Parse normal #1', () => {
const importer = new ObjImporter();
importer.parseOBJLine('vn -1.0 -0.5 0.0');