First
This commit is contained in:
commit
98e799b7df
21 changed files with 1936 additions and 0 deletions
BIN
wwwroot/GruLogo_Inverted.png
Normal file
BIN
wwwroot/GruLogo_Inverted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
wwwroot/gruner.png
Normal file
BIN
wwwroot/gruner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
28
wwwroot/index.html
Normal file
28
wwwroot/index.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="icon" type="image/x-icon" href="https://cdn.autodesk.io/favicon.ico">
|
||||
<link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.css">
|
||||
<link rel="stylesheet" href="./main.css">
|
||||
<title>Autodesk Platform Services: Simple Viewer</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="header">
|
||||
<img class="logo" src="./gruner.png" >
|
||||
<span class="title">Simple Viewer</span>
|
||||
|
||||
<input style="display: none" type="file" id="input">
|
||||
</div>
|
||||
<div id="preview"></div>
|
||||
<div id="overlay"></div>
|
||||
<script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.js"></script>
|
||||
<script>modelURN = '<%=modelURN%>'</script>
|
||||
<script src="./main.js" type="module"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
55
wwwroot/main.css
Normal file
55
wwwroot/main.css
Normal file
|
@ -0,0 +1,55 @@
|
|||
body, html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
font-family: ArtifaktElement;
|
||||
}
|
||||
|
||||
#header, #preview, #overlay {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#header {
|
||||
height: 3em;
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#preview, #overlay {
|
||||
top: 3em;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
#overlay {
|
||||
z-index: 1;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
padding: 1em;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#overlay > .notification {
|
||||
margin: auto;
|
||||
padding: 1em;
|
||||
max-width: 50%;
|
||||
background: white;
|
||||
}
|
||||
|
||||
#header > * {
|
||||
height: 2em;
|
||||
margin: 0 0.5em;
|
||||
font-size: 1em;
|
||||
font-family: ArtifaktElement;
|
||||
}
|
||||
|
||||
#header .title {
|
||||
flex: 1 0 auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#models {
|
||||
flex: 0 1 auto;
|
||||
min-width: 2em;
|
||||
}
|
110
wwwroot/main.js
Normal file
110
wwwroot/main.js
Normal file
|
@ -0,0 +1,110 @@
|
|||
import { initViewer, loadModel } from "./viewer.js";
|
||||
|
||||
// Declare the index number of the model in the array
|
||||
const urnModelID = window.modelURN;
|
||||
console.log(urnModelID)
|
||||
|
||||
|
||||
// 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 resp = await fetch("/api/theurn");
|
||||
// if (!resp.ok) {
|
||||
// throw new Error(await resp.text());
|
||||
// }
|
||||
// const data = await resp.json();
|
||||
// const urn = data.urn;
|
||||
const resp1 = await fetch("/api/models");
|
||||
const allmodels = await resp1.json();
|
||||
const resp2 = await fetch("/api/selectedmodel")
|
||||
const selectModelName = await resp2.json();
|
||||
// const data2 = await resp2.json();
|
||||
for (let i = 0; i < allmodels.length; i++){
|
||||
if (allmodels[i].name == selectModelName.name){
|
||||
console.log(allmodels[i].urn);
|
||||
changeTitle(allmodels[i].name)
|
||||
return allmodels[i].urn;
|
||||
}
|
||||
}
|
||||
// const urns = models.map((model) => model.urn);
|
||||
// const titles = models.map((model) => model.name);
|
||||
// const randomIndex = Math.floor(Math.random() * urns.length);
|
||||
// console.log(urns)
|
||||
// changeTitle(titles[urnModelID]);
|
||||
// return urn;
|
||||
} catch (err) {
|
||||
alert("Could not list models. See the console for more details.");
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
initViewer(document.getElementById("preview")).then((viewer) => {
|
||||
loadModelwithViewer(viewer);
|
||||
});
|
||||
|
||||
|
||||
async function loadModelwithViewer(viewer) {
|
||||
if (window.onModelSelectedTimeout) {
|
||||
clearTimeout(window.onModelSelectedTimeout);
|
||||
delete window.onModelSelectedTimeout;
|
||||
}
|
||||
const urn = await getModelsUrn();
|
||||
window.location.hash = urn;
|
||||
|
||||
try {
|
||||
const resp = await fetch(`/api/models/${urn}/status`);
|
||||
if (!resp.ok) {
|
||||
throw new Error(await resp.text());
|
||||
}
|
||||
const status = await resp.json();
|
||||
switch (status.status) {
|
||||
case "n/a":
|
||||
showNotification(`Model has not been translated.`);
|
||||
break;
|
||||
case "inprogress":
|
||||
showNotification(`Model is being translated (${status.progress})...`);
|
||||
window.onModelSelectedTimeout = setTimeout(
|
||||
onModelSelected,
|
||||
5000,
|
||||
viewer,
|
||||
urn
|
||||
);
|
||||
break;
|
||||
case "failed":
|
||||
showNotification(
|
||||
`Translation failed. <ul>${status.messages
|
||||
.map((msg) => `<li>${JSON.stringify(msg)}</li>`)
|
||||
.join("")}</ul>`
|
||||
);
|
||||
break;
|
||||
default:
|
||||
clearNotification();
|
||||
loadModel(viewer, urn);
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
alert("Could not load model. See the console for more details.");
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
function showNotification(message) {
|
||||
const overlay = document.getElementById("overlay");
|
||||
overlay.innerHTML = `<div class="notification">${message}</div>`;
|
||||
overlay.style.display = "flex";
|
||||
}
|
||||
|
||||
function clearNotification() {
|
||||
const overlay = document.getElementById("overlay");
|
||||
overlay.innerHTML = "";
|
||||
overlay.style.display = "none";
|
||||
}
|
59
wwwroot/viewer.js
Normal file
59
wwwroot/viewer.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
async function getAccessToken(callback) {
|
||||
try {
|
||||
const resp = await fetch("/api/auth/token");
|
||||
if (!resp.ok) {
|
||||
throw new Error(await resp.text());
|
||||
}
|
||||
const { access_token, expires_in } = await resp.json();
|
||||
callback(access_token, expires_in);
|
||||
} catch (err) {
|
||||
alert("Could not obtain access token. See the console for more details.");
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
export function initViewer(container) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
Autodesk.Viewing.Initializer(
|
||||
{ env: "AutodeskProduction", getAccessToken },
|
||||
function () {
|
||||
const config = {
|
||||
extensions: ["Autodesk.DocumentBrowser"],
|
||||
};
|
||||
const viewer = new Autodesk.Viewing.GuiViewer3D(container, config);
|
||||
viewer.start();
|
||||
viewer.setTheme("light-theme");
|
||||
resolve(viewer);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function loadModel(viewer, urn) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
function onDocumentLoadSuccess(doc) {
|
||||
resolve(viewer.loadDocumentNode(doc, doc.getRoot().getDefaultGeometry()));
|
||||
}
|
||||
function onDocumentLoadFailure(code, message, errors) {
|
||||
reject({ code, message, errors });
|
||||
}
|
||||
viewer.setLightPreset(0);
|
||||
Autodesk.Viewing.Document.load(
|
||||
"urn:" + urn,
|
||||
onDocumentLoadSuccess,
|
||||
onDocumentLoadFailure
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const onToolbarCreated = (e) => {
|
||||
const group = viewer.toolbar.getControl("settingsTools");
|
||||
group.removeControl("toolbar-modelStructureTool");
|
||||
group.removeControl("toolbar-propertiesTool");
|
||||
//group.removeControl('toolbar-settingsTool');
|
||||
//group.removeControl('toolbar-fullscreenTool');
|
||||
viewer.removeEventListener(
|
||||
Autodesk.Viewing.TOOLBAR_CREATED_EVENT,
|
||||
onToolbarCreated
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue