ThetaVox

Hex Planet System

Documentation

About

Create and paint hexagonal sphere planets with tiles, props, rivers, and terrain deformation. A complete planetary generation system for strategy games and simulations.

Key Features

Technical Details

Getting Started Guide

Creating Your First Planet

  1. Create a Tileset: Go to Window → Planet → Tileset Editor. Create new tilesets or edit existing ones to define your terrain types.
  2. Generate Planet: In the scene hierarchy, go to Create → 3D Object → Planet. The frequency slider controls subdivision and tile count (formula: Total tiles = 10 × frequency² + 2).
  3. Paint Your Planet: Open Window → Planet → Planet Painter to apply tiles, place props, add rivers, and deform terrain. Note: After recompile, click "Regenerate Mesh" to reload tile information.

Working with Props

Rivers and Pathfinding

Editor Tips

Planet Architecture Guide

Icosahedron Generator Overview

The planet mesh generation follows a two-step process:

  1. Subdivision: Start with a base icosahedron (20-sided polyhedron) and subdivide each triangular face based on frequency. Higher frequency = more subdivisions = more triangles.
  2. Dual Mesh Generation: Generate a dual mesh by computing centroids of triangles. These centroids become vertices of the tile mesh, creating hexagonal tiles (with 12 pentagons at original vertices) covering the sphere uniformly.

Raycast to Tile Lookup

When clicking or hovering over the planet:

  1. Raycast: TileRaycaster performs Physics.Raycast from camera through mouse position
  2. Find TileManager: Search hierarchy to locate TileManager
  3. World to Local: Convert world hit point to local planet space
  4. Spatial Lookup: Use spatial grid to quickly find nearby tiles (O(1) vs O(n))
  5. Tile Found: Return closest Tile object with all data (id, type, neighbors, props, etc.)

Key Data Structures

baseUnitDualVertices - Master vertex array with two parts:

Tile Class Properties:

The Tile class can be expanded for game-specific logic: structures, resources, units, fog of war, etc.

Spawning Structures on Tiles

IcosahedronGenerator provides these methods:

Pathfinding System

Pathfinding.cs - Core A* Algorithm

TilePathfinder.cs - MonoBehaviour Wrapper

Core API:

PathAgent.cs - Movement Execution

Core API:

Territory System

Creating Territories

Auto-assign materials (random cycling):

Territory t = territories.CreateTerritory(tiles);

Automatically assigns materials from the pool using random selection. Tiles parameter can be null for dynamic addition later.

Custom materials:

Material borderMat = /* your material */;
Material fillMat = /* your material */;
Territory t = territories.CreateTerritory(tiles, borderMat, fillMat);

Managing Territory Tiles

Add tiles incrementally:

territory.AddTile(tileId);
territories.RefreshTerritory(territory);

Remove tiles incrementally:

territory.RemoveTile(tileId);
territories.RefreshTerritory(territory);

Replace all tiles at once:

territories.SetTerritoryTiles(territoryId, newTileList);

Remove tile and update lookup:

territories.RemoveTileFromTerritory(territory, tileId);

Querying Territories

// Find which territory contains a tile
Territory t = territories.GetTerritoryForTile(tileId);  // Returns Territory or null
int id = territories.GetTerritoryIdForTile(tileId);     // Returns ID or -1

// Get territory by ID
Territory t = territories.GetTerritory(territoryId);

// Get all territories
List<Territory> allTerritories = territories.GetAllTerritories();

// Check if territory contains tile
bool contains = territory.ContainsTile(tileId);

Visual Control & Cleanup

// Show/hide territory
territory.Show();
territory.Hide();

// Destroy single territory
territories.DestroyTerritory(territory);

// Clear all territories
territories.ClearAllTerritories();

Setup Requirements

Place material pairs in Resources/Materials/ folder with sequential naming (gap-free):

Works with any number of material pairs (minimum 1 required). System stops loading at first missing pair.