mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-19 22:24:17 +01:00
chore(deps): update dependency @vue/tsconfig to ^0.8.0 (#251)
* chore(deps): update dependency @vue/tsconfig to ^0.8.0 * Fix new ts issues * Add null checks for selection and model objects throughout frontend This improves robustness by handling cases where selection or model objects may be missing or undefined, preventing runtime errors. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Yeicor <4929005+yeicor@users.noreply.github.com>
This commit is contained in:
@@ -161,9 +161,9 @@ function addLine3D(p1: Vector3, p2: Vector3, centerText?: string, lineAttrs: { [
|
||||
function removeLine3D(id: number): boolean {
|
||||
if (!scene.value || !(id in lines.value)) return false;
|
||||
scene.value.removeHotspot(new Hotspot({name: 'line' + id + '_start'}));
|
||||
lines.value[id].startHotspot.parentElement?.remove()
|
||||
lines.value[id]?.startHotspot.parentElement?.remove()
|
||||
scene.value.removeHotspot(new Hotspot({name: 'line' + id + '_end'}));
|
||||
lines.value[id].endHotspot.parentElement?.remove()
|
||||
lines.value[id]?.endHotspot.parentElement?.remove()
|
||||
delete lines.value[id];
|
||||
scene.value.queueRender() // Needed to update the hotspots
|
||||
return true;
|
||||
@@ -175,17 +175,17 @@ function onCameraChangeLine(lineId: number) {
|
||||
if (!(lineId in lines.value) || !(elem.value)) return // Silently ignore (not updated yet)
|
||||
// Update start and end 2D positions
|
||||
let {x: xB, y: yB} = elem.value.getBoundingClientRect();
|
||||
let {x, y} = lines.value[lineId].startHotspot.getBoundingClientRect();
|
||||
lines.value[lineId].start2D = [x - xB, y - yB];
|
||||
let {x: x2, y: y2} = lines.value[lineId].endHotspot.getBoundingClientRect();
|
||||
lines.value[lineId].end2D = [x2 - xB, y2 - yB];
|
||||
let {x, y} = lines.value[lineId]?.startHotspot.getBoundingClientRect() ?? {x: 0, y: 0};
|
||||
if (lines.value[lineId]) lines.value[lineId].start2D = [x - xB, y - yB];
|
||||
let {x: x2, y: y2} = lines.value[lineId]?.endHotspot.getBoundingClientRect() ?? {x: 0, y: 0};
|
||||
if (lines.value[lineId]) lines.value[lineId].end2D = [x2 - xB, y2 - yB];
|
||||
|
||||
// Update the center text size if needed
|
||||
if (svg.value && lines.value[lineId].centerText && lines.value[lineId].centerTextSize[0] === 0) {
|
||||
if (svg.value && lines.value[lineId]?.centerText && lines.value[lineId]?.centerTextSize[0] === 0) {
|
||||
let text = svg.value.getElementsByClassName('line' + lineId + '_text')[0] as SVGTextElement | undefined;
|
||||
if (text) {
|
||||
let bbox = text.getBBox();
|
||||
lines.value[lineId].centerTextSize = [bbox.width, bbox.height];
|
||||
if (lines.value[lineId]) lines.value[lineId].centerTextSize = [bbox.width, bbox.height];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,96 @@
|
||||
import {ModelViewerElement} from '@google/model-viewer';
|
||||
import {$scene} from "@google/model-viewer/lib/model-viewer-base";
|
||||
import {settings} from "../misc/settings.ts";
|
||||
import { ModelViewerElement } from "@google/model-viewer";
|
||||
import { $scene } from "@google/model-viewer/lib/model-viewer-base";
|
||||
import { settings } from "../misc/settings.ts";
|
||||
|
||||
export let currentSceneRotation = 0; // radians, 0 is the default rotation
|
||||
|
||||
export async function setupLighting(modelViewer: ModelViewerElement) {
|
||||
modelViewer[$scene].environmentIntensity = (await settings).environmentIntensity;
|
||||
// Code is mostly copied from the example at: https://modelviewer.dev/examples/stagingandcameras/#turnSkybox
|
||||
let lastX: number;
|
||||
let panning = false;
|
||||
let radiansPerPixel: number;
|
||||
modelViewer[$scene].environmentIntensity = (await settings).environmentIntensity;
|
||||
// Code is mostly copied from the example at: https://modelviewer.dev/examples/stagingandcameras/#turnSkybox
|
||||
let lastX: number;
|
||||
let panning = false;
|
||||
let radiansPerPixel: number;
|
||||
|
||||
const startPan = () => {
|
||||
const orbit = modelViewer.getCameraOrbit();
|
||||
const {radius} = orbit;
|
||||
radiansPerPixel = -1 * radius / modelViewer.getBoundingClientRect().height;
|
||||
modelViewer.interactionPrompt = 'none';
|
||||
};
|
||||
const startPan = () => {
|
||||
const orbit = modelViewer.getCameraOrbit();
|
||||
const { radius } = orbit;
|
||||
radiansPerPixel = (-1 * radius) / modelViewer.getBoundingClientRect().height;
|
||||
modelViewer.interactionPrompt = "none";
|
||||
};
|
||||
|
||||
const updatePan = (thisX: number) => {
|
||||
const delta = (thisX - lastX) * radiansPerPixel;
|
||||
lastX = thisX;
|
||||
currentSceneRotation += delta;
|
||||
const orbit = modelViewer.getCameraOrbit();
|
||||
orbit.theta += delta;
|
||||
modelViewer.cameraOrbit = orbit.toString();
|
||||
modelViewer.resetTurntableRotation(currentSceneRotation);
|
||||
modelViewer.jumpCameraToGoal();
|
||||
}
|
||||
const updatePan = (thisX: number) => {
|
||||
const delta = (thisX - lastX) * radiansPerPixel;
|
||||
lastX = thisX;
|
||||
currentSceneRotation += delta;
|
||||
const orbit = modelViewer.getCameraOrbit();
|
||||
orbit.theta += delta;
|
||||
modelViewer.cameraOrbit = orbit.toString();
|
||||
modelViewer.resetTurntableRotation(currentSceneRotation);
|
||||
modelViewer.jumpCameraToGoal();
|
||||
};
|
||||
|
||||
modelViewer.addEventListener('mousedown', (event) => {
|
||||
panning = event.metaKey || event.shiftKey;
|
||||
if (!panning)
|
||||
return;
|
||||
modelViewer.addEventListener(
|
||||
"mousedown",
|
||||
(event) => {
|
||||
panning = event.metaKey || event.shiftKey;
|
||||
if (!panning) return;
|
||||
|
||||
lastX = event.clientX;
|
||||
startPan();
|
||||
event.stopPropagation();
|
||||
}, true);
|
||||
lastX = event.clientX;
|
||||
startPan();
|
||||
event.stopPropagation();
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
modelViewer.addEventListener('touchstart', (event) => {
|
||||
const {targetTouches, touches} = event;
|
||||
panning = targetTouches.length === 2 && targetTouches.length === touches.length;
|
||||
if (!panning)
|
||||
return;
|
||||
modelViewer.addEventListener(
|
||||
"touchstart",
|
||||
(event) => {
|
||||
const { targetTouches, touches } = event;
|
||||
panning = targetTouches.length === 2 && targetTouches.length === touches.length;
|
||||
if (!panning) return;
|
||||
|
||||
lastX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX);
|
||||
startPan();
|
||||
}, true);
|
||||
lastX = 0.5 * ((targetTouches[0]?.clientX ?? 0) + (targetTouches[1]?.clientX ?? 0));
|
||||
startPan();
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
document.addEventListener('mousemove', (event) => {
|
||||
if (!panning)
|
||||
return;
|
||||
document.addEventListener(
|
||||
"mousemove",
|
||||
(event) => {
|
||||
if (!panning) return;
|
||||
|
||||
updatePan(event.clientX);
|
||||
event.stopPropagation();
|
||||
}, true);
|
||||
updatePan(event.clientX);
|
||||
event.stopPropagation();
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
modelViewer.addEventListener('touchmove', (event) => {
|
||||
if (!panning || event.targetTouches.length !== 2)
|
||||
return;
|
||||
modelViewer.addEventListener(
|
||||
"touchmove",
|
||||
(event) => {
|
||||
if (!panning || event.targetTouches.length !== 2) return;
|
||||
|
||||
const {targetTouches} = event;
|
||||
const thisX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX);
|
||||
updatePan(thisX);
|
||||
}, true);
|
||||
const { targetTouches } = event;
|
||||
const thisX = 0.5 * ((targetTouches[0]?.clientX ?? 0) + (targetTouches[1]?.clientX ?? 0));
|
||||
updatePan(thisX);
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
document.addEventListener('mouseup', (event) => {
|
||||
panning = false;
|
||||
}, true);
|
||||
document.addEventListener(
|
||||
"mouseup",
|
||||
(event) => {
|
||||
panning = false;
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
modelViewer.addEventListener('touchend', (event) => {
|
||||
panning = false;
|
||||
}, true);
|
||||
}
|
||||
modelViewer.addEventListener(
|
||||
"touchend",
|
||||
(event) => {
|
||||
panning = false;
|
||||
},
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user