AxiomWolf

PROJECTS

Interactive Marching Cubes (MCC25)

2025-07-05 · 642 words

In this project, I have implemented a live-editable marching cubes algorithm in VR.

This was my first year contributing to the MMC, taking place in Resonite over the course of February.

During the idea gathering stage in January, I have had some ideas to expand on my polygon triangulation tool. Although I wanted to do something voxel based with greedy meshing at first, I decided, with the help of a friend, that marching cubes would be a simpler approach.

Although I originally wanted the tool to be used as a sculpting tool, I rand into performance issues even with several optimizations. Due to this, the project was re-structured to become a educational world instead.

You can visit the world in Resonite to learn more, or use the tool from resrec:///U-1TtGn3kT3bc/R-BCF190D17FEEBB6CFCB37D11F595E060EA17B4BF094E5D82A3FF037647B4ABFD.

Documentation

Many subsystems of the tool don’t run every update, instead using a timer to only run sometimes. In addition, the marching is set so that it will only march through one chunk per frame. While this causes latency, it helps to keep the FPS more reasonable.

Visuals

This section handles the visuals for the tool.

Grid

This positions the debug grid.

DataVisual

This updates the interior visual of the debug grid.

RadiusVisual

This drives the size of the draw point as well as moving it towards the tip reference.

Cursor

This subsystem manages the cursor, allowing the tool to access the proper cell in the data structure.

Position

update_cell_ref

This keeps track of the integer position of the current cell. Triggers updates on change.

UpdateCellRef

update_cell_ref

This handles the logic for updating the current cell.

CreateCell

create_cell: int3

Creates a new cell slot with the correct name.

Cleanup

This cleans up empty cells every 100 updates.

DesktopPosition

This positions the Tip Reference to the center of the desktop's screen when equipped on desktop.

DrawPoint

This positions the drawing point, where new parts of the sculpt are drawn. This is important in the flatten mode, since it locks the point to one plane.

Brush

This handles drawing on the grid.

Draw

This draws, updating the data inside the cells.

For optimization, the iteration is first limited to only cell ID's that are numerically close to the brush's bounding box. Next, this is further filtered to cells that intersect the actual sphere of effect. Last, all cells within are updated with their new data.

Grow Grid

create_cell: int3

Every 10 updates, this checks if all cells within the brush's bounding box exist. If not, the cell is created.

QuickRadius

This allows for desktop users to update the brush radius using their mouse.

Marching

This contains the main marching cube algorithm.

March

march: int3

set_tri: uint

set_tri: uint

This performs the marching cubes algorithm on the given cell. It recursively creates triangles based on the correct case.

Schedule

march: int3

Calls the march function once per frame on a cell that requires updating.

BakeIdle

Bakes cells that weren't updated every 15 seconds.

Management

Manages individual sculpts.

DetachSculpt

detach_sculpt

Detaches a sculpt from the tool, removing its references.

AttachSculpt

detect_sculpts_callback: Slot

Attaches a sculpt following a visual process. It broadcasts Word/sculpt_tool_detect_sculpts to all sculpts in the world to determine their locations.

CreateSculpt

create_sculpt

create_sculpt_wizard

Manages creating sculpts.

Finalize

finalize

Manages finalizing, baking, and detaching the sculpt.