$ show freezy/VisualPinball.Engine
VisualPinball.Engine is a comprehensive pinball simulation engine and Unity package for authoring and playing virtual pinball tables. It provides a complete pipeline for importing Visual Pinball (.vpx) files, generating 3D meshes and physics colliders for every playfield element (bumpers, flippers, ramps, rubbers, targets, etc.), and running a Burst-compiled physics simulation with collision detection, flipper mechanics, nudge, and game logic wiring (switches, coils, lamps). The codebase is structured as a Unity package with extensive editor tooling (inspectors, manager windows, asset browser, packaging system) and a runtime player. It is not a standalone application but a library/framework that integrates deeply with Unity's editor and runtime. The architecture is modular, with clear separation of concerns: data classes with BiffAttribute-based binary serialization, mesh generators, collider generators, API interfaces for game logic, and a packaging system for distributing tables as .vpe files. The code demonstrates high craftsmanship in physics simulation, mesh tessellation, and binary format handling, though some legacy components and editor coupling exist.
The LLM identified 5 files worth highlighting for reuse:
Declarative attribute system for reading and writing the Visual Pinball binary format (VPX). Each field in a data class is annotated with [BiffString], [BiffFloat], etc., and the base BiffData class uses reflection to serialize/deserialize records. This pattern is self-contained and could be extracted for any binary format that uses record-based storage with type-length-value encoding.
Interface for serializing Unity component state into byte arrays for the .vpe package format. Implemented by dozens of components (lights, sounds, physics materials, etc.). The pattern is clean and reusable: each component defines a Pack()/Unpack() method that writes/reads a struct via a PackageApi.Packer. Could be adapted for any game engine's component serialization needs.
Implements Catmull-Rom spline interpolation with recursive subdivision for smooth curves. Used by rubber, metal wire guides, and other curve-based playfield items. The code is self-contained, uses only basic math, and could be reused in any project requiring spline-based shape generation.
Struct-based triangle collider with hit-test using barycentric coordinates. Part of the physics engine's narrow phase. The collider is Burst-compatible and stateless, making it reusable in any jobified physics system. Demonstrates efficient collision detection for mesh-based objects.
Generates 3D mesh for rubber rings from drag points using Catmull-Rom spline tessellation. The generator is isolated, takes only data input, and produces a Mesh object. This pattern is repeated for other items (ramps, surfaces, metal wire guides) and could be extracted as a general spline-to-mesh utility.