### Example Usage of ProceduralToolkit in Unity Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Demonstrates how to import and use the ProceduralToolkit namespace in a Unity C# script. This example logs a random color generated by the RandomE.colorHSV utility. It requires Unity 2022.3 LTS or later and assumes the toolkit is installed. ```csharp using UnityEngine; using ProceduralToolkit; public class ReadmeExample : MonoBehaviour { private void Update() { Debug.Log(string.Format("{0}", RandomE.colorHSV.ToHtmlStringRGB())); } } ``` -------------------------------- ### Shader Include Paths (HLSL) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Demonstrates how to include shader libraries in HLSL, depending on the installation type. ```hlsl #include "Packages/com.syomus.proceduraltoolkit/Shaders/SDF.cginc" ``` ```hlsl #include "Assets/ProceduralToolkit/Shaders/SDF.cginc" ``` -------------------------------- ### Generate Procedural Building in C# Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Demonstrates how to generate a single procedural building using the BuildingGenerator. It involves setting up facade and roof strategies, defining the building's foundation polygon, configuring various parameters like the number of floors, roof type, and color palette, and finally calling the Generate method. Dependencies include UnityEngine, ProceduralToolkit, and System.Collections.Generic. ```csharp using UnityEngine; using ProceduralToolkit; using ProceduralToolkit.Buildings; using System.Collections.Generic; public class BuildingExample : MonoBehaviour { void GenerateBuilding() { // Create building generator var generator = new BuildingGenerator(); // Set up facade strategies var facadePlanner = ScriptableObject.CreateInstance(); var facadeConstructor = ScriptableObject.CreateInstance(); generator.SetFacadePlanner(facadePlanner); generator.SetFacadeConstructor(facadeConstructor); // Set up roof strategies var roofPlanner = ScriptableObject.CreateInstance(); var roofConstructor = ScriptableObject.CreateInstance(); generator.SetRoofPlanner(roofPlanner); generator.SetRoofConstructor(roofConstructor); // Define building footprint (foundation polygon) List foundation = new List { new Vector2(-5f, -5f), new Vector2(5f, -5f), new Vector2(5f, 5f), new Vector2(-5f, 5f) }; // Configure building parameters var config = new BuildingGenerator.Config { floors = RandomE.Range(3, 8), entranceInterval = 12f, hasAttic = RandomE.Chance(0.5f), roofConfig = new RoofConfig { type = RoofType.Flat, thickness = 0.2f, overhang = 0.2f }, palette = new Palette { socleColor = ColorE.silver, wallColor = ColorE.white, roofColor = ColorE.gray / 4, frameColor = ColorE.white * 0.7f, glassColor = new Color(0.6f, 0.8f, 1f, 0.5f) } }; // Generate the building Transform building = generator.Generate( foundationPolygon: foundation, config: config, parent: transform ); Debug.Log($"Generated {config.floors}-floor building"); } void GenerateMultipleBuildings() { // Reuse generator for efficiency var generator = new BuildingGenerator(); generator.SetFacadePlanner(ScriptableObject.CreateInstance()); generator.SetFacadeConstructor(ScriptableObject.CreateInstance()); generator.SetRoofPlanner(ScriptableObject.CreateInstance()); generator.SetRoofConstructor(ScriptableObject.CreateInstance()); // Generate grid of buildings for (int x = 0; x < 5; x++) { for (int z = 0; z < 5; z++) { Vector3 position = new Vector3(x * 15f, 0, z * 15f); // Random foundation size float size = RandomE.Range(4f, 7f); List foundation = new List { new Vector2(-size, -size), new Vector2(size, -size), new Vector2(size, size), new Vector2(-size, size) }; // Random configuration var config = new BuildingGenerator.Config { floors = RandomE.Range(2, 6), hasAttic = RandomE.Chance(0.3f), roofConfig = new RoofConfig { type = RandomE.GetRandom( RoofType.Flat, RoofType.Hipped, RoofType.Gabled ), thickness = 0.2f, overhang = 0.3f }, palette = new Palette { socleColor = RandomE.colorHSV.ToColor(), wallColor = ColorE.white, roofColor = RandomE.colorHSV.WithV(0.3f).ToColor() } }; Transform building = generator.Generate(foundation, config, transform); building.position = position; } } } } ``` -------------------------------- ### Manipulate Colors with ColorHSV (C#) Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Demonstrates creating, converting, and manipulating colors using the ColorHSV class from Procedural Toolkit. Supports conversion to Unity's Color, modification of HSV components, generation of color schemes, and use of predefined HTML colors. Requires Unity and the Procedural Toolkit library. ```csharp using UnityEngine; using ProceduralToolkit; public class ColorExample : MonoBehaviour { void Start() { // Create color in HSV space ColorHSV baseColor = new ColorHSV( h: 200f, // Blue hue s: 0.8f, // High saturation v: 0.9f, // Bright a: 1f // Opaque ); // Convert to Unity Color Color rgbColor = baseColor.ToColor(); // Modify HSV components ColorHSV darker = baseColor.WithV(0.5f); ColorHSV desaturated = baseColor.WithS(0.3f); ColorHSV shifted = baseColor.WithOffsetH(30f); // Generate color schemes ColorHSV complementary = baseColor.GetComplementary(); ColorHSV[] triadic = baseColor.GetTriadic(); ColorHSV[] tetradic = baseColor.GetTetradic(); // Use predefined HTML colors Color silver = ColorE.silver; Color aqua = ColorE.aqua; Color crimson = ColorE.crimson; // Modify color components Color withAlpha = silver.WithA(0.5f); Color brightened = aqua * 1.5f; Color darkened = crimson / 2f; // Apply to material var renderer = GetComponent(); renderer.material.color = baseColor.ToColor(); } void CreateRainbow() { int colorCount = 7; for (int i = 0; i < colorCount; i++) { float hue = (360f / colorCount) * i; ColorHSV color = new ColorHSV(hue, 1f, 1f); // Create colored object GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); obj.transform.position = new Vector3(i * 2f, 0, 0); obj.GetComponent().material.color = color.ToColor(); } } } ``` -------------------------------- ### Array and Collection Extensions - C# Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Demonstrates looped array access, shuffling collections, and flood fill algorithms (4-connectivity and 8-connectivity). These functions are useful for procedural generation and data manipulation. ```csharp using UnityEngine; using ProceduralToolkit; using System.Collections.Generic; public class ArrayExample : MonoBehaviour { void ArrayOperations() { int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // Looped getters (wrap around at boundaries) int looped = array.GetLooped(10); // Gets index 1 (10 % 9) int negative = array.GetLooped(-1); // Gets last element // Looped setters array.SetLooped(10, 999); // Sets index 1 // Shuffle collection array.Shuffle(); List list = new List { "a", "b", "c", "d" }; list.Shuffle(); Debug.Log($"Shuffled: {string.Join(", ", array)}"); } void FloodFillExample() { // Create 2D grid int width = 10; int height = 10; int[,] grid = new int[width, height]; // Set up some walls for (int x = 3; x < 7; x++) { grid[x, 5] = 1; // Wall } // Flood fill using 4-connectivity var filled = new HashSet(); ArrayE.FloodFill4( startX: 0, startY: 0, width: width, height: height, isValidCell: (x, y) => { // Valid if in bounds and not a wall return x >= 0 && x < width && y >= 0 && y < height && grid[x, y] != 1; }, floodCell: (x, y) => { filled.Add(new Vector2Int(x, y)); grid[x, y] = 2; // Mark as filled } ); Debug.Log($"Filled {filled.Count} cells"); // 8-connectivity flood fill (includes diagonals) var filled8 = new HashSet(); ArrayE.FloodFill8( startX: 0, startY: 0, width: width, height: height, isValidCell: (x, y) => grid[x, y] != 1, floodCell: (x, y) => filled8.Add(new Vector2Int(x, y)) ); } void PracticalFloodFill() { // Use for terrain region detection int mapWidth = 50; int mapHeight = 50; bool[,] walkable = new bool[mapWidth, mapHeight]; // ... populate walkable areas ... // Find all connected walkable regions var regions = new List>(); bool[,] visited = new bool[mapWidth, mapHeight]; for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { if (walkable[x, y] && !visited[x, y]) { var region = new HashSet(); ArrayE.FloodFill4( x, y, mapWidth, mapHeight, isValidCell: (cx, cy) => walkable[cx, cy] && !visited[cx, cy], floodCell: (cx, cy) => { visited[cx, cy] = true; region.Add(new Vector2Int(cx, cy)); } ); regions.Add(region); } } } Debug.Log($"Found {regions.Count} walkable regions"); } } ``` -------------------------------- ### Path Offsetting Utility (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Provides seamless interoperability with Unity for path offsetting operations, using the Clipper library. ```csharp using UnityEngine; public class PathOffsetter { // Offsets a path by a specified amount. public Path OffsetPath(Path path, float offset) { // ... implementation details ... return null; } } ``` -------------------------------- ### Perform Specialized Vector Operations in C# Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Demonstrates various vector operations using Procedural Toolkit's VectorE class. This includes calculating the perpendicular dot product, signed angles, rotating vectors, and performing swizzle operations to reorder vector components. It requires Unity's Vector2 and Vector3 types. ```csharp using UnityEngine; using ProceduralToolkit; public class VectorExample : MonoBehaviour { void VectorOperations() { Vector2 a = new Vector2(1f, 0f); Vector2 b = new Vector2(0f, 1f); // Perpendicular dot product (2D cross product, useful for winding) float perpDot = VectorE.PerpDot(a, b); Debug.Log($"Perp dot: {perpDot}"); // 1.0 // Get 360-degree signed angle float angle360 = VectorE.Angle360(a, b); Debug.Log($"360 angle: {angle360}"); // 90 // Rotate vectors Vector2 rotatedCW = a.RotateCW(45f); Vector2 rotatedCCW = a.RotateCCW(45f); Vector2 rotated90CW = a.RotateCW90(); Vector2 rotated90CCW = a.RotateCCW90(); Debug.Log($"Rotated CW 45°: {rotatedCW}"); Debug.Log($"Rotated CCW 45°: {rotatedCCW}"); // Swizzle operations (reorder components) Vector2 vec2D = new Vector2(1f, 2f); Vector3 xyz = vec2D.ToVector3XY(z: 3f); // (1, 2, 3) Vector3 xzy = vec2D.ToVector3XZ(y: 3f); // (1, 3, 2) Vector3 yxz = vec2D.ToVector3YZ(x: 3f); // (3, 1, 2) Debug.Log($"XY swizzle: {xyz}"); Debug.Log($"XZ swizzle: {xzy}"); } void GeometricVectorUse() { // Use perpendicular dot for point-line side test Vector2 lineStart = Vector2.zero; Vector2 lineEnd = new Vector2(5f, 0f); Vector2 point = new Vector2(2f, 1f); Vector2 lineDir = (lineEnd - lineStart).normalized; Vector2 toPoint = point - lineStart; float side = VectorE.PerpDot(lineDir, toPoint); if (side > 0) Debug.Log("Point is on the left"); else if (side < 0) Debug.Log("Point is on the right"); else Debug.Log("Point is on the line"); // Calculate angle for AI steering Vector2 forward = transform.right; Vector2 toTarget = (Vector2)(target.position - transform.position); float angle = VectorE.Angle360(forward, toTarget.normalized); // Determine turn direction if (angle > 180f) Debug.Log("Turn right"); else if (angle < 180f && angle > 0f) Debug.Log("Turn left"); } GameObject target; } ``` -------------------------------- ### Create Geometric Primitives (C#) Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Generates various 2D and 3D geometric primitives like quads, hexagons, planes, cubes, spheres, cylinders, and tori using MeshDraft. Supports partial shapes such as domes and open boxes. Requires Unity and the Procedural Toolkit library. ```csharp using UnityEngine; using ProceduralToolkit; public class PrimitivesExample : MonoBehaviour { void CreatePrimitives() { // 2D Primitives MeshDraft quad = MeshDraft.Quad( origin: Vector3.zero, width: Vector3.right * 2f, length: Vector3.forward * 2f ); MeshDraft hexagon = MeshDraft.Hexagon(radius: 1f); MeshDraft plane = MeshDraft.Plane( xSize: 10f, zSize: 10f, xSegments: 10, zSegments: 10 ); // 3D Primitives MeshDraft cube = MeshDraft.Cube(size: 2f); MeshDraft sphere = MeshDraft.Sphere( radius: 1f, longitudeSegments: 32, latitudeSegments: 16 ); MeshDraft cylinder = MeshDraft.Cylinder( radius: 1f, segmentCount: 24, height: 3f ); MeshDraft torus = MeshDraft.Torus( radius: 2f, segmentCount: 32, tubeRadius: 0.5f, tubeSegmentCount: 16 ); // Partial shapes MeshDraft dome = MeshDraft.PartialSphere( radius: 5f, horizontalAngle: 360f, minVerticalAngle: 0f, maxVerticalAngle: 90f, longitudeSegments: 32, latitudeSegments: 16 ); MeshDraft openBox = MeshDraft.PartialBox( xSize: 2f, ySize: 2f, zSize: 2f, useLeft: true, useRight: true, useBottom: true, useTop: false, useFront: true, useBack: true ); // Apply mesh GetComponent().mesh = dome.ToMesh(); } } ``` -------------------------------- ### Procedural Facade Planner (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Controls the layout of building facades. ```csharp using UnityEngine; public class ProceduralFacadePlanner { // Plans the layout of a facade. public FacadeLayout PlanFacade(FacadeConfig config) { // ... implementation details ... return null; } } ``` -------------------------------- ### Procedural Roof Planner (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Generates a roof description based on input configuration. ```csharp using UnityEngine; public class ProceduralRoofPlanner { // Plans a roof structure. public RoofDescription PlanRoof(RoofConfig config) { // ... implementation details ... return null; } } ``` -------------------------------- ### Procedural Facade Constructor (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Constructs facade elements based on a facade plan. ```csharp using UnityEngine; public class ProceduralFacadeConstructor { // Constructs a facade from a plan. public void ConstructFacade(FacadeLayout layout) { // ... implementation details ... } } ``` -------------------------------- ### Path Clipping Utility (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Provides seamless interoperability with Unity for path clipping operations, using the Clipper library. ```csharp using UnityEngine; public class PathClipper { // Clips a path using the Clipper library. public void ClipPath(Path path, Path clipPath) { // ... implementation details ... } } ``` -------------------------------- ### Tessellation Wrapper (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md A wrapper class for the LibTessDotNet library, simplifying tessellation operations. ```csharp using UnityEngine; public class Tessellator { // Tessellates a polygon. public Mesh TessellatePolygon(Polygon polygon) { // ... implementation details ... return null; } } ``` -------------------------------- ### Transition Animations (HLSL) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Collection of transition animation functions for shaders. ```hlsl // Transitions.cginc - Collection of transition animations. // Example function: float linearTransition(float t) { return clamp(t, 0.0, 1.0); } ``` -------------------------------- ### FastNoise Library Integration (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Provides access to the FastNoise C# library for noise generation. ```csharp using UnityEngine; public class FastNoiseGenerator { // Generates noise using FastNoise. public float GetNoise(float x, float y) { // ... implementation details ... return 0.0f; } } ``` -------------------------------- ### Procedural Roof Constructor (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Constructs a roof structure based on a roof plan. ```csharp using UnityEngine; public class ProceduralRoofConstructor { // Constructs a roof from a plan. public void ConstructRoof(RoofDescription description) { // ... implementation details ... } } ``` -------------------------------- ### Building Generator Configurator (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Configurator for the BuildingGenerator with UI and editor controls. ```csharp using UnityEngine; public class BuildingGeneratorConfigurator : MonoBehaviour { // Configuration settings for the building generator. // ... properties ... } ``` -------------------------------- ### Generate Points on Geometric Shapes using C# Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Generates points on 2D circles and 3D spheres, and within circles. It also creates regular polygons and star polygons. Points can be visualized in Unity. ```csharp using UnityEngine; using ProceduralToolkit; using System.Collections.Generic; public class GeometryExample : MonoBehaviour { void GeneratePoints() { // Points on 2D circle List circlePoints = Geometry.PointsOnCircle2( radius: 5f, count: 12 ); List offsetCircle = Geometry.PointsOnCircle2( center: new Vector2(10f, 0f), radius: 3f, count: 8 ); // Evenly distributed points inside circle List insidePoints = Geometry.PointsInCircle2( radius: 5f, count: 50 ); // Points on 3D sphere List spherePoints = Geometry.PointsOnSphere( radius: 10f, count: 100 ); // Point on sphere with specific angles Vector3 point = Geometry.PointOnSphere( radius: 5f, horizontalAngle: 45f, verticalAngle: 30f ); // Generate polygons List pentagon = Geometry.Polygon2( vertices: 5, radius: 3f ); List star = Geometry.StarPolygon2( vertices: 5, innerRadius: 1f, outerRadius: 3f ); // Visualize points foreach (var p in circlePoints) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = new Vector3(p.x, 0, p.y); sphere.transform.localScale = Vector3.one * 0.2f; } } void ProcessPolygon() { List polygon = Geometry.Polygon2(6, 5f); // Calculate properties float area = Geometry.GetArea(polygon); float perimeter = Geometry.GetPerimeter(polygon); Geometry.Orientation orientation = Geometry.GetOrientation(polygon); Rect bounds = Geometry.GetRect(polygon); Debug.Log($"Area: {area}, Perimeter: {perimeter}"); Debug.Log($"Orientation: {orientation}"); // Offset polygon (positive = outward, negative = inward) List expanded = Geometry.OffsetPolygon(polygon, 1f); List contracted = Geometry.OffsetPolygon(polygon, -0.5f); // Get angle at vertex for (int i = 0; i < polygon.Count; i++) { int prev = (i - 1 + polygon.Count) % polygon.Count; int next = (i + 1) % polygon.Count; Vector2 bisector = Geometry.GetAngleBisector( polygon[prev], polygon[i], polygon[next], out float angle ); Debug.Log($"Vertex {i} angle: {angle} degrees"); } } } ``` -------------------------------- ### Building Generator Configurator Editor (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Custom inspector for the BuildingGeneratorConfigurator. ```csharp using UnityEditor; using UnityEngine; [CustomEditor(typeof(BuildingGeneratorConfigurator))] public class BuildingGeneratorConfiguratorEditor : Editor { public override void OnInspectorGUI() { // ... implementation for custom inspector ... } } ``` -------------------------------- ### Active Plan Representation (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Represents the active plan during the straight skeleton generation process. ```csharp using UnityEngine; public class Plan { // Represents the active plan state. // ... properties and methods ... } ``` -------------------------------- ### Building Generator Component (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md A component for generating procedural buildings. ```csharp using UnityEngine; public class BuildingGeneratorComponent : MonoBehaviour { // Generates a building mesh and paints its vertices. public void GenerateBuilding() { // ... implementation details ... } } ``` -------------------------------- ### Straight Skeleton Generation (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Generates a straight skeleton for a given polygon. The algorithm is based on the work of Tom Kelly. Requires `StraightSkeleton.cs` and `Plan.cs`. ```csharp using UnityEngine; public class StraightSkeletonGenerator { // Computes a straight skeleton for the input polygon. public void GenerateSkeleton(Polygon polygon) { // ... implementation details ... } } ``` -------------------------------- ### Calculate 2D Distances using Procedural Toolkit Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Calculates various 2D distances including point-to-line, point-to-segment, point-to-circle, and segment-to-segment. This C# code utilizes the `ProceduralToolkit.Geometry` namespace and requires Unity. ```csharp using UnityEngine; using ProceduralToolkit; using ProceduralToolkit.Geometry; public class DistanceExample : MonoBehaviour { void Calculate2DDistances() { Vector2 point = new Vector2(3f, 4f); // Distance from point to line Line2 line = new Line2(Vector2.zero, Vector2.right); float distToLine = Distance2D.PointLine(point, line); // Distance from point to segment Segment2 segment = new Segment2( new Vector2(-5f, 0f), new Vector2(5f, 0f) ); float distToSegment = Distance2D.PointSegment(point, segment); // Distance from point to circle Circle2 circle = new Circle2(Vector2.zero, 2f); float distToCircle = Distance2D.PointCircle(point, circle); // Distance between segments Segment2 seg1 = new Segment2(Vector2.zero, Vector2.right * 3f); Segment2 seg2 = new Segment2( new Vector2(1f, 2f), new Vector2(1f, -2f) ); float segmentDist = Distance2D.SegmentSegment(seg1, seg2); Debug.Log($"Point to line: {distToLine}"); Debug.Log($"Point to segment: {distToSegment}"); Debug.Log($"Point to circle: {distToCircle}"); Debug.Log($"Segment to segment: {segmentDist}"); } // Other methods would follow... } ``` -------------------------------- ### Easing Functions (HLSL) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Normalized easing functions for use in shaders. ```hlsl // Easing.cginc - Normalized easing functions. // Example function: float easeInOutQuad(float t) { return t < 0.5 ? 2.0*t*t : 1.0 - pow(-2.0*t + 2.0, 2.0) / 2.0; } ``` -------------------------------- ### Chair Generator (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Main class for generating procedural chairs. ```csharp using UnityEngine; public class ChairGenerator : MonoBehaviour { // Generates a chair based on input configuration. public void GenerateChair(ChairConfig config) { // ... implementation details ... } } ``` -------------------------------- ### Chair Generator Configurator (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Configurator for the ChairGenerator with UI and editor controls. ```csharp using UnityEngine; public class ChairGeneratorConfigurator : MonoBehaviour { // Configuration settings for the chair generator. // ... properties ... } ``` -------------------------------- ### Ruleset Property Drawer (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Custom inspector drawer for the CellularAutomaton.Ruleset type. ```csharp using UnityEditor; using UnityEngine; [CustomPropertyDrawer(typeof(CellularAutomaton.Ruleset))] public class RulesetDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // ... implementation for drawing Ruleset property ... } } ``` -------------------------------- ### Calculate 3D Distances using Procedural Toolkit Source: https://context7.com/syomus/proceduraltoolkit/llms.txt Calculates various 3D distances including point-to-line, point-to-ray, point-to-segment, point-to-sphere, and line-to-line. This C# code utilizes the `ProceduralToolkit.Geometry` namespace and requires Unity. ```csharp using UnityEngine; using ProceduralToolkit; using ProceduralToolkit.Geometry; public class DistanceExample : MonoBehaviour { // Other methods would precede... void Calculate3DDistances() { Vector3 point = new Vector3(1f, 2f, 3f); // Distance from point to line Line3 line = new Line3(Vector3.zero, Vector3.up); float distToLine = Distance3D.PointLine(point, line); // Distance from point to ray Ray ray = new Ray(Vector3.zero, Vector3.forward); float distToRay = Distance3D.PointRay(point, ray); // Distance from point to segment Segment3 segment = new Segment3( new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f) ); float distToSegment = Distance3D.PointSegment(point, segment); // Distance from point to sphere Sphere sphere = new Sphere(Vector3.zero, 3f); float distToSphere = Distance3D.PointSphere(point, sphere); // Distance between lines Line3 line1 = new Line3(Vector3.zero, Vector3.right); Line3 line2 = new Line3(Vector3.up, Vector3.forward); float lineDist = Distance3D.LineLine(line1, line2); Debug.Log($"Point to line: {distToLine}"); Debug.Log($"Point to sphere: {distToSphere}"); Debug.Log($"Line to line: {lineDist}"); } } ``` -------------------------------- ### Gradient Skybox Shader (ShaderLab) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md A simple shader for creating a gradient skybox. ```shaderlab Shader "Procedural Toolkit/Gradient Skybox" { Properties { _TopColor ("Top Color", Color) = (0.0, 0.5, 1.0, 1.0) _BottomColor ("Bottom Color", Color) = (1.0, 0.8, 0.5, 1.0) } SubShader { Tags { "RenderType" = "Skybox" } Cull Off Fog { Mode Off } // ... rest of the shader code ... } } ``` -------------------------------- ### Procedural Toolkit Editor Menu (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Adds a submenu to the Unity editor's GameObject menu for creating procedural primitives. ```csharp using UnityEditor; public class ProceduralToolkitMenu { [MenuItem("GameObject/Procedural Toolkit/Create Cube", false, 0)] public static void CreateCube() { // ... implementation to create a procedural cube ... } } ``` -------------------------------- ### Color HSV Property Drawer (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Custom inspector drawer for the ColorHSV type. ```csharp using UnityEditor; using UnityEngine; [CustomPropertyDrawer(typeof(ColorHSV))] public class ColorHSVDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // ... implementation for drawing ColorHSV property ... } } ``` -------------------------------- ### Chair Generator Configurator Editor (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Custom inspector for the ChairGeneratorConfigurator. ```csharp using UnityEditor; using UnityEngine; [CustomEditor(typeof(ChairGeneratorConfigurator))] public class ChairGeneratorConfiguratorEditor : Editor { public override void OnInspectorGUI() { // ... implementation for custom inspector ... } } ``` -------------------------------- ### Mesh Filter Extension for Saving (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Adds a utility to save MeshFilter meshes via the context menu in the editor. ```csharp using UnityEngine; using UnityEditor; public static class MeshFilterExtension { [MenuItem("GameObject/Save Mesh", false, 0)] public static void SaveMesh(MenuCommand command) { // ... implementation to save mesh ... } } ``` -------------------------------- ### Polygon Asset Container (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md A ScriptableObject used as a container for polygon vertices. ```csharp using UnityEngine; [CreateAssetMenu(fileName = "PolygonAsset", menuName = "ProceduralToolkit/Polygon Asset", order = 1)] public class PolygonAsset : ScriptableObject { public Vector2[] vertices; } ``` -------------------------------- ### Signed Distance Functions (HLSL) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md A collection of signed distance functions used in shaders. ```hlsl // SDF.cginc - Collection of signed distance functions. // Example function: float sdSphere(vec3 p, float r) { return length(p) - r; } ``` -------------------------------- ### Polygon Representation (C#) Source: https://github.com/syomus/proceduraltoolkit/blob/master/README.md Represents a straight skeleton, storing its structure and data. ```csharp using UnityEngine; public class StraightSkeleton { // Represents the generated straight skeleton. // ... properties and methods ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.