Runtime bounding boxes in Unity

Posted by admin on July 6, 2011 in Unity3d |
A Runtime bounding boxes example The Unity has its own bounding boxes buit in editor which show up when you manipulate the objects, like transform boxes and collider boxes, but those are unavailable at runtime. This project can help you to draw the bounding boxes ingame, using GL.Lines. The boxes get aligned to the local space of the GameObjects where they are attached. The points calculation is taken from the renderers.bounds from all renderers in the GameObject hierarchy. Alternatively if you wanted some other size - than calculated from the renderers bounds - for your bounding box, the script contains a functionality to use the box collider instead. You can attach and size a box collider to the GameObject, check the “colliderbased” variable on the script in the inspector – and the calculation will follow the box collider. Obviously in order to get a mouse-click interaction on the objects – like in the demo scene - there have to be colliders attached to GameObject. If  the parent GameObject itself has no collider and the colliders are attached to the child objects only, it is necessary to attach a rigidbody to the parent GameObject in order to pass on the mouse-click collider interaction to parent. The below screenshot links to the webplayer demo. BoundBoxes You can download the complete package, containing the demo scene from the picture above from here:
Some  of the models used in the scene come from here: A version with simpler scene - if you prefer not to clutter your disk too much - is available on the AssetStoreas the BoundBoxes package. A bit advanced version of this package is  also available at the Unity AssetStore as the DimBoxes package. That will also let you place the dimensions and extension lines, here is the demo: DimBoxes The demo scene in the DimBoxes package is a bit simplified, but the scripts used are the same. All the above should work fine both in Unity Indie as well as Unity Pro. You can also have a look at the 3d object viewer that I created with that in the link below.: 3d object viewer This however uses the Unity Pro feature of dynamic loading of the streamed scenes. The WebPlayer itself has 150 kB  or  even less of data only and subsequent scenes are loaded/unloaded into it.


Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2011-2021 virtualPlayground All rights reserved.
VP based on Desk Mess Mirrored v1.8.3 theme from