/
index.html
84 lines (78 loc) · 3.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fern A-Frame Components | HUD</title>
<script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>
<script src="https://mrdoob.github.io/stats.js/build/stats.min.js"></script>
<script src="/js/hud.umd.min.js"></script>
<script>
AFRAME.registerSystem('stats-js', {
schema: {},
init: function() {
this.stats = new Stats();
this.textures = [];
},
textureForPanel: function(panel) {
if(!this.textures[panel]) {
this.stats.showPanel(panel);
const canvas = this.stats.dom.children[panel];
if(!canvas) {
return null;
}
const texture = new THREE.Texture(canvas);
texture.generateMipmaps = false;
texture.needsUpdate = true;
this.textures[panel] = texture;
}
return this.textures[panel];
},
tick: function() {
this.stats.begin();
},
tock: function() {
this.stats.end();
for(const texture of this.textures) {
if(texture) {
texture.needsUpdate = true;
}
}
}
});
AFRAME.registerComponent('stats-js', {
schema: { type: 'number', default: 0 },
update: function() {
const mesh = this.el.getObject3D('mesh');
mesh.material.map = this.system.textureForPanel(this.data);
}
})
</script>
</head>
<body>
<a-scene>
<a-sky color="#ECECEC"></a-sky>
<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
<a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
<a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<!-- Camera rig -->
<a-entity id="rig">
<a-camera id="camera">
<a-hud horizontal-fov="60" vertical-fov="45" scale-factor="0.5">
<a-hud-element align="center" content-size="2.0 0.1" hud-size="0.5" anchor="center">
<a-plane width="2.0" height="0.2" color="red"></a-plane>
<a-text value="Center a-text" color="black" align="center"></a-text>
</a-hud-element>
<a-hud-element align="bottom" content-size="1 1" hud-size="0.2" anchor="bottom"><a-plane color="yellow"></a-plane></a-hud-element>
<a-hud-element align="top-left" content-size="0.8 0.48" hud-size="0.2" anchor="top-left"><a-plane width="0.8" height="0.48" color="white" shader="flat" stats-js="0"></a-plane></a-hud-element>
<a-hud-element align="top" content-size="0.8 0.48" hud-size="0.2" anchor="top"><a-plane width="0.8" height="0.48" color="white" shader="flat" stats-js="1"></a-plane></a-hud-element>
<a-hud-element align="left" content-size="0.8 0.48" hud-size="0.2" anchor="left"><a-plane width="0.8" height="0.48" color="white" shader="flat" stats-js="2"></a-plane></a-hud-element>
</a-entity>
</a-camera>
<!-- Hands -->
<a-entity hand-controls="hand: left"></a-entity>
<a-entity hand-controls="hand: right"></a-entity>
</a-entity>
</a-scene>
<!-- GITHUB_CORNER_RIGHT -->
</body>
</html>