I've been meaning to write documentation on using the plugin programmetically. Haven't had the opportunity yet, but I've added an RFE to do so.
In the mean time, there are decent code examples provided which should get you started. Take a look at:
Assets\Plugins\HoudiniEngineUnity\Scripts\Examples\HEU_ScriptParameterExample.cs
Assets\Plugins\HoudiniEngineUnity\Scripts\Parameters\HEU_ParameterAccessor.cs
Assets\Plugins\HoudiniEngineUnity\Scripts\Parameters\HEU_ParameterUtility.cs
HEU_ScriptParameterExample.cs has an example of accessing and setting parameters, then cooking. The others are helpers to query and change parameter values.
Here is a sample code to create an HDA from a file path, set an input gameobject, set a float parameter, and cook it with a callback.
public class TestProcessInputs
{
public const string HDAPath = "Assets/HDAs/Input/polyreduce.hda";
public static HEU_HoudiniAsset InstatiatedAsset(string assetPath)
{
// Instantiate the processor HDA. This will load and cook into Unity scene with defautl values.
GameObject assetGO = HEU_HAPIUtility.InstantiateHDA(HDAPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), false);
if (assetGO != null && assetGO.GetComponent<HEU_HoudiniAssetRoot>() != null)
{
HEU_HoudiniAssetRoot assetRoot = assetGO.GetComponent<HEU_HoudiniAssetRoot>();
if (assetRoot != null)
{
return assetRoot._houdiniAsset;
}
}
return null;
}
// This will merge all selected inputs and submit to HDA. Result will be a merged output.
[MenuItem("Test/ProcesInput")]
public static void TestProcessInput()
{
GameObject[] selectedGOs = Selection.gameObjects;
if(selectedGOs != null && selectedGOs.Length > 0)
{
// Instantiate the processor HDA. This will load and cook into Unity scene with defautl values.
HEU_HoudiniAsset asset = InstatiatedAsset(HDAPath);
if (asset)
{
// Now get the object path parameter (with name objpath1). We're going to add
// selected gameobjects with meshes in as a list of inputs.
HEU_ParameterData inputParam = asset.Parameters.GetParameter("objpath1");
if (inputParam != null && inputParam._paramInputNode != null)
{
inputParam._paramInputNode.KeepWorldTransform = true;
int numSelectedObjects = selectedGOs.Length;
for (int i = 0; i < numSelectedObjects; ++i)
{
inputParam._paramInputNode.AddInputObjectAtEnd(selectedGOs[i]);
}
// Flag for upload of input meshes
inputParam._paramInputNode.RequiresUpload = true;
}
// Set poly reduce param to 50%
HEU_ParameterAccessor.SetFloat(asset, "percentage", 50f);
// Add cooked callback
asset._cookedEvent.AddListener(CookedCallback);
// Cook the HDA asynchronously (can send false to bAsync if want to wait)
asset.RequestCook(bCheckParametersChanged: true, bAsync: true, bSkipCookCheck: true, bUploadParameters: true);
}
}
}
public static void CookedCallback(HEU_HoudiniAsset asset, bool success, List<GameObject> outputs)
{
// Cooking done. Bake it out and remove the HDA.
Debug.LogFormat("Asset {0} has cooked with result: {1}", asset.AssetName, success);
asset.RequestBakeInPlace();
}
}
Feel free to ask me questions on anything else here.