-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (142 loc) · 5.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>QPIX - Viewer</title>
<link rel="icon" type="image/x-icon" href="src/favicon.png">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css"
type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
html,
body {
margin: 0;
padding: 0;
height: 100vh;
}
#pointcloud-btn {
position: absolute;
z-index: 100;
margin-top: 15px;
margin-left: 75px;
height: 40px;
background-color: #2a2a2a;
color: white;
}
#pointcloud-btn:hover {
color: #00bfff;
border: 1px solid #00bfff;
}
#back-btn {
position: absolute;
z-index: 100;
margin-top: 15px;
margin-left: 15px;
height: 40px;
background-color: #2a2a2a;
color: white;
}
#back-btn:hover {
color: #00bfff;
border: 1px solid #00bfff;
}
#viewer {
height: 100%;
}
</style>
</head>
<body>
<main id="main">
<div id="viewer"></div>
<button type="button" id="back-btn" onclick="location.href='https://www.qpix.ai'"><img width="30" height="30"
src="https://img.icons8.com/3d-fluency/94/left.png" alt="left" /></button>
<button type="button" id="pointcloud-btn">Point Cloud</button>
</main>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"></script>
<script src="scripts/potree/potree.js"></script>
<script src="scripts/potree/PotreeExtension.js"></script>
<script>
var viewer;
var options = {
env: 'AutodeskProduction',
api: 'derivativeV2',
getAccessToken: getForgeToken
};
var documentId = 'urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cXBpeF9zYW1wbGVfMTIzNDUvRkxPT1IxLmdsdGY';
Autodesk.Viewing.Initializer(options, function onInitialized() {
var htmlElement = document.getElementById('viewer');
if (htmlElement) {
const config = {
extensions: ['PotreeExtension']
};
viewer = new Autodesk.Viewing.GuiViewer3D(htmlElement, config);
viewer.start(null, null, null, null, {
webglInitParams: {
useWebGL2: false
}
});
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
}
});
function onDocumentLoadSuccess(doc) {
var viewable = doc.getRoot().getDefaultGeometry();
if (viewable) {
viewer.loadDocumentNode(doc, viewable).then(function (result) {
$('#pointcloud-btn').on('click', function () {
loadPointCloud(viewer, "http://127.0.0.1:3000/scripts/potree/data/Stair/cloud.js");
});
}).catch(function (err) {
console.log('Viewable failed to load.');
console.log(err);
});
}
}
function onDocumentLoadFailure(viewerErrorCode) {
console.error('onDocumentLoadFailure() - errorCode: ' + viewerErrorCode);
jQuery('#viewer').html('<p>Translation in progress... Please try refreshing the page.</p>');
}
function getForgeToken(callback) {
const requestData = {
client_id: "pMj1ZGawdKDmwzTktKyZNTG1kkF6BrYj",
client_secret: "lEAjI1fMUhov7sMq",
grant_type: 'client_credentials',
scope: 'viewables:read'
};
jQuery.ajax({
method: 'POST',
url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
data: requestData,
}).then(function (response) {
callback(response.access_token, response.expires_in);
})
.catch(function (error) {
callback(null, null, error);
});
}
async function loadPointCloud(viewer, url) {
const potreeExtension = viewer.getExtension('PotreeExtension');
if (!potreeExtension) {
alert('PotreeExtension not available');
return;
}
let name = `Pointcloud from ${url}`;
let position = new THREE.Vector3(0, 0, -25);
let scale = new THREE.Vector3(5, 5, 5);
const pointcloud = await potreeExtension.loadPointCloud(name, url, position, scale);
const bbox = pointcloud.boundingBox.clone().expandByVector(scale);
viewer.navigation.fitBounds(false, bbox);
}
</script>
</body>
</html>