Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A 3D model Previewer using the 'Online 3D Viewer' code #58

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions 6.1curlcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1755,3 +1755,51 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
```



### 3D model Previewer using the 'Online 3D Viewer' code (beta)

More info here (https://kovacsv.github.io/Online3DViewer/index.html)

__Note:__ There are many mimetypes that can be rendered as 3D models. You can add more mimetypes by adding more entries to the "contentType" field.

```bash
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
'{
"displayName":"Read 3D model",
"description":"Read the 3D model file using X3D from X_ITE.",
"toolName":"3D model Previewer",
"scope":"file",
"types":["preview"],
"toolUrl":"https://gdcc.github.io/dataverse-previewers/previewers/v1.4/X3DPreview.html",
"toolParameters": {
"queryParameters":[
{"fileid":"{fileId}"},
{"siteUrl":"{siteUrl}"},
{"datasetid":"{datasetId}"},
{"datasetversion":"{datasetVersion}"},
{"locale":"{localeCode}"}
]
},
"contentType":"model/obj",
"allowedApiCalls": [
{
"name": "retrieveFileContents",
"httpMethod": "GET",
"urlTemplate": "/api/v1/access/datafile/{fileId}?gbrecs=true",
"timeOut": 3600
},
{
"name": "downloadFile",
"httpMethod": "GET",
"urlTemplate": "/api/v1/access/datafile/{fileId}?gbrecs=false",
"timeOut": 3600
},
{
"name": "getDatasetVersionMetadata",
"httpMethod": "GET",
"urlTemplate": "/api/v1/datasets/{datasetId}/versions/{datasetVersion}",
"timeOut": 3600
}
]
}'
```
39 changes: 39 additions & 0 deletions previewers/betatest/O3DPreview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>

<head>
<meta charset="utf-8">
<title class="textPreview">3D model Preview</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="js/xss.js"></script>
<script src="lib/jquery.i18n.js"></script>
<script src="lib/jquery.i18n.messagestore.js"></script>
<script src="lib/jquery.i18n.language.js"></script>
<script type="text/javascript" src="js/retriever.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css"
integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="css/preview.css" />
<!-- Load locally downloaded from https://kovacsv.github.io/ -->
<script type="text/javascript" src="lib/o3dv/o3dv.min.js"></script>
</head>

<body class="container">
<main><img id='logo' alt='Site Logo'>
<h1 class="page-title o3dPreview">3D model Preview</h1>
<div class='preview-container'>
<div class='preview-header'></div>
<div class='preview'>
<!-- Small because it is a preview, you can go full-screen via the menu if needed -->
<div id="o3d_viewer" class="online_3d_viewer"
style="width: 100%; height: 480px; border:1px solid lightgrey;">
</div>
</div>
</div>
</main>
<script type="text/javascript" src="js/o3dview.js"></script>
</body>

</html>
81 changes: 81 additions & 0 deletions previewers/betatest/js/o3dview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
$(document).ready(function() {
startPreview(true);
});

function translateBaseHtmlPage() {
var o3dPreviewText = $.i18n( "o3dPreviewText" );
$( '.o3dPreviewText' ).text( o3dPreviewText );
}

function writeContentAndData(data, fileUrl, file, title, authors) {
addStandardPreviewHeader(file, title, authors);

/** Human readable formats could also be displayed (as text or xml or json).
options = {}; // Custom rules
$('.preview').append($("<pre/>").html(filterXSS(data,options)));
*/

// set the location of the external libraries
OV.SetExternalLibLocation ('../lib/o3dv/libs');

// get the parent element of the viewer
let parentDiv = document.getElementById ('o3d_viewer');

// initialize the viewer with the parent element and some parameters
let viewer = new OV.EmbeddedViewer (parentDiv, {
camera : new OV.Camera (
new OV.Coord3D (-1.5, 2.0, 3.0),
new OV.Coord3D (0.0, 0.0, 0.0),
new OV.Coord3D (0.0, 1.0, 0.0),
45.0
),
backgroundColor : new OV.RGBAColor (255, 255, 255, 255),
defaultColor : new OV.RGBColor (200, 200, 200),
edgeSettings : new OV.EdgeSettings (false, new OV.RGBColor (0, 0, 0), 1),
/**
environmentSettings : new OV.EnvironmentSettings (
[
'assets/envmaps/fishermans_bastion/posx.jpg',
'assets/envmaps/fishermans_bastion/negx.jpg',
'assets/envmaps/fishermans_bastion/posy.jpg',
'assets/envmaps/fishermans_bastion/negy.jpg',
'assets/envmaps/fishermans_bastion/posz.jpg',
'assets/envmaps/fishermans_bastion/negz.jpg'
],
false
)
*/
});

console.log("Start loading file: " + file.filename + " From: " + fileUrl);

// load a model providing model urls
//viewer.LoadModelFromUrlList ([
// fileUrl
//]);

// It tries tio get a filename from the URL, which won't work here
//
// https://github.com/kovacsv/Online3DViewer/issues/424
//
//const dataBlob = await fetch(fileUrl).then(res => res.blob());
//const dataFile = new File([dataBlob], file); // must manually provide correct extension
//viewer.LoadModelFromFileList([dataFile]);

// TODO fix problem with the filename, only have it in 'Open In New Window' link
filename = "";
if (file.hasOwnProperty("filename")) {
console.log("File has filename: " + file.filename);
filename = file.filename;
} else {
console.log("File has no filename, try extracting it from the page");
// Note that we are in an iframe, so we need to get the filename from the parent
filename = window.parent.$(".file-title-label").text();
console.log("filename: " + filename);
}
const dataFile = new File([data], filename);
viewer.LoadModelFromFileList([dataFile]);

// TODO, force to view whole object if possible?
//viewer.FitAll ();
}
Loading