Skip to content

Fix crash when slicing 3MF files without vertex normals - #192

Merged
jgphilpott merged 4 commits into
mainfrom
copilot/fix-error-slicing-model
Jul 1, 2026
Merged

Fix crash when slicing 3MF files without vertex normals#192
jgphilpott merged 4 commits into
mainfrom
copilot/fix-error-slicing-model

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

3MF files from MakerWorld (and similar sources) omit vertex normals from geometry data. The Polytree library's fromMesh() unconditionally accesses geometry.attributes.normal.array, throwing TypeError: Cannot read properties of undefined (reading 'array') when the attribute is absent.

Changes

  • src/slicer/slice.coffee — After cloning the mesh geometry, call computeVertexNormals() when the normal attribute is missing. Operates only on the internal clone; original mesh is unmodified.
# Ensure geometry has vertex normals before slicing.
# Some file formats (e.g., 3MF from MakerWorld) do not include normal data.
# Polytree.fromMesh requires normals to convert mesh geometry into polygons.
if not mesh.geometry.attributes.normal
    mesh.geometry.computeVertexNormals()
  • src/slicer/slice.test.coffee — Adds a Mesh Without Normals test that constructs a BufferGeometry with position data only (no normals), confirms slicing completes without throwing, produces valid G-code, and leaves the original geometry unmodified.

Copilot AI changed the title [WIP] Fix error slicing model when reading properties of undefined Fix crash when slicing 3MF files without vertex normals Jul 1, 2026
Copilot AI requested a review from jgphilpott July 1, 2026 04:53
@jgphilpott
jgphilpott marked this pull request as ready for review July 1, 2026 09:46
Copilot AI review requested due to automatic review settings July 1, 2026 09:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents slicing from crashing on meshes whose geometry omits vertex normals (common in some 3MF exports) by computing normals on the slicer’s internal geometry clone, and adds a regression test to ensure slicing succeeds without mutating the original input geometry.

Changes:

  • Compute vertex normals on the cloned mesh geometry when the normal attribute is missing before invoking Polytree slicing.
  • Add a new test case covering slicing a mesh that has position data but no vertex normals.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/slicer/slice.coffee Computes missing vertex normals on the cloned geometry to avoid Polytree slicing crashes.
src/slicer/slice.test.coffee Adds a regression test ensuring slicing succeeds when normals are absent and the original geometry remains unmodified.

Comment thread src/slicer/slice.coffee
Comment thread src/slicer/slice.test.coffee Outdated
@jgphilpott
jgphilpott merged commit a68aad6 into main Jul 1, 2026
1 check passed
@jgphilpott
jgphilpott deleted the copilot/fix-error-slicing-model branch July 1, 2026 10:27
Copilot AI mentioned this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error slicing model: Cannot read properties of undefined (reading 'array') when slicing 3mf from MakerWorld

3 participants