Skip to content

Commit

Permalink
Throw error in CSG when adding a mesh that lacks indices, positions o…
Browse files Browse the repository at this point in the history
…r normals (#15237)

* throw error when mesh lacks indices, positions or normals

* remove unused imports and added eslint ignores
  • Loading branch information
rapid-images-tore-levenstam authored Jun 28, 2024
1 parent d711471 commit 338d5ec
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/dev/core/src/Meshes/csg.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -547,11 +547,24 @@ export class CSG {
throw "BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh";
}

const indices = <IndicesArray>mesh.getIndices(),
positions = <FloatArray>mesh.getVerticesData(VertexBuffer.PositionKind),
normals = <FloatArray>mesh.getVerticesData(VertexBuffer.NormalKind),
uvs = <FloatArray>mesh.getVerticesData(VertexBuffer.UVKind),
vertColors = <FloatArray>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) {
// 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";
}

const subMeshes = mesh.subMeshes;

Expand Down

0 comments on commit 338d5ec

Please sign in to comment.