Procedural Toolkit

repository·master·Indexed 25 days ago

https://github.com/syomus/proceduraltoolkit

A procedural generation library for Unity (version 0.2.4-preview) providing tools for mesh generation, geometry algorithms, cellular automata, and building generation. It includes modules for building and chair generation, low poly terrain, maze generation, 2D character creation, and SDF shader libraries. The toolkit also provides wrappers for third-party libraries including FastNoiseLib, LibTessDotNet, and ClipperLib.

Tokens
1.9K
Snippets
3
Records
19
Agent score
84%

What's inside Procedural Toolkit

  1. Overview of Procedural Toolkit Runtime modules

    master

    The toolkit is organized into several functional modules:

    Core Runtime

    • ArrayE: Extensions for Arrays and Lists (e.g., looped getters, flood fills).
    • CellularAutomaton: Generic two-state cellular automaton.
    • ColorE / ColorHSV: Color extensions and HSV color representation.
    • MeshDraft / CompoundMeshDraft: Helpers for mesh generation.
    • RandomE: Random data generation and collection extensions.
    • VectorE / TextureE / MeshE: Extensions for Unity's core types.

    Building Generation

    • BuildingGenerator: The main class for generating reusable buildings based on configurations and strategies.
    • Layout / Facade / Roof: Interfaces and classes for facade and roof generation (e.g., HorizontalLayout, VerticalLayout, FacadePlanner).

    Geometry & Algorithms

    • Geometry: Utility class for computational geometry (point samplers, etc.).
    • Primitives: Representations for Circle2, Circle3, Sphere, Line2, Line3, Segment2, and Segment3.
    • Intersections / Distance / Closest: Specialized modules for intersection, distance, and closest point algorithms.
    • StraightSkeleton: Tools for straight skeleton generation via StraightSkeletonGenerator.

    Third-Party Wrappers

    • ClipperLib: Access Clipper via PathClipper and PathOffsetter.
    • LibTessDotNet: Access LibTess via the Tessellator wrapper.
    • FastNoiseLib: Integration of the FastNoise library.
  2. Overview of LibTessDotNet

    master

    LibTessDotNet is a robust and fast tessellator for .NET designed to produce polygons with N vertices (where N >= 3) and perform triangulation. It is compatible with .NET Framework 2.0, making it suitable for use with Mono, Unity, or XNA.

    Key capabilities include:

    • Tessellating arbitrary complex polygons (self-intersecting, coincident vertices).
    • Supporting advanced winding rules: even/odd, non zero, positive, negative, and |winding| >= 2.
    • Custom input support, including custom vertex attributes (e.g., UV coordinates) with merging callbacks.
    • Forcing input contour orientation (clockwise/counterclockwise).
    • Single and double precision support.
    • Compatibility with polygons computed using the Clipper library.
  3. Install Procedural Toolkit via Asset Store or .unitypackage

    master

    You can also install the toolkit by importing it from the Unity Asset Store or downloading a release from the GitHub Releases page.

    Note: If you have previous versions of the toolkit installed, it is highly recommended to delete them before importing a newer version.

  4. Utilize Signed Distance Functions (SDF) in shaders

    master

    The toolkit includes a shader library for utilizing SDF functions. Examples include:

    • StarPolygon: Demonstrates 'normal' vs 'cheap' polygon functions.
    • Shapes: Demonstrates available shapes.
    • DistanceOperations: Shows combining shapes (e.g., square and circle) using different functions.
    • Easing: Demonstrates easing curves and motion.
    • Transitions: Shows sequencing and animation techniques.
    • Animation: Demonstrates complex pattern creation and animation in shaders.
  5. Use the BuildingGenerator for procedural buildings

    master

    The BuildingGenerator creates entire meshes from scratch and paints vertices. Note that generated meshes do not have UV maps, so they are not compatible with the Standard shader.

    Key components for building generation:

    • BuildingGeneratorComponent: A minimal implementation example.
    • BuildingGeneratorConfigurator: A UI-based configurator with editor controls.
    • ProceduralFacadePlanner: Controls facade layouts.
    • ProceduralFacadeConstructor: Used with the planner for facade construction.
    • ProceduralRoofPlanner: Generates roof descriptions.
    • ProceduralRoofConstructor: Used with the roof planner for construction.
    • ProceduralFacadeElements: A collection of procedural facade panels.
    • PolygonAsset: A ScriptableObject used to contain vertices.
  6. Generate Mazes with MazeGenerator

    master

    The MazeGenerator creates mazes based on input configuration and can draw the generation process onto a texture.

    Key components:

    • MazeGeneratorConfigurator: UI controls for the generator.
    • Maze: The graph representation of the generated maze.
  7. Get started with Procedural Toolkit in C#

    master

    After installation, import the ProceduralToolkit namespace to access the library's features.

    If you are using Assembly Definitions, you must add ProceduralToolkit as a reference in your assembly definition file.

    using UnityEngine;
    using ProceduralToolkit;
    
    public class ReadmeExample : MonoBehaviour
    {
        private void Update()
        {
            Debug.Log(string.Format("<color=#{0}>{0}</color>", RandomE.colorHSV.ToHtmlStringRGB()));
        }
    }
  8. Install Procedural Toolkit via Unity Package Manager

    master

    The recommended installation method is using the Unity Package Manager as a Git package. Ensure Git is installed and available in your system's PATH.

    Add the package using the following URL: https://github.com/Syomus/ProceduralToolkit.git#upm

    https://github.com/Syomus/ProceduralToolkit.git#upm
  9. Use the ChairGenerator for procedural chairs

    master

    The ChairGenerator is the main class for generating chair meshes from scratch.

    Key components:

    • ChairGeneratorConfigurator: Provides UI and editor controls for configuration.
    • Armrests, Backs, and Stretchers: Specific constructors for chair parts.
  10. Generate 2D Characters

    master

    The CharacterGenerator creates a sprite set and a random name for 2D characters.

    Key components:

    • Character: A container for sprite renderers.
    • NameGenerator: Generates random names from a large array.
    • CharacterGeneratorConfigurator: UI for configuring the generator.
  11. Run Cellular Automata simulations

    master

    The CellularAutomaton class can be used to run simulations, with the results drawn onto a texture.

    Note: Some rulesets require a noise value different from the default setting. Use CellularAutomatonConfigurator for UI-based control.