Skip to content

Commit

Permalink
Enable logarithmic depth buffer for snapping examples
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Sep 13, 2023
1 parent fc14ed0 commit 2bd7a5b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
24 changes: 20 additions & 4 deletions examples/picking/snapToEdge.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h3>Components Used</h3>

const viewer = new Viewer({
canvasId: "myCanvas",
logarithmicDepthBufferEnabled: true,
dtxEnabled: true // Enable data texture model representation
});

Expand Down Expand Up @@ -67,14 +68,14 @@ <h3>Components Used</h3>
markerDiv.style.position = "absolute";
markerDiv.style.pointerEvents = "none";

viewer.scene.input.on("mousemove", function (canvasPos) {
// Mouse and touch input

function updateCursorPosition(canvasPos) {
const snapPickResult = viewer.scene.snapPick({
canvasPos: canvasPos,
canvasPos,
snapRadius: 30,
snapMode: "edge",
});

if (snapPickResult && snapPickResult.snappedCanvasPos) {
markerDiv.style.marginLeft = `${snapPickResult.snappedCanvasPos[0] - 10}px`;
markerDiv.style.marginTop = `${snapPickResult.snappedCanvasPos[1] - 10}px`;
Expand All @@ -86,7 +87,22 @@ <h3>Components Used</h3>
markerDiv.style.background = "white";
markerDiv.style.border = "1px solid black";
}
});
}

function mouseUpdateCursorPosition(event) {
event.preventDefault();
updateCursorPosition([event.clientX, event.clientY]);
}

function touchUpdateCursorPosition(event) {
event.preventDefault();
const touch = event.touches[0];
updateCursorPosition([touch.clientX, touch.clientY]);
}

document.addEventListener("mousemove", mouseUpdateCursorPosition);
document.addEventListener("touchstart", touchUpdateCursorPosition);
document.addEventListener("touchmove", touchUpdateCursorPosition);


</script>
Expand Down
23 changes: 19 additions & 4 deletions examples/picking/snapToVertex.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h3>Components Used</h3>

const viewer = new Viewer({
canvasId: "myCanvas",
logarithmicDepthBufferEnabled: true,
dtxEnabled: true // Enable data texture model representation
});

Expand Down Expand Up @@ -67,14 +68,14 @@ <h3>Components Used</h3>
markerDiv.style.position = "absolute";
markerDiv.style.pointerEvents = "none";

viewer.scene.input.on("mousemove", function (canvasPos) {
// Mouse and touch input

function updateCursorPosition(canvasPos) {
const snapPickResult = viewer.scene.snapPick({
canvasPos: canvasPos,
canvasPos,
snapRadius: 30,
snapMode: "vertex",
});

if (snapPickResult && snapPickResult.snappedCanvasPos) {
markerDiv.style.marginLeft = `${snapPickResult.snappedCanvasPos[0] - 10}px`;
markerDiv.style.marginTop = `${snapPickResult.snappedCanvasPos[1] - 10}px`;
Expand All @@ -86,8 +87,22 @@ <h3>Components Used</h3>
markerDiv.style.background = "white";
markerDiv.style.border = "1px solid black";
}
});
}

function mouseUpdateCursorPosition(event) {
event.preventDefault();
updateCursorPosition([event.clientX, event.clientY]);
}

function touchUpdateCursorPosition(event) {
event.preventDefault();
const touch = event.touches[0];
updateCursorPosition([touch.clientX, touch.clientY]);
}

document.addEventListener("mousemove", mouseUpdateCursorPosition);
document.addEventListener("touchstart", touchUpdateCursorPosition);
document.addEventListener("touchmove", touchUpdateCursorPosition);

</script>
</html>
23 changes: 19 additions & 4 deletions examples/picking/snapToVertex_vbo.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h3>Components Used</h3>

const viewer = new Viewer({
canvasId: "myCanvas",
logarithmicDepthBufferEnabled: true,
dtxEnabled: false // Disable data texture model representation
});

Expand Down Expand Up @@ -67,14 +68,14 @@ <h3>Components Used</h3>
markerDiv.style.position = "absolute";
markerDiv.style.pointerEvents = "none";

viewer.scene.input.on("mousemove", function (canvasPos) {
// Mouse and touch input

function updateCursorPosition(canvasPos) {
const snapPickResult = viewer.scene.snapPick({
canvasPos: canvasPos,
canvasPos,
snapRadius: 30,
snapMode: "vertex",
});

if (snapPickResult && snapPickResult.snappedCanvasPos) {
markerDiv.style.marginLeft = `${snapPickResult.snappedCanvasPos[0] - 10}px`;
markerDiv.style.marginTop = `${snapPickResult.snappedCanvasPos[1] - 10}px`;
Expand All @@ -86,8 +87,22 @@ <h3>Components Used</h3>
markerDiv.style.background = "white";
markerDiv.style.border = "1px solid black";
}
});
}

function mouseUpdateCursorPosition(event) {
event.preventDefault();
updateCursorPosition([event.clientX, event.clientY]);
}

function touchUpdateCursorPosition(event) {
event.preventDefault();
const touch = event.touches[0];
updateCursorPosition([touch.clientX, touch.clientY]);
}

document.addEventListener("mousemove", mouseUpdateCursorPosition);
document.addEventListener("touchstart", touchUpdateCursorPosition);
document.addEventListener("touchmove", touchUpdateCursorPosition);

</script>
</html>

0 comments on commit 2bd7a5b

Please sign in to comment.