Generate a Cube that wraps a 3D model in Unity

Introduction

The objective of this solution is to find a box with the minimum volume that encloses a 3D model in Unity.

The following video is in spanish but you can activate the English subtitles. I explain how to use the solution and what things to take into account when creating the 3D model in order not to have problems in Unity.

Download Files

Below you can download the Unity Package to import in your project.

Inside the package come two files, a Script called “WrappingCube” that must be assigned to the object we want to wrap with the box. The other file is a predefined transparent material, it can be assigned to the space in the inspector of the WrappingCube component, this material will be assigned automatically to the cube.

How to use the solution

Just add this script to the object you want to wrap with a box, make sure to add it to the one that has the Mesh Renderer Component, if you add this script to an empty GameObject it won’t work.

How the wrapping box is generated

To generate the cube something called “Bounding Box” is used, which is precisely a box that encloses the object, however one detail must be taken into account and that is that this bounding box is axis-oriented, therefore if we rotate the piece, the bounding box will adjust its dimensions of width, length and height until it completely covers the model.

Therefore, for this solution to work, the 3D model must come with the standardized orientation from the 3D modelling software, this means orienting the model in a consistent way according to the global coordinate axes and then applying the rotation to the object.

Scroll to Top
Secured By miniOrange