Reader small image

You're reading from  Unity Cookbook - Fifth Edition

Product typeBook
Published inNov 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781805123026
Edition5th Edition
Languages
Tools
Right arrow
Authors (3):
Shaun Ferns
Shaun Ferns
author image
Shaun Ferns

Shaun is a lecturer at Technological University Dublin. He is currently teaching on the BA (Hons) in Creative Digital Media where he is lead in the delivery of the Multimedia Stream. He is currently exploring serious games for construction-related training as well as the opportunities transmedia provides in improving user experience and engagement in cultural archive artifacts. His educational research is currently driven by his interest in self-determined learning (heutagogy), rhizomatic learning theory, micro-credentialing /digital badging, and curriculum development.
Read more about Shaun Ferns

Sinéad Murphy
Sinéad Murphy
author image
Sinéad Murphy

Sinead Murphy is currently Data Analytics Manager for the Irish NGO Trocaire. She has over 25 years of computing experience, including freelance IT training and database consulting, university lecturing in mathematics, IT skills and programming at TU Dublin (Ireland) and Middlesex University (London). She is a published academic, with undergraduate and postgraduate degrees in mathematics, computing and data science. She is passionate about the use of IT for understanding and visualising data, and using that understanding to make meaningful differences in the world. She is currently exploring the use of Python and Unity for data analytics and interactive visualisations.
Read more about Sinéad Murphy

View More author details
Right arrow

Creating 3D Geometry with ProBuilder

There are two main ways to get 3D objects for use in your Unity games. One way is to import 3D models created outside of Unity, such as with dedicated 3D modeling applications like Blender, 3D Studio Max, and Maya. Many 3D models are available from the Unity Asset Store and other online websites such as TurboSquid.com. A second way is to create your own 3D objects inside the Unity Editor, using the ProBuilder package. ProBuilder is a Unity package that can be added to any project. It allows you to create and manipulate geometry inside the Unity editor. While Terrains are great for creating terrains, ProBuilder allows you to create 3D objects and then manipulate them, such as by extruding or moving vertices, edges, or faces. You can also paint them with colors or texture them with materials.

Whether working with dedicated 3D modeling applications or ProBuilder, there are some fundamental concepts that you need to understand to get the most out...

Getting started with ProBuilder

In this recipe, we’ll set up the ProBuilder tools and create several 3D game assets.

Figure 7.2: The 4 x 4 x 4 cube-based object we’ll create in this recipe

Getting ready

For this recipe, you need a brick-like texture. We’ve provided the file Yellow_brick_wall.jpg in folder 07_01.

How to do it...

To create geometry with ProBuilder, follow these steps:

  1. Create a new Unity 3D project.
  2. Open the Package Manager panel by choosing Windows | Package Manager. Set the Packages list to Unity Registry. Locate the ProBuilder package and install it for this project. You should now have a new Unity menu, Tools, with a single option, ProBuilder.
  3. Open the ProBuilder tools panel by choosing Menu: Tools | ProBuilder | ProBuilder Window. Dock this panel somewhere convenient so you can always see it, for example, as a column between the Hierarchy and Scene panels.
  4. Use the right-mouse-button menu...

Transforming an object through scaling and coloring

In this recipe, we’ll take things further, transforming the object with some scaling, adding simple colors with Vertex Coloring, and then texturing faces with an image-based material.

Figure 7.12: The swimming-pool-topped pyramid object we’ll create in this recipe

Getting ready

This recipe continues from the previous one. So keep working on that one, or make a copy and work on that copy.

How to do it...

To transform an object through scaling and coloring, follow these steps:

  1. In the ProBuilder tools panel, display the Vertex Colors Editor panel by clicking the Vertex Colors icon/button.
  2. Select the top face of your Cube object, and click the Apply button next to the yellow vertex color. Your object should now have a yellow top face.

Figure 7.13: Setting the color of a face using Vertex Colors

  1. Select the yellow top face, and scale this face a little smaller...

Creating a house with ProBuilder

If you quickly want to create a more detailed prototype, maybe based on an actual building, we can combine the techniques that we used in the previous recipe to extrude a complex building. In this recipe, we will demonstrate how to make a square room that includes a window and a door. Following the same process, a building of any shape can be made using ProBuilder:

Figure 7.16: The one-room house created in this recipe

Getting ready

You’ll need the ProBuilder package installed for this recipe, and also the grid snapping setup. Either work on a copy of the previous recipe, or create a new 3D project and follow steps 1—8 of the first recipe in this chapter, Getting Started with ProBuilder.

How to do it...

To create a house with ProBuilder, follow these steps:

  1. Create a new 3D project. Add the ProBuilder package, and set up visible grid snapping in increments of 1 Unity unit (as shown in the first recipe...

Exploring ProBuilder Boolean operations to add a window to our house

A powerful feature when working with 3D-modeling applications is the use of Boolean operations to create or change shapes by combining shapes together in additive/subtractive ways. ProBuilder offers three Boolean operations (currently in a beta-style “experimental” mode). In this recipe, we’ll learn how to subtract one shape from another to create window spaces in the walls of our house.

Figure 7.19: The window added to the back wall of our house using a Boolean shape subtraction

Getting ready

This recipe builds on the previous one, so make a copy of that project and work on that copy.

How to do it...

To explore ProBuilder Boolean operations to add a window to our house, perform the following steps:

  1. Enable the ProBuilder experimental tools by opening the Preferences panel, selecting the ProBuilder tab, and checking the Experimental Features Enabled option....

Organizing level geometry as empty GameObject children

Many beginners working with 3D modeling tools have trouble navigating and orienting the scene being edited once it contains many objects of different sizes. A simple yet effective approach is to make all related 3D objects children to an empty GameObject, positioned at the “center” of those objects. You can use this method if you want to quickly create a more detailed prototype, maybe based on an actual building. We can combine the techniques that we used in the previous recipe to extrude a complex building. In this recipe, we will demonstrate how to parent GameObject whose children are a yellow floor plane, a blue staircase, and a green cone. Following the same process, a building of any shape can be made using ProBuilder:

Figure 7.23: Collection of ProBuilder objects as children of an empty GameObject

Getting ready

You’ll need the ProBuilder package installed for this recipe, and also grid...

Further reading

This section contains some sources that provide more information about the topics that were covered in this chapter.

You can learn more about modeling in Unity with ProBuilder:

Learn more on Discord

To join the Discord community for this book – where you can share feedback, ask questions to the author, and learn about new releases – follow the QR code below:

https://packt.link/unitydev

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity Cookbook - Fifth Edition
Published in: Nov 2023Publisher: PacktISBN-13: 9781805123026
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (3)

author image
Shaun Ferns

Shaun is a lecturer at Technological University Dublin. He is currently teaching on the BA (Hons) in Creative Digital Media where he is lead in the delivery of the Multimedia Stream. He is currently exploring serious games for construction-related training as well as the opportunities transmedia provides in improving user experience and engagement in cultural archive artifacts. His educational research is currently driven by his interest in self-determined learning (heutagogy), rhizomatic learning theory, micro-credentialing /digital badging, and curriculum development.
Read more about Shaun Ferns

author image
Sinéad Murphy

Sinead Murphy is currently Data Analytics Manager for the Irish NGO Trocaire. She has over 25 years of computing experience, including freelance IT training and database consulting, university lecturing in mathematics, IT skills and programming at TU Dublin (Ireland) and Middlesex University (London). She is a published academic, with undergraduate and postgraduate degrees in mathematics, computing and data science. She is passionate about the use of IT for understanding and visualising data, and using that understanding to make meaningful differences in the world. She is currently exploring the use of Python and Unity for data analytics and interactive visualisations.
Read more about Sinéad Murphy