/// <summary> /// Load a NodeSync file and create its construct in Unity. /// </summary> /// <param name="filePath">Path to the NodeSync file</param> /// <param name="name">Name of the NodeSync node</param> void CreateNodeSyncFromFile(string filePath, string name) { HEU_SessionBase session = HEU_SessionManager.GetDefaultSession(); if (session == null || !session.IsSessionValid()) { return; } HAPI_NodeId parentNodeID = -1; string nodeName = name; HAPI_NodeId newNodeID = -1; // This loads the node network from file, and returns the node that was created // with newNodeID. It is either a SOP object, or a subnet object. // The actual loader (HEU_ThreadedTaskLoadGeo) will deal with either case. if (!session.LoadNodeFromFile(filePath, parentNodeID, nodeName, true, out newNodeID)) { Log(string.Format("Failed to load node network from file: {0}.", filePath)); return; } // Wait until finished if (!HEU_HAPIUtility.ProcessHoudiniCookStatus(session, nodeName)) { Log(string.Format("Failed to cook loaded node with name: {0}.", nodeName)); return; } GameObject newGO = HEU_GeneralUtility.CreateNewGameObject(nodeName); HEU_NodeSync nodeSync = newGO.AddComponent <HEU_NodeSync>(); nodeSync.InitializeFromHoudini(session, newNodeID, nodeName, filePath); }
public static void CreatePDGAssetLink() { GameObject selectedGO = Selection.activeGameObject; if (selectedGO != null) { HEU_HoudiniAssetRoot assetRoot = selectedGO.GetComponent<HEU_HoudiniAssetRoot>(); if (assetRoot != null) { if (assetRoot._houdiniAsset != null) { string name = string.Format("{0}_PDGLink", assetRoot._houdiniAsset.AssetName); GameObject go = HEU_GeneralUtility.CreateNewGameObject(name); HEU_PDGAssetLink assetLink = go.AddComponent<HEU_PDGAssetLink>(); assetLink.Setup(assetRoot._houdiniAsset); Selection.activeGameObject = go; } else { HEU_Logger.LogError("Selected gameobject is not an instantiated HDA. Failed to create PDG Asset Link."); } } else { HEU_Logger.LogError("Selected gameobject is not an instantiated HDA. Failed to create PDG Asset Link."); } } else { //HEU_Logger.LogError("Nothing selected. Select an instantiated HDA first."); HEU_EditorUtility.DisplayErrorDialog("PDG Asset Link", "No HDA selected. You must select an instantiated HDA first.", "OK"); } }
private Transform GetLoadRootTransform() { if (_loadRootGameObject == null) { _loadRootGameObject = HEU_GeneralUtility.CreateNewGameObject(_assetName + " _OUTPUTS"); } return _loadRootGameObject.transform; }
public static void CreateNodeSync(HEU_SessionBase session, string opName, string nodeNabel) { if (session == null) { session = HEU_SessionManager.GetDefaultSession(); } if (session == null || !session.IsSessionValid()) { return; } HAPI_NodeId newNodeID = -1; HAPI_NodeId parentNodeId = -1; if (!session.CreateNode(parentNodeId, opName, nodeNabel, true, out newNodeID)) { HEU_Logger.LogErrorFormat("Unable to create merge SOP node for connecting input assets."); return; } if (parentNodeId == -1) { // When creating a node without a parent, for SOP nodes, a container // geometry object will have been created by HAPI. // In all cases we want to use the node ID of that object container // so the below code sets the parent's node ID. // But for SOP/subnet we actually do want the subnet SOP node ID // hence the useSOPNodeID argument here is to override it. bool useSOPNodeID = opName.Equals("SOP/subnet"); HAPI_NodeInfo nodeInfo = new HAPI_NodeInfo(); if (!session.GetNodeInfo(newNodeID, ref nodeInfo)) { return; } if (nodeInfo.type == HAPI_NodeType.HAPI_NODETYPE_SOP) { if (!useSOPNodeID) { newNodeID = nodeInfo.parentId; } } else if (nodeInfo.type != HAPI_NodeType.HAPI_NODETYPE_OBJ) { HEU_Logger.LogErrorFormat("Unsupported node type {0}", nodeInfo.type); return; } } GameObject newGO = HEU_GeneralUtility.CreateNewGameObject(nodeNabel); HEU_NodeSync nodeSync = newGO.AddComponent<HEU_NodeSync>(); nodeSync.InitializeFromHoudini(session, newNodeID, nodeNabel, ""); }
private void SetupGameObjectAndTransform(HEU_PartData partData, HEU_HoudiniAsset parentAsset) { // Checking for nulls for undo safety if (partData == null || parentAsset == null || parentAsset.OwnerGameObject == null || parentAsset.RootGameObject == null) { return; } // Set a valid gameobject for this part if (partData.OutputGameObject == null) { partData.SetGameObject(HEU_GeneralUtility.CreateNewGameObject()); } // The parent is either the asset root, OR if this is instanced and not visible, then the HDA data is the parent // The parent transform is either the asset root (for a display node), // or the HDA_Data gameobject (for instanced, not visible, intermediate, editable non-display nodes) Transform partTransform = partData.OutputGameObject.transform; if (partData.IsPartInstanced() || (_containerObjectNode.IsInstanced() && !_containerObjectNode.IsVisible()) || partData.IsPartCurve() || (IsIntermediateOrEditable() && !Displayable)) { partTransform.parent = parentAsset.OwnerGameObject.transform; } else { partTransform.parent = parentAsset.RootGameObject.transform; } HEU_GeneralUtility.CopyFlags(partTransform.parent.gameObject, partData.OutputGameObject, true); // Reset to origin partTransform.localPosition = Vector3.zero; partTransform.localRotation = Quaternion.identity; partTransform.localScale = Vector3.one; // Destroy the children generated from ComposeNChildren HEU_GeneralUtility.DestroyAutoGeneratedChildren(partData.OutputGameObject); }
private void SetupGeoCurveGameObjectAndTransform(HEU_Curve curve) { if (ParentAsset == null) { return; } if (curve.TargetGameObject == null) { curve.TargetGameObject = HEU_GeneralUtility.CreateNewGameObject(); } // For geo curve, the parent is the HDA_Data Transform curveTransform = curve.TargetGameObject.transform; curveTransform.parent = ParentAsset.OwnerGameObject.transform; HEU_GeneralUtility.CopyFlags(curveTransform.parent.gameObject, curve.TargetGameObject, true); // Reset to origin curveTransform.localPosition = Vector3.zero; curveTransform.localRotation = Quaternion.identity; curveTransform.localScale = Vector3.one; }
/// <summary> /// Load the geometry generated as results of the given work item, of the given TOP node. /// The load will be done asynchronously. /// Results must be tagged with 'file', and must have a file path, otherwise will not be loaded. /// </summary> /// <param name="session">Houdini Engine session that the TOP node is in</param> /// <param name="topNode">TOP node that the work item belongs to</param> /// <param name="workItemInfo">Work item whose results to load</param> /// <param name="resultInfos">Results data</param> /// <param name="workItemID">The work item's ID. Required for clearning its results.</param> internal void LoadResults(HEU_SessionBase session, HEU_TOPNodeData topNode, HAPI_PDG_WorkitemInfo workItemInfo, HAPI_PDG_WorkitemResultInfo[] resultInfos, HAPI_PDG_WorkitemId workItemID, System.Action<HEU_TOPNodeData, HEU_SyncedEventData> OnSynced) { // Create HEU_GeoSync objects, set results, and sync it string workItemName = HEU_SessionManager.GetString(workItemInfo.nameSH, session); //HEU_Logger.LogFormat("Work item: {0}:: name={1}, results={2}", workItemInfo.index, workItemName, workItemInfo.numResults); // Clear previously generated result ClearWorkItemResultByID(topNode, workItemID); if (resultInfos == null || resultInfos.Length == 0) { return; } HEU_TOPWorkResult result = GetWorkResultByID(topNode, workItemID); if (result == null) { result = new HEU_TOPWorkResult(); result._workItemIndex = workItemInfo.index; result._workItemID = workItemID; topNode._workResults.Add(result); } // Load each result geometry int numResults = resultInfos.Length; _numTotalResults = numResults; _numLoadingResults = 0; for (int i = 0; i < numResults; ++i) { if (resultInfos[i].resultTagSH <= 0 || resultInfos[i].resultSH <= 0) { continue; } string tag = HEU_SessionManager.GetString(resultInfos[i].resultTagSH, session); string path = HEU_SessionManager.GetString(resultInfos[i].resultSH, session); //HEU_Logger.LogFormat("Result for work item {0}: result={1}, tag={2}, path={3}", result._workItemIndex, i, tag, path); if (string.IsNullOrEmpty(tag) || !tag.StartsWith("file")) { continue; } string name = string.Format("{0}_{1}_{2}", topNode._parentName, workItemName, workItemInfo.index); // Get or create parent GO if (topNode._workResultParentGO == null) { topNode._workResultParentGO = HEU_GeneralUtility.CreateNewGameObject(topNode._nodeName); HEU_GeneralUtility.SetParentWithCleanTransform(GetLoadRootTransform(), topNode._workResultParentGO.transform); topNode._workResultParentGO.SetActive(topNode._showResults); } GameObject newOrExistingGO = null; int existingObjectIndex = -1; for (int j = 0; j < result._generatedGOs.Count; j++) { if (result._generatedGOs[j] != null) { HEU_GeoSync oldGeoSync = result._generatedGOs[j].GetComponent<HEU_GeoSync>(); if (oldGeoSync != null && oldGeoSync._filePath == path) { oldGeoSync.Reset(); existingObjectIndex = j; newOrExistingGO = result._generatedGOs[j]; break; } } } if (existingObjectIndex < 0) { newOrExistingGO = HEU_GeneralUtility.CreateNewGameObject(name);; result._generatedGOs.Add(newOrExistingGO); } HEU_GeneralUtility.SetParentWithCleanTransform(topNode._workResultParentGO.transform, newOrExistingGO.transform); // HEU_GeoSync does the loading HEU_GeoSync geoSync = newOrExistingGO.GetComponent<HEU_GeoSync>(); if (geoSync == null) { geoSync = newOrExistingGO.AddComponent<HEU_GeoSync>(); } geoSync._filePath = path; geoSync.SetOutputCacheDirectory(_outputCachePathRoot); if (geoSync != null && OnSynced != null) { System.Action<HEU_SyncedEventData> OnSyncedCallback = (HEU_SyncedEventData Data) => { _numLoadingResults++; if (_numLoadingResults >= _numTotalResults) { OnSynced(topNode, Data); } if (geoSync) { geoSync.OnSynced = null; } }; geoSync.OnSynced = OnSyncedCallback; } geoSync.StartSync(); } }