Skip to content
Open
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
19 changes: 19 additions & 0 deletions packages/editor/src/lib/glb-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function prepareSceneForExport(
}

pruneNonRenderableMeshes(scene, identityNodes)
normalizeGeometryIndex(scene)
convertMaterials(scene)

const { clips, clipNamesByNode } = bakeAnimationClips(cloneByOriginal, nodes)
Expand Down Expand Up @@ -219,6 +220,24 @@ function pruneNonRenderableMeshes(root: THREE.Object3D, identityNodes: Set<THREE
}
}

/**
* Coerce every surviving mesh's `geometry.index` from `undefined` to `null`.
* three r184's STLExporter (and the OBJ/GLB paths) guard with `index !== null`
* and then read `index.count`; a `BufferGeometry` whose index was never set
* reports `undefined`, which passes that guard and crashes with
* `Cannot read properties of undefined (reading 'count')`. `BufferGeometry`
* treats `null` as "no index" (non-indexed draw), so this is the safe form the
* exporters expect. Fixes Sentry MONOREPO-EDITOR-E0.
*/
function normalizeGeometryIndex(root: THREE.Object3D) {
root.traverse((object) => {
const mesh = object as THREE.Mesh
if (!mesh.isMesh) return
const geometry = mesh.geometry as THREE.BufferGeometry | undefined
if (geometry && geometry.index === undefined) geometry.index = null
})
}

function isRenderableMesh(mesh: THREE.Mesh): boolean {
const position = mesh.geometry?.getAttribute('position')
if (!position || position.count === 0) return false
Expand Down
Loading