-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautorotate.html
More file actions
77 lines (70 loc) · 2.14 KB
/
autorotate.html
File metadata and controls
77 lines (70 loc) · 2.14 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
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Model auto-rotate</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<h1>Model: auto-rotate test</h1>
<hr />
<p>
A model's <code>DOMMatrixReadOnly entityTransform</code> can be set to
display a certain side, or to automatically animate the content.
</p>
<h2>HTML</h2>
<pre>
<model alt="A model of a teapot">
<source src="./teapot.usdz" type="model/vnd.usdz+zip" />
<source src="./teapot.glb" type="model/gltf-binary" />
</model>
</pre
>
<h2>JavaScript:</h2>
<pre>
let initialTransform;
const model = document.querySelector('model');
await model.ready;
initialTransform = model.entityTransform.translate(0,0,-0.05);
requestAnimationFrame(update);
function update() {
try {
const angleY = performance.now()/10;
model.entityTransform = initialTransform.rotate(0, angleY,0);
} catch(error) {
console.warn("failed to set transform", error);
}
requestAnimationFrame(update);
}
</pre
>
<br />
<model alt="A model of a teapot">
<source src="./teapot.usdz" type="model/vnd.usdz+zip" />
<source src="./teapot.glb" type="model/gltf-binary" />
<img
src="./teapot-fallback-black.jpg"
alt="An image of a model of a teapot" />
</model>
</div>
<script type="module">
let initialTransform;
const model = document.querySelector('model');
await model.ready;
initialTransform = model.entityTransform.translate(0, 0, -0.05);
requestAnimationFrame(update);
function update() {
try {
const angleY = performance.now() / 10;
model.entityTransform = initialTransform.rotate(0, angleY, 0);
} catch (error) {
console.warn('failed to set transform', error);
}
requestAnimationFrame(update);
}
</script>
</body>
</html>