Cave Rock Population

Tool Guide

Written by: Brandon L’Abbe

Project Nautilus


Project Nautilus

1. Purpose

The Cave Rock Population Tool is a tool that will generate many prefabs onto a mesh. In practicality, this was intended to be used to generate rocks within a cave mesh, whether that be rocks that would be generated on the seafloor, or stalactites placed upon the ceiling. The user then would be able to go into the scene and delete any unnecessary rocks, or adjust rocks that seem a little bit out of place, which should be faster than placing all of the rocks by hand.

2. Method 

This tool works by inputting a prefab. Once a prefab has been connected to the tool, the tool will search for the first mesh within that prefab (which should only be the cave). The user will then be able to use the tool to either visualize the mesh (as either vertices or vertex normals) or generate the rocks onto the cave mesh. This tool allows the user to input a rock prefab and choose whether they would like the prefab to be placed on the ceiling of the cave or the floor of the cave. When the user chooses to generate rocks in the cave, the tool will process all of the mesh’s vertex normals to determine whether each vertex is on the ceiling of the cave, or on the floor. This determination is made by calculating the Vector Dot production between the vertex normal and the world's universal up vector. This dot product will return a positive value if the vertex is pointing upwards (therefore on the floor), or a negative value if the vertex is pointing downwards (therefore on the ceiling). The tool also allows you to set an Angle of Tolerance. This value represents the angle above and below the horizontal plane that you would not like to represent ceiling or ground vertices (you wouldn’t want a stalactite placed on a wall just because it’s vertex was pointed 1 degree upward!).

3. Tool Setup

To access the tool, you must drop down the “My Tools” menu from the list of drop downs at the top of the Unity Window. In that dropdown, select “Cave Population”. If you do not see either of these, then you may not have the Tool installed in your version of the repo! To confirm this, if you go to Assets/Scripts/Tools, you should see two scripts named “CavePopulation” and “MeshVisualizer”. If you don’t see these, then you do not have the tool in your version of the repository. Once you open the tool, it will open a Unity tab that you can dock to any area of your editor.


4. Tool Settings & Usage

Attached below is a screenshot of what the entire tool window with all of it’s settings looks like:

Here I will explain every part of the tool window in the form of a bulleted list. Indented sections are hidden behind it’s parent section.

  • Cave Object [Object Input]: Here you will place the world object that represents the cave in your Unity scene.
  • Should Visualize Mesh? [Checkbox]: Will toggle whether you are visualizing the vertex data within the scene.
  • Visualizer Mode [Drop Down]:
    If set to “Vertex”, it will visualize the vertices in your scene as yellow spheres. If you have the bounding sphere enabled, any vertices within the bounding sphere will be colored red.
    If set to “Normal/No Indication”, it will visualize the vertex normals in your scene as yellow lines.
    If set to “Normal/Vertical Indication”, it will visualize the vertex normals in your scenes as lines, and give them color depending on which way the script determines them to be facing. Red lines represent the ground, Blue lines represent the ceiling, and Yellow lines represent vertices that are neither ceiling nor ground based off of the “Angle of Tolerance” that you set below.
  • # of Items [Slider 1-1000]: Determines how many vertices are visualized in the scene at one time. Setting this amount too high has shown to drop the FPS of the editor down to an unbearable rate, so I have capped this amount at 1,000.
  • Showing Item # through # out of # [Text Box]: Shows you which vertices or vertex normals you are using based on their index numbers.
  • Previous Set/Next Set [Buttons]: These allow you to scroll through which vertices you are viewing, since there is a cap on how many you can view at a time.
  • Angle of Tolerance [Slider 0-75]: The number of degrees above and below the horizontal that you would not like to be considered ceiling or floor.
  • Regression Into Mesh [Slider 0.0-1.0]: The length that the rocks will be placed inside of the cave mesh. Setting 0.0 would place the rocks on top of the vertices (which look unnatural). Setting 1.0 would place the rocks 1 unit within the cave mesh so that they overlap and look more natural.
  • Gen Object Prefab [Prefab Object]: The rock prefab that you would like to be generated into the cave.
  • Is Ceiling? [Checkbox]: Determines whether the rock prefab will be generated into the ceiling or into the floor.
  • Should Rotate to Normals? [Checkbox]: When checked, all generated rocks will be rotated so that they face the same direction as the vertex that they were generated on.
  • Bound Gen to Sphere? [Checkbox]: When checked, a sphere will be created in the scene called “Cave Tool Bounding Sphere” and all generated objects will only generate on vertices that are within this sphere. The radius of this sphere is determined by the X scale on the transform,so when manipulating this object in the scene it is recommended to link the X, Y, and Z scale together and manipulate them in sync.
  • Distribution Percentage [Slider 1-100%]: What percentage of the floor/ceiling vertices should generate Rocks?
  • Populate Cave [Button]: Populates the cave ceiling/floor using the settings above. All of the rocks will be placed in an empty game object called “Rocks Generated”. This should make it easy to delete all of them if you mess up

5. Images

Mesh normal visualization:

Vertices visualized with the Bounding Sphere:

Generating stalactites into the cave:

Generated rocks on the cave floor:

5. Final Notes/Improvements

This tool is in no means a final version. As a Tools programmer, my job is to improve our tools as much as it is to make new ones. So if you have any ideas of tweaks or addons to this tool that would improve your usage of it, please reach out! I’m happy to listen to any tool ideas or how I can make my current tools better! If you have any issues using the tool, please reach out and I can do my best to help!