summaryrefslogtreecommitdiffstats
path: root/Scripts/Fold/Editor/README.md
blob: 7e6224acf64d06dfa3f7cdbe54b4c7358d18b92f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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.

## 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);
```