summaryrefslogtreecommitdiffstats
path: root/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts')
-rwxr-xr-xScripts/Fold/Editor/FoldEditorWindow.cs87
-rwxr-xr-xScripts/Fold/Editor/FoldPipelineBuilder.cs42
-rwxr-xr-xScripts/Fold/Editor/README.md41
3 files changed, 129 insertions, 41 deletions
diff --git a/Scripts/Fold/Editor/FoldEditorWindow.cs b/Scripts/Fold/Editor/FoldEditorWindow.cs
index e2a94e1..e8faf1f 100755
--- a/Scripts/Fold/Editor/FoldEditorWindow.cs
+++ b/Scripts/Fold/Editor/FoldEditorWindow.cs
@@ -205,12 +205,15 @@ public class FoldEditorWindow : EditorWindow
menu.AddItem(new GUIContent("Plane to Tube"), false, () => AddOperation(new PlaneToTubeOp()));
menu.AddItem(new GUIContent("Plane to Hemi-Octahedron"), false, () => AddOperation(new PlaneToHemiOctahedronOp()));
menu.AddItem(new GUIContent("Hemi-Octahedron to Plane"), false, () => AddOperation(new HemiOctahedronToPlaneOp()));
+ menu.AddItem(new GUIContent("Plane to Octahedron"), false, () => AddOperation(new PlaneToOctahedronOp()));
+ menu.AddItem(new GUIContent("Octahedron to Plane"), false, () => AddOperation(new OctahedronToPlaneOp()));
menu.AddSeparator("");
menu.AddItem(new GUIContent("Point Align"), false, () => AddOperation(new PointAlignOp()));
menu.AddItem(new GUIContent("Axis Align"), false, () => AddOperation(new AxisAlignOp()));
menu.AddSeparator("");
menu.AddItem(new GUIContent("Scale"), false, () => AddOperation(new ScaleOp()));
menu.AddItem(new GUIContent("Translate"), false, () => AddOperation(new TranslateOp()));
+ menu.AddItem(new GUIContent("Rotate"), false, () => AddOperation(new RotateOp()));
menu.AddItem(new GUIContent("Norm Conversion"), false, () => AddOperation(new NormConversionOp()));
menu.AddItem(new GUIContent("Seal"), false, () => AddOperation(new SealOp()));
menu.AddSeparator("");
@@ -274,6 +277,9 @@ public class FoldEditorWindow : EditorWindow
FoldPipelineBuilder.Opcodes.HemiOctahedronToPlane => new HemiOctahedronToPlaneOp(slot),
FoldPipelineBuilder.Opcodes.Scale => new ScaleOp(slot),
FoldPipelineBuilder.Opcodes.Translate => new TranslateOp(slot),
+ FoldPipelineBuilder.Opcodes.PlaneToOctahedron => new PlaneToOctahedronOp(slot),
+ FoldPipelineBuilder.Opcodes.OctahedronToPlane => new OctahedronToPlaneOp(slot),
+ FoldPipelineBuilder.Opcodes.Rotate => new RotateOp(slot),
FoldPipelineBuilder.Opcodes.PointAlign => new PointAlignOp(slot),
FoldPipelineBuilder.Opcodes.AxisAlign => new AxisAlignOp(slot),
FoldPipelineBuilder.Opcodes.NormConversion => new NormConversionOp(slot),
@@ -418,6 +424,37 @@ public class TranslateOp : DeformOperation
}
[System.Serializable]
+public class RotateOp : DeformOperation
+{
+ public Vector3 center = Vector3.zero;
+ public Vector3 axis = Vector3.up;
+ public float angleDeg = 90f;
+ public float t = 1f;
+
+ public RotateOp() { }
+ public RotateOp(FoldSlot slot)
+ {
+ center = slot.vec0;
+ axis = slot.vec1;
+ angleDeg = slot.float0 * Mathf.Rad2Deg;
+ t = slot.float1;
+ }
+
+ public override string GetDisplayName() => "Rotate";
+
+ public override void DrawParameters()
+ {
+ center = EditorGUILayout.Vector3Field("Center", center);
+ axis = EditorGUILayout.Vector3Field("Axis", axis);
+ angleDeg = EditorGUILayout.Slider("Angle", angleDeg, 0f, 360f);
+ t = EditorGUILayout.Slider("Interpolation (t)", t, 0f, 1f);
+ }
+
+ public override void ApplyTo(FoldPipelineBuilder builder) =>
+ builder.Rotate(center, axis, angleDeg * Mathf.Deg2Rad, t);
+}
+
+[System.Serializable]
public class HemiOctahedronToPlaneOp : DeformOperation
{
public Vector3 p = Vector3.zero;
@@ -443,6 +480,56 @@ public class HemiOctahedronToPlaneOp : DeformOperation
}
[System.Serializable]
+public class PlaneToOctahedronOp : DeformOperation
+{
+ public Vector3 p = Vector3.zero;
+ public Vector3 r = Vector3.right;
+ public Vector3 s = Vector3.forward;
+ public float t = 1f;
+
+ public PlaneToOctahedronOp() { }
+ public PlaneToOctahedronOp(FoldSlot slot) { p = slot.vec0; r = slot.vec1; s = slot.vec2; t = slot.float0; }
+
+ public override string GetDisplayName() => "Plane to Octahedron";
+
+ public override void DrawParameters()
+ {
+ p = EditorGUILayout.Vector3Field("Origin (p)", p);
+ r = EditorGUILayout.Vector3Field("R Axis", r);
+ s = EditorGUILayout.Vector3Field("S Axis", s);
+ t = EditorGUILayout.Slider("Interpolation (t)", t, 0f, 1f);
+ }
+
+ public override void ApplyTo(FoldPipelineBuilder builder) =>
+ builder.PlaneToOctahedron(p, r, s, t);
+}
+
+[System.Serializable]
+public class OctahedronToPlaneOp : DeformOperation
+{
+ public Vector3 p = Vector3.zero;
+ public Vector3 r = Vector3.right;
+ public Vector3 s = Vector3.forward;
+ public float t = 1f;
+
+ public OctahedronToPlaneOp() { }
+ public OctahedronToPlaneOp(FoldSlot slot) { p = slot.vec0; r = slot.vec1; s = slot.vec2; t = slot.float0; }
+
+ public override string GetDisplayName() => "Octahedron to Plane";
+
+ public override void DrawParameters()
+ {
+ p = EditorGUILayout.Vector3Field("Origin (p)", p);
+ r = EditorGUILayout.Vector3Field("R Axis", r);
+ s = EditorGUILayout.Vector3Field("S Axis", s);
+ t = EditorGUILayout.Slider("Interpolation (t)", t, 0f, 1f);
+ }
+
+ public override void ApplyTo(FoldPipelineBuilder builder) =>
+ builder.OctahedronToPlane(p, r, s, t);
+}
+
+[System.Serializable]
public class PointAlignOp : DeformOperation
{
public Vector3 po = Vector3.zero;
diff --git a/Scripts/Fold/Editor/FoldPipelineBuilder.cs b/Scripts/Fold/Editor/FoldPipelineBuilder.cs
index 2dc2291..731ceeb 100755
--- a/Scripts/Fold/Editor/FoldPipelineBuilder.cs
+++ b/Scripts/Fold/Editor/FoldPipelineBuilder.cs
@@ -60,6 +60,9 @@ public class FoldPipelineBuilder
public const int HemiOctahedronToPlane = 10;
public const int Scale = 11;
public const int Translate = 12;
+ public const int PlaneToOctahedron = 13;
+ public const int OctahedronToPlane = 14;
+ public const int Rotate = 15;
}
FoldPipelineBuilder() { }
@@ -133,6 +136,45 @@ public class FoldPipelineBuilder
return this;
}
+ public FoldPipelineBuilder PlaneToOctahedron(Vector3 p, Vector3 r, Vector3 s, float t)
+ {
+ slots.Add(new FoldSlot
+ {
+ opcode = Opcodes.PlaneToOctahedron,
+ vec0 = p,
+ vec1 = r,
+ vec2 = s,
+ float0 = t
+ });
+ return this;
+ }
+
+ public FoldPipelineBuilder OctahedronToPlane(Vector3 p, Vector3 r, Vector3 s, float t)
+ {
+ slots.Add(new FoldSlot
+ {
+ opcode = Opcodes.OctahedronToPlane,
+ vec0 = p,
+ vec1 = r,
+ vec2 = s,
+ float0 = t
+ });
+ return this;
+ }
+
+ public FoldPipelineBuilder Rotate(Vector3 center, Vector3 axis, float angle, float t)
+ {
+ slots.Add(new FoldSlot
+ {
+ opcode = Opcodes.Rotate,
+ vec0 = center,
+ vec1 = axis,
+ float0 = angle,
+ float1 = t
+ });
+ return this;
+ }
+
public FoldPipelineBuilder HemiOctahedronToPlane(Vector3 p, Vector3 r, Vector3 s, float t)
{
slots.Add(new FoldSlot
diff --git a/Scripts/Fold/Editor/README.md b/Scripts/Fold/Editor/README.md
index d2b7494..7e6224a 100755
--- a/Scripts/Fold/Editor/README.md
+++ b/Scripts/Fold/Editor/README.md
@@ -89,47 +89,6 @@ 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: