Add view presets

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

View file

@ -45,7 +45,7 @@ A step-by-step checklist for porting MatterControl's design features to a Vue +
- [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
- [x] Add "reset view" function (home position) - [x] Add "reset view" function (home position)
- [ ] Add view presets (front, back, top, bottom, left, right) - [x] Add view presets (front, back, top, bottom, left, right)
- [ ] Add orthographic/perspective toggle - [ ] Add orthographic/perspective toggle
### Scene State Management ### Scene State Management

View file

@ -27,6 +27,18 @@ let controls: OrbitControls
const HOME_POSITION = new THREE.Vector3(5, 5, 5) const HOME_POSITION = new THREE.Vector3(5, 5, 5)
const HOME_TARGET = new THREE.Vector3(0, 0, 0) const HOME_TARGET = new THREE.Vector3(0, 0, 0)
const VIEW_DISTANCE = 10
type ViewPreset = 'front' | 'back' | 'top' | 'bottom' | 'left' | 'right'
const VIEW_POSITIONS: Record<ViewPreset, THREE.Vector3> = {
front: new THREE.Vector3(0, 0, VIEW_DISTANCE),
back: new THREE.Vector3(0, 0, -VIEW_DISTANCE),
top: new THREE.Vector3(0, VIEW_DISTANCE, 0),
bottom: new THREE.Vector3(0, -VIEW_DISTANCE, 0),
left: new THREE.Vector3(-VIEW_DISTANCE, 0, 0),
right: new THREE.Vector3(VIEW_DISTANCE, 0, 0),
}
function initScene() { function initScene() {
if (!containerRef.value) return if (!containerRef.value) return
@ -169,6 +181,16 @@ function resetView() {
controls.update() controls.update()
} }
function setViewPreset(preset: ViewPreset) {
const position = VIEW_POSITIONS[preset]
camera.position.copy(position)
controls.target.set(0, 0, 0)
camera.up.set(0, 1, 0)
if (preset === 'top') camera.up.set(0, 0, -1)
if (preset === 'bottom') camera.up.set(0, 0, 1)
controls.update()
}
function cleanup() { function cleanup() {
if (animationFrameId) { if (animationFrameId) {
cancelAnimationFrame(animationFrameId) cancelAnimationFrame(animationFrameId)
@ -199,6 +221,7 @@ onBeforeUnmount(() => {
defineExpose({ defineExpose({
fitToSelection, fitToSelection,
resetView, resetView,
setViewPreset,
}) })
</script> </script>