Files
Pier_v1/src/view/fit.ts
T
ypshimandClaude Haiku 5.5 1d31d2f3a9 feat(abut): 교대 형상·입력 패널과 교각 받침·솔플레이트 개편
- 교대 형상(src/core/abut, 3D 장면, 목록·카메라·맞춤)과 교대 입력 패널 추가
- 교각 받침 기준 카드 제거, 솔플레이트 규칙을 교각별 입력으로 변경
- 받침 ELEVATION·솔플레이트 TABLE을 모델값으로 연결
- 교대 입력값 카드: 형식 행에 시점·종점 표시, 제목을 "A1 입력값 [입력]"으로 변경
- 테스트 614건 통과, 타입 검사 통과

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-11-03 14:51:34 +09:00

29 lines
1.0 KiB
TypeScript

import * as THREE from 'three';
/**
* Camera that contains a sphere (2026-11-03): keeps the view direction of `position → target`, moves the target to the
* sphere centre, and backs off until the sphere fits both the vertical and the horizontal field of view.
*/
export function fitCamera(
position: THREE.Vector3,
target: THREE.Vector3,
sphere: THREE.Sphere,
fovDeg: number,
aspect: number,
margin = 1.1,
): { position: THREE.Vector3; target: THREE.Vector3 } {
const halfV = THREE.MathUtils.degToRad(fovDeg / 2);
// The narrower of the two half-angles decides how far back the camera must stand.
const halfH = Math.atan(Math.tan(halfV) * aspect);
const halfFov = Math.min(halfV, halfH);
const fit = (sphere.radius / Math.sin(halfFov)) * margin;
const dir = position.clone().sub(target);
const current = dir.length();
const dist = Math.max(current, fit);
dir.normalize();
return {
position: sphere.center.clone().add(dir.multiplyScalar(dist)),
target: sphere.center.clone(),
};
}