Skip to content

Commit

Permalink
fix(core): unsupported props warns correction
Browse files Browse the repository at this point in the history
### Description

- Add new `vNode` extended types
  - `TresVNodeObject`
  - `TresVNode`
- Add a `TresObject` to collider
  • Loading branch information
Neosoulink committed Oct 28, 2024
1 parent 574778f commit 00530a3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/components/colliders/BaseCollider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ onUnmounted(() => {
</script>

<template>
<slot></slot>
<TresGroup>
<slot></slot>
</TresGroup>
</template>
4 changes: 2 additions & 2 deletions src/types/collision.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Collider, RigidBody } from '@dimforge/rapier3d-compat'
import type { Object3D } from 'three'
import type { TresVNodeObject } from './object'

export interface CollisionSource {
collider: Collider
rigidBody: RigidBody | undefined
};

export interface sourceTarget {
object: Object3D
object: TresVNodeObject
context: CollisionSource
}

Expand Down
15 changes: 15 additions & 0 deletions src/types/object.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import type { TresObject } from '@tresjs/core'
import type { SetupContext, VNode } from 'vue'

/** @description */
export type TresVNode = Omit<VNode, 'children'> & {
__vnode: VNode & {
children: Array<TresVNode>
ctx: SetupContext
}
children: Array<TresVNode>
ctx: SetupContext
}

export type TresVNodeObject = TresObject & { __vnode: TresVNode }

/** @description Utility type to exclude properties with the type `never` */
export type NonNever<T extends object> = {
[K in keyof T as T[K] extends never ? never : K]: T[K];
Expand Down
8 changes: 4 additions & 4 deletions src/utils/collisions.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -20,7 +20,7 @@ export const getSourceFromColliderHandle = (world: World, handle: ColliderHandle

export const get3DGroupFromSource = (source: CollisionSource, scene: Ref<Scene>) => {
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
}
Expand All @@ -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 })
}
2 changes: 1 addition & 1 deletion src/utils/intersections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

0 comments on commit 00530a3

Please sign in to comment.