Skip to content

Commit 2abdd2f

Browse files
committed
docs: update demo
1 parent f6be7db commit 2abdd2f

3 files changed

Lines changed: 41 additions & 30 deletions

File tree

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createMemo, onCleanup, type Ref } from "solid-js"
1+
import { createEffect, createMemo, onCleanup, type Ref } from "solid-js"
22
import type { Event } from "three"
33
import { OrbitControls as ThreeOrbitControls } from "three-stdlib"
4-
import { useThree, type S3 } from "../../src/index.ts"
4+
import { useFrame, useThree, type S3 } from "../../src/index.ts"
55
import { manageProps } from "../../src/props.ts"
6-
import { every, whenEffect } from "../../src/utils/conditionals.ts"
6+
import { whenEffect } from "../../src/utils/conditionals.ts"
77
import { processProps } from "./process-props.ts"
88

99
export type OrbitControlsProps = S3.ClassProps<typeof ThreeOrbitControls> & {
@@ -39,36 +39,46 @@ export function OrbitControls(props: OrbitControlsProps) {
3939
],
4040
)
4141
const three = useThree()
42-
const controls = createMemo(() => new ThreeOrbitControls(config.camera ?? three.camera))
43-
44-
whenEffect(controls, controls => {
45-
controls.connect(props.domElement ?? three.gl.domElement)
46-
onCleanup(() => controls.dispose())
42+
const controls = createMemo<ThreeOrbitControls>(previous => {
43+
previous?.dispose()
44+
return new ThreeOrbitControls(config.camera ?? three.camera)
4745
})
4846

49-
whenEffect(
50-
every(controls, () => config.onStart),
51-
([controls, callback]) => {
52-
controls.addEventListener("start", callback)
53-
onCleanup(() => controls.removeEventListener("start", callback))
54-
},
55-
)
56-
whenEffect(
57-
every(controls, () => config.onChange),
58-
([controls, callback]) => {
59-
controls.addEventListener("change", callback)
60-
onCleanup(() => controls.removeEventListener("change", callback))
61-
},
62-
)
63-
whenEffect(
64-
every(controls, () => config.onEnd),
65-
([controls, callback]) => {
66-
controls.addEventListener("end", callback)
67-
onCleanup(() => controls.removeEventListener("end", callback))
68-
},
69-
)
47+
useFrame(() => controls().update())
48+
49+
whenEffect(controls, controls => controls.connect(props.domElement ?? three.gl.domElement))
50+
51+
createEffect(() => {
52+
const callback = config.onStart
53+
if (!callback) return
54+
const _controls = controls()
55+
_controls.addEventListener("start", callback)
56+
onCleanup(() => _controls.removeEventListener("start", callback))
57+
})
58+
createEffect(() => {
59+
const callback = config.onChange
60+
if (!callback) return
61+
const _controls = controls()
62+
_controls.addEventListener("change", callback)
63+
onCleanup(() => _controls.removeEventListener("change", callback))
64+
})
65+
createEffect(() => {
66+
const callback = config.onEnd
67+
if (!callback) return
68+
const _controls = controls()
69+
_controls.addEventListener("end", callback)
70+
onCleanup(() => _controls.removeEventListener("end", callback))
71+
})
7072

7173
manageProps(controls, rest)
7274

7375
return null!
7476
}
77+
78+
function createEventListener() {
79+
const callback = config.onStart
80+
if (!callback) return
81+
const _controls = controls()
82+
_controls.addEventListener("start", callback)
83+
onCleanup(() => _controls.removeEventListener("start", callback))
84+
}

playground/examples/SimpleSolar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function OrbitPath(
3838

3939
return (
4040
<T.Line
41-
pointerEvents={false}
41+
raycastable={false}
4242
ref={props.ref}
4343
onPointerMove={event => {
4444
event.stopPropagation()

playground/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
body {
22
padding: 0px;
33
margin: 0px;
4+
font-family: arial;
45
}

0 commit comments

Comments
 (0)