Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiprima committed Apr 9, 2024
1 parent 797b7e9 commit 89ff747
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
// camera.position.set(0, 0, 150000);
// camera.position.set(0, 0, 1250);

const camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 1, 20000);
camera.position.set(0, 0, 11000);
const camera = window._camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 1, 30000);
camera.position.z = 21000;
const originalZ = camera.position.z;
camera.lookAt(new THREE.Vector3(0, 0, 0));
scene.add(camera);

Expand All @@ -59,7 +60,7 @@
ZEPHYR.CreateImageViewer(scene, options.target,0);

// Annotation tools
toolbar(scene, camera, renderer, controls);
toolbar(scene, camera, renderer, controls, originalZ);

function animate() {
controls.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DragControls } from "three/addons/controls/DragControls.js";
/**
* Handles the process of selecting objects in a scene for editing, including adding edit handles and a deletion button.
*/
export function edit(scene, camera, renderer, controls) {
export function edit(scene, camera, renderer, controls, originalZ) {
let clicked = false;
let intersectableObjects = [];
let editButton = createButton({
Expand Down Expand Up @@ -98,7 +98,7 @@ export function edit(scene, camera, renderer, controls) {
}

const minDistance = 322;
const maxDistance = 11000;
const maxDistance = originalZ;

function calculateThreshold(currentDistance, minThreshold, maxThreshold) {
// Clamp currentDistance within the range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,21 @@ export function rectangle(scene, camera, renderer, controls, options) {

let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;

imgCoords.forEach(vertex => {
if (vertex.x < minX) minX = vertex.x;
if (vertex.x > maxX) maxX = vertex.x;
if (vertex.y < minY) minY = vertex.y;
if (vertex.y > maxY) maxY = vertex.y;
});
for (let i = 0; i < imgCoords.length; i += 2) {
const x = imgCoords[i];
const y = imgCoords[i + 1];

minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
}

const width = maxX - minX;
const height = maxY - minY;

// console.log({minX, maxX, minY, maxY, width, height});

let url = getUrl(scene);
if (url) {
const newUrl = `${url}/${Math.round(minX)},${Math.round(minY)},${Math.round(width)},${Math.round(height)}/512,/0/default.png`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createButton } from "./elements.js";

export function zoomControl(camera, controls) {
export function zoomControl(camera, controls, originalZ) {
// Create the select element (dropdown)
const dropdown = document.createElement('select');
dropdown.id = 'zoomLevel';
Expand Down Expand Up @@ -28,7 +28,7 @@ export function zoomControl(camera, controls) {

// Defined min and max distances for zooming
const minDistance = 322; // Fully zoomed in (without losing too much clarity)
const maxDistance = 11000; // Fully zoomed out (original camera.position.z)
const maxDistance = originalZ; // Fully zoomed out (original camera.position.z)

dropdown.addEventListener('change', function() {
const zoomSelection = parseFloat(this.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { zoomControl, lockRotate, resetCamera } from "./helpers/zoomControl.js";
import { screenCapture } from "./helpers/elements.js";
import { shading } from "./helpers/shading.js";

export function toolbar(scene, camera, renderer, controls) {
export function toolbar(scene, camera, renderer, controls, originalZ) {
// Enable drawing on the scene
enableDrawing(scene, camera, renderer, controls);
rectangle(scene, camera, renderer, controls, {
Expand All @@ -23,7 +23,7 @@ export function toolbar(scene, camera, renderer, controls) {
ellipse(scene, camera, renderer, controls);
polygon(scene, camera, renderer, controls);
hollowBrush(scene, camera, renderer, controls);
edit(scene, camera, renderer, controls);
edit(scene, camera, renderer, controls, originalZ);
shading(scene);
grid(scene, camera, renderer);
ruler(scene, camera, renderer, controls);
Expand All @@ -37,5 +37,5 @@ export function toolbar(scene, camera, renderer, controls) {
save(scene);
lockRotate(controls);
resetCamera(controls);
zoomControl(camera, controls);
zoomControl(camera, controls, originalZ);
}

0 comments on commit 89ff747

Please sign in to comment.