Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit 59a691e

Browse files
committed
refactor(core): use SFC for components
### Description - Replace looped components pattern with `SFC` for colliders
1 parent 7a11432 commit 59a691e

10 files changed

Lines changed: 93 additions & 57 deletions

src/components/RigidBody.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { ShallowRef } from 'vue'
1515
import { useRapierContext } from '../composables'
1616
import { createColliderPropsFromObject, createRigidBody } from '../core'
1717
import { makePropsWatcherRB } from '../utils/props'
18-
import { BaseCollider } from './colliders'
18+
import { Collider } from './colliders'
1919
import type {
2020
ColliderProps,
2121
ExposedRigidBody,
@@ -164,7 +164,7 @@ onUnmounted(() => {
164164

165165
<template>
166166
<TresGroup ref="bodyGroup">
167-
<BaseCollider
167+
<Collider
168168
v-for="(_props, id) in autoColliderProps"
169169
:key="id"
170170
:shape="_props.shape"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="ball" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="capsule" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="cone" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="cuboid" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="cylinder" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="heightfield" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="hull" v-bind="props" />
10+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import Collider from './BaseCollider.vue'
3+
import type { ColliderProps } from '../../types'
4+
5+
const props = defineProps<Partial<Omit<ColliderProps, 'shape'>>>()
6+
</script>
7+
8+
<template>
9+
<Collider shape="trimesh" v-bind="props" />
10+
</template>

src/components/colliders/index.ts

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,26 @@
1-
import type { Component } from 'vue'
2-
3-
import BaseCollider from './BaseCollider.vue'
4-
import type { ColliderProps, ColliderShape } from '../../types'
5-
6-
const shapePrefixes: ColliderShape[] = [
7-
'ball',
8-
'cuboid',
9-
'capsule',
10-
'cone',
11-
'cylinder',
12-
'hull',
13-
'trimesh',
14-
'heightfield',
15-
]
16-
const otherColliders = {} as Record<
17-
Capitalize<`${ColliderShape}Collider`>,
18-
Component<Omit<ColliderProps, 'shape'>>
19-
>
20-
21-
for (const shape of shapePrefixes) {
22-
otherColliders[
23-
`${
24-
(shape.charAt(0).toUpperCase()
25-
+ shape.slice(1)) as Capitalize<ColliderShape>
26-
}Collider`
27-
] = {
28-
extends: BaseCollider,
29-
props: {
30-
...BaseCollider.props,
31-
shape: undefined,
32-
},
33-
setup(props, ctx) {
34-
return {
35-
...BaseCollider?.setup?.(
36-
{ ...props, shape } as Parameters<
37-
Exclude<(typeof BaseCollider)['setup'], undefined>
38-
>['0'],
39-
ctx,
40-
),
41-
}
42-
},
43-
}
44-
}
45-
461
/** @description `Collider` with the shape set to `ball` */
47-
export const BallCollider = otherColliders.BallCollider
2+
export { default as BallCollider } from './BallCollider.vue'
3+
4+
/** @description `Collider` with no shape set */
5+
export { default as Collider } from './BaseCollider.vue'
486

497
/** @description `Collider` with the shape set to `capsule` */
50-
export const CapsuleCollider = otherColliders.CapsuleCollider
8+
export { default as CapsuleCollider } from './CapsuleCollider.vue'
519

5210
/** @description `Collider` with the shape set to `cone` */
53-
export const ConeCollider = otherColliders.ConeCollider
11+
export { default as ConeCollider } from './ConeCollider.vue'
5412

5513
/** @description `Collider` with the shape set to `cuboid` */
56-
export const CuboidCollider = otherColliders.CuboidCollider
14+
export { default as CuboidCollider } from './CuboidCollider.vue'
5715

5816
/** @description `Collider` with the shape set to `cylinder` */
59-
export const CylinderCollider = otherColliders.CylinderCollider
17+
export { default as CylinderCollider } from './CylinderCollider.vue'
6018

6119
/** @description `Collider` with the shape set to `heightfield` */
62-
export const HeightfieldCollider = otherColliders.HeightfieldCollider
20+
export { default as HeightfieldCollider } from './HeightfieldCollider.vue'
6321

6422
/** @description `Collider` with the shape set to `hull` */
65-
export const HullCollider = otherColliders.HullCollider
23+
export { default as HullCollider } from './HullCollider.vue'
6624

6725
/** @description `Collider` with the shape set to `trimesh` */
68-
export const TrimeshCollider = otherColliders.TrimeshCollider
69-
70-
export { default as BaseCollider } from './BaseCollider.vue'
26+
export { default as TrimeshCollider } from './TrimeshCollider.vue'

0 commit comments

Comments
 (0)