Book Image

Getting Started with React VR

By : John Gwinner
Book Image

Getting Started with React VR

By: John Gwinner

Overview of this book

This book takes you on a journey to create intuitive and interactive Virtual Reality experiences by creating your first VR application using React VR 2.0.0. It starts by getting you up to speed with Virtual Reality (VR) and React VR components. It teaches you what Virtual Reality (VR) really is, why it works, how to describe 3D objects, the installation of Node.js (version 9.2.0) and WebVR browser. You will learn 3D polygon modeling, texturing, animating virtual objects and adding sound to your VR world. You will also discover ways to extend React VR with new features and native Three.js. You will learn how to include existing high-performance web code into your VR app. This book will also take you through upgrading and publishing your app. By the end of this book, you'll have a deep knowledge of Virtual Reality and a full-fledged working VR app to add to your profile!
Table of Contents (20 chapters)
Title Page
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Preface

Virtual Reality, from a computer standpoint, has been around since the 1960s. It started up again in a big way in the late 90's, and then mostly collapsed for a while—although it's never really gone away. It is back now, and, this time, it is here to stay.

What has made this change is the cell phone—the large, high-resolution display technology used in cell phones has helped created HMDs (Head Mounted Displays, or VR Goggles). Circuits and computers are also vastly faster than they used to be; computer graphics that used to cost a quarter of a million dollars in 1998 now costs less than two thousand and is even faster.

Building VR worlds has always been difficult, however. You had to be a C++ programmer and know an immense amount about high speed programming, real-time graphics, geometry, and other complex topics. This has been simplified in the last few years with game development engines—simplified, but only to a point. 

With React VR, it is even simpler. You can code a VR world now using React syntax, a simple declarative HTML-like language. If you want to create a box, you just declare a box with the right width, height, and so forth, instead of having to write procedural code. The syntax may be simple, but these worlds can be event driven, animated, and responsive to user input as well as obtaining information from the web.

This will enable you to build complex virtual worlds with simple JavaScript and HTML-like code. This uses a new browser-based programming paradigm called WebVR; regular browsers on PCs and on mobile devices can now view worlds in VR.

You can do this too, and this book will show you how. 

What this book covers

Chapter 1, What is Virtual Reality, Really?, shows what Virtual Reality really is—how the right combination of movement and images makes things look real, even if they aren't completely realistic.

Chapter 2Flatland and Beyond: VR Programming, is about the different ways that we can program VR and gets us started with React VR and Node.js.

Chapter 3, 3D or Reality in Dimensions Other than X and Y, introduces us to 3D math, coordinates, and how to describe objects in React VR.

Chapter 4, The React VR Library, describes the major components and objects in the React VR library.

Chapter 5, Your First VR App, shows us how to create our first major VR world, including downloading and using photo-realistic background images.

Chapter 6, Working with Poly and the Gon Family, introduces us to polygon modeling, and the free software program called Blender, for doing 3D modeling.

Chapter 7, Sitting Down with a (Virtual) Teapot, continues our introduction to Blender, showing how to texture map and include these 3D objects into our VR world.

Chapter 8Breath Life in Your World, introduces the Animation API and ways to make our objects move and sound real.

Chapter 9, Do It Yourself – Native Modules and three.js, demonstrates how to stay within React VR and build even more complex worlds.

Chapter 10, Bringing in the Real Live World, connects our VR worlds to real-world APIs and enables us to bring in graphical data all the way from Mars.

Chapter 11, Take a Walk on the Wild Side, develops code and user interface to let us walk around in VR and then promptly end up in a (constructed for fun) maze.

Chapter 12, Publishing Your App, and Where to Go from Here, shows us how to upgrade and publish our worlds; we also discuss monetization and where VR could go in 5 years.

What you need for this book

You will need a Windows PC, of nearly any type; for maximum enjoyment, you will need  VR rig. Either an HTC Vive, Oculus Rift, a Samsung Gear VR, Google Daydream, or other VR goggles (including the Google Cardboard) and a cell phone.

You can develop these WebVR worlds even if you don't have a sophisticated Head Mounted Display (HMD) or VR Headset ; you can view them in flat mode on your regular computer screen.  You can pick up a simple VR cell phone holder/headset (Google Cardboard or similar) for less than 20 dollars or even free in many places, so don't let hardware be a barrier to learning about the next great thing.

Who this book is for

This book is for anyone who wants to learn Virtual Reality on the web and create engaging 3D websites with WebVR through React VR. You will pick this up quickest if you have already known some JavaScript, and even faster if you already know React or React Native. Even if you don't, the book will show you step by step what to do. If you already know how to do polygon modeling, this will help, but this book will also show people how to use the free and open source Blender to do some basic modeling if needed, and where to get free downloads. You do not need a VR rig to be able to enjoy this book—you can do the samples with a regular PC and even publish it on the internet.

 

Conventions

In this book, you will find a number of text styles 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: "Components are real things, not just labels or placeholders, as they have built in ways to present themselves through the world via a render() function."

A block of code is set as follows:

<Box
 dimWidth={4}
 dimDepth={1}
 dimHeight={9}
 lit
/>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

f:
mkdir f:\reactVR
cd \reactVR

Any command-line input or output is written as follows:

npm install mersenne-twister --save

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Once you have the polygons assigned, click on View->Front then click on Mesh->UV Unwrap->Cylinder Projection."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in 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 at www.packtpub.com/authors.

Customer support

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.

Downloading the example code

You can download the example code files for this book 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 emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Getting-Started-with-React-VR. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book 

We also provide you with 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 https://www.packtpub.com/sites/default/files/downloads/GettingStartedwithReactVR_ColorImages.pdf.

Errata

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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.