Add orbit controls
This commit is contained in:
parent
eb263061c1
commit
e19eee5f74
2 changed files with 13 additions and 1 deletions
2
TODO.md
2
TODO.md
|
|
@ -42,7 +42,7 @@ A step-by-step checklist for porting MatterControl's design features to a Vue +
|
||||||
- [x] Add option to toggle axis visibility
|
- [x] Add option to toggle axis visibility
|
||||||
|
|
||||||
### Camera Controls
|
### Camera Controls
|
||||||
- [ ] Install and configure OrbitControls (zoom, pan, orbit)
|
- [x] Install and configure OrbitControls (zoom, pan, orbit)
|
||||||
- [ ] Add "fit to selection" camera function
|
- [ ] Add "fit to selection" camera function
|
||||||
- [ ] Add "reset view" function (home position)
|
- [ ] Add "reset view" function (home position)
|
||||||
- [ ] Add view presets (front, back, top, bottom, left, right)
|
- [ ] Add view presets (front, back, top, bottom, left, right)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
|
import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
|
@ -22,6 +23,7 @@ let animationFrameId: number
|
||||||
let resizeObserver: ResizeObserver
|
let resizeObserver: ResizeObserver
|
||||||
let gridHelper: THREE.GridHelper
|
let gridHelper: THREE.GridHelper
|
||||||
let axisHelper: THREE.AxesHelper
|
let axisHelper: THREE.AxesHelper
|
||||||
|
let controls: OrbitControls
|
||||||
|
|
||||||
function initScene() {
|
function initScene() {
|
||||||
if (!containerRef.value) return
|
if (!containerRef.value) return
|
||||||
|
|
@ -42,6 +44,11 @@ function initScene() {
|
||||||
renderer.setPixelRatio(window.devicePixelRatio)
|
renderer.setPixelRatio(window.devicePixelRatio)
|
||||||
containerRef.value.appendChild(renderer.domElement)
|
containerRef.value.appendChild(renderer.domElement)
|
||||||
|
|
||||||
|
// Setup orbit controls
|
||||||
|
controls = new OrbitControls(camera, renderer.domElement)
|
||||||
|
controls.enableDamping = true
|
||||||
|
controls.dampingFactor = 0.05
|
||||||
|
|
||||||
// Add lighting
|
// Add lighting
|
||||||
addLighting()
|
addLighting()
|
||||||
|
|
||||||
|
|
@ -129,6 +136,7 @@ function setupResizeObserver() {
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
animationFrameId = requestAnimationFrame(animate)
|
animationFrameId = requestAnimationFrame(animate)
|
||||||
|
controls.update()
|
||||||
renderer.render(scene, camera)
|
renderer.render(scene, camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,6 +149,10 @@ function cleanup() {
|
||||||
resizeObserver.disconnect()
|
resizeObserver.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (controls) {
|
||||||
|
controls.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
if (renderer) {
|
if (renderer) {
|
||||||
renderer.dispose()
|
renderer.dispose()
|
||||||
renderer.domElement.remove()
|
renderer.domElement.remove()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue