-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pull in TrackballControls as CadControls (#66)
* pull in TrackballControls as CadControls * Rename CadControls.js to CadControls.ts --------- Co-authored-by: av8ta <[email protected]>
- Loading branch information
1 parent
ed67c2d
commit 85e48e6
Showing
5 changed files
with
733 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.