Add reset view function

This commit is contained in:
Nettika 2026-01-29 00:00:58 -08:00
parent fa7370da4f
commit 2235d3ed63
No known key found for this signature in database
2 changed files with 13 additions and 3 deletions

View file

@ -44,7 +44,7 @@ A step-by-step checklist for porting MatterControl's design features to a Vue +
### Camera Controls ### Camera Controls
- [x] Install and configure OrbitControls (zoom, pan, orbit) - [x] Install and configure OrbitControls (zoom, pan, orbit)
- [x] Add "fit to selection" camera function - [x] Add "fit to selection" camera function
- [ ] Add "reset view" function (home position) - [x] Add "reset view" function (home position)
- [ ] Add view presets (front, back, top, bottom, left, right) - [ ] Add view presets (front, back, top, bottom, left, right)
- [ ] Add orthographic/perspective toggle - [ ] Add orthographic/perspective toggle

View file

@ -25,6 +25,9 @@ let gridHelper: THREE.GridHelper
let axisHelper: THREE.AxesHelper let axisHelper: THREE.AxesHelper
let controls: OrbitControls let controls: OrbitControls
const HOME_POSITION = new THREE.Vector3(5, 5, 5)
const HOME_TARGET = new THREE.Vector3(0, 0, 0)
function initScene() { function initScene() {
if (!containerRef.value) return if (!containerRef.value) return
@ -35,8 +38,8 @@ function initScene() {
// Create camera // Create camera
const { clientWidth: width, clientHeight: height } = containerRef.value const { clientWidth: width, clientHeight: height } = containerRef.value
camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000) camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000)
camera.position.set(5, 5, 5) camera.position.copy(HOME_POSITION)
camera.lookAt(0, 0, 0) camera.lookAt(HOME_TARGET)
// Create renderer // Create renderer
renderer = new THREE.WebGLRenderer({ antialias: true }) renderer = new THREE.WebGLRenderer({ antialias: true })
@ -160,6 +163,12 @@ function fitToSelection(objects: THREE.Object3D[]) {
controls.update() controls.update()
} }
function resetView() {
camera.position.copy(HOME_POSITION)
controls.target.copy(HOME_TARGET)
controls.update()
}
function cleanup() { function cleanup() {
if (animationFrameId) { if (animationFrameId) {
cancelAnimationFrame(animationFrameId) cancelAnimationFrame(animationFrameId)
@ -189,6 +198,7 @@ onBeforeUnmount(() => {
defineExpose({ defineExpose({
fitToSelection, fitToSelection,
resetView,
}) })
</script> </script>