42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
|
import { initViewer } from "./viewer.js";
|
|||
|
|
|||
|
// Function to change the title text
|
|||
|
function changeTitle(newTitle) {
|
|||
|
const titleElement = document.querySelector(".title");
|
|||
|
if (titleElement) {
|
|||
|
titleElement.textContent = newTitle;
|
|||
|
} else {
|
|||
|
console.error("Title element not found");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
async function getModelsUrn() {
|
|||
|
try {
|
|||
|
const resp1 = await fetch("/api/models"); // api call to get all available models
|
|||
|
const allmodels = await resp1.json();
|
|||
|
const resp2 = await fetch("/api/selectedmodel"); // api call to get configured model name
|
|||
|
const selectModelName = await resp2.json();
|
|||
|
const selectedUrns = [];
|
|||
|
for (let j = 0; j < selectModelName.length; j++) {
|
|||
|
for (let i = 0; i < allmodels.length; i++) {
|
|||
|
if (allmodels[i].name === selectModelName[j].filename) {
|
|||
|
changeTitle("Model Viewer");
|
|||
|
selectedUrns.push(allmodels[i].urn);
|
|||
|
break; // Exit the inner loop if a match is found
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return selectedUrns;
|
|||
|
} catch (err) {
|
|||
|
alert("Could not list models. See the console for more details.");
|
|||
|
console.error(err);
|
|||
|
}
|
|||
|
}
|
|||
|
async function start() {
|
|||
|
const selModelss = await getModelsUrn();
|
|||
|
// console.log("yoooooo", selModelss)
|
|||
|
initViewer(document.getElementById("preview"), selModelss);
|
|||
|
}
|
|||
|
|
|||
|
start();
|