From 050cde0a0ce7fdfe1194dbc70b31dce8bad5efd4 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Tue, 16 Aug 2022 01:10:29 +0200 Subject: [PATCH] Fix z-fighting and lowres-layer interaction --- src/MapViewer.js | 20 +++++++++----------- src/map/lowres/LowresVertexShader.js | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/MapViewer.js b/src/MapViewer.js index 5ad4287..ea22cec 100644 --- a/src/MapViewer.js +++ b/src/MapViewer.js @@ -177,16 +177,14 @@ export class MapViewer { this.raycaster.setFromCamera(normalizedScreenPos, this.camera); // check Object3D interactions - /* const intersectScenes = [this.map.hiresTileManager.scene, this.markers]; for (let i = 0; i < this.map.lowresTileManager.length; i++) { intersectScenes.push(this.map.lowresTileManager[i].scene); } - */ - let intersects = this.raycaster.intersectObjects([this.map.hiresTileManager.scene, this.markers], true); + let intersects = this.raycaster.intersectObjects(intersectScenes, true); let hit = null; - let lowresHit = null; + let lowresHits = []; let hiresHit = null; let covered = false; for (let i = 0; i < intersects.length; i++) { @@ -208,11 +206,11 @@ export class MapViewer { let parentRoot = object; while(parentRoot.parent) parentRoot = parentRoot.parent; - /* - if (parentRoot === this.map.lowresTileManager.scene) { - if (!lowresHit) lowresHit = intersects[i]; + for (let l = 0; l < this.map.lowresTileManager.length; l++) { + if (parentRoot === this.map.lowresTileManager[l].scene) { + if (!lowresHits[l]) lowresHits[l] = intersects[i]; + } } - */ if (parentRoot === this.map.hiresTileManager.scene) { if (!hiresHit) hiresHit = intersects[i]; @@ -225,9 +223,9 @@ export class MapViewer { })) return; } - //if (parentRoot !== this.map.lowresTileManager.scene) { + if (parentRoot !== this.map.lowresTileManager[0].scene) { covered = true; - //} + } } } } @@ -237,7 +235,7 @@ export class MapViewer { data: data, hit: hit, hiresHit: hiresHit, - lowresHit: lowresHit, + lowresHits: lowresHits, intersections: intersects, ray: this.raycaster.ray }); diff --git a/src/map/lowres/LowresVertexShader.js b/src/map/lowres/LowresVertexShader.js index 5229a7f..067a552 100644 --- a/src/map/lowres/LowresVertexShader.js +++ b/src/map/lowres/LowresVertexShader.js @@ -53,7 +53,7 @@ void main() { vPosition = position; vec4 meta = texture(textureImage, posToMetaUV(position.xz)); - vPosition.y += metaToHeight(meta); + vPosition.y = metaToHeight(meta) + 1.0 - position.x * 0.0001 - position.z * 0.0002; //including small offset-tilt to prevent z-fighting vec4 worldPos = modelMatrix * vec4(vPosition, 1); vec4 viewPos = viewMatrix * worldPos;