Skip to content

Commit 006f353

Browse files
committed
Added handling for branching with multiple input curve nodes being created and merged for sub-splines created for each branch.
1 parent 9e516cc commit 006f353

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

Plugins/HoudiniEngineUnity/Scripts/Utility/HEU_InputInterfaceSpline.cs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
133133
return false;
134134
}
135135

136-
string inputName = null;
136+
string inputName = inputObject.name + "_0";
137137
HAPI_NodeId newNodeID = HEU_Defines.HEU_INVALID_NODE_ID;
138138
session.CreateInputCurveNode(out newNodeID, inputName);
139139
if (newNodeID == HEU_Defines.HEU_INVALID_NODE_ID || !HEU_HAPIUtility.IsNodeValidInHoudini(session, newNodeID))
@@ -161,6 +161,70 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
161161
return false;
162162
}
163163

164+
bool createMergeNode = inputSplines._inputSplines.Count() > 1;
165+
if (!createMergeNode)
166+
return true;
167+
168+
// Create merge node to merge branching splines
169+
HAPI_NodeId mergeNodeId = HEU_Defines.HEU_INVALID_NODE_ID;
170+
HAPI_NodeId parentId = HEU_HAPIUtility.GetParentNodeID(session, inputNodeID);
171+
172+
if (!session.CreateNode(parentId, "merge", "rajat-merge", false, out mergeNodeId))
173+
{
174+
HEU_Logger.LogErrorFormat("Unable to create merge SOP node for connecting input assets.");
175+
return false;
176+
}
177+
178+
if (!session.ConnectNodeInput(mergeNodeId, 0, newNodeID))
179+
{
180+
HEU_Logger.LogErrorFormat("Unable to connect to input node!");
181+
return false;
182+
}
183+
184+
if (!session.SetNodeDisplay(mergeNodeId, 1))
185+
{
186+
HEU_Logger.LogWarningFormat("Unable to set display flag!");
187+
}
188+
inputNodeID = mergeNodeId;
189+
190+
HAPI_NodeId branchNodeID;
191+
string branchName = inputObject.name;
192+
HEU_InputDataSpline branchSpline;
193+
int inputNodeIndex = 1;
194+
for (int i = 1; i < inputSplines._inputSplines.Count(); i++)
195+
{
196+
session.CreateInputCurveNode(out branchNodeID, branchName + "_" + i);
197+
if (branchNodeID == HEU_Defines.HEU_INVALID_NODE_ID || !HEU_HAPIUtility.IsNodeValidInHoudini(session, branchNodeID))
198+
{
199+
HEU_Logger.LogError("Failed to create new input cruve node in Houdini session!");
200+
return false;
201+
}
202+
203+
branchSpline = inputSplines._inputSplines[i];
204+
if (!UploadData(session, branchNodeID, branchSpline, true))
205+
{
206+
if (!session.CookNode(branchNodeID, false))
207+
{
208+
HEU_Logger.LogError("New input curve node failed to cook!");
209+
return false;
210+
}
211+
return false;
212+
}
213+
214+
if (!session.ConnectNodeInput(mergeNodeId, i, branchNodeID))
215+
{
216+
HEU_Logger.LogErrorFormat("Unable to connect to input node!");
217+
return false;
218+
}
219+
inputNodeIndex++;
220+
}
221+
222+
if (!session.CookNode(inputNodeID, false))
223+
{
224+
HEU_Logger.LogError("New input node failed to cook!");
225+
return false;
226+
}
227+
164228
return true;
165229
}
166230

@@ -170,7 +234,7 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
170234
public class HEU_InputDataSpline
171235
{
172236
public Spline _spline;
173-
237+
public Transform _transform;
174238
public bool _closed;
175239
public int _count;
176240
public float _length;
@@ -201,6 +265,7 @@ public HEU_InputDataSplines GenerateSplineDataFromGameObject(GameObject inputObj
201265
{
202266
HEU_InputDataSpline inputSpline = new HEU_InputDataSpline();
203267
inputSpline._spline = spline;
268+
inputSpline._transform = inputObject.transform;
204269
inputSpline._closed = spline.Closed;
205270
inputSpline._count = spline.Count;
206271
inputSpline._length = spline.GetLength();
@@ -218,7 +283,7 @@ public HEU_InputDataSplines GenerateSplineDataFromGameObject(GameObject inputObj
218283
/// <param name="inputNodeID">ID of the input node</param>
219284
/// <param name="inputData">Container of the mesh geometry</param>
220285
/// <returns>True if successfully uploaded data</returns>
221-
public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_InputDataSpline inputSpline)
286+
public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_InputDataSpline inputSpline, bool toWorld = false)
222287
{
223288
// Set the input curve info of the newly created input curve
224289
HAPI_InputCurveInfo inputCurveInfo = new HAPI_InputCurveInfo();
@@ -242,6 +307,7 @@ public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_Inp
242307
float splineResolution = settings != null ? settings.SamplingResolution : 0.5f;
243308

244309
int numRefinedSplinePoints = splineResolution > 0.0f ? Mathf.CeilToInt(splineLength / splineResolution) + 1 : numControlPoints;
310+
Matrix4x4 localToWorld = inputSpline._transform.localToWorldMatrix;
245311

246312
float[] posArr;
247313
float[] rotArr;
@@ -255,7 +321,8 @@ public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_Inp
255321
for (int i = 0; i < numControlPoints; i++)
256322
{
257323
BezierKnot knot = inputSpline._knots[i];
258-
HEU_HAPIUtility.ConvertPositionUnityToHoudini(knot.Position, out posArr[i * 3 + 0], out posArr[i * 3 + 1], out posArr[i * 3 + 2]);
324+
float3 pos = toWorld ? localToWorld.MultiplyPoint(knot.Position) : knot.Position;
325+
HEU_HAPIUtility.ConvertPositionUnityToHoudini(pos, out posArr[i * 3 + 0], out posArr[i * 3 + 1], out posArr[i * 3 + 2]);
259326
HEU_HAPIUtility.ConvertRotationUnityToHoudini(knot.Rotation, out rotArr[i * 4 + 0], out rotArr[i * 4 + 1], out rotArr[i * 4 + 2], out rotArr[i * 4 + 3]);
260327
}
261328
}
@@ -269,6 +336,10 @@ public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_Inp
269336
for (int i = 0; i < numRefinedSplinePoints; i++)
270337
{
271338
float3 pos = SplineUtility.EvaluatePosition<Spline>(inputSpline._spline, currentDistance / splineLength);
339+
if (toWorld)
340+
{
341+
pos = localToWorld.MultiplyPoint(pos);
342+
}
272343
HEU_HAPIUtility.ConvertPositionUnityToHoudini(pos, out posArr[i * 3 + 0], out posArr[i * 3 + 1], out posArr[i * 3 + 2]);
273344

274345
currentDistance += splineResolution;

0 commit comments

Comments
 (0)