File size: 4,832 Bytes
6744e6e c0fd12b 6744e6e c0fd12b |
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 |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Aframe and Three.js Keyboard Interaction Demo</title>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script src="https://threejs.org/build/three.js"></script>
</head>
<body>
<a-scene keyboard-shortcuts>
<a-entity position="0 1.6 0">
<a-entity id="camera" camera look-controls wasd-controls></a-entity>
</a-entity>
<a-sky color="#0000ff"></a-sky>
<a-entity id="lettersContainer"></a-entity>
</a-scene>
<script>
AFRAME.registerComponent('keyboard-shortcuts', {
init: function () {
window.addEventListener('keydown', (event) => {
const key = event.key.toLowerCase();
if (key.length === 1 && /^[a-z]+$/.test(key)) {
this.generateLetter(key);
}
});
},
generateLetter: function (key) {
const lettersContainer = document.querySelector('#lettersContainer');
const letter = document.createElement('a-entity');
letter.setAttribute('text', {
value: key.toUpperCase(),
align: 'center',
font: 'https://cdn.aframe.io/fonts/Exo2SemiBold.fnt',
width: 2
});
letter.setAttribute('position', '0 1 -5');
letter.setAttribute('rotation', '0 0 0');
letter.setAttribute('scale', '1 1 1');
letter.setAttribute('letter', '');
lettersContainer.appendChild(letter);
}
});
AFRAME.registerComponent('letter', {
init: function () {
this.el.setAttribute('animation', {
property: 'rotation',
to: '0 360 0',
dur: 2000,
easing: 'linear',
loop: true
});
this.el.setAttribute('animation__position', {
property: 'position',
to: '0 1 20',
dur: 2000,
easing: 'linear',
loop: true
});
}
});
</script>
</body>
</html>
Here's an example of an A-Frame and Three.js demonstration that includes keyboard interaction, dynamically generated 3D letters, camera and WASD control, and a skybox with blue, yellow, and white chaos-driven visuals. Additionally, it includes a function to call a web service and display the results.
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Aframe and Three.js Keyboard Interaction Demo</title>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script src="https://threejs.org/build/three.js"></script>
</head>
<body>
<a-scene keyboard-shortcuts>
<a-entity position="0 1.6 0">
<a-entity id="camera" camera look-controls wasd-controls></a-entity>
</a-entity>
<a-sky color="#0000ff"></a-sky>
<a-entity id="lettersContainer"></a-entity>
</a-scene>
<script>
AFRAME.registerComponent('keyboard-shortcuts', {
init: function () {
window.addEventListener('keydown', (event) => {
const key = event.key.toLowerCase();
if (key.length === 1 && /^[a-z]+$/.test(key)) {
this.generateLetter(key);
}
});
},
generateLetter: function (key) {
const lettersContainer = document.querySelector('#lettersContainer');
const letter = document.createElement('a-entity');
letter.setAttribute('text', {
value: key.toUpperCase(),
align: 'center',
font: 'https://cdn.aframe.io/fonts/Exo2SemiBold.fnt',
width: 2
});
letter.setAttribute('position', '0 1 -5');
letter.setAttribute('rotation', '0 0 0');
letter.setAttribute('scale', '1 1 1');
letter.setAttribute('letter', '');
lettersContainer.appendChild(letter);
}
});
AFRAME.registerComponent('letter', {
init: function () {
this.el.setAttribute('animation', {
property: 'rotation',
to: '0 360 0',
dur: 2000,
easing: 'linear',
loop: true
});
this.el.setAttribute('animation__position', {
property: 'position',
to: '0 1 20',
dur: 2000,
easing: 'linear',
loop: true
});
}
});
// Call web service and display results
fetch('https://api11.salmonground-a8f39f59.centralus.azurecontainerapps.io/selftest')
.then(response => response.json())
.then(data => console.log(data));
</script>
</body>
</html> |