awacke1 commited on
Commit
b7cccf7
·
1 Parent(s): 61c8c09

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +90 -108
index.html CHANGED
@@ -1,123 +1,105 @@
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
- <meta charset="utf-8">
5
- <title>A-Frame and Three.js Example</title>
6
- <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
7
- <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
8
- <script src="https://cdn.rawgit.com/mrdoob/three.js/r128/examples/js/loaders/MTLLoader.js"></script>
9
- <script src="https://cdn.rawgit.com/mrdoob/three.js/r128/examples/js/loaders/OBJLoader.js"></script>
10
- <script src="https://unpkg.com/@aframe/physics-system/dist/aframe-physics-system.min.js"></script>
11
- <script src="https://unpkg.com/@aframe/physics-debugger/dist/aframe-physics-debugger.min.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  </head>
13
  <body>
14
- <a-scene physics="debug: true;">
15
- <a-assets>
16
- <img id="sky" src="https://i.imgur.com/1RGMGKj.jpg">
17
- </a-assets>
18
- <a-entity id="player" position="0 10 0" camera look-controls kinematic-body></a-entity>
19
- <a-entity id="iceland" static-body environment="preset:forest;groundYScale:10;groundTexture:https://i.imgur.com/HeYwiie.jpg"></a-entity>
20
 
21
- <script>
22
- var loader = new THREE.OBJLoader();
23
- var mtlLoader = new THREE.MTLLoader();
24
- mtlLoader.load('https://threejs.org/examples/models/obj/landscape/outdoor/', function(materials) {
25
- materials.preload();
26
- loader.setMaterials(materials);
27
- loader.load('https://threejs.org/examples/models/obj/landscape/outdoor/', function(object) {
28
- var voxelSize = 10;
29
- var voxelGeometry = new THREE.BoxGeometry(voxelSize, voxelSize, voxelSize);
30
- var voxelMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, wireframe: true });
31
- var voxelCount = 0;
32
- object.traverse(function(child) {
33
- if (child instanceof THREE.Mesh) {
34
- var mesh = new THREE.Mesh(voxelGeometry, voxelMaterial);
35
- mesh.position.set(child.position.x, child.position.y, child.position.z);
36
- mesh.scale.set(voxelSize, voxelSize, voxelSize);
37
- mesh.castShadow = true;
38
- mesh.receiveShadow = true;
39
- mesh.userData['originalPosition'] = mesh.position.clone();
40
- mesh.userData['originalRotation'] = mesh.rotation.clone();
41
- mesh.userData['id'] = voxelCount++;
42
- mesh.name = 'voxel';
43
- document.querySelector('#iceland').object3D.add(mesh);
44
- }
45
- });
46
 
47
- animate();
48
- });
49
- });
 
 
 
50
 
51
- function animate() {
52
- requestAnimationFrame(animate);
 
 
 
53
 
54
- var delta = 0.01;
55
- document.querySelectorAll('[name="voxel"]').forEach(function(voxel) {
56
- voxel.rotation.x += delta;
57
- voxel.rotation.y += delta;
58
- voxel.rotation.z += delta;
59
- });
60
 
61
- var player = document.querySelector('#player');
62
- var position = player.getAttribute('position');
63
- if (position.y < -100) {
64
- player.setAttribute('position', '0 10 0');
65
- player.setAttribute('velocity', '0 0 0');
66
- player.setAttribute('rotation', '0 0 0');
67
- }
68
 
69
- var camera = player.querySelector('a-camera');
70
- var camPosition = camera.getAttribute('position');
71
- var camRotation = camera.getAttribute('rotation');
72
- var forward = new THREE.Vector3(0, 0, -1);
73
- var right = new THREE.Vector3(1, 0, 0);
74
- var up = new THREE.Vector3(0, 1, 0);
75
- forward.applyQuaternion(camera.object3D.quaternion);
76
- right.applyQuaternion(camera.object3D.quaternion);
77
- up.applyQuaternion(camera.object3D.quaternion);
78
 
79
- var speed = 5;
80
- var velocity = new THREE.Vector3(0, 0, 0);
81
- if (keys.KeyW) {
82
- velocity.add(forward.clone().multiplyScalar(speed));
83
- }
84
- if (keys.KeyS) {
85
- velocity.sub(forward.clone().multiplyScalar(speed));
86
- }
87
- if (keys.KeyD) {
88
- velocity.add(right.clone().multiplyScalar(speed));
89
- }
90
- if (keys.KeyA) {
91
- velocity.sub(right.clone().multiplyScalar(speed));
92
- }
93
- if (keys.Space) {
94
- velocity.add(up.clone().multiplyScalar(speed));
95
- }
96
- if (keys.ShiftLeft) {
97
- velocity.sub(up.clone().multiplyScalar(speed));
98
- }
99
- player.setAttribute('velocity', velocity);
100
 
101
- document.querySelector('[camera]').setAttribute('wasd-controls', '');
102
- document.querySelector('[camera]').setAttribute('look-controls', '');
103
- document.querySelector('[camera]').setAttribute('kinematic-body', '');
104
- document.querySelector('[camera]').setAttribute('wasd-flying-controls', '');
105
- }
106
 
107
- function onKeyDown(event) {
108
- keys[event.code] = true;
109
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- function onKeyUp(event) {
112
- keys[event.code] = false;
113
- }
114
-
115
- document.addEventListener('keydown', onKeyDown);
116
- document.addEventListener('keyup', onKeyUp);
117
-
118
- var keys = {};
119
- </script>
120
- </a-scene>
121
-
122
- </body>
123
- </html>
 
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
+ <meta charset="utf-8">
5
+ <title>Minnesota Map</title>
6
+ <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
7
+ <script src="https://unpkg.com/aframe-environment-component/dist/aframe-environment-component.min.js"></script>
8
+ <script src="https://unpkg.com/@aframe/physics-system"></script>
9
+ <style>
10
+ #canvas {
11
+ height: 500px;
12
+ width: 800px;
13
+ }
14
+ .button {
15
+ background-color: #222;
16
+ border: none;
17
+ color: white;
18
+ font-size: 16px;
19
+ padding: 10px 16px;
20
+ text-align: center;
21
+ text-decoration: none;
22
+ display: inline-block;
23
+ margin: 4px 2px;
24
+ cursor: pointer;
25
+ }
26
+ .link {
27
+ color: #8CEEEF;
28
+ }
29
+ </style>
30
  </head>
31
  <body>
32
+ <a-scene physics="debug: true;">
33
+ <a-entity environment="preset: forest"></a-entity>
 
 
 
 
34
 
35
+ <!-- Define the polygons for Minnesota -->
36
+ <a-entity position="0 0 -5">
37
+ <a-entity position="-2.5 0 0">
38
+ <a-polygon fill="#2D6C4E" vertices="0 0, 1 0, 0.5 1" static-body></a-polygon>
39
+ <a-polygon fill="#2D6C4E" vertices="0.5 1, 1 0, 1 1" static-body></a-polygon>
40
+ <a-polygon fill="#2D6C4E" vertices="0 0, 0 1, 0.5 1" static-body></a-polygon>
41
+ <a-polygon fill="#2D6C4E" vertices="0.5 0, 1 0, 0.5 1" static-body></a-polygon>
42
+ </a-entity>
43
+ <a-entity position="2.5 0 0">
44
+ <a-polygon fill="#2D6C4E" vertices="0 0, 1 0, 0.5 1" static-body></a-polygon>
45
+ <a-polygon fill="#2D6C4E" vertices="0 0, 0 1, 0.5 1" static-body></a-polygon>
46
+ <a-polygon fill="#2D6C4E" vertices="0.5 0, 1 0, 1 1" static-body></a-polygon>
47
+ <a-polygon fill="#2D6C4E" vertices="0.5 0, 0.5 1, 1 1" static-body></a-polygon>
48
+ </a-entity>
49
+ </a-entity>
 
 
 
 
 
 
 
 
 
 
50
 
51
+ <!-- Define the camera and buttons -->
52
+ <a-entity id="player" position="0 50 0" kinematic-body>
53
+ <a-entity id="camera" camera look-controls kinematic-body></a-entity>
54
+ <a-entity id="zoomIn" class="button" position="-2.5 0 0" rotation="0 0 180" onclick="zoomIn()">+</a-entity>
55
+ <a-entity id="zoomOut" class="button" position="2.5 0 0" onclick="zoomOut()">-</a-entity>
56
+ </a-entity>
57
 
58
+ <!-- Define the script to update the video texture -->
59
+ <script>
60
+ const video = document.querySelector('#video');
61
+ const canvas = document.querySelector('#videoTextureCanvas');
62
+ const ctx = canvas.getContext('2d');
63
 
64
+ function updateVideoTexture() {
65
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
66
+ const texture = document.querySelector('#videoTexture');
67
+ texture.needsUpdate = true;
68
+ }
 
69
 
70
+ video.addEventListener('play', function() {
71
+ setInterval(updateVideoTexture, 16);
72
+ });
73
+ </script>
 
 
 
74
 
75
+ <script>
76
+ // Get the camera entity
77
+ const player = document.querySelector('#player');
78
+ const camera = document.querySelector('#camera');
 
 
 
 
 
79
 
80
+ // Define the zoom in and zoom out functions
81
+ function zoomIn() {
82
+ camera.setAttribute('position', {x: camera.getAttribute('position').x, y: camera.getAttribute('position').y - 5, z: camera.getAttribute('position').z});
83
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
+ function zoomOut() {
86
+ camera.setAttribute('position', {x: camera.getAttribute('position').x, y: camera.getAttribute('position').y + 5, z: camera.getAttribute('position').z});
87
+ }
 
 
88
 
89
+ // Define the gravity and physics for the player
90
+ player.addEventListener('componentinitialized', function (evt) {
91
+ if (evt.detail.name !== 'kinematic-body') { return; }
92
+ const physics = player.getAttribute('physics');
93
+ physics.debug = false;
94
+ physics.driver = 'physics';
95
+ physics.debug = true;
96
+ physics.debugInterval = 500;
97
+ physics.debugTiming = 'interval';
98
+ player.setAttribute('physics', physics);
99
+ player.body.linearDamping = 0.9;
100
+ player.body.angularDamping = 0.9;
101
+ player.body.gravity.y = -30;
102
+ player.body.mass = 80;
103
+ });
104
+ </script>
105