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(); } }