Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add orthographic camera support #157

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Points,
Camera,
PerspectiveCamera,
OrthographicCamera,
WebGLRenderer,
Texture,
Euler
Expand Down Expand Up @@ -370,14 +371,22 @@ class Loader3DTiles {

// Assumes camera fov, near and far are not changing
if (!sseDenominator || camera.aspect != lastCameraAspect) {
const loadersFrustum = new PerspectiveFrustum({
fov: (camera.fov / 180) * Math.PI,
aspectRatio: camera.aspect,
near: camera.near,
far: camera.far,
});
if (camera instanceof PerspectiveCamera) {
const loadersFrustum = new PerspectiveFrustum({
fov: (camera.fov / 180) * Math.PI,
aspectRatio: camera.aspect,
near: camera.near,
far: camera.far,
});
sseDenominator = loadersFrustum.sseDenominator;

} else if (camera instanceof OrthographicCamera) {
const width = camera.right - camera.left;
const height = camera.top - camera.bottom;
sseDenominator = Math.max(width, height);

sseDenominator = loadersFrustum.sseDenominator;
}

lastCameraAspect = camera.aspect;

if (options.debug) {
Expand Down Expand Up @@ -795,9 +804,17 @@ function disposeNode(node) {
}
}

function cameraChanged(camera:Camera, lastCameraTransform:Matrix4, lastCameraAspect: number) {
return !camera.matrixWorld.equals(lastCameraTransform) ||
!((<PerspectiveCamera>camera).aspect == lastCameraAspect);
function cameraChanged(camera: Camera, lastCameraTransform: Matrix4, lastCameraAspect?: number) {
// check if camera position changed
const positionChanged = !camera.matrixWorld.equals(lastCameraTransform);

// if camera is Perspective, check camera aspect also
if (camera instanceof PerspectiveCamera) {
return positionChanged || camera.aspect !== lastCameraAspect;
}

// check only position for Orthographic camera
return positionChanged;
}

export { Loader3DTiles, PointCloudColoring, Shading, Runtime, GeoCoord, GeoTransform, LoaderOptions, LoaderProps };