Skip to content

Commit

Permalink
Change environment when button clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinika committed Aug 8, 2023
1 parent 2329fcc commit 734de16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
6 changes: 5 additions & 1 deletion modules/client-mobile/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ AFRAME.registerComponent("fit", {
this.el.sceneEl.camera.zoom = distance / newDistance;
}
}
});
});

function changeEnvironment() {
console.log("FROM INDEX")
}
Binary file removed modules/client-mobile/www/assets/blue-button.jpg
Binary file not shown.
Binary file removed modules/client-mobile/www/assets/blue-button.png
Binary file not shown.
29 changes: 22 additions & 7 deletions modules/client-mobile/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<body>

<a-scene environment=" preset: forest">
<a-scene environment="preset: forest">
<a-assets>
<a-asset-item id="microbit-asset" src="assets/microbit.glb"></a-asset-item>
<a-asset-item id="cover-asset" src="assets/cover.glb"></a-asset-item>
Expand All @@ -19,31 +19,46 @@

<a-entity light="type: hemisphere; color: #FFF; intensity: 0.5" position="0 100 1"></a-entity>
<a-camera position="0 1 1" wasd-controls fit="#joystick"></a-camera>
<a-entity id="mouseCursor" cursor="rayOrigin: mouse" raycaster="objects: #buttons"></a-entity>
<a-entity id="mouseCursor" cursor="rayOrigin: mouse" raycaster="objects: .joystick-button"></a-entity>


<a-entity gltf-model="#joystick" id="joystick" position="0 1 0.75" scale="0.15 0.15 0.15" rotation="0 270 270"
mixin="buttonclick"></a-entity>

<!-- Joystick buttons -->
<a-entity position="-0.013 0.986 0.798" rotation="0 30 0">
<a-sphere id="buttons" mixin="buttonclick" radius="0.019" geometry="primitive: sphere" color="blue"></a-sphere>
<a-sphere id="change-environment" class="joystick-button" mixin="buttonclick" radius="0.019"
geometry="primitive: sphere" color="blue"></a-sphere>
</a-entity>

<a-entity position="0.016 1.012 0.798" rotation="0 30 0">
<a-sphere id="buttons" mixin="buttonclick" radius="0.019" geometry="primitive: sphere" color="orange"></a-sphere>
<a-sphere class="joystick-button" mixin="buttonclick" radius="0.019" geometry="primitive: sphere"
color="orange"></a-sphere>
</a-entity>

<a-entity position="0.051 1.017 0.798" rotation="0 30 0">
<a-sphere id="buttons" mixin="buttonclick" radius="0.019" geometry="primitive: sphere" color="green"></a-sphere>
<a-sphere class="joystick-button" mixin="buttonclick" radius="0.019" geometry="primitive: sphere"
color="green"></a-sphere>
</a-entity>

<a-entity position="0.084 1.006 0.810" rotation="0 30 0">
<a-sphere id="buttons" mixin="buttonclick" radius="0.019" geometry="primitive: sphere" color="purple"></a-sphere>
<a-sphere class="joystick-button" mixin="buttonclick" radius="0.019" geometry="primitive: sphere"
color="purple"></a-sphere>
</a-entity>
</a-scene>

<script>
const allEnvironments = ['forest', 'egypt', 'checkerboard', 'goaland', 'yavapai', 'goldmine', 'threetowers', 'poison', 'arches', 'tron', 'japan', 'dream', 'volcano', 'starry', 'osiris', 'moon']
let currentEnvironmentIndex = 0;

</a-scene>
const changeEnvironmentButton = document.getElementById('change-environment');

changeEnvironmentButton.addEventListener('click', () => {
const scene = document.querySelector('a-scene');
const nextEnvironmentIndex = (currentEnvironmentIndex + 1) % (allEnvironments.length);
scene.setAttribute('environment', `preset: ${allEnvironments[nextEnvironmentIndex]}`);
currentEnvironmentIndex = nextEnvironmentIndex;
});
</script>

</body>

0 comments on commit 734de16

Please sign in to comment.