origin fixed
This commit is contained in:
commit
01bfbd5767
22 changed files with 1890 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 |
29
wwwroot/index.html
Normal file
29
wwwroot/index.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
<!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;
|
||||
}
|
41
wwwroot/main.js
Normal file
41
wwwroot/main.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
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();
|
89
wwwroot/viewer.js
Normal file
89
wwwroot/viewer.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
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, urns) {
|
||||
const viewerOptions = {
|
||||
extensions: [],
|
||||
};
|
||||
|
||||
Autodesk.Viewing.Initializer(
|
||||
{ env: "AutodeskProduction", getAccessToken },
|
||||
() => {
|
||||
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(
|
||||
container,
|
||||
viewerOptions
|
||||
);
|
||||
viewer.start();
|
||||
viewer.addEventListener(
|
||||
Autodesk.Viewing.TOOLBAR_CREATED_EVENT,
|
||||
onToolbarCreated
|
||||
);
|
||||
urns.map((m) => {
|
||||
addViewable(viewer, m);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function addViewable(viewer, urn, xform, offset) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
function onDocumentLoadSuccess(doc) {
|
||||
const viewable = doc.getRoot().getDefaultGeometry();
|
||||
const options = {
|
||||
//preserveView: true,
|
||||
keepCurrentModels: true,
|
||||
modelSpace: true, // 2D drawings
|
||||
applyRefPoint: true, // 3D shared coordinates
|
||||
applyScaling: 'm', // force all models to same scale
|
||||
globalOffset: {x:0,y:0,z:0}, // force all models to origin
|
||||
//placementTransform: (new THREE.Matrix4()).setPosition(m.xform)
|
||||
};
|
||||
if (xform) {
|
||||
options.placementTransform = xform;
|
||||
}
|
||||
if (offset) {
|
||||
options.globalOffset = offset;
|
||||
}
|
||||
viewer
|
||||
.loadDocumentNode(doc, viewable, options)
|
||||
.then(resolve)
|
||||
.catch(reject)
|
||||
// .then(onToolbarCreated(viewer));
|
||||
}
|
||||
function onDocumentLoadFailure(code) {
|
||||
console.error(`Document load failed with error code: ${code}`);
|
||||
console.error(`Failed URN: ${urn}`);
|
||||
// console.error(`Access Token: ${accessToken}`); // Log the access token if possible
|
||||
reject(`Could not load document (${code}).`);
|
||||
}
|
||||
console.log(urn);
|
||||
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