Houdini Engine for Unity
 All Files Pages
Inputs

Sending data upstream, that is from Unity into Houdini, is a very useful and powerful feature. This allows data in Unity to be used as input to a Houdini asset, cook it, then send the generated output back out to Unity.

This can be achieved in 2 ways:

The primary mechanism to send and use input data is via Object Merge nodes. Either an existing Object Merge node is used or a new one created, and connected to the asset.

The following input data are currently supported:

  • Unity mesh
  • HDA (as node connection)
  • Terrain (see Terrain Input)

The following input data are planned to be supported:

  • Curve Inputs

Node Inputs

By design, SOPs have node connectors for passing geometries. This allows SOP type assets to also have node connectors for inputting geometries. Those inputs can be configured by changing the Minimum Inputs and Maximum Inputs values in the "Operator Type Properties" dialog of the assets.

Unity_AssetInputNode.png

All inputs created in this way will be listed in the Inputs Interface. These are treated the same as the Object Path Input Parameter inputs.


Object Path Input Parameter

Object Path Inputs are created from Operator Path parameters that accepts a path to a Houdini node. In order to input geometry, the Op Filter needs to be set either to "Any Object" or "Any SOP". When geometry is assigned to this parameter, Houdini Engine will create the appropriate Houdini nodes that will represent the input geometry. The asset can then use these nodes to access the geometry.

These can be used for both Object-type assets and SOP-type assets to input geometry, but it is more common to use Node Inputs connections directly for SOP-type assets.

Unity_InputOperatorPath.png

Although the Operator Path Parameter can be created manually, the simplest way to create one is to create an Object Merge SOP and expose its "Object (objpath)" parameter to the asset level. The geometry can then be accessed from the output of the Object Merge SOP. It will then appear in Unity as the Inputs Interface on the asset UI:

HDA Input Type

Unity_InputNodeUI.png

Input Type

Type of input data. Currently supporting Unity Mesh (GameObject or Prefab), and HDA (Input Assets). The above images show the Inputs Interface for those types.

Keep World Transform

This affects how the input object's transform is marshalled from Unity into Houdini. When geometry is marshalled to Houdini through an input, an Object Merge node is used to connect the asset and the geometry. For Node Inputs, the Object Merge node is automatically created by Houdini Engine, and set up in the same way that an object merge is used for Object Path Inputs.

  • If Keep World Transform is checked, the Object Merge used connect the input will have its Transform type parameter set to Into This Object, causing the input geometry to use its Unity world transform values in Houdini. Therefore if the input was at (0,10,0) in Unity, it will be at (0,10,0) in Houdini.
  • If unchecked, the Object Merge's Transform type parameter will be set to None, causing the geometry to use its Unity transform as offset from its Object transform. Therefore if the input was at (0,10,0) then it will be 10 units higher in Houdini from its Object transform.
Unity_ObjectMerge_Transform.png

Note that you can further modify this behaviour by setting the Transform type parameter of the HDA's own Object Merge node. Essentially, this setting uses the local (HDA's transform) or the world transform for the input object. The table below describes the possible combinations:

HDA's Object Merge Transform Type Keep World Transform Result of Input Transform
None Off Uses HDA transform (i.e. at HDA position)
None On Uses HDA's transform + offset of input
Into This Object Off Identity transform (i.e. at world origin)
Input This Object On Uses input's transform (i.e. at input's world position)

In most situations, either the first row (at HDA position) or last row (at input position) is the desired outcome of the input geometry's position.

Pack Geometry Before Merging

Only available for Unity Mesh input type

If checked, all the different Unity meshes will be packed individually before being merged into the asset's input. This allows to have each object available as a Packed Primitive in Houdini, making instancing and differentiating objects easier.

Input Objects

Only available for Unity Mesh input type

This is a dynamic list of input objects (GameObjects or Prefabs) that should contain Unity Mesh data (specifically should have MeshFilter Component with valid mesh geometry). When marshalling the geometry, the name of the GameObject will be assigned as the primitive attribute named unity_input_mesh_name. This attribute can be used in Houdini to separate the meshes. If the GameObject has assigned materials, the material names will also be set on a primitive attribute named unity_material. This way the material assignment can survive the roundtrip back to Unity.

Transform Offset - Each input object can be assigned a transform offset that adds to the world transform of the input object, if Keep World Transform is enabled.

Input Assets

Only available for HDA input type

For HDA input type, this can be used to specify multiple HDAs in the Unity scene. Only the root GameObject of the HDA (the one with the Houdini Engine UI) is accepted here. When set, the plug-in will create a new Object Merge node in the Houdini Engine session, specify the path to the HDA in the "Object (objpath)" parameter, and connect the new Object Merge node to the current asset. This is more efficient than uploading the geometry created by one asset into another, since the connection is directly made in the Houdini Engine session.


Custom Input Scripts

Custom scripts can be easily added to the plug-in's input mechanism allowing to add support for uploading custom input data or override built-in scripts. For example, users can add their own input script for uploading meshes or terrains instead of using the built-in scripts.

HEU_InputUtility.cs is the utility class that manages input interface scripts, which are derived from HEU_InputInterface.cs. A class derived from HEU_InputInterface registers itself with HEU_InputUtility. When an input object needs to be uploaded into Houdini, HEU_InputUtility finds and uses the registered HEU_InputInterface that can upload that object, based on the priority set by the user.

HEU_InputInterfaceMesh.cs and HEU_InputInterfaceTerrain.cs both provide examples of HEU_InputInterface derived classes handling uploading of mesh and terrain objects, respectively.

To add a custom input script hook, create a new class that derives from HEU_InputInterface, fill in the required methods, then copy and edit the OnScriptsReloaded function from HEU_InputInterfaceMesh.cs, and add the [InitializeOnLoadMethod], and [UnityEditor.Callbacks.DidReloadScripts] attributes. These attributes will invoke the OnScriptsReloaded function, which automatically creates a new custom interface object, and registers it with HEU_InputUtility when the Unity Editor scripts are reloaded.