Skip to content

Commit

Permalink
Naively scale up gLTFs for now, add orbit controls (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
franknoirot authored Oct 19, 2023
1 parent a666f6c commit 00594de
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/components/ModelPreviewer.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
<script lang="ts">
import { T } from '@threlte/core'
import { GLTF } from '@threlte/extras'
import { GLTF, OrbitControls, interactivity } from '@threlte/extras'
interactivity()
export let dataUrl: string
let shouldAutoRotate = true
const AUTO_ROTATE_PAUSE = 5000
let autorotateTimeout: ReturnType<typeof setTimeout> | undefined
const disableAutoRotate = () => {
shouldAutoRotate = false
clearTimeout(autorotateTimeout)
}
const reenableAutoRotate = () => {
autorotateTimeout = setTimeout(function () {
shouldAutoRotate = true
}, AUTO_ROTATE_PAUSE)
}
</script>

<T.PerspectiveCamera
makeDefault
on:create={({ ref }) => {
ref.lookAt(0, 1, 0)
}}
/>
<T.PerspectiveCamera makeDefault fov={50} position={[20, 20, 20]}>
<OrbitControls
enableDamping
autoRotate={shouldAutoRotate}
on:start={disableAutoRotate}
on:end={reenableAutoRotate}
/>
</T.PerspectiveCamera>

<T.AmbientLight color="white" />
<T.DirectionalLight color="white" />
<T.DirectionalLight color="white" position={[5, 0, -5]} />

<GLTF
url={dataUrl}
position={[0, 1, 0]}
on:load={(payload) => {
console.log('loaded', payload)
}}
/>
<GLTF url={dataUrl} position={[0, 0, 0]} scale={300} />

0 comments on commit 00594de

Please sign in to comment.