Three.js is an easy-to-learn 3D graphics library for the web. This book explains the Three.js API and how to use it to build immersive online games. By the time you finish this book, you'll be able to reach millions of gamers through their web browsers, and you'll build exciting projects such as a first-person shooter along the way.
I've been building games for more than a decade. When I discovered Three.js, the first project I built was very similar to the first-person shooter game you'll build in Chapter 3, Exploring and Interacting. I was hooked by how quickly I could create fun games with no prior exposure to the library.
In Game Development with Three.js, I've tried to stay true to that exploratory spirit. I hope you have as much fun reading it as I had writing it.
Chapter 1, Hello, Three.js, describes what Three.js is and what it does, how to start writing code with it, and a basic scene.
Chapter 2, Building a World, explains the components of a Three.js scene including renderers, geometries, materials, and lighting for building a procedurally generated city.
Chapter 3, Exploring and Interacting, explains mouse and keyboard interaction, basic physics, and creating a first-person shooter game.
Chapter 4, Adding Detail, explains particle systems, sound, graphic effects, and managing external assets such as 3D models in addition to building a capture-the-flag game.
Chapter 5, Design and Development, describes game design for the web, including development processes, performance considerations, and the basics of networking.
You will need a web browser. To fully experience all the features discussed in this book, use Chrome 22 or later or Firefox 22 or later. Internet Explorer 11 or later should also work. A text editor is also recommended, especially if you are not using Chrome, as discussed in Chapter 1, Hello, Three.js. You will need an Internet connection at certain points in the book such as when downloading the Three.js library (these points will be identified in the text).
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The
THREE variable is global."
A block of code is set as follows:
renderer = new THREE.CanvasRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement);
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
renderer = new THREE.WebGLRenderer();
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "If you want to experiment with WebGL features that are still in development, you can enable some of them in Canary's about:flags page."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to
<[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output.You can download this file from http://www.packtpub.com/sites/default/files/downloads/8539OS_Images.pdf
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at
<[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at
<[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.