A scene and its shapes
Build a 3D scene from tags and place shapes in it.
Your scene is drawn in 3D by your own browser, inside this tab. No headset needed.
A scene
A-Frame builds 3D and VR scenes out of HTML tags. Everything goes inside <a-scene>. <a-box> is a cube.
position takes three numbers: how far right, how far up, and how far towards you. You stand at the centre looking forwards, so a negative third number puts a shape in front of you.
Load the example and press Run. Drag in the view to look around. The same scene opens in a VR headset with no changes.
<a-scene>
<a-box position="0 1.5 -3" color="tomato"></a-box>
</a-scene>Your turn: place a box
Put a shape where you can see it.
Practice task
Write a scene with one box at position 0 1 -4.
Your answer is run and checked in the lesson. Try it now.
Spheres and cylinders
<a-sphere> is a ball. Its size is set with radius, the distance from its centre to its surface.
<a-cylinder> is a tube. It has a radius and a height.
Distances in A-Frame are in metres, so a radius of 0.5 makes a ball one metre across.
<a-scene>
<a-sphere position="-1 1.25 -4" radius="1.25" color="crimson"></a-sphere>
<a-cylinder position="2 0.75 -4" radius="0.5" height="1.5" color="gold"></a-cylinder>
</a-scene>Always close the tag
Every A-Frame tag needs its closing tag, even though nothing goes between them: <a-box></a-box>.
If a closing tag is missing, the browser treats the shapes after it as being inside that one. They then move and turn with it, which is rarely what you meant.
<a-scene>
<a-box position="-1 1 -3" color="teal"></a-box>
<a-box position="1 1 -3" color="orange"></a-box>
</a-scene>Your turn: two shapes
Place a ball and a tube side by side.
Practice task
Write a scene with a sphere at position 1 1 -4 and a cylinder at position -1 1 -4.
Your answer is run and checked in the lesson. Try it now.