Search - User list
Full Version: Import mesh from Unity to Houdini
Root » Houdini Engine for Unity » Import mesh from Unity to Houdini
HaloFX
Is it posible to import all geometry in scene from Unity to Houdini for some calculations?
seelan
You can import geometry by exposing the object path parameter in an object merge, or adding inputs to an asset. The plugin will create input fields on the asset's UI in Unity allowing to place any number of gameobjects with meshes into it.

If you want to import all meshes in a scene, you'd need to write a custom Editor script that can grab all gameobjects and add to the input field.

I pasted this code sample in another thread, but copying it here. This editor script instantiates an HDA that takes in input geometry, sets the selected gameobject as input, and cooks it. You can expand this out to do all meshes.

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();
	}
}
HaloFX
Wow this is really cool!
Many thanks for code sharing, seelan!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB