Skip to content

Commit

Permalink
fixed bug Tresjs#460 (Tresjs#467)
Browse files Browse the repository at this point in the history
Co-authored-by: Alvaro Saburido <[email protected]>
  • Loading branch information
Tinoooo and alvarosabu authored Dec 13, 2023
1 parent 378d1d0 commit 0f83422
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ let scene: TresScene | null = null

const { logError } = useLogger()

const supportedPointerEvents = [
'onClick',
'onPointerMove',
'onPointerEnter',
'onPointerLeave',
]

export const nodeOps: RendererOptions<TresObject, TresObject> = {
createElement(tag, _isSVG, _anchor, props) {
if (!props) props = {}
Expand Down Expand Up @@ -75,7 +82,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
},
insert(child, parent) {
if (parent && parent.isScene) scene = parent as unknown as TresScene

const parentObject = parent || scene

if (child?.isObject3D) {
Expand All @@ -87,10 +94,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
}

if (
child?.onClick
|| child?.onPointerMove
|| child?.onPointerEnter
|| child?.onPointerLeave
child && supportedPointerEvents.some(eventName => child[eventName])
) {
if (!scene?.userData.tres__registerAtPointerEventHandler)
throw 'could not find tres__registerAtPointerEventHandler on scene\'s userData'
Expand Down Expand Up @@ -127,7 +131,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
tresObject3D.material?.dispose()
tresObject3D.material = undefined
}

if (!object3D.userData.tres__geometryViaProp) {
tresObject3D.geometry?.dispose()
tresObject3D.geometry = undefined
Expand All @@ -149,10 +153,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
throw 'could not find tres__deregisterAtPointerEventHandler on scene\'s userData'

if (
object?.onClick
|| object?.onPointerMove
|| object?.onPointerEnter
|| object?.onPointerLeave
object && supportedPointerEvents.some(eventName => object[eventName])
)
deregisterAtPointerEventHandler?.(object as Object3D)
}
Expand Down Expand Up @@ -230,8 +231,11 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
if (value === '') value = true
// Set prop, prefer atomic methods if applicable
if (isFunction(target)) {
if (Array.isArray(value)) node[finalKey](...value)
else node[finalKey](value)
//don't call pointer event callback functions
if (!supportedPointerEvents.includes(prop)) {
if (Array.isArray(value)) node[finalKey](...value)
else node[finalKey](value)
}
return
}
if (!target?.set && !isFunction(target)) root[finalKey] = value
Expand Down

0 comments on commit 0f83422

Please sign in to comment.