Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
fix(core): add check for material and geometry but parent is not a mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jul 28, 2022
1 parent 49b4c7f commit 6c3943d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libs/core/src/lib/abstracts/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ export abstract class NgtInstance<
}
}

// return early if instance is material or geometry but parent isn't a Mesh
if (
(propertyToAttach[0] === 'material' || propertyToAttach[0] === 'geometry') &&
!is.mesh(parentInstanceRef.value)
) {
return;
}

// retrieve the current value on the parentInstance so we can reset it later
this.__ngt__.previousAttachValue = propertyToAttach.reduce(
(value: any, property) => value[property],
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/lib/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const is = {
obj: (a: unknown): a is object => a === Object(a) && !is.arr(a) && typeof a !== 'function',
material: (a: unknown): a is THREE.Material => !!a && (a as THREE.Material)['isMaterial'],
geometry: (a: unknown): a is THREE.BufferGeometry => !!a && (a as THREE.BufferGeometry)['isBufferGeometry'],
mesh: (a: unknown): a is THREE.Mesh => !!a && (a as THREE.Mesh).isMesh,
orthographic: (a: unknown): a is THREE.OrthographicCamera =>
!!a && (a as THREE.OrthographicCamera).isOrthographicCamera,
perspective: (a: unknown): a is THREE.PerspectiveCamera => !!a && (a as THREE.PerspectiveCamera).isPerspectiveCamera,
Expand Down

0 comments on commit 6c3943d

Please sign in to comment.