Skip to main content

Build yourself a Planet - Web VR

Using Mozzila's brilliant AFrame, a web-based Virtual Reality model of a planet with rings and include a moon with an image on it.





Step 1. Basic Planet
The first step is to set a new site in Glitch.com  and then add a white sphere on a black background.


<html>

  <head>

    <script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>

  </head>

  <body>

    <a-scene>

     <a-sphere position="0 1.25 -5" radius="3" color="white" >

      </a-sphere>   

      <a-sky color="black"></a-sky>

    </a-scene>

  </body>

</html>

 

 

Using the Aframe 'tags' to create a white sphere and to create a black background

Step 2: Rotate the planet and add some colour
Now we can add a surface to the planet by finding an appropriate image to wrap around the sphere. in this example, I used the site Solar Systems Scope (https://www.solarsystemscope.com/textures/) and downloaded an image of Jupiter's surface (https://www.solarsystemscope.com/textures/download/2k_jupiter.jpg).

 

(a)If you are using Glitch: This needs to be copied into the assets folder of the project and the URL generated (by left-clicking on the image when it is in the folder) copied.

(b)On you own site upload the image to the same folder as the webpage the ‘URL’ will be filename

(c ) Alternatively use this URL in either approach https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2F2k_jupiter.jpg?v=1573393224376

 

Now by adding src="" and in the speech-marks paste in the URL for the image; the image wraps around the sphere.

<html>

  <head>

    <script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>

  </head>

  <body>

    <a-scene>

     <a-sphere position="0 1.25 -5" radius="3" color="white" src="https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2F2k_jupiter.jpg?v=1573393224376"

               animation="property: rotation; to: 0 360 0; loop: true; dur: 10000">

 

      </a-sphere>   

      <a-sky color="black"></a-sky>

    </a-scene>

  </body>

</html>

 

Now to rotate it  add, also within the , section animation="property: rotation; to: 0 360 0; loop: true; dur: 10000" (see above or the code at the end of the post for more details).

 



Step 3: Adding ring
In Aframe if you nest another object with the <></> of another object it's position is set relative to the first object. This principle is going to be used here put a ring around the planet. The first stage is to add the ring object is used for this and a the same rotating animation is used. We are going to use a squashed doughnut shape <a-torus> to do this. One the webpage is running you will probably need use the down arrow key to zoom out to see the ring.

 

<html>

  <head>

    <script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>

  </head>

  <body>

    <a-scene>

     <a-sphere position="0 1.25 -5" radius="3" color="white" src="https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2F2k_jupiter.jpg?v=1573393224376"

               animation="property: rotation; to: 0 360 0; loop: true; dur: 10000">

          <a-torus position="0 0 0"

                 arc="360"

                 rotation="90 0 0"

                 color="white" radius="5"

                 radius-tubular="0.05"

                 animation="property: rotation; to:  90 0 0; loop: true; dur: 3000">

         </a-torus>

 

      </a-sphere>   

      <a-sky color="black"></a-sky>

    </a-scene>

  </body>

</html>

 


Step 4: Adding a moon
The process is really just combining elements of the steps 1-3. Create a new sphere,set the radius to something around 0.25 to 0.5; colour it with whatever you feel is appropriate, add an image (in the example code one has been added) if you want, set a rotation (it is is fun to play with these a bit and place the moon on the ring (setting position="5 0 0" in this case does this.

If the images are accessible as web sources this could be a great option.



<html>

  <head>

    <script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>

  </head>

  <body>

    <a-scene>

     <a-sphere position="0 1.25 -5" radius="3" color="white" src="https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2F2k_jupiter.jpg?v=1573393224376"

               animation="property: rotation; to: 0 360 0; loop: true; dur: 10000">

          <a-torus position="0 0 0"

                 arc="360"

                 rotation="90 0 0"

                 color="white" radius="5"

                 radius-tubular="0.05"

                 animation="property: rotation; to:  90 0 0; loop: true; dur: 3000">

              <a-sphere position="5 0 0"

                 rotation="0 0 0"

                 radius="0.5"

                 color="yellow" src="https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2Fpanic.png?v=1573395380360"

                 animation="property: rotation; to:  0 259 0; loop: true; dur: 3000">

              </a-sphere>

 

         </a-torus>

 

      </a-sphere>   

      <a-sky color="black"></a-sky>

    </a-scene>

  </body>

</html>

 

 

Step 5: Lets us add some text.

So we might want to put some text into the world we can do that with <a-text value=””>

<html>

  <head>

    <script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script>

  </head>

  <body>

    <a-scene>

     <a-sphere position="0 1.25 -5" radius="3" color="white" src="https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2F2k_jupiter.jpg?v=1573393224376"

               animation="property: rotation; to: 0 360 0; loop: true; dur: 10000">

          <a-torus position="0 0 0"

                 arc="360"

                 rotation="90 0 0"

                 color="white" radius="5"

                 radius-tubular="0.05"

                 animation="property: rotation; to:  90 0 0; loop: true; dur: 3000">

              <a-sphere position="5 0 0"

                 rotation="0 0 0"

                 radius="0.5"

                 color="yellow" src="https://cdn.glitch.com/febf6408-3c33-4608-ac90-b087753e5792%2Fpanic.png?v=1573395380360"

                 animation="property: rotation; to:  0 259 0; loop: true; dur: 3000">

              </a-sphere>

 

         </a-torus>

      </a-sphere> 

      <a-text value="Planet CCCU Computing" position="0 4 -2"></a-text>

      <a-sky color="black"></a-sky>

    </a-scene>

  </body>

</html>

 

We can get interesting effects if we add the text between  </a-sphere> and </a-torus> Try adding this in there. <a-text value="Planet CCCU Computing" position="0 3 -2"></a-text>

 

Have a play with altering the text and putting the line elsewhere in the code. What happens?

 

 

 

Step 6:

Now going to use an image to change the background. The image is "space" by fleskw is licensed with CC BY 2.0. To view a copy of this license, visit https://creativecommons.org/licenses/by/2.0 You will need to change the sky colour to a light colour for this to work. So change the sky line in the code to

 

      <a-sky color="white" src="https://cdn.glitch.com/425c1a98-7ba9-463d-817d-6b491a516246%2F97b3bf6d-ced1-4041-80d4-b6c9a98ba43d.jfif?v=1614341330757"></a-sky>

 

 

 

 

L



All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Comments

  1. Education is another area which has adopted virtual reality for teaching and learning situations. The advantage of this is that it enables large groups of students to interact with each other as well as within a three dimensional environment.
    VR Canada

    ReplyDelete
  2. I agree this material is taken from from some teaching I do on VR

    ReplyDelete

Post a Comment

Popular posts from this blog

Robot Software

In the previous blog posts for this 'series' "It is a good time...."  Post 1  looked at the hardware unpinning some of this positive rise in robots; Post 2  looked at social robots; Post 3  looked at a collection of small robots; Post 4 looked at further examples of small robots Robots, such as the forthcoming Buddy and JIBO, will be based some established open sourceand other technologies. Jibo will be based around various technologies including Electron and JavaScript (for more details see:  http://blog.jibo.com/2015/07/29/jibo-making-development-readily-accessible-to-all-developers/ ). Buddy is expected to be developed around tools for Unity3d, Arduino and OpenCV, and support Python, C++, C#, Java and JavaScript (for more details see http://www.roboticstrends.com/article/customize_your_buddy_companion_robot_with_this_software_development_kit ).  This post contin ues with some of the software being used with the smaller robots.  A number ...

Speech Recognition in Scratch 3 - turning Hello into Bonjour!

The Raspberry Pi Foundation recently released a programming activity Alien Language , with support Dale from Machine Learning for Kids , that is a brilliant use of Scratch 3 - Speech Recognition to control a sprite in an alien language. Do the activity, and it is very much worth doing, and it will make sense! I  would also recommend going to the  machinelearningforkids.co.uk   site anyway it is full of exciting things to do (for example loads of activities  https://machinelearningforkids.co.uk/#!/worksheets  ) . Scratch 3 has lots of extensions that are accessible through the Extension button in the Scratch 3 editor (see below) which add new fun new blocks to play with. The critical thing for this post is  Machine Learning for Kids  have created a Scratch 3 template with their own extensions for Scratch 3 within it  https://machinelearningforkids.co.uk/scratch3/ . One of which is a Speech to Text extension (see below). You must use this one ...

Escape the Maze with a VR robot - Vex VR

You don't need to buy a robot to get programming a robot, now there are a range of free and relatively simple to start with robot simulators to play with. Three examples are listed below: - Make code for Lego EV3  https://robotsandphysicalcomputing.blogspot.com/2020/05/programming-robots-virtually-3-lego-ev3.html   - i Robot simulator  https://robotsandphysicalcomputing.blogspot.com/2020/04/programming-robots-virtually-2-irobot.html - Vex robotics Vexcode VR   https://robotsandphysicalcomputing.blogspot.com/2020/04/programming-robots-virtually-1-vexcode.html   It is the last one of these ( https://www.vexrobotics.com/vexcode-vr ) that is the focus of this post and return to hit, after an earlier discussion in  https://robotsandphysicalcomputing.blogspot.com/2020/04/programming-robots-virtually-1-vexcode.html   .  Two of the nice things about the package, apart from being free, are it uses a Scratch-like programming language and it provides a ...