Merge pull request #935 from openglobus/read-depth-buffer-fix

Read depth buffer fix
This commit is contained in:
Michael Gevlich 2025-10-09 13:44:37 +02:00 committed by GitHub
commit bc6b6aea92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 20 deletions

View File

@ -13,7 +13,21 @@ import {Plane} from "../math/Plane";
import { createEvents, EventsHandler } from "../Events"; import { createEvents, EventsHandler } from "../Events";
interface ITouchNavigationParams extends IControlParams { interface ITouchNavigationParams extends IControlParams {
/**
* Inertia factor.
* Default: 0.007
*/
inertia?: number; inertia?: number;
/**
* Limit for tilt angle.
* Default: 0.1
*/
minSlope?: number;
/**
* Limit for touch jerk speed to prevent unexpected camera zooming.
* Default: 0.3
*/
jerkLimit?: number;
} }
export type TouchNavigationEventsList = [ export type TouchNavigationEventsList = [
@ -41,6 +55,9 @@ const TOUCH_NAVIGATION_EVENTS: TouchNavigationEventsList = [
*/ */
"doubletapzoom", "doubletapzoom",
]; ];
const DEFAULT_INERTIA = 0.007;
const DEFAULT_MIN_SLOPE = 0.1;
const DEFAULT_JERK_LIMIT = 0.3;
class TouchExt { class TouchExt {
public x: number; public x: number;
@ -86,8 +103,10 @@ class TouchExt {
* Touch pad planet camera dragging control. * Touch pad planet camera dragging control.
* @class * @class
* @extends {Control} * @extends {Control}
* @param {ITouchNavigationParams} [options] - Mouse navigation options: * @param {ITouchNavigationParams} [options] - Touch navigation options:
* @param {number} [options.inertia] - inertia factor. Default is 0.007 * @param {number} [options.inertia] - inertia factor. Default is 0.007
* @param {number} [options.minSlope] - minimal slope for vertical camera movement. Default is 0.1
* @param {number} [options.jerkLimit] - limit for touch jerk speed to prevent unexpected camera movement. Default is 0.08
* @fires og.TouchNavigation#inertiamove * @fires og.TouchNavigation#inertiamove
* @fires og.TouchNavigation#drag * @fires og.TouchNavigation#drag
* @fires og.TouchNavigation#doubletapzoom * @fires og.TouchNavigation#doubletapzoom
@ -96,6 +115,8 @@ export class TouchNavigation extends Control {
public grabbedPoint: Vec3; public grabbedPoint: Vec3;
public inertia: number; public inertia: number;
public minSlope: number;
public jerkLimit: number;
public events: EventsHandler<TouchNavigationEventsList>; public events: EventsHandler<TouchNavigationEventsList>;
protected grabbedSpheroid: Sphere; protected grabbedSpheroid: Sphere;
@ -117,7 +138,9 @@ export class TouchNavigation extends Control {
this.events = createEvents<TouchNavigationEventsList>(TOUCH_NAVIGATION_EVENTS, this); this.events = createEvents<TouchNavigationEventsList>(TOUCH_NAVIGATION_EVENTS, this);
this.grabbedPoint = new Vec3(); this.grabbedPoint = new Vec3();
this.inertia = options.inertia != undefined ? options.inertia : 0.007; this.inertia = options.inertia != undefined ? options.inertia : DEFAULT_INERTIA;
this.minSlope = options.minSlope != undefined ? options.minSlope : DEFAULT_MIN_SLOPE;
this.jerkLimit = options.jerkLimit != undefined ? options.jerkLimit : DEFAULT_JERK_LIMIT;
this.grabbedSpheroid = new Sphere(); this.grabbedSpheroid = new Sphere();
this.planet = null; this.planet = null;
this.qRot = new Quat(); this.qRot = new Quat();
@ -288,14 +311,14 @@ export class TouchNavigation extends Control {
t1.y = (e.sys!.touches.item(1)!.clientY - e.sys!.offsetTop) * handler.pixelRatio; t1.y = (e.sys!.touches.item(1)!.clientY - e.sys!.offsetTop) * handler.pixelRatio;
const middle = t0.vec.add(t1.vec).scale(0.5); const middle = t0.vec.add(t1.vec).scale(0.5);
const earthMiddlePoint = this.planet!.getCartesianFromPixelTerrain( const earthMiddlePoint = this.planet!.getCartesianFromPixelEllipsoid(
middle middle
); );
if (earthMiddlePoint) { if (earthMiddlePoint) {
this.pointOnEarth = earthMiddlePoint this.pointOnEarth = earthMiddlePoint;
const prevAngle = Math.atan2(t0.prev_y - t1.prev_y, t0.prev_x - t1.prev_x) const prevAngle = Math.atan2(t0.prev_y - t1.prev_y, t0.prev_x - t1.prev_x);
const curAngle = Math.atan2(t0.y - t1.y, t0.x - t1.x) const curAngle = Math.atan2(t0.y - t1.y, t0.x - t1.x);
const deltaAngle = curAngle - prevAngle; const deltaAngle = curAngle - prevAngle;
const distanceToPointOnEarth = cam.eye.distance(this.pointOnEarth); const distanceToPointOnEarth = cam.eye.distance(this.pointOnEarth);
@ -303,8 +326,9 @@ export class TouchNavigation extends Control {
const zoomCur = t0.vec.sub(t1.vec); const zoomCur = t0.vec.sub(t1.vec);
const zoomPrev = t0.vecPrev.sub(t1.vecPrev); const zoomPrev = t0.vecPrev.sub(t1.vecPrev);
let scale = zoomCur.length() / zoomPrev.length(); let scale = zoomCur.length() / zoomPrev.length();
scale = scale > 1.08 ? 1.08 : scale < 0.92 ? 0.92 : scale; const jerkMax = 1 + this.jerkLimit;
const jerkMin = 1 - this.jerkLimit;
scale = scale > jerkMax ? jerkMax : scale < jerkMin ? jerkMin : scale;
let d = distanceToPointOnEarth * -(1 - scale); let d = distanceToPointOnEarth * -(1 - scale);
cam.eye.addA(cam.getForward().scale(d)); cam.eye.addA(cam.getForward().scale(d));
cam.rotateAround(-deltaAngle, false, this.pointOnEarth, this.earthUp!); cam.rotateAround(-deltaAngle, false, this.pointOnEarth, this.earthUp!);
@ -315,7 +339,7 @@ export class TouchNavigation extends Control {
var l = 0.5 / distanceToPointOnEarth * cam._lonLat.height * math.RADIANS; var l = 0.5 / distanceToPointOnEarth * cam._lonLat.height * math.RADIANS;
if (l > 0.003) l = 0.003; if (l > 0.003) l = 0.003;
cam.rotateHorizontal(l * -panOffset.x, false, this.pointOnEarth, this.earthUp!); cam.rotateHorizontal(l * -panOffset.x, false, this.pointOnEarth, this.earthUp!);
cam.rotateVertical(l * -panOffset.y, this.pointOnEarth, 0.1); cam.rotateVertical(l * -panOffset.y, this.pointOnEarth, this.minSlope);
cam.checkTerrainCollision(); cam.checkTerrainCollision();
cam.update(); cam.update();

View File

@ -996,8 +996,10 @@ class Renderer {
*/ */
public draw() { public draw() {
this.activeCamera!.checkMoveEnd(); this.activeCamera!.checkMoveEnd();
let e = this.events; let e = this.events;
let pointerEvent = e.pointerEvent();
let pointerFree = !e.mouseState.leftButtonDown && !e.mouseState.rightButtonDown;
let touchTrigger = e.touchState.touchStart || e.touchState.touchEnd;
e.handleEvents(); e.handleEvents();
let sceneFramebuffer = this.sceneFramebuffer!; let sceneFramebuffer = this.sceneFramebuffer!;
@ -1017,8 +1019,7 @@ class Renderer {
let frustums = this.activeCamera!.frustums; let frustums = this.activeCamera!.frustums;
let pointerEvent = e.pointerEvent();
let pointerFree = !e.mouseState.leftButtonDown && !e.mouseState.rightButtonDown && !e.touchState.touching && !e.touchState.moving;
// Rendering scene nodes and entityCollections // Rendering scene nodes and entityCollections
let rn = this._renderNodesArr; let rn = this._renderNodesArr;
@ -1046,7 +1047,7 @@ class Renderer {
e.dispatch(e.drawtransparent, this); e.dispatch(e.drawtransparent, this);
if (pointerEvent && pointerFree) { if ((pointerEvent && pointerFree) || touchTrigger) {
this._drawPickingBuffer(0); this._drawPickingBuffer(0);
} }
@ -1066,7 +1067,7 @@ class Renderer {
this._drawEntityCollections(i); this._drawEntityCollections(i);
if (pointerEvent && pointerFree) { if ((pointerEvent && pointerFree) || touchTrigger) {
this._drawPickingBuffer(i); this._drawPickingBuffer(i);
} }
@ -1080,7 +1081,7 @@ class Renderer {
this.blitFramebuffer && (sceneFramebuffer as Multisample).blitTo(this.blitFramebuffer, 0); this.blitFramebuffer && (sceneFramebuffer as Multisample).blitTo(this.blitFramebuffer, 0);
if (pointerEvent && pointerFree) { if ((pointerEvent && pointerFree) || touchTrigger) {
this._readPickingBuffer(); this._readPickingBuffer();
this._readDepthBuffer(); this._readDepthBuffer();
} }

View File

@ -337,14 +337,10 @@ class RendererEvents extends Events<RendererEventsType> implements RendererEvent
} }
public pointerEvent(): boolean { public pointerEvent(): boolean {
let ms = this.mouseState, let ms = this.mouseState;
ts = this.touchState;
return ( return (
ms.moving || ms.moving ||
ms.justStopped || ms.justStopped ||
ts.moving ||
ts.touchStart ||
ts.touchEnd ||
ms.wheelDelta !== 0 ms.wheelDelta !== 0
) )
} }