chore: install prettier
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
export const utopiaUrn = 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGtxYjhrbHBnZWtsZ2tlbHBzanBoYzljMm5neXhtbjY0cXZocHNhcXVodjQ2emVuLWJhc2ljLWFwcC8yNi4wMS4xNiUyMC0lMjBFeHBvcnQlMjBUTUIlMjAtJTIwUGhhbiUyMG1lbS5kd2c';
|
||||
export const blankUrn = 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGtxYjhrbHBnZWtsZ2tlbHBzanBoYzljMm5neXhtbjY0cXZocHNhcXVodjQ2emVuLWJhc2ljLWFwcC9ibGFuay5kd2c';
|
||||
export const utopiaUrn =
|
||||
"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGtxYjhrbHBnZWtsZ2tlbHBzanBoYzljMm5neXhtbjY0cXZocHNhcXVodjQ2emVuLWJhc2ljLWFwcC8yNi4wMS4xNiUyMC0lMjBFeHBvcnQlMjBUTUIlMjAtJTIwUGhhbiUyMG1lbS5kd2c";
|
||||
export const blankUrn =
|
||||
"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGtxYjhrbHBnZWtsZ2tlbHBzanBoYzljMm5neXhtbjY0cXZocHNhcXVodjQ2emVuLWJhc2ljLWFwcC9ibGFuay5kd2c";
|
||||
|
||||
export async function getAccessToken(callback) {
|
||||
try {
|
||||
const { access_token, expires_in } = await $fetch('/api/apsAuthToken');
|
||||
const { access_token, expires_in } = await $fetch("/api/apsAuthToken");
|
||||
callback(access_token, expires_in);
|
||||
} catch (err) {
|
||||
console.error('Could not obtain access token. Error:', err);
|
||||
console.error("Could not obtain access token. Error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,15 +33,15 @@ export function loadModel(viewer, urn, xform) {
|
||||
}
|
||||
|
||||
function showNotification(message) {
|
||||
const overlay = document.getElementById('overlay');
|
||||
const overlay = document.getElementById("overlay");
|
||||
overlay.innerHTML = `<div class="notification">${message}</div>`;
|
||||
overlay.style.display = 'flex';
|
||||
overlay.style.display = "flex";
|
||||
}
|
||||
|
||||
function clearNotification() {
|
||||
const overlay = document.getElementById('overlay');
|
||||
overlay.innerHTML = '';
|
||||
overlay.style.display = 'none';
|
||||
const overlay = document.getElementById("overlay");
|
||||
overlay.innerHTML = "";
|
||||
overlay.style.display = "none";
|
||||
}
|
||||
|
||||
export async function setupModelSelection(viewer) {
|
||||
@@ -52,16 +54,16 @@ export async function setupModelSelection(viewer) {
|
||||
const res = await $fetch(`/api/models/${utopiaUrn}/status`);
|
||||
const { status } = res;
|
||||
switch (status.status) {
|
||||
case 'n/a':
|
||||
case "n/a":
|
||||
showNotification(`Model has not been translated.`);
|
||||
break;
|
||||
case 'inprogress':
|
||||
case "inprogress":
|
||||
showNotification(`Model is being translated (${status.progress})...`);
|
||||
window.onModelSelectedTimeout = setTimeout(onModelSelected, 5000, viewer, utopiaUrn);
|
||||
break;
|
||||
case 'failed':
|
||||
case "failed":
|
||||
showNotification(
|
||||
`Translation failed. <ul>${status.messages.map((msg) => `<li>${JSON.stringify(msg)}</li>`).join('')}</ul>`,
|
||||
`Translation failed. <ul>${status.messages.map((msg) => `<li>${JSON.stringify(msg)}</li>`).join("")}</ul>`,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
@@ -70,6 +72,6 @@ export async function setupModelSelection(viewer) {
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Could not load model. Error:', err);
|
||||
console.error("Could not load model. Error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
import { blankUrn, utopiaUrn } from '@/components/viewer/utils/aps-init';
|
||||
import { isNotNil } from 'es-toolkit';
|
||||
import { blankUrn, utopiaUrn } from "@/components/viewer/utils/aps-init";
|
||||
import { isNotNil } from "es-toolkit";
|
||||
|
||||
function isTemInsideLand(landBounds, temBounds) {
|
||||
const tolerance = 0.007;
|
||||
return (
|
||||
landBounds.min.x - temBounds.min.x <= tolerance
|
||||
&& landBounds.min.y - temBounds.min.y <= tolerance
|
||||
&& landBounds.max.x - temBounds.max.x >= -tolerance
|
||||
&& landBounds.max.y - temBounds.max.y >= -tolerance
|
||||
landBounds.min.x - temBounds.min.x <= tolerance &&
|
||||
landBounds.min.y - temBounds.min.y <= tolerance &&
|
||||
landBounds.max.x - temBounds.max.x >= -tolerance &&
|
||||
landBounds.max.y - temBounds.max.y >= -tolerance
|
||||
);
|
||||
}
|
||||
|
||||
export function findTemInside(land, tems) {
|
||||
const temInside = tems.find(tem => {
|
||||
const temBounds = tem.bounds[0];
|
||||
const temInside = tems.find((tem) => {
|
||||
const temBounds = tem.bounds[0];
|
||||
|
||||
for (const landBounds of land.bounds) {
|
||||
if (isTemInsideLand(landBounds, temBounds)) return true;
|
||||
if (isTemInsideLand(landBounds, temBounds)) return true;
|
||||
}
|
||||
});
|
||||
|
||||
return temInside;
|
||||
}
|
||||
|
||||
export const getTradeCodeFromTem = (tem) => tem.properties.find(prop => prop.displayName === 'LO').displayValue;
|
||||
export const objIsTem = (obj) => obj.name && obj.name.startsWith('Blk003');
|
||||
export const getTradeCodeFromTem = (tem) => tem.properties.find((prop) => prop.displayName === "LO").displayValue;
|
||||
export const objIsTem = (obj) => obj.name && obj.name.startsWith("Blk003");
|
||||
export const objIsLand = (obj) => {
|
||||
const layerProp = obj.properties.find((prop) => prop.displayName === 'Layer');
|
||||
const layerProp = obj.properties.find((prop) => prop.displayName === "Layer");
|
||||
if (!layerProp) return false;
|
||||
const globalWidthProp = obj.properties.find((prop) => prop.displayName === 'Global width');
|
||||
const globalWidthProp = obj.properties.find((prop) => prop.displayName === "Global width");
|
||||
return (
|
||||
layerProp.displayValue === '1-bodim' ||
|
||||
layerProp.displayValue === '0' /* special case - Z.E02.02A */
|
||||
) && globalWidthProp.displayValue === 0;
|
||||
}
|
||||
(layerProp.displayValue === "1-bodim" || layerProp.displayValue === "0") /* special case - Z.E02.02A */ &&
|
||||
globalWidthProp.displayValue === 0
|
||||
);
|
||||
};
|
||||
|
||||
export function findLandByTradeCode(trade_code, lands, temsInside) {
|
||||
const foundTemIndex = temsInside.findIndex(tem => tem && getTradeCodeFromTem(tem) === trade_code);
|
||||
const foundTemIndex = temsInside.findIndex((tem) => tem && getTradeCodeFromTem(tem) === trade_code);
|
||||
return foundTemIndex >= 0 ? [lands[foundTemIndex], foundTemIndex] : undefined;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export function pan(viewer) {
|
||||
const position = navigation.getPosition();
|
||||
const target = navigation.getTarget();
|
||||
|
||||
// offset both target and position to maintain angle
|
||||
// offset both target and position to maintain angle
|
||||
const panOffset = new THREE.Vector3(2, 0, 0);
|
||||
navigation.setPosition(position.clone().add(panOffset));
|
||||
navigation.setTarget(target.clone().add(panOffset));
|
||||
@@ -53,53 +53,53 @@ export function pan(viewer) {
|
||||
|
||||
export function unloadUnusedExtensions(viewer) {
|
||||
viewer.addEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT, (e) => {
|
||||
if (
|
||||
['Autodesk.Measure', 'Autodesk.DocumentBrowser', 'Autodesk.DefaultTools.NavTools'].includes(e.extensionId)
|
||||
) {
|
||||
if (["Autodesk.Measure", "Autodesk.DocumentBrowser", "Autodesk.DefaultTools.NavTools"].includes(e.extensionId)) {
|
||||
viewer.unloadExtension(e.extensionId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function addTemSelectionListener(viewer, products, openProductViewModal, openNoPermissionModal) {
|
||||
viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, (e) => {
|
||||
viewer.clearSelection();
|
||||
if (e.selections.length !== 1) return;
|
||||
const [selectedObj] = e.selections;
|
||||
const { model, dbIdArray } = selectedObj;
|
||||
if (dbIdArray.length !== 1) return;
|
||||
viewer.addEventListener(
|
||||
Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT,
|
||||
(e) => {
|
||||
viewer.clearSelection();
|
||||
if (e.selections.length !== 1) return;
|
||||
const [selectedObj] = e.selections;
|
||||
const { model, dbIdArray } = selectedObj;
|
||||
if (dbIdArray.length !== 1) return;
|
||||
|
||||
if (model.loader.svfUrn === utopiaUrn) {
|
||||
const [dbId] = dbIdArray;
|
||||
viewer.getProperties(dbId, (obj) => {
|
||||
if (!objIsTem(obj)) return;
|
||||
if (model.loader.svfUrn === utopiaUrn) {
|
||||
const [dbId] = dbIdArray;
|
||||
viewer.getProperties(dbId, (obj) => {
|
||||
if (!objIsTem(obj)) return;
|
||||
|
||||
const trade_code = getTradeCodeFromTem(obj);
|
||||
const product = products.find(p => p.trade_code === trade_code);
|
||||
const trade_code = getTradeCodeFromTem(obj);
|
||||
const product = products.find((p) => p.trade_code === trade_code);
|
||||
product ? openProductViewModal(product) : openNoPermissionModal();
|
||||
});
|
||||
} else if (model.loader.svf.isSceneBuilder) {
|
||||
const [dbId] = dbIdArray;
|
||||
const product = products.find((p) => p.id === dbId);
|
||||
product ? openProductViewModal(product) : openNoPermissionModal();
|
||||
});
|
||||
} else if (model.loader.svf.isSceneBuilder) {
|
||||
const [dbId] = dbIdArray;
|
||||
const product = products.find(p => p.id === dbId);
|
||||
product ? openProductViewModal(product) : openNoPermissionModal();
|
||||
} else if (model.loader.svfUrn === blankUrn) {
|
||||
viewer.clearSelection(); // make unselectable
|
||||
}
|
||||
},
|
||||
(err) => console.error(err),
|
||||
} else if (model.loader.svfUrn === blankUrn) {
|
||||
viewer.clearSelection(); // make unselectable
|
||||
}
|
||||
},
|
||||
(err) => console.error(err),
|
||||
);
|
||||
}
|
||||
|
||||
export function getLayerNames() {
|
||||
const { viewer } = window;
|
||||
if (!viewer) return;
|
||||
if (!viewer.impl) return;
|
||||
|
||||
if (!viewer) return;
|
||||
if (!viewer.impl) return;
|
||||
|
||||
const layerNames = viewer.impl.layers.indexToLayer
|
||||
.filter(obj => isNotNil(obj)) // not counting root
|
||||
.filter(obj => obj.visible)
|
||||
.filter((obj) => isNotNil(obj)) // not counting root
|
||||
.filter((obj) => obj.visible)
|
||||
.map(({ layer }) => layer.name)
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
return layerNames;
|
||||
}
|
||||
@@ -108,5 +108,5 @@ export function applyLayerSetting(layersetting, store) {
|
||||
const { viewer } = window;
|
||||
viewer.setLayerVisible(null, false); // first, hide everything
|
||||
viewer.setLayerVisible(layersetting?.detail || null, true); // show specific ones, or all if there's no setting
|
||||
store.commit('layersetting', layersetting);
|
||||
store.commit("layersetting", layersetting);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ export async function renderSvg(relativePath) {
|
||||
const svgRes = await fetch(relativePath);
|
||||
const svgText = await svgRes.text();
|
||||
const parser = new DOMParser();
|
||||
const svgDoc = parser.parseFromString(svgText, 'image/svg+xml');
|
||||
const svgDoc = parser.parseFromString(svgText, "image/svg+xml");
|
||||
const svgElement = svgDoc.documentElement;
|
||||
|
||||
return svgElement;
|
||||
@@ -12,21 +12,21 @@ export function html(tag, props = {}, children = []) {
|
||||
const element = document.createElement(tag);
|
||||
|
||||
Object.entries(props).forEach(([key, value]) => {
|
||||
if (key === 'textContent' || key === 'innerHTML') {
|
||||
if (key === "textContent" || key === "innerHTML") {
|
||||
element[key] = value;
|
||||
} else if (key === 'style' && typeof value === 'object') {
|
||||
} else if (key === "style" && typeof value === "object") {
|
||||
Object.assign(element.style, value);
|
||||
} else if (key === 'class') {
|
||||
} else if (key === "class") {
|
||||
element.className = value;
|
||||
} else if (key.startsWith('on')) {
|
||||
} else if (key.startsWith("on")) {
|
||||
element.addEventListener(key.slice(2).toLowerCase(), value);
|
||||
} else {
|
||||
element.setAttribute(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
children.flat().forEach(child => {
|
||||
if (typeof child === 'string') {
|
||||
children.flat().forEach((child) => {
|
||||
if (typeof child === "string") {
|
||||
element.appendChild(document.createTextNode(child));
|
||||
} else if (child instanceof Node) {
|
||||
element.appendChild(child);
|
||||
|
||||
@@ -10,22 +10,22 @@ export class GeometryCallback {
|
||||
let pt2 = new THREE.Vector3().set(x2, y2, 0).applyMatrix4(this.vpXform);
|
||||
|
||||
this.lines.push({
|
||||
x1: pt1.x,
|
||||
x1: pt1.x,
|
||||
y1: pt1.y,
|
||||
x2: pt2.x,
|
||||
y2: pt2.y
|
||||
x2: pt2.x,
|
||||
y2: pt2.y,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function getBounds(dbId, frags) {
|
||||
let fragIds = frags.fragments.dbId2fragId[dbId];
|
||||
if (typeof fragIds === 'number') {
|
||||
let fragIds = frags.fragments.dbId2fragId[dbId];
|
||||
if (typeof fragIds === "number") {
|
||||
fragIds = [fragIds];
|
||||
};
|
||||
}
|
||||
|
||||
const bounds = fragIds.map(fId => {
|
||||
const bound = new THREE.Box3();
|
||||
const bounds = fragIds.map((fId) => {
|
||||
const bound = new THREE.Box3();
|
||||
const boundsCallback = new Autodesk.Viewing.Private.BoundsCallback(bound);
|
||||
const mesh = frags.getVizmesh(fId);
|
||||
const vbr = new Autodesk.Viewing.Private.VertexBufferReader(mesh.geometry, viewer.impl.use2dInstancing);
|
||||
@@ -33,7 +33,7 @@ export function getBounds(dbId, frags) {
|
||||
return bound;
|
||||
});
|
||||
|
||||
return bounds;
|
||||
return bounds;
|
||||
}
|
||||
|
||||
export function extractPoints(lines) {
|
||||
@@ -50,8 +50,10 @@ export function extractPoints(lines) {
|
||||
|
||||
for (let i = 0; i < allPoints.length; i++) {
|
||||
const element = allPoints[i];
|
||||
|
||||
const notFound = !pointsDeduped.find(pt => Math.abs(pt.x - element.x) < tolerance && Math.abs(pt.y - element.y) < tolerance);
|
||||
|
||||
const notFound = !pointsDeduped.find(
|
||||
(pt) => Math.abs(pt.x - element.x) < tolerance && Math.abs(pt.y - element.y) < tolerance,
|
||||
);
|
||||
if (notFound) pointsDeduped.push(element);
|
||||
}
|
||||
|
||||
@@ -61,9 +63,9 @@ export function extractPoints(lines) {
|
||||
export function sortByAngle(points) {
|
||||
// Calculate centroid
|
||||
const centroid = new THREE.Vector3();
|
||||
points.forEach(v => centroid.add(v));
|
||||
points.forEach((v) => centroid.add(v));
|
||||
centroid.divideScalar(points.length);
|
||||
|
||||
|
||||
// Sort by angle around centroid
|
||||
return points.slice().sort((a, b) => {
|
||||
const angleA = Math.atan2(a.y - centroid.y, a.x - centroid.x);
|
||||
@@ -73,23 +75,15 @@ export function sortByAngle(points) {
|
||||
}
|
||||
|
||||
export function getColorByIndex(i) {
|
||||
const colors = [
|
||||
'magenta',
|
||||
'red',
|
||||
'orange',
|
||||
'yellow',
|
||||
'chartreuse',
|
||||
'green',
|
||||
'blue',
|
||||
]
|
||||
if (i === 0) return 'black';
|
||||
const colors = ["magenta", "red", "orange", "yellow", "chartreuse", "green", "blue"];
|
||||
if (i === 0) return "black";
|
||||
return colors[i % 7];
|
||||
}
|
||||
|
||||
/**
|
||||
* - THREE.Color: `{ r: number, g: number, b: number }`
|
||||
* - THREE.Vector4: `{ x: number, y: number, z: number, w: number }`
|
||||
*
|
||||
*
|
||||
* @param {string} colorStr e.g. `'#ff0000'`, `'white'`, `'hotpink'`
|
||||
* @returns A Vector4 object
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user