mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
adjust model size
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import * as THREE from 'three';
|
||||
|
||||
export const sortByDate = (
|
||||
{ date: a }: { date: string },
|
||||
{ date: b }: { date: string }
|
||||
@ -118,3 +120,34 @@ export const debounce: Debounce = (fn, ms) => {
|
||||
}, ms);
|
||||
};
|
||||
};
|
||||
|
||||
export const frameArea = (
|
||||
sizeToFitOnScreen: number,
|
||||
boxSize: number,
|
||||
boxCenter: THREE.Vector3,
|
||||
camera: THREE.PerspectiveCamera
|
||||
) => {
|
||||
const halfSizeToFitOnScreen = sizeToFitOnScreen * 0.5;
|
||||
const halfFovY = THREE.MathUtils.degToRad(camera.fov * 0.5);
|
||||
const distance = halfSizeToFitOnScreen / Math.tan(halfFovY);
|
||||
// compute a unit vector that points in the direction the camera is now
|
||||
// in the xz plane from the center of the box
|
||||
const direction = new THREE.Vector3()
|
||||
.subVectors(camera.position, boxCenter)
|
||||
.multiply(new THREE.Vector3(1, 0, 1))
|
||||
.normalize();
|
||||
|
||||
// move the camera to a position distance units way from the center
|
||||
// in whatever direction the camera was from the center already
|
||||
camera.position.copy(direction.multiplyScalar(distance).add(boxCenter));
|
||||
|
||||
// pick some near and far values for the frustum that
|
||||
// will contain the box.
|
||||
camera.near = boxSize / 100;
|
||||
camera.far = boxSize * 100;
|
||||
|
||||
camera.updateProjectionMatrix();
|
||||
|
||||
// point the camera to look at the center of the box
|
||||
camera.lookAt(boxCenter.x, boxCenter.y, boxCenter.z);
|
||||
};
|
Reference in New Issue
Block a user