From 1b37050129d219db897b5af20f28ae1beaba3f3e Mon Sep 17 00:00:00 2001 From: Nathan Mande Date: Mon, 28 Oct 2024 16:43:19 +0200 Subject: [PATCH] fix(core): unsupported props warns correction ### Description - Add new `vNode` extended types - `TresVNodeObject` - `TresVNode` - Add a `TresObject` to collider --- src/components/colliders/BaseCollider.vue | 4 +++- src/types/collision.ts | 4 ++-- src/types/object.ts | 15 +++++++++++++++ src/utils/collisions.ts | 8 ++++---- src/utils/intersections.ts | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/components/colliders/BaseCollider.vue b/src/components/colliders/BaseCollider.vue index cadf883..9430378 100644 --- a/src/components/colliders/BaseCollider.vue +++ b/src/components/colliders/BaseCollider.vue @@ -98,5 +98,7 @@ onUnmounted(() => { diff --git a/src/types/collision.ts b/src/types/collision.ts index ee8ab5a..c74267c 100644 --- a/src/types/collision.ts +++ b/src/types/collision.ts @@ -1,5 +1,5 @@ import type { Collider, RigidBody } from '@dimforge/rapier3d-compat' -import type { Object3D } from 'three' +import type { TresVNodeObject } from './object' export interface CollisionSource { collider: Collider @@ -7,7 +7,7 @@ export interface CollisionSource { }; export interface sourceTarget { - object: Object3D + object: TresVNodeObject context: CollisionSource } diff --git a/src/types/object.ts b/src/types/object.ts index cf7a9e4..387aa78 100644 --- a/src/types/object.ts +++ b/src/types/object.ts @@ -1,3 +1,18 @@ +import type { TresObject } from '@tresjs/core' +import type { SetupContext, VNode } from 'vue' + +/** @description */ +export type TresVNode = Omit & { + __vnode: VNode & { + children: Array + ctx: SetupContext + } + children: Array + ctx: SetupContext +} + +export type TresVNodeObject = TresObject & { __vnode: TresVNode } + /** @description Utility type to exclude properties with the type `never` */ export type NonNever = { [K in keyof T as T[K] extends never ? never : K]: T[K]; diff --git a/src/utils/collisions.ts b/src/utils/collisions.ts index 62a777e..de0d489 100644 --- a/src/utils/collisions.ts +++ b/src/utils/collisions.ts @@ -1,7 +1,7 @@ import type { ColliderHandle, World } from '@dimforge/rapier3d-compat' import type { Scene } from 'three' import type { Ref } from 'vue' -import type { CollisionSource, collisionType, sourceTarget } from '../types/collision' +import type { CollisionSource, collisionType, sourceTarget, TresVNodeObject } from '../types' export const getSourceFromColliderHandle = (world: World, handle: ColliderHandle) => { const collider = world.getCollider(handle) @@ -20,7 +20,7 @@ export const getSourceFromColliderHandle = (world: World, handle: ColliderHandle export const get3DGroupFromSource = (source: CollisionSource, scene: Ref) => { const uuid = (source.rigidBody?.userData as { uuid?: string })?.uuid - const currentRigidBodyNode = scene.value.getObjectByProperty('uuid', uuid) + const currentRigidBodyNode = scene.value.getObjectByProperty('uuid', uuid) as TresVNodeObject return currentRigidBodyNode } @@ -30,6 +30,6 @@ export const collisionEmisor = ( target: sourceTarget, started: boolean, ) => { - const collisionType: collisionType = started ? 'enter' : 'exit'; - (source.object as any)?.__vnode?.ctx?.emit?.(`collision-${collisionType}`, { source, target }) + const collisionType: collisionType = started ? 'enter' : 'exit' + source.object?.__vnode?.ctx?.emit?.(`collision-${collisionType}`, { source, target }) } diff --git a/src/utils/intersections.ts b/src/utils/intersections.ts index 0eee354..7c98368 100644 --- a/src/utils/intersections.ts +++ b/src/utils/intersections.ts @@ -6,7 +6,7 @@ export const emitIntersection = ( started: boolean, ) => { const collisionType: collisionType = started ? 'enter' : 'exit' - const colliderNode = (source.object as any)?.__vnode?.children?.[1]?.children?.find((child: any) => child?.component?.exposed?.instance?.value === source.context.collider) + const colliderNode = source.object?.__vnode?.children?.[1]?.children?.find(child => child?.component?.exposed?.instance?.value === source.context.collider) colliderNode?.component?.emit?.(`intersection-${collisionType}`, { source, target }) }