# Fold - Vertex Deformation Pipeline Builder A visual editor and fluent API for building vertex deformation pipelines. ## Quick Start ### Using the Editor Window Open `Tools > yum_food > Fold` to access the dockable pipeline editor: 1. Select a target material 2. Click "Add Operation" to add deformation operations 3. Configure parameters for each operation 4. Reorder operations with ▲▼ buttons 5. Click "Apply to Material" to write the pipeline to the material Use "Load Presets" for common pipelines. ### Using the Fluent API ```csharp using UnityEngine; // Apply to a material FoldPipelineBuilder.Create() .For(material) .TubeToPlane(Vector3.zero, Vector3.right, Vector3.forward, 1f) .NormConversion(2f, 1f, 1f) .Apply(); ``` ## Available Operations ### TubeToPlane(p, r, s, t) Unfolds a tube into a plane. - `p`: Origin point (Vector3) - `r`: R axis direction (Vector3) - `s`: S axis direction (Vector3) - `t`: Interpolation factor (float, 0-1) ### PlaneToTube(p, r, s, t) Folds a plane into a tube. - Same parameters as TubeToPlane ### PlaneToHemiOctahedron(p, r, s, t) Maps a plane to a hemi-octahedron (half octahedron) shape. - `p`: Origin point (Vector3) - `r`: R axis direction (Vector3) - `s`: S axis direction (Vector3) - `t`: Interpolation factor (float, 0-1) Useful for creating dome-like or hemisphere projections from planar geometry. ### PointAlign(po, pp, r, t) Aligns geometry to a point. - `po`: Original point (Vector3) - `pp`: Target point (Vector3) - `r`: Rotation axis (Vector3) - `t`: Interpolation factor (float, 0-1) ### AxisAlign(po, pp, r, t) Aligns geometry along an axis. - Same parameters as PointAlign ### NormConversion(inputK, outputK, t) Converts between different norms (L1, L2, L∞). - `inputK`: Input norm (float, e.g., 1 for L1, 2 for L2, ∞ for L∞) - `outputK`: Output norm (float) - `t`: Interpolation factor (float, 0-1) Common conversions: - Sphere to box: `NormConversion(2f, float.PositiveInfinity, 1f)` - Box to sphere: `NormConversion(float.PositiveInfinity, 2f, 1f)` - Diamond to sphere: `NormConversion(1f, 2f, 1f)` ### Seal(A, k, st, t) Sealing operation for closing geometry. - `A`: Amplitude (float) - `k`: Smoothness factor (float) - `st`: Scale factor (float) - `t`: Interpolation factor (float, 0-1) ### SineWaves() Applies sine wave deformation. ### FBM() Applies fractal Brownian motion deformation. ### Custom(opcode, f0-f3, v0-v3) For advanced use cases or custom opcodes. ## Presets (Code) Use built-in presets from code: ```csharp FoldPresets.TubeToPlaneFull(material); FoldPresets.NormConvL2ToL1(material); FoldPresets.NormConvL2ToLinf(material); ``` ## Adding Custom Presets Edit `FoldEditorWindow.cs` to add presets to the "Load Presets" menu: ```csharp // In ShowPresetsMenu(): menu.AddItem(new GUIContent("My Custom Effect"), false, () => LoadPreset_MyEffect()); // Add the preset loader method: void LoadPreset_MyEffect() { operations.Clear(); AddOperation(new TubeToPlaneOp()); var norm = new NormConversionOp(); norm.inputK = 2f; norm.outputK = 1f; AddOperation(norm); } ``` Or use the fluent API in code: ```csharp public static void MyCustomEffect(Material mat) => FoldPipelineBuilder.Create() .For(mat) .TubeToPlane(Vector3.zero, Vector3.right, Vector3.forward, 1f) .NormConversion(2f, 1f, 0.5f) .Apply(); ``` ## Pipeline Chaining Operations are applied in the order they're chained: ```csharp FoldPipelineBuilder.Create() .For(material) .TubeToPlane(...) // Step 1 .NormConversion(...) // Step 2 .PointAlign(...) // Step 3 .Seal(...) // Step 4 .Apply(); // Execute ``` The shader supports up to 16 operations per material. ## Clearing Deformations In the Fold window, click "Clear All" to remove all operations from the pipeline. Via code: ```csharp targetMaterial.SetFloat("_Vertex_Deformation_Enabled", 0f); ```