From bd53300bc1fc5f01f63da78b4831a4155c17f232 Mon Sep 17 00:00:00 2001 From: Tore Levenstam <152867686+rapid-images-tore-levenstam@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:28:40 +0200 Subject: [PATCH 1/2] throw error when mesh lacks indices, positions or normals --- packages/dev/core/src/Meshes/csg.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/dev/core/src/Meshes/csg.ts b/packages/dev/core/src/Meshes/csg.ts index b50d5329ba7..c356ed28161 100644 --- a/packages/dev/core/src/Meshes/csg.ts +++ b/packages/dev/core/src/Meshes/csg.ts @@ -547,11 +547,21 @@ export class CSG { throw "BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh"; } - const indices = mesh.getIndices(), - positions = mesh.getVerticesData(VertexBuffer.PositionKind), - normals = mesh.getVerticesData(VertexBuffer.NormalKind), - uvs = mesh.getVerticesData(VertexBuffer.UVKind), - vertColors = mesh.getVerticesData(VertexBuffer.ColorKind); + const indices = mesh.getIndices(), + positions = mesh.getVerticesData(VertexBuffer.PositionKind), + normals = mesh.getVerticesData(VertexBuffer.NormalKind), + uvs = mesh.getVerticesData(VertexBuffer.UVKind), + vertColors = mesh.getVerticesData(VertexBuffer.ColorKind); + + if (indices === null) { + throw "BABYLON.CSG: Mesh has no indices"; + } + if (positions === null) { + throw "BABYLON.CSG: Mesh has no positions"; + } + if (normals === null) { + throw "BABYLON.CSG: Mesh has no normals"; + } const subMeshes = mesh.subMeshes; From aa9c0f03919d52ab77de93d513952f48912241d4 Mon Sep 17 00:00:00 2001 From: Tore Levenstam <152867686+rapid-images-tore-levenstam@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:36:26 +0200 Subject: [PATCH 2/2] remove unused imports and added eslint ignores --- packages/dev/core/src/Meshes/csg.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/dev/core/src/Meshes/csg.ts b/packages/dev/core/src/Meshes/csg.ts index c356ed28161..2723cd1988e 100644 --- a/packages/dev/core/src/Meshes/csg.ts +++ b/packages/dev/core/src/Meshes/csg.ts @@ -1,4 +1,4 @@ -import type { Nullable, FloatArray, IndicesArray } from "../types"; +import type { Nullable } from "../types"; import type { Scene } from "../scene"; import { Quaternion, Matrix, Vector3, Vector2 } from "../Maths/math.vector"; import { VertexBuffer } from "../Buffers/buffer"; @@ -554,12 +554,15 @@ export class CSG { vertColors = mesh.getVerticesData(VertexBuffer.ColorKind); if (indices === null) { + // eslint-disable-next-line no-throw-literal throw "BABYLON.CSG: Mesh has no indices"; } if (positions === null) { + // eslint-disable-next-line no-throw-literal throw "BABYLON.CSG: Mesh has no positions"; } if (normals === null) { + // eslint-disable-next-line no-throw-literal throw "BABYLON.CSG: Mesh has no normals"; }