-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
97 lines (83 loc) · 3.26 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<!-- lib-->
<script desc="lib-js">
<%= htmlWebpackPlugin.options.templateParameters.myscript %>
</script>
<!-- data,image,model-->
<script desc="model-data">
<%= htmlWebpackPlugin.options.templateParameters.model_base64_data %>
</script>
<script desc="img-data">
<%= htmlWebpackPlugin.options.templateParameters.images_base64_data %>
</script>
<script desc="mp3-data">
<%= htmlWebpackPlugin.options.templateParameters.mp3_base64_data %>
</script>
<script>
function b64toBlob(b64Data, contentType = "", sliceSize = 512) {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, {
type: contentType,
});
return blob;
}
const contentType = "application/octet-stream";
function getModelURL(model) {
return URL.createObjectURL(b64toBlob(model, contentType));
}
var blobUrl = getModelURL(scene_model);
var myviewer = null;
setTimeout(function() {
myviewer = new marmoset.WebViewer(document.body.clientWidth, window.innerHeight - 200, blobUrl);
document.getElementById("view").appendChild(myviewer.domRoot);
myviewer.loadScene();
}, 300);
function changeView(model) {
document.querySelector("#view div").remove();
myviewer.unload();
blobUrl = getModelURL(model);
delete myviewer.canvas;
myviewer = null;
myviewer = new marmoset.WebViewer(document.body.clientWidth, window.innerHeight - 200, blobUrl);
document.getElementById("view").appendChild(myviewer.domRoot);
myviewer.loadScene();
}
</script>
</head>
<body>
<div id="view"></div>
<button onclick="changeView(scene_model)">model1-scene.mview</button>
<button onclick="changeView(test_model)">model2-test.mview</button>
<p>desc here...</p>
<p>first pic</p>
<img id="img1" width="100%" height="100%" />
<audio controls>
<source id="mp3" type="audio/mpeg">
</audio>
<p>second pic</p>
<img id="img2" width="100%" height="100%" />
</body>
<script>
// image use example
// filename_img : data:image/png|gif|jpg
document.getElementById("img2").src = `data:image/png;base64,${show_img}`;
document.getElementById("img1").src = `data:image/png;base64,${show_img}`;
document.getElementById("mp3").src = `data:audio/mpeg;base64,${LaSoLa_mp3 }`;
</script>
</html>