Skip to content

Commit

Permalink
pull in TrackballControls as CadControls (#66)
Browse files Browse the repository at this point in the history
* pull in TrackballControls as CadControls

* Rename CadControls.js to CadControls.ts

---------

Co-authored-by: av8ta <[email protected]>
  • Loading branch information
MattFerraro and av8ta authored May 31, 2024
1 parent ed67c2d commit 85e48e6
Show file tree
Hide file tree
Showing 5 changed files with 733 additions and 2 deletions.
43 changes: 43 additions & 0 deletions applications/web/src/components/CadControls.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import {forwardEventHandlers, T, useTask, useParent, useThrelte} from "@threlte/core"
import type {Camera} from "three"
import {TrackballControls as ThreeTrackballControls} from "./CadControls.js"
import {onDestroy} from "svelte"
import {useControlsContext} from "./useControlsContext"
import type {TrackballControlsEvents, TrackballControlsProps, TrackballControlsSlots} from "./TrackballControls.svelte"
type $$Props = TrackballControlsProps
type $$Events = TrackballControlsEvents
type $$Slots = TrackballControlsSlots
const parent = useParent()
const isCamera = (p: any): p is Camera => {
return p.isCamera
}
const {renderer, invalidate} = useThrelte()
if (!isCamera($parent)) {
throw new Error("Parent missing: <TrackballControls> need to be a child of a <Camera>")
}
export const ref = new ThreeTrackballControls($parent, renderer.domElement)
useTask(ref.update, {
autoInvalidate: false,
})
const component = forwardEventHandlers()
const {trackballControls} = useControlsContext()
trackballControls.set(ref)
onDestroy(() => trackballControls.set(undefined))
</script>

<T is={ref} let:ref {...$$restProps} bind:this={$component} on:change={invalidate}>
<slot {ref} />
</T>
Loading

0 comments on commit 85e48e6

Please sign in to comment.