-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo-3dobj.js
77 lines (66 loc) · 1.84 KB
/
demo-3dobj.js
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
// @ts-check
export class Demo3DObj extends HTMLElement {
#objtranslate
#objrotate
#obj
constructor() {
super();
this.#objtranslate = '';
this.#objrotate = '';
}
connectedCallback() {
this.innerHTML = `
<style>
.scene {
width: 200px;
height: 200px;
margin: 200px;
perspective: 500px;
}
.obj {
width: 200px;
height: 200px;
position: relative;
transform-style: preserve-3d;
transform: translateZ(-1000px);
transition: transform 100ms;
}
.plane {
position: absolute;
width: 200px;
height: 200px;
border: 5px solid black;
border-radius: 50%;
}
.red {
background: rgba(255,0,0,0.5);
transform: rotateY(-90deg)
}
.green {
background: rgba(0,255,0,0.5);
transform: rotateX( 90deg)
}
.blue {
background: rgba(0,0,255,0.5);
}
</style>
<div class="scene">
<div class="obj">
<div class="plane red"></div>
<div class="plane green"></div>
<div class="plane blue"></div>
</div>
</div>
`;
this.#obj = this.querySelector('.obj');
}
setTranslation(x, y, z) {
this.#objtranslate = `translateX(${x}px) translateY(${y}px) translateZ(${z}px) `;
this.#obj.style.transform = this.#objtranslate + this.#objrotate;
}
setRotation(rx, ry, rz) {
this.#objrotate = `rotateX(${rx}deg) rotateY(${ry}deg) rotateZ(${rz}deg) `;
this.#obj.style.transform = this.#objtranslate + this.#objrotate;
}
}
customElements.define('demo-3dobj', Demo3DObj);