@@ -126,7 +126,7 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
126126 }
127127
128128 // Get spline data from the input object
129- HEU_InputDataSplines inputSplines = GenerateSplineDataFromGameObject ( inputObject ) ;
129+ HEU_InputDataSplineContainer inputSplines = GenerateSplineDataFromGameObject ( inputObject ) ;
130130 if ( inputSplines == null || inputSplines . _inputSplines == null || inputSplines . _inputSplines . Count ( ) == 0 )
131131 {
132132 HEU_Logger . LogError ( "No valid splines found on input objects." ) ;
@@ -144,7 +144,7 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
144144 inputNodeID = newNodeID ;
145145
146146 HEU_InputDataSpline inputSpline = inputSplines . _inputSplines [ 0 ] ;
147- if ( ! UploadData ( session , inputNodeID , inputSpline ) )
147+ if ( ! UploadData ( session , inputNodeID , inputSpline , Matrix4x4 . identity ) )
148148 {
149149 if ( ! session . CookNode ( inputNodeID , false ) )
150150 {
@@ -155,21 +155,16 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
155155 return false ;
156156 }
157157
158- if ( ! session . CookNode ( inputNodeID , false ) )
159- {
160- HEU_Logger . LogError ( "New input node failed to cook!" ) ;
161- return false ;
162- }
163-
158+ // The spline is made up of branching sub-splines.
159+ // Create an input node for each branching spline and object-merge it to the root spline.
164160 bool createMergeNode = inputSplines . _inputSplines . Count ( ) > 1 ;
165161 if ( ! createMergeNode )
166162 return true ;
167163
168- // Create merge node to merge branching splines
169164 HAPI_NodeId mergeNodeId = HEU_Defines . HEU_INVALID_NODE_ID ;
170165 HAPI_NodeId parentId = HEU_HAPIUtility . GetParentNodeID ( session , inputNodeID ) ;
171166
172- if ( ! session . CreateNode ( parentId , "merge" , "rajat-merge" , false , out mergeNodeId ) )
167+ if ( ! session . CreateNode ( parentId , "merge" , null , false , out mergeNodeId ) )
173168 {
174169 HEU_Logger . LogErrorFormat ( "Unable to create merge SOP node for connecting input assets." ) ;
175170 return false ;
@@ -187,21 +182,20 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
187182 }
188183 inputNodeID = mergeNodeId ;
189184
185+ Matrix4x4 localToWorld = inputSplines . _transform . localToWorldMatrix ;
190186 HAPI_NodeId branchNodeID ;
191- string branchName = inputObject . name ;
192187 HEU_InputDataSpline branchSpline ;
193- int inputNodeIndex = 1 ;
194188 for ( int i = 1 ; i < inputSplines . _inputSplines . Count ( ) ; i ++ )
195189 {
196- session . CreateInputCurveNode ( out branchNodeID , branchName + "_" + i ) ;
190+ session . CreateInputCurveNode ( out branchNodeID , inputObject . name + "_" + i ) ;
197191 if ( branchNodeID == HEU_Defines . HEU_INVALID_NODE_ID || ! HEU_HAPIUtility . IsNodeValidInHoudini ( session , branchNodeID ) )
198192 {
199193 HEU_Logger . LogError ( "Failed to create new input cruve node in Houdini session!" ) ;
200194 return false ;
201195 }
202196
203197 branchSpline = inputSplines . _inputSplines [ i ] ;
204- if ( ! UploadData ( session , branchNodeID , branchSpline , true ) )
198+ if ( ! UploadData ( session , branchNodeID , branchSpline , localToWorld ) )
205199 {
206200 if ( ! session . CookNode ( branchNodeID , false ) )
207201 {
@@ -216,7 +210,6 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
216210 HEU_Logger . LogErrorFormat ( "Unable to connect to input node!" ) ;
217211 return false ;
218212 }
219- inputNodeIndex ++ ;
220213 }
221214
222215 if ( ! session . CookNode ( inputNodeID , false ) )
@@ -234,7 +227,6 @@ public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI
234227 public class HEU_InputDataSpline
235228 {
236229 public Spline _spline ;
237- public Transform _transform ;
238230 public bool _closed ;
239231 public int _count ;
240232 public float _length ;
@@ -244,9 +236,10 @@ public class HEU_InputDataSpline
244236 /// <summary>
245237 /// Contains input geometry for multiple splines.
246238 /// </summary>
247- public class HEU_InputDataSplines : HEU_InputData
239+ public class HEU_InputDataSplineContainer : HEU_InputData
248240 {
249241 public List < HEU_InputDataSpline > _inputSplines = new List < HEU_InputDataSpline > ( ) ;
242+ public Transform _transform ;
250243 }
251244
252245 /// <summary>
@@ -255,25 +248,26 @@ public class HEU_InputDataSplines : HEU_InputData
255248 /// </summary>
256249 /// <param name="inputObject">GameObject containing a Spline component</param>
257250 /// <returns>A valid input data strcuture containing spline data</returns>
258- public HEU_InputDataSplines GenerateSplineDataFromGameObject ( GameObject inputObject )
251+ public HEU_InputDataSplineContainer GenerateSplineDataFromGameObject ( GameObject inputObject )
259252 {
260253 SplineContainer splineContainer = inputObject . GetComponent < SplineContainer > ( ) ;
261254 IReadOnlyList < Spline > splines = splineContainer . Splines ;
262255
263- HEU_InputDataSplines splineData = new HEU_InputDataSplines ( ) ;
256+ HEU_InputDataSplineContainer splineContainerData = new HEU_InputDataSplineContainer ( ) ;
264257 foreach ( Spline spline in splines )
265258 {
266- HEU_InputDataSpline inputSpline = new HEU_InputDataSpline ( ) ;
267- inputSpline . _spline = spline ;
268- inputSpline . _transform = inputObject . transform ;
269- inputSpline . _closed = spline . Closed ;
270- inputSpline . _count = spline . Count ;
271- inputSpline . _length = spline . GetLength ( ) ;
272- inputSpline . _knots = spline . Knots . ToArray < BezierKnot > ( ) ;
273-
274- splineData . _inputSplines . Add ( inputSpline ) ;
259+ HEU_InputDataSpline splineData = new HEU_InputDataSpline ( ) ;
260+ splineData . _spline = spline ;
261+ splineData . _closed = spline . Closed ;
262+ splineData . _count = spline . Count ;
263+ splineData . _length = spline . GetLength ( ) ;
264+ splineData . _knots = spline . Knots . ToArray < BezierKnot > ( ) ;
265+
266+ splineContainerData . _inputSplines . Add ( splineData ) ;
275267 }
276- return splineData ;
268+ splineContainerData . _transform = inputObject . transform ;
269+
270+ return splineContainerData ;
277271 }
278272
279273 /// <summary>
@@ -283,16 +277,14 @@ public HEU_InputDataSplines GenerateSplineDataFromGameObject(GameObject inputObj
283277 /// <param name="inputNodeID">ID of the input node</param>
284278 /// <param name="inputData">Container of the mesh geometry</param>
285279 /// <returns>True if successfully uploaded data</returns>
286- public bool UploadData ( HEU_SessionBase session , HAPI_NodeId inputNodeID , HEU_InputDataSpline inputSpline , bool toWorld = false )
280+ public bool UploadData ( HEU_SessionBase session , HAPI_NodeId inputNodeID , HEU_InputDataSpline inputSpline , Matrix4x4 localToWorld )
287281 {
288282 // Set the input curve info of the newly created input curve
289283 HAPI_InputCurveInfo inputCurveInfo = new HAPI_InputCurveInfo ( ) ;
290284 inputCurveInfo . curveType = HAPI_CurveType . HAPI_CURVETYPE_BEZIER ;
291- inputCurveInfo . order = 4 ; // Recommended default
285+ inputCurveInfo . order = 4 ;
292286 inputCurveInfo . closed = inputSpline . _closed ;
293287 inputCurveInfo . reverse = false ;
294-
295- // Curve always goes through the specified points
296288 inputCurveInfo . inputMethod = HAPI_InputCurveMethod . HAPI_CURVEMETHOD_BREAKPOINTS ;
297289 inputCurveInfo . breakpointParameterization = HAPI_InputCurveParameterization . HAPI_CURVEPARAMETERIZATION_UNIFORM ;
298290 if ( ! session . SetInputCurveInfo ( inputNodeID , 0 , ref inputCurveInfo ) )
@@ -301,18 +293,16 @@ public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_Inp
301293 return false ;
302294 }
303295
304- // Calculate the number of refined point we want
296+ // Calculate the number of refined points we want
305297 int numControlPoints = inputSpline . _knots . Count ( ) ;
306298 float splineLength = inputSpline . _length ;
307- float splineResolution = settings != null ? settings . SamplingResolution : 0.5f ;
308-
299+ float splineResolution = settings != null ? settings . SamplingResolution : 0.0f ;
309300 int numRefinedSplinePoints = splineResolution > 0.0f ? Mathf . CeilToInt ( splineLength / splineResolution ) + 1 : numControlPoints ;
310- Matrix4x4 localToWorld = inputSpline . _transform . localToWorldMatrix ;
311301
312302 float [ ] posArr ;
313303 float [ ] rotArr ;
314304 float [ ] scaleArr ;
315- if ( numRefinedSplinePoints < numControlPoints )
305+ if ( numRefinedSplinePoints <= numControlPoints )
316306 {
317307 // There's not enough refined points, so we'll use the control points instead
318308 posArr = new float [ numControlPoints * 3 ] ;
@@ -321,7 +311,10 @@ public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_Inp
321311 for ( int i = 0 ; i < numControlPoints ; i ++ )
322312 {
323313 BezierKnot knot = inputSpline . _knots [ i ] ;
324- float3 pos = toWorld ? localToWorld . MultiplyPoint ( knot . Position ) : knot . Position ;
314+
315+ // For branching sub-splines, apply local transform on vertices to get the merged spline
316+ float3 pos = localToWorld . MultiplyPoint ( knot . Position ) ;
317+
325318 HEU_HAPIUtility . ConvertPositionUnityToHoudini ( pos , out posArr [ i * 3 + 0 ] , out posArr [ i * 3 + 1 ] , out posArr [ i * 3 + 2 ] ) ;
326319 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 ] ) ;
327320 }
@@ -336,22 +329,32 @@ public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_Inp
336329 for ( int i = 0 ; i < numRefinedSplinePoints ; i ++ )
337330 {
338331 float3 pos = SplineUtility . EvaluatePosition < Spline > ( inputSpline . _spline , currentDistance / splineLength ) ;
339- if ( toWorld )
340- {
341- pos = localToWorld . MultiplyPoint ( pos ) ;
342- }
343- HEU_HAPIUtility . ConvertPositionUnityToHoudini ( pos , out posArr [ i * 3 + 0 ] , out posArr [ i * 3 + 1 ] , out posArr [ i * 3 + 2 ] ) ;
332+
333+ // For branching sub-splines, apply local transform on vertices to get the merged spline
334+ pos = localToWorld . MultiplyPoint ( pos ) ;
344335
336+ HEU_HAPIUtility . ConvertPositionUnityToHoudini ( pos , out posArr [ i * 3 + 0 ] , out posArr [ i * 3 + 1 ] , out posArr [ i * 3 + 2 ] ) ;
345337 currentDistance += splineResolution ;
346338 }
347339 }
348340
349- bool hapi_result = session . SetInputCurvePositionsRotationsScales (
350- inputNodeID , 0 ,
351- posArr , 0 , posArr . Length ,
352- rotArr , 0 , rotArr . Length ,
353- scaleArr , 0 , 0
354- ) ;
341+ bool hasRotations = rotArr . Length == posArr . Length ;
342+ bool hasScales = scaleArr . Length == posArr . Length ;
343+ bool hapi_result = false ;
344+ if ( ! hasRotations && ! hasScales )
345+ {
346+ hapi_result = session . SetInputCurvePositions ( inputNodeID , 0 , posArr , 0 , posArr . Length ) ;
347+ }
348+ else
349+ {
350+ hapi_result = session . SetInputCurvePositionsRotationsScales (
351+ inputNodeID , 0 ,
352+ posArr , 0 , posArr . Length ,
353+ rotArr , 0 , rotArr . Length ,
354+ scaleArr , 0 , 0
355+ ) ;
356+ }
357+
355358 if ( ! hapi_result )
356359 {
357360 HEU_Logger . LogError ( "Failed to set input curve positions." ) ;
0 commit comments