forked from cgwire/js-3d-model-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
178 lines (161 loc) · 4.75 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Javascript 3D Model Viewer</title>
<style>
body {
margin: 0;
padding: 0;
background: white;
font-family: Geneva, sans-serif;
}
p {
margin: 0;
padding: 0;
}
a {
color: #3CB371;
}
#viewer {
width: 100%;
height: 400px;
margin: auto;
background: #000000;
margin-top: 2em;
}
.button {
border-radius: 0.2em;
background-color: white;
color: #3CB371;
border: 3px solid #3CB371;
font-weight: bold;
padding: 1em;
cursor: pointer;
}
.center {
text-align: center;
margin-top: 2em;
}
canvas {
display: block;
}
pre {
padding: 1em;
max-width: 900px;
margin: auto;
margin-top: 4em;
font-size: 1.2em;
}
.footer {
padding-bottom: 2em;
}
</style>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.15.0/themes/prism.min.css"
/>
</head>
<body>
<div class="content">
<header class="center"><h1>Javascript 3D Model Viewer</h1></header>
<div id="viewer" style="">
</div>
<div class="center">
<span id="name">Sample 01</span>
<span id="loading"></span>
</div>
<div class="center">
<button class="button" id="sample-1-button">
Sample 1
</button>
<button class="button" id="sample-2-button">
Sample 2
</button>
<button class="button" id="sample-3-button">
Sample 3
</button>
</div>
<div class="center">
<button class="button" id="fullscreen-button">
Go Full Screen
</button>
</div>
<div style="margin: 2em auto; max-width: 900px">
<pre><code class="language-javascript">var modelPlayer = this['js-3d-model-viewer'];
var viewerElement = document.getElementById('viewer')
var scene = modelPlayer.prepareScene(viewerElement)
modelPlayer.loadObject(scene, './assets/sample.obj')
var fullScreenButton = document.getElementById('fullscreen-button')
fullScreenButton.addEventListener('click', function () {
modelPlayer.goFullScreen(viewerElement)
})</code></pre>
</div>
<footer class="center footer">
<a href="https://github.com/cgwire/js-3d-model-viewer">
See sources on Github
</a>
</footer>
</div>
<script src="./dist/js-3d-model-viewer.js"></script>
<script>
var modelPlayer = this['js-3d-model-viewer']
var nameElement = document.getElementById('name')
var loadingElement = document.getElementById('loading')
var viewerElement = document.getElementById('viewer')
var scene = modelPlayer.prepareScene(viewerElement)
viewerElement.addEventListener('loading', function (event) {
if (event.detail.loaded === 0) {
nameElement.innerHTML = 'Loading...'
}
var progress = Math.floor(100 * event.detail.loaded / event.detail.total)
loadingElement.innerHTML = progress + '%'
})
modelPlayer.loadObject(scene, './assets/sample.obj', null, function () {
nameElement.innerHTML = 'Sample 01'
loadingElement.innerHTML = ''
})
var fullScreenButton = document.getElementById('fullscreen-button')
fullScreenButton.addEventListener('click', function () {
modelPlayer.goFullScreen(viewerElement)
})
var sample1Button = document.getElementById('sample-1-button')
sample1Button.addEventListener('click', function () {
modelPlayer.clearScene(scene)
modelPlayer.resetCamera(scene)
modelPlayer.loadObject(scene, './assets/sample.obj', null, function () {
nameElement.innerHTML = 'Sample 01'
loadingElement.innerHTML = ''
})
})
var sample2Button = document.getElementById('sample-2-button')
sample2Button.addEventListener('click', function () {
modelPlayer.clearScene(scene)
modelPlayer.resetCamera(scene)
modelPlayer.loadObject(
scene,
'./assets/sample_02.obj',
'./assets/sample_02.mtl',
function () {
nameElement.innerHTML = 'Sample 02'
loadingElement.innerHTML = ''
})
})
var sample3Button = document.getElementById('sample-3-button')
sample3Button.addEventListener('click', function () {
modelPlayer.clearScene(scene)
modelPlayer.resetCamera(scene)
modelPlayer.loadObject(
scene,
'./assets/sample_03.obj',
'./assets/sample_03.mtl',
function () {
nameElement.innerHTML = 'Sample 03'
loadingElement.innerHTML = ''
})
})
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.15.0/prism.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.15.0/components/prism-javascript.js"></script>
</body>
</html>