diff options
Diffstat (limited to 'Scripts/Fold/Editor/README.md')
| -rw-r--r-- | Scripts/Fold/Editor/README.md | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/Scripts/Fold/Editor/README.md b/Scripts/Fold/Editor/README.md new file mode 100644 index 0000000..8305abf --- /dev/null +++ b/Scripts/Fold/Editor/README.md @@ -0,0 +1,131 @@ +# Vertex Deformation Fluent Builder + +A simple, code-first API for building vertex deformation pipelines without visual node editors. + +## Quick Start + +```csharp +using UnityEngine; + +// Apply to a material +VertexDeformationBuilder.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 + +### 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 + +Use built-in presets from anywhere: + +```csharp +VertexDeformationPresets.TubeToPlaneFull(material); +VertexDeformationPresets.NormConvL2ToL1(material); +VertexDeformationPresets.NormConvL2ToLinf(material); +``` + +## GUI Window + +Open `Window > Vertex Deformation Presets` for a GUI with buttons for common operations. + +## Adding Custom Presets + +1. Edit `VertexDeformationPresets` class: + +```csharp +public static void MyCustomEffect(Material mat) => + VertexDeformationBuilder.Create() + .For(mat) + .TubeToPlane(Vector3.zero, Vector3.right, Vector3.forward, 1f) + .NormConversion(2f, 1f, 0.5f) + .Seal(0.1f, 2f, 0.8f, 1f) + .Apply(); +``` + +2. Add button in `VertexDeformationEditorWindow`: + +```csharp +if (GUILayout.Button("My Custom Effect")) + VertexDeformationPresets.MyCustomEffect(targetMaterial); +``` + +## Pipeline Chaining + +Operations are applied in the order they're chained: + +```csharp +VertexDeformationBuilder.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 + +```csharp +// Via GUI: Use "Clear All Deformations" button + +// Via code: +targetMaterial.SetFloat("_Vertex_Deformation_Enabled", 0f); +``` + +## Examples + +See `VertexDeformationExamples.cs` for menu items under `Tools > Vertex Deformation > Example: ...` |
