-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
121 lines (106 loc) · 3.38 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Model-viewer Course</title>
<meta name="description" content="Examples " />
<meta name="author" content="Me" />
<meta property="og:title" content="Model-viewer" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://" />
<meta property="og:description" content="Examples" />
<meta property="og:image" content="image.png" />
<link
rel="apple-touch-icon"
sizes="180x180"
href="../assets/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32 "
href="../assets/favicon/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="../assets/favicon/favicon-16x16.png"
/>
<link rel="manifest" href="../assets/favicon/site.webmanifest" />
<link rel="stylesheet" href="../css/styles.css" />
<style>
model-viewer {
width: 400px;
height: 600px;
margin: 0 auto;
}
.controls {
background-color: white;
border-radius: 4px;
border: none;
/* position: absolute;
top: 16px;
right: 16px; */
}
</style>
</head>
<body>
<!-- Import the component -->
<script
type="module"
src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.0.1/model-viewer.min.js"
></script>
<model-viewer
id="knight"
src="/assets/knightNoCubeNes.glb"
alt="A 3D model of a cartoon animated knight"
ar
ar-modes="webxr scene-viewer quick-look"
environment-image="neutral"
animation-name="NesAnim"
autoplay
camera-controls
>
<div class="controls" ,="" id="anim-controls">
<button data-anim="Look Around">look around</button>
<button data-anim="Die">Die</button>
<button data-anim="Dance">Dance</button>
</div>
</model-viewer>
<script>
let nro = 0;
const modelViewer = document.querySelector("model-viewer#knight");
modelViewer.addEventListener("load", (ev) => {
console.log(modelViewer.availableAnimations);
//modelViewer.play({repetitions:1});
});
modelViewer.addEventListener("loop", (ev) => {
// nro = modelViewer.animationName === "Die" ? 2 : 1;
console.log("nro " + nro + " the animation is looping");
// if (nro == 1) {
// modelViewer.animationName = "Die";
// }
if (modelViewer.animationName != "Walking") {
//modelViewer.pause();
modelViewer.animationName = "Walking";
console.log("pause");
}
});
// modelViewer.addEventListener("finished", (ev) => {
// console.log("animacion finalizada");
// });
document
.querySelector("#anim-controls")
.addEventListener("click", (event) => {
const anim = event.target.dataset.anim;
console.log("clic aniNes");
modelViewer.animationName = anim;
modelViewer.play({ repetitions: 1 });
console.log(anim + " clic");
console.log("nro igual a " + nro);
});
</script>
</body>
</html>