瀏覽代碼

fix: optional chaining on object pointer events

alvarosabu 2 年之前
父節點
當前提交
421a7d54c0
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      src/components/TresScene.ts

+ 3 - 3
src/components/TresScene.ts

@@ -97,11 +97,11 @@ export const TresScene = defineComponent<TresSceneProps>({
           if (intersects.length > 0) {
           if (intersects.length > 0) {
             currentInstance = intersects[0]
             currentInstance = intersects[0]
             if (prevInstance === null) {
             if (prevInstance === null) {
-              currentInstance.object.events.onPointerEnter?.(currentInstance)
+              currentInstance.object?.events?.onPointerEnter?.(currentInstance)
             }
             }
           } else {
           } else {
             if (prevInstance !== null) {
             if (prevInstance !== null) {
-              currentInstance?.object.events.onPointerLeave?.(prevInstance)
+              currentInstance?.object?.events?.onPointerLeave?.(prevInstance)
               currentInstance = null
               currentInstance = null
             }
             }
           }
           }
@@ -112,7 +112,7 @@ export const TresScene = defineComponent<TresSceneProps>({
 
 
       useEventListener(canvas.value, 'click', () => {
       useEventListener(canvas.value, 'click', () => {
         if (currentInstance === null) return
         if (currentInstance === null) return
-        currentInstance.object.events.onClick?.(currentInstance)
+        currentInstance.object?.events?.onClick?.(currentInstance)
       })
       })
     }
     }