-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
74 lines (58 loc) · 2.85 KB
/
index.html
File metadata and controls
74 lines (58 loc) · 2.85 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Request Screenshot | DriveWorks</title>
<style>
body { background: #eee; padding: 1em 2em; margin: 0; font-family: sans-serif; }
img { max-width: 100%; }
</style>
</head>
<body>
<h1>Generate a static image from a 3D Preview Control</h1>
<div id="output">Loading...</div>
<script src="config.js"></script>
<script>
// Run on client load
async function dwClientLoaded() {
try {
// Create DriveWorks API client
const DW_CLIENT = new window.DriveWorksLiveClient(config.serverUrl);
// Login to group
await DW_CLIENT.loginGroup(config.groupAlias);
// Create Specification
const specification = await DW_CLIENT.createSpecification(config.groupAlias, config.projectName);
// [OPTIONAL] Pass options as Constants (ensure Constants are exposed, with canEdit="true", in DriveWorksConfigUser.xml)
if (config.constantName) {
await DW_CLIENT.getSpecificationConstantByName(config.groupAlias, specification.id, config.constantName);
await DW_CLIENT.updateConstantValue(config.groupAlias, specification.id, config.constantName, "#00ff00");
}
// Request screenshot
const screenshotRequest = await DW_CLIENT.requestScreenshot(config.groupAlias, specification.id, "MyPreviewControl", {
screenshotWidth: "500",
screenshotHeight: "500",
screenshotRotationZoom: "-150|15|4|0.5|1|1.5" // RotateX|RotateY|Zoom or RotateX|RotateY|Zoom|PanX|PanY|PanZ
});
// Render screenshot
const screenshot = screenshotRequest.screenshotResult.previewUrl;
document.querySelector("#output").innerHTML = `<img src="data:image/png;base64,${screenshot}" />`;
} catch (error) {
console.log(error);
document.querySelector("#output").innerHTML = error;
}
};
</script>
<!-- Option A) Directly load Client Library -->
<!-- <script src="https://YOUR-THEME-SERVER.COM/DriveworksLiveIntegrationClient.min.js" onload="dwClientLoaded()"></script> -->
<!-- Option B) Inject Client Library dynamically from server url in config file -->
<script>
(function(doc, script) {
script = doc.createElement("script");
script.src = config.serverUrl + "/DriveWorksLiveIntegrationClient.min.js";
script.onload = () => dwClientLoaded(); // Custom local function run when client has loaded
doc.body.appendChild(script);
}(document));
</script>
</body>
</html>