private void Awake() { #if HOUDINIENGINEUNITY_ENABLED if (_sessionID != HEU_SessionData.INVALID_SESSION_ID) { HEU_SessionBase session = HEU_SessionManager.GetSessionWithID(_sessionID); if (session == null || !HEU_HAPIUtility.IsNodeValidInHoudini(session, _cookNodeID)) { // Reset session and node IDs if these don't exist (could be from scene load). _sessionID = HEU_SessionData.INVALID_SESSION_ID; _cookNodeID = HEU_Defines.HEU_INVALID_NODE_ID; } } #endif }
/// <summary> /// Creates a heightfield network inside the same object as connectNodeID. /// Uploads the terrain data from inputObject into the new heightfield network, incuding /// all terrain layers/alphamaps. /// </summary> /// <param name="session">Session that connectNodeID exists in</param> /// <param name="connectNodeID">The node to connect the network to. Most likely a SOP/merge node</param> /// <param name="inputObject">The gameobject containing the Terrain components</param> /// <param name="inputNodeID">The created heightfield network node ID</param> /// <returns>True if created network and uploaded heightfield data.</returns> public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI_NodeId connectNodeID, GameObject inputObject, out HAPI_NodeId inputNodeID) { inputNodeID = HEU_Defines.HEU_INVALID_NODE_ID; // Create input node, cook it, then upload the geometry data if (!HEU_HAPIUtility.IsNodeValidInHoudini(session, connectNodeID)) { Debug.LogError("Connection node is invalid."); return false; } HEU_InputDataTerrain idt = GenerateTerrainDataFromGameObject(inputObject); if (idt == null) { return false; } HAPI_NodeId parentNodeID = HEU_HAPIUtility.GetParentNodeID(session, connectNodeID); idt._parentNodeID = parentNodeID; if (!CreateHeightFieldInputNode(session, idt)) { return false; } if (!UploadHeightValuesWithTransform(session, idt)) { return false; } inputNodeID = idt._heightfieldNodeID; if (!UploadAlphaMaps(session, idt)) { return false; } if (!session.CookNode(inputNodeID, false)) { Debug.LogError("New input node failed to cook!"); return false; } return true; }
/// <summary> /// Creates a mesh input node and uploads the mesh data from inputObject. /// </summary> /// <param name="session">Session that connectNodeID exists in</param> /// <param name="connectNodeID">The node to connect the network to. Most likely a SOP/merge node</param> /// <param name="inputObject">The gameobject containing the mesh components</param> /// <param name="inputNodeID">The created input node ID</param> /// <returns>True if created network and uploaded mesh data.</returns> public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI_NodeId connectNodeID, GameObject inputObject, out HAPI_NodeId inputNodeID) { inputNodeID = HEU_Defines.HEU_INVALID_NODE_ID; // Create input node, cook it, then upload the geometry data if (!HEU_HAPIUtility.IsNodeValidInHoudini(session, connectNodeID)) { Debug.LogError("Connection node is invalid."); return false; } // Get upload meshes from input object HEU_InputDataMeshes inputMeshes = GenerateMeshDatasFromGameObject(inputObject); if (inputMeshes == null || inputMeshes._inputMeshes == null || inputMeshes._inputMeshes.Count == 0) { Debug.LogError("No valid meshes found on input objects."); return false; } string inputName = null; HAPI_NodeId newNodeID = HEU_Defines.HEU_INVALID_NODE_ID; session.CreateInputNode(out newNodeID, inputName); if (newNodeID == HEU_Defines.HEU_INVALID_NODE_ID || !HEU_HAPIUtility.IsNodeValidInHoudini(session, newNodeID)) { Debug.LogError("Failed to create new input node in Houdini session!"); return false; } inputNodeID = newNodeID; if (!session.CookNode(inputNodeID, false)) { Debug.LogError("New input node failed to cook!"); return false; } return UploadData(session, inputNodeID, inputMeshes); }
private void DisconnectAndDestroyInputs(HEU_SessionBase session) { // First disconnect the merge node from its connections DisconnectConnectedMergeNode(session); // Clear out input HDA hooks (upstream callback) ClearConnectedInputHDAs(); if (session != null) { // Delete the input nodes that were created foreach (HAPI_NodeId nodeID in _inputObjectsConnectedAssetIDs) { if (nodeID != HEU_Defines.HEU_INVALID_NODE_ID) { session.DeleteNode(nodeID); } } // Delete the SOP/merge we created if (_connectedNodeID != HEU_Defines.HEU_INVALID_NODE_ID && HEU_HAPIUtility.IsNodeValidInHoudini(session, _connectedNodeID)) { // We'll delete the parent Object because we presume to have created the SOP/merge ourselves. // If the parent Object doesn't get deleted, it sticks around unused. HAPI_NodeInfo parentNodeInfo = new HAPI_NodeInfo(); if (session.GetNodeInfo(_connectedNodeID, ref parentNodeInfo)) { if (parentNodeInfo.parentId != HEU_Defines.HEU_INVALID_NODE_ID) { session.DeleteNode(parentNodeInfo.parentId); } } } } _inputObjectsConnectedAssetIDs.Clear(); _connectedNodeID = HEU_Defines.HEU_INVALID_NODE_ID; }
/// <summary> /// Creates a mesh input node and uploads the mesh data from inputObject. /// </summary> /// <param name="session">Session that connectNodeID exists in</param> /// <param name="connectNodeID">The node to connect the network to. Most likely a SOP/merge node</param> /// <param name="inputObject">The gameobject containing the mesh components</param> /// <param name="inputNodeID">The created input node ID</param> /// <returns>True if created network and uploaded mesh data.</returns> public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI_NodeId connectNodeID, GameObject inputObject, out HAPI_NodeId inputNodeID) { inputNodeID = HEU_Defines.HEU_INVALID_NODE_ID; // Create input node, cook it, then upload the geometry data if (!HEU_HAPIUtility.IsNodeValidInHoudini(session, connectNodeID)) { HEU_Logger.LogError("Connection node is invalid."); return false; } bool bExportColliders = settings != null && settings.ExportColliders == true; // Get upload meshes from input object HEU_InputDataMeshes inputMeshes = GenerateMeshDatasFromGameObject(inputObject, bExportColliders); if (inputMeshes == null || inputMeshes._inputMeshes == null || inputMeshes._inputMeshes.Count == 0) { HEU_Logger.LogError("No valid meshes found on input objects."); return false; } string inputName = null; HAPI_NodeId newNodeID = HEU_Defines.HEU_INVALID_NODE_ID; session.CreateInputNode(out newNodeID, inputName); if (newNodeID == HEU_Defines.HEU_INVALID_NODE_ID || !HEU_HAPIUtility.IsNodeValidInHoudini(session, newNodeID)) { HEU_Logger.LogError("Failed to create new input node in Houdini session!"); return false; } inputNodeID = newNodeID; if (!UploadData(session, inputNodeID, inputMeshes)) { if (!session.CookNode(inputNodeID, false)) { HEU_Logger.LogError("New input node failed to cook!"); return false; } return false; } bool createMergeNode = false; HAPI_NodeId mergeNodeId = HEU_Defines.HEU_INVALID_NODE_ID; if (bExportColliders) { createMergeNode = true; } if (!createMergeNode) { return true; } HAPI_NodeId parentId = HEU_HAPIUtility.GetParentNodeID(session, newNodeID); if (!session.CreateNode(parentId, "merge", null, false, out mergeNodeId)) { HEU_Logger.LogErrorFormat("Unable to create merge SOP node for connecting input assets."); return false; } if (!session.ConnectNodeInput(mergeNodeId, 0, newNodeID)) { HEU_Logger.LogErrorFormat("Unable to connect to input node!"); return false; } if (!session.SetNodeDisplay(mergeNodeId, 1)) { HEU_Logger.LogWarningFormat("Unable to set display flag!"); } inputNodeID = mergeNodeId; if (bExportColliders) { if (!UploadColliderData(session, mergeNodeId, inputMeshes, parentId)) { return false; } } if (!session.CookNode(inputNodeID, false)) { HEU_Logger.LogError("New input node failed to cook!"); return false; } return true; }
/// <summary> /// Creates a heightfield network inside the same object as connectNodeID. /// Uploads the terrain data from inputObject into the new heightfield network, incuding /// all terrain layers/alphamaps. /// </summary> /// <param name="session">Session that connectNodeID exists in</param> /// <param name="connectNodeID">The node to connect the network to. Most likely a SOP/merge node</param> /// <param name="inputObject">The gameobject containing the Terrain components</param> /// <param name="inputNodeID">The created heightfield network node ID</param> /// <returns>True if created network and uploaded heightfield data.</returns> public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, HAPI_NodeId connectNodeID, GameObject inputObject, out HAPI_NodeId inputNodeID) { inputNodeID = HEU_Defines.HEU_INVALID_NODE_ID; // Create input node, cook it, then upload the geometry data if (!HEU_HAPIUtility.IsNodeValidInHoudini(session, connectNodeID)) { Debug.LogError("Connection node is invalid."); return(false); } HEU_InputDataTerrain idt = GenerateTerrainDataFromGameObject(inputObject); if (idt == null) { return(false); } HAPI_NodeId parentNodeID = HEU_HAPIUtility.GetParentNodeID(session, connectNodeID); idt._parentNodeID = parentNodeID; if (!CreateHeightFieldInputNode(session, idt)) { return(false); } HAPI_VolumeInfo volumeInfo = new HAPI_VolumeInfo(); if (!UploadHeightValuesWithTransform(session, idt, ref volumeInfo)) { return(false); } inputNodeID = idt._heightfieldNodeID; bool bMaskSet = false; if (!UploadAlphaMaps(session, idt, ref volumeInfo, out bMaskSet)) { return(false); } if (!bMaskSet) { // While the default HF created by the input node also creates a default mask layer, // we still need to set the mask layer's transform. So this uses the base VolumeInfo // to do just that. if (!SetMaskLayer(session, idt, ref volumeInfo)) { return(false); } } if (!session.CookNode(inputNodeID, false)) { Debug.LogError("New input node failed to cook!"); return(false); } return(true); }