Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error in CSG when adding a mesh that lacks indices, positions or normals #15237

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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