Import mesh from Unity to Houdini
2673 2 1- HaloFX
- Member
- 7 posts
- Joined: July 2018
- Offline
- seelan
- Member
- 571 posts
- Joined: May 2017
- Offline
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.
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(); } }
Edited by seelan - Sept. 6, 2018 09:58:43
- HaloFX
- Member
- 7 posts
- Joined: July 2018
- Offline
-
- Quick Links