Hello World has long been a staple of computer programming. A Hello World program is usually the first program you write when learning a new language. It is a program who's full purpose and functionality is to display the text "Hello World" on the screen of the computer. As the programming languages and tools we use have evolved so has the Hello World program. Sratch3D ventures to add one more step into that evelutionary process. As you follow along with this tutorial and write your first scratch3D Hello World program you will learn how to render 3-D text to the screen, create a 3-D earth and learn how to rotate objects in a scratch3D.
Next we must navigate to the events tab in the blocks menu. Then we must drag and drop a "When Flag Clicked" block out to our work area.
Next we want to go back to the "More Blocks" tab, find the "New 3D World" block and then drag and drop it underneath the "When Flag Clicked" block.
The "New 3D World" block takes in three arguments. First a scene type for this tutorial we want to choose "Space". Next it takes in a "Width" and a "Height". The width and hight determine the size of our "scene" (meaning the amount of space that all of our shapes, characters and other 3D objects can inhabit).
Next we need to make a variable to hold our 3D earth. This will allow us to change and manipulate that object in the future. First we need to click on the "Data" tab, then click on "Make a Variable". Now lets name our variable "Earth" and click "ok"
Next we want to drag and drop the "Set Earth to" block that we just created underneath the "New 3D World" block.
We now want to return back to the "More Blocks" tab and find the "New Planet" block. Once you find it drag it out to work and drop it into the white box of you "Set Earth to" block. When our program is ran this will give set the value of our "Earth" variable to that to the 3D object we our creating with the "New Planet" block.
Our "New Planet" block takes in 5 arguments. First the type of planet you wish to create. There are currently 11 options in the drop down menu. A quick shoot out to Mr. Doob for his Three.x planets which was used to create the planets in Scratch3D. (http://learningthreejs.com/blog/2013/09/16/how-to-make-the-earth-in-webgl/)
The Block also takes in a X position, Y position, and Z position. In in scratch3D the center of the screen has the coordinates (X:0 Y:0 Z: 0). Finally the block takes in a Diameter value, this determines the size of our planet.
We now need to create another variable to hold the 3D text. Click on the "Data" tab, click "Make a Variable", name it Text, click ok and lastly drag and drop the new "Set 'Text' to" block underneath the "Set 'Earth' to" block.
Next we return to the "More Blocks" tab, then drag and drop a "3D Text" block into the "Set 'Text' to" block. Just like in the pervious block this will give the variable we specify the of any 3D object we pass into it.
The 3D text block takes in 5 arguments. First the text you want to transform in a 3D text and display in your scene, second the font size and then the X, Y, Z position where you want the text within your scene.
Let's now add in some camera controls so that we can change our view of our 3D scene. Find the "Add Camera Controls" block, then drag and drop at the bottom of your code stack. The "Camera Controls" block takes in 3 arguments to customize the way the controls work. The first is the camera view type. A First Person view will position the from a first person view point. This will give the feeling that you are walking around through the 3D world. The second camera type and the one we will be using for this tutorial is the "Mouse/Trackball". This Camera Control seting will allow you to rotate your camera around a certain point in your scene and zoom in and out on that point. Next the block takes in a "Move Speed". This allows you to set the speed that your camera moves. Last the block takes in a "Look Speed" this is the speed at which your camera rotates.
We now add in a "forever" block. This block will continue to loop through executing any code blocks that are inside of it until the red stop sign is clicked. When using Scratch3D it is good practice to always click the red stop sign after you close the scene window. This will prevent any code from continuing to be executed within a loop.
Now we find the 'Rotate" block and place it inside of the forever loop. This block takes in three arguments, the the variable that holds the 3D object we wish to rotate, the axis we want to rotate the variable along, and the number of degrees we want to rotate to 3D object.
The final block we have to add into our Hello World program is the variable that we want to rotate one degree on every iteration of our forever loop. So we go back to the "Data" tab, get the "Earth" variable, then drag and drop it into our "Rotate" block. Since our "Forever" block will continue to loop through and execute each block inside it once on every loop. Our 3D Earth will now rotate one degree along the X axis with every loop of the forever block until the red stop sign is pressed.
You are now ready to click the green flag and run your first Scratch3D program! Scratch 3D does run in a separate window so if you do not see a new window open when you click the green flag you may have to go into your browser settings and enable popup windows for scratchx.