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
|
using UnityEditor;
using UnityEngine;
public static class VertexDeformationExamples
{
[MenuItem("Tools/Vertex Deformation/Example: Tube to Plane")]
static void Example_TubeToPlane()
{
var mat = Selection.activeObject as Material;
if (mat == null)
{
EditorUtility.DisplayDialog("Error", "Select a material in the Project window", "OK");
return;
}
VertexDeformationBuilder.Create()
.For(mat)
.TubeToPlane(
p: Vector3.zero,
r: Vector3.right,
s: Vector3.forward,
t: 1f)
.Apply();
}
[MenuItem("Tools/Vertex Deformation/Example: Complex Pipeline")]
static void Example_ComplexPipeline()
{
var mat = Selection.activeObject as Material;
if (mat == null)
{
EditorUtility.DisplayDialog("Error", "Select a material in the Project window", "OK");
return;
}
VertexDeformationBuilder.Create()
.For(mat)
.TubeToPlane(Vector3.zero, Vector3.right, Vector3.forward, 1f)
.NormConversion(inputK: 2f, outputK: 1f, t: 1f)
.PointAlign(
po: new Vector3(0, 0, 0),
pp: new Vector3(0, 1, 0),
r: Vector3.right,
t: 0.5f)
.Apply();
Debug.Log("Applied 3-step deformation pipeline to " + mat.name);
}
[MenuItem("Tools/Vertex Deformation/Example: Add Custom Preset")]
static void Example_ShowHowToAddPreset()
{
EditorUtility.DisplayDialog("How to Add Presets",
"1. Open VertexDeformationPresets class\n\n" +
"2. Add a new static method:\n\n" +
"public static void MyCustomPreset(Material mat) =>\n" +
" VertexDeformationBuilder.Create()\n" +
" .For(mat)\n" +
" .TubeToPlane(...)\n" +
" .NormConversion(...)\n" +
" .Apply();\n\n" +
"3. Add a button in VertexDeformationEditorWindow:\n\n" +
"if (GUILayout.Button(\"My Custom Preset\"))\n" +
" VertexDeformationPresets.MyCustomPreset(targetMaterial);",
"OK");
}
[MenuItem("Tools/Vertex Deformation/Example: All Opcodes")]
static void Example_AllOpcodes()
{
EditorUtility.DisplayDialog("All Available Operations",
"TubeToPlane(p, r, s, t)\n" +
"PlaneToTube(p, r, s, t)\n" +
"PointAlign(po, pp, r, t)\n" +
"AxisAlign(po, pp, r, t)\n" +
"NormConversion(inputK, outputK, t)\n" +
"Seal(A, k, st, t)\n" +
"SineWaves()\n" +
"FBM()\n\n" +
"Custom(opcode, f0, f1, f2, f3, v0, v1, v2, v3)\n\n" +
"Chain them with method calls:\n" +
".TubeToPlane(...).NormConversion(...).Apply()",
"OK");
}
public static class CustomPresetIdeas
{
public static void CylinderToPlane(Material mat) =>
VertexDeformationBuilder.Create()
.For(mat)
.TubeToPlane(Vector3.zero, Vector3.up, Vector3.right, 1f)
.Apply();
public static void SphereToBox(Material mat) =>
VertexDeformationBuilder.Create()
.For(mat)
.NormConversion(inputK: 2f, outputK: float.PositiveInfinity, t: 1f)
.Apply();
public static void BoxToSphere(Material mat) =>
VertexDeformationBuilder.Create()
.For(mat)
.NormConversion(inputK: float.PositiveInfinity, outputK: 2f, t: 1f)
.Apply();
public static void TubeUnfoldAndFlatten(Material mat) =>
VertexDeformationBuilder.Create()
.For(mat)
.TubeToPlane(Vector3.zero, Vector3.right, Vector3.forward, 1f)
.NormConversion(inputK: 2f, outputK: 1f, t: 0.5f)
.Seal(A: 0.1f, k: 2f, st: 0.8f, t: 1f)
.Apply();
}
}
|