/// <summary> /// Do the geometry loading in Houdini in a thread. /// Creates a file node, loads the bgeo, then retrives the geometry into local buffers. /// </summary> protected override void DoWork() { _loadData._loadStatus = HEU_LoadData.LoadStatus.STARTED; //Debug.LogFormat("DoWork: Loading {0}", _filePath); if (_session == null || !_session.IsSessionValid()) { SetLog(HEU_LoadData.LoadStatus.ERROR, "Invalid session!"); return; } // Check file path if (!HEU_Platform.DoesPathExist(_filePath)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("File not found at {0}", _filePath)); return; } #if true // Make sure file type is supported //if (!_filePath.EndsWith(".bgeo") && !_filePath.EndsWith(".bgeo.sc")) //{ // SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Only .bgeo or .bgeo.sc files are supported.")); // return; //} // Create file SOP if (_loadData._fileNodeID == HEU_Defines.HEU_INVALID_NODE_ID) { if (!CreateFileNode(out _loadData._fileNodeID)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to create file node in Houdini.")); return; } } Sleep(); HAPI_NodeId displayNodeID = GetDisplayNodeID(_loadData._fileNodeID); if (displayNodeID == HEU_Defines.HEU_INVALID_NODE_ID) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to get display node of file geo node.")); return; } // Set the file parameter if (!SetFileParm(displayNodeID, _filePath)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to set file path parm.")); return; } // Cooking it will load the bgeo if (!_session.CookNode(_loadData._fileNodeID, false)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to cook node.")); return; } // Wait until cooking has finished bool bResult = true; HAPI_State statusCode = HAPI_State.HAPI_STATE_STARTING_LOAD; while (bResult && statusCode > HAPI_State.HAPI_STATE_MAX_READY_STATE) { bResult = _session.GetStatus(HAPI_StatusType.HAPI_STATUS_COOK_STATE, out statusCode); Sleep(); } // Check cook results for any errors if (statusCode == HAPI_State.HAPI_STATE_READY_WITH_COOK_ERRORS || statusCode == HAPI_State.HAPI_STATE_READY_WITH_FATAL_ERRORS) { string statusString = _session.GetStatusString(HAPI_StatusType.HAPI_STATUS_COOK_RESULT, HAPI_StatusVerbosity.HAPI_STATUSVERBOSITY_ERRORS); SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Cook failed: {0}.", statusString)); return; } #else // Load the file using HAPI_LoadGeoFromFile if (_loadData._fileNodeID == HEU_Defines.HEU_INVALID_NODE_ID) { Debug.Log("Creating file node with path: " + _filePath); if (!_session.CreateNode(-1, "SOP/file", "loadfile", true, out _loadData._fileNodeID)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to create geo SOP in Houdini.")); return; } if (!_session.LoadGeoFromFile(_loadData._fileNodeID, _filePath)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to create file node in Houdini.")); return; } } HAPI_NodeId displayNodeID = GetDisplayNodeID(_loadData._fileNodeID); #endif // Note that object instancing is not supported. Instancers currently supported are // part and point instancing. // Get the various types of geometry (parts) from the display node List<HAPI_PartInfo> meshParts = new List<HAPI_PartInfo>(); List<HAPI_PartInfo> volumeParts = new List<HAPI_PartInfo>(); List<HAPI_PartInfo> instancerParts = new List<HAPI_PartInfo>(); List<HAPI_PartInfo> curveParts = new List<HAPI_PartInfo>(); List<HAPI_PartInfo> scatterInstancerParts = new List<HAPI_PartInfo>(); if (!QueryParts(displayNodeID, ref meshParts, ref volumeParts, ref instancerParts, ref curveParts, ref scatterInstancerParts)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to query parts on node.")); return; } Sleep(); // Create Unity mesh buffers if (!GenerateMeshBuffers(_session, displayNodeID, meshParts, _generateOptions._splitPoints, _generateOptions._useLODGroups, _generateOptions._generateUVs, _generateOptions._generateTangents, _generateOptions._generateNormals, out _loadData._meshBuffers)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to generate mesh data from parts.")); return; } // Create Unity terrain buffers if (!GenerateTerrainBuffers(_session, displayNodeID, volumeParts, scatterInstancerParts, out _loadData._terrainBuffers)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to generate terrain data from volume parts.")); return; } // Create instancers (should come after normal geometry has been generated above) if (!GenerateInstancerBuffers(_session, displayNodeID, instancerParts, out _loadData._instancerBuffers)) { SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Unable to generate data from instancer parts.")); return; } SetLog(HEU_LoadData.LoadStatus.SUCCESS, "Completed!"); }
public static void LoadShelves() { bool bSaveShelf = false; _shelves.Clear(); // Always add the default shelf HEU_Shelf defaultShelf = AddShelf(HEU_Defines.HEU_HENGINE_SHIPPED_SHELF, HEU_Defines.HEU_HENGINE_TOOLS_SHIPPED_FOLDER); defaultShelf._defaultShelf = true; List<string> shelfEntries = HEU_PluginSettings.HEngineToolsShelves; if (shelfEntries == null || shelfEntries.Count == 0) { shelfEntries = new List<string>(); } // Convert shelf path + name to actual shelf objects int numShelves = shelfEntries.Count; for (int i = 0; i < numShelves; i++) { string shelfName = ""; string shelfPath = ""; GetSplitShelfEntry(shelfEntries[i], out shelfName, out shelfPath); // Ignore default shelf because we added it already if (shelfPath.Equals(HEU_Defines.HEU_HENGINE_TOOLS_SHIPPED_FOLDER)) { continue; } if (!string.IsNullOrEmpty(shelfName) && !string.IsNullOrEmpty(shelfPath)) { HEU_Shelf newShelf = new HEU_Shelf(); newShelf._shelfName = shelfName; newShelf._shelfPath = shelfPath; _shelves.Add(newShelf); } else { Debug.LogWarningFormat("Found invalid shelf with entry: {0}", shelfEntries[i]); shelfEntries.RemoveAt(i); i--; bSaveShelf = true; } } foreach (HEU_Shelf shelf in _shelves) { string realShelfPath = HEU_HAPIUtility.GetRealPathFromHFSPath(shelf._shelfPath); if (!HEU_Platform.DoesPathExist(realShelfPath)) { Debug.LogWarningFormat("Shelf path does not exist: {0}", realShelfPath); } else { bool bShelfLoaded = LoadToolsFromDirectory(realShelfPath, out shelf._tools); if (!bShelfLoaded) { Debug.LogWarningFormat("Failed to load shelf {0} at path {1}", shelf._shelfName, realShelfPath); } } } _currentSelectedShelf = HEU_PluginSettings.HEngineShelfSelectedIndex; if (_currentSelectedShelf < 0 || _currentSelectedShelf >= _shelves.Count) { _currentSelectedShelf = 0; HEU_PluginSettings.HEngineShelfSelectedIndex = _currentSelectedShelf; } if (bSaveShelf) { SaveShelf(); } _shelvesLoaded = true; }
/// <summary> /// Returns true if file or folder at inPath exists. Supports inPath with environment mapped values /// such as <HFS> or $. /// </summary> /// <param name="inPath">Path to check. Could be either file or folder.</param> /// <returns>True if file or folder exists</returns> public static bool DoesMappedPathExist(string inPath) { string realPath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(inPath); return(HEU_Platform.DoesPathExist(realPath)); }