-
Notifications
You must be signed in to change notification settings - Fork 19
/
AdjustUVComponent.cs
95 lines (83 loc) · 3.6 KB
/
AdjustUVComponent.cs
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
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
using IntraLattice.Properties;
// Summary: This component can be used to adjust the UV-Map of a surface, for alignment purposes.
// ===============================================================================
// Details: - When using the uvw-conform components, the orientation of the surface UV-maps is important.
// ===============================================================================
// Author(s): Aidan Kurtz (http://aidankurtz.com)
namespace IntraLattice.CORE.Components.Utility
{
public class AdjustUVComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the AdjustUVComponent class.
/// </summary>
public AdjustUVComponent()
: base("Adjust UV", "AdjustUV",
"Adjusts the UV-map of a surface for proper alignment with other surfaces/axes.",
"Intralattice", "Utils")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddSurfaceParameter("Surface", "Surf", "Surface to adjust.", GH_ParamAccess.item);
pManager.AddBooleanParameter("Swap UV", "SwapUV", "Swap the uv parameters.", GH_ParamAccess.item, false);
pManager.AddBooleanParameter("Reverse U", "ReverseU", "Reverse the u-parameter direction.", GH_ParamAccess.item, false);
pManager.AddBooleanParameter("Reverse V", "ReverseV", "Reverse the v-parameter direction.", GH_ParamAccess.item, false);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddSurfaceParameter("Adjusted surface", "Surf", "Surface with adjusted uv-map.", GH_ParamAccess.item);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
// 1. Retrieve and validate data
Surface surf = null;
bool swapUV = false;
bool reverseU = false;
bool reverseV = false;
if (!DA.GetData(0, ref surf)) { return; }
if (!DA.GetData(1, ref swapUV)) { return; }
if (!DA.GetData(2, ref reverseU)) { return; }
if (!DA.GetData(3, ref reverseV)) { return; }
if (surf == null) { return; }
// 2. Make adjustments, if specified.
if (swapUV) surf = surf.Transpose();
if (reverseU) surf.Reverse(0, true);
if (reverseV) surf.Reverse(1, true);
// 3. Set output
DA.SetData(0, surf);
}
/// <summary>
/// Provides an Icon for the component.
/// Icons need to be 24x24 pixels.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
return Resources.adjustUV;
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("{3372eac1-1545-4fca-9a25-72c4563aaa1f}"); }
}
}
}