public static void GetAttributeStringDataHelper(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string name, ref HAPI_AttributeInfo info, ref HAPI_StringHandle[] data) { int originalTupleSize = info.tupleSize; bool bResult = false; for (HAPI_AttributeOwner type = 0; type < HAPI_AttributeOwner.HAPI_ATTROWNER_MAX; ++type) { bResult = session.GetAttributeInfo(geoID, partID, name, type, ref info); if (bResult && info.exists) { break; } } if (!bResult || !info.exists) { return; } if (originalTupleSize > 0) { info.tupleSize = originalTupleSize; } data = new HAPI_StringHandle[info.count * info.tupleSize]; bResult = session.GetAttributeStringData(geoID, partID, name, ref info, data, 0, info.count); if(!bResult) { Debug.LogErrorFormat("Failed to get string IDs for attribute {0}", name); } }
public void ReinitializePDGContext() { HEU_SessionBase session = GetHAPIPDGSession(); if (session == null || !session.IsSessionValid()) { _pdgContextIDs = null; return; } int numContexts = 0; HAPI_StringHandle[] contextNames = new HAPI_StringHandle[_pdgContextSize]; HAPI_PDG_GraphContextId[] contextIDs = new HAPI_PDG_GraphContextId[_pdgContextSize]; if (!session.GetPDGGraphContexts(out numContexts, contextNames, contextIDs, _pdgContextSize) || numContexts <= 0) { _pdgContextIDs = null; return; } if (_pdgContextIDs == null || numContexts != _pdgContextIDs.Length) { _pdgContextIDs = new HAPI_PDG_GraphContextId[numContexts]; } for (int i = 0; i < numContexts; ++i) { _pdgContextIDs[i] = contextIDs[i]; //Debug.LogFormat("PDG Context: {0} - {1}", HEU_SessionManager.GetString(contextNames[i], session), contextIDs[i]); } }
/// <summary> /// Query the currently active PDG graph contexts in the Houdini Engine session. /// Should be done each time to get latest set of graph contexts. /// </summary> public void ReinitializePDGContext() { #if HOUDINIENGINEUNITY_ENABLED HEU_SessionBase session = GetHAPIPDGSession(); if (session == null || !session.IsSessionValid()) { _pdgContextIDs = null; return; } int numContexts = 0; HAPI_StringHandle[] contextNames = new HAPI_StringHandle[_pdgContextSize]; HAPI_PDG_GraphContextId[] contextIDs = new HAPI_PDG_GraphContextId[_pdgContextSize]; if (!session.GetPDGGraphContexts(out numContexts, contextNames, contextIDs, _pdgContextSize) || numContexts <= 0) { _pdgContextIDs = null; return; } if (_pdgContextIDs == null || numContexts != _pdgContextIDs.Length) { _pdgContextIDs = new HAPI_PDG_GraphContextId[numContexts]; } // TODO: might be okay to just use _pdgContextIDs above instead of doing a copy here for (int i = 0; i < numContexts; ++i) { _pdgContextIDs[i] = contextIDs[i]; //Debug.LogFormat("PDG Context: {0} - {1}", HEU_SessionManager.GetString(contextNames[i], session), contextIDs[i]); } #endif }
public static bool LoadHDAFile(HEU_SessionBase session, string assetPath, out HAPI_NodeId assetLibraryID, out string[] assetNames) { assetLibraryID = HEU_Defines.HEU_INVALID_NODE_ID; assetNames = new string[0]; // Load the file string validAssetPath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(assetPath); if (validAssetPath != null) { assetPath = validAssetPath; HAPI_AssetLibraryId libraryID = 0; bool bResult = session.LoadAssetLibraryFromFile(assetPath, false, out libraryID); if (!bResult) { return(false); } int assetCount = 0; bResult = session.GetAvailableAssetCount(libraryID, out assetCount); if (!bResult) { return(false); } Debug.AssertFormat(assetCount > 0, "Houdini Engine: Invalid Asset Count of {0}", assetCount); HAPI_StringHandle[] assetNameLengths = new HAPI_StringHandle[assetCount]; bResult = session.GetAvailableAssets(libraryID, ref assetNameLengths, assetCount); if (!bResult) { return(false); } // Sanity check that our array hasn't changed size Debug.Assert(assetNameLengths.Length == assetCount, "Houdini Engine: Invalid Asset Names"); assetNames = new string[assetCount]; for (int i = 0; i < assetCount; ++i) { assetNames[i] = HEU_SessionManager.GetString(assetNameLengths[i]); } return(true); } return(false); }
/// <summary> /// Helper to parse spare parm containing the filter key words. /// </summary> /// <param name="session">Houdini Engine session that the TOP node is in</param> /// <param name="topNodeID">TOP node to get spare parm from</param> /// <param name="nodeInfo">Previously queried TOP node info</param> /// <param name="nodeTags">Tag data to populate</param> private static void ParseHEngineData(HEU_SessionBase session, HAPI_NodeId topNodeID, ref HAPI_NodeInfo nodeInfo, ref TOPNodeTags nodeTags) { // Turn off session logging error when querying string parm that might not be there bool bLogError = session.LogErrorOverride; session.LogErrorOverride = false; int numStrings = nodeInfo.parmStringValueCount; HAPI_StringHandle henginedatash = 0; if (numStrings > 0 && session.GetParamStringValue(topNodeID, "henginedata", 0, out henginedatash)) { string henginedatastr = HEU_SessionManager.GetString(henginedatash, session); //HEU_Logger.Log("HEngine data: " + henginedatastr); if (!string.IsNullOrEmpty(henginedatastr)) { string[] tags = henginedatastr.Split(','); if (tags != null && tags.Length > 0) { foreach (string t in tags) { if (t.Equals("show")) { nodeTags._showHEngineData = true; nodeTags._show = true; } else if (t.Equals("autoload")) { nodeTags._autoloadHEngineData = true; nodeTags._autoload = true; } } } } } // Logging error back on session.LogErrorOverride = bLogError; }
private void PopulateAttributeData(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, HEU_AttributeData attributeData, ref HAPI_AttributeInfo attributeInfo) { attributeData._attributeInfo = attributeInfo; int tupleSize = attributeInfo.tupleSize; int attributeCount = attributeInfo.count; int arraySize = attributeCount * tupleSize; // First reset arrays if the type had changed since last sync if ((attributeInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_INT && attributeData._attributeType != HEU_AttributeData.AttributeType.INT) || (attributeInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_FLOAT && attributeData._attributeType != HEU_AttributeData.AttributeType.FLOAT) || (attributeInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_STRING && attributeData._attributeType != HEU_AttributeData.AttributeType.STRING)) { // Reset arrays if type is different attributeData._floatValues = null; attributeData._stringValues = null; attributeData._intValues = null; attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; if(attributeInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_INT) { attributeData._attributeType = HEU_AttributeData.AttributeType.INT; } else if (attributeInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_FLOAT) { attributeData._attributeType = HEU_AttributeData.AttributeType.FLOAT; } else if (attributeInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_STRING) { attributeData._attributeType = HEU_AttributeData.AttributeType.STRING; } } // Make sure the internal array is correctly sized for syncing. if (attributeData._attributeType == HEU_AttributeData.AttributeType.INT) { if (attributeData._intValues == null) { attributeData._intValues = new int[arraySize]; attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; } else if (attributeData._intValues.Length != arraySize) { System.Array.Resize<int>(ref attributeData._intValues, arraySize); attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; } attributeData._floatValues = null; attributeData._stringValues = null; if (attributeData._attributeState == HEU_AttributeData.AttributeState.INVALID) { int[] data = new int[0]; HEU_GeneralUtility.GetAttribute(session, geoID, partID, attributeData._name, ref attributeInfo, ref data, session.GetAttributeIntData); for (int i = 0; i < attributeCount; ++i) { for (int tuple = 0; tuple < tupleSize; ++tuple) { attributeData._intValues[i * tupleSize + tuple] = data[i * tupleSize + tuple]; } } } } else if (attributeData._attributeType == HEU_AttributeData.AttributeType.FLOAT) { if (attributeData._floatValues == null) { attributeData._floatValues = new float[arraySize]; attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; } else if (attributeData._floatValues.Length != arraySize) { System.Array.Resize<float>(ref attributeData._floatValues, arraySize); attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; } attributeData._intValues = null; attributeData._stringValues = null; if (attributeData._attributeState == HEU_AttributeData.AttributeState.INVALID) { float[] data = new float[0]; HEU_GeneralUtility.GetAttribute(session, geoID, partID, attributeData._name, ref attributeInfo, ref data, session.GetAttributeFloatData); for (int i = 0; i < attributeCount; ++i) { for (int tuple = 0; tuple < tupleSize; ++tuple) { attributeData._floatValues[i * tupleSize + tuple] = data[i * tupleSize + tuple]; } } } } else if (attributeData._attributeType == HEU_AttributeData.AttributeType.STRING) { if (attributeData._stringValues == null) { attributeData._stringValues = new string[arraySize]; attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; } else if (attributeData._stringValues.Length != arraySize) { System.Array.Resize<string>(ref attributeData._stringValues, arraySize); attributeData._attributeState = HEU_AttributeData.AttributeState.INVALID; } attributeData._intValues = null; attributeData._floatValues = null; if (attributeData._attributeState == HEU_AttributeData.AttributeState.INVALID) { HAPI_StringHandle[] data = new HAPI_StringHandle[0]; HEU_GeneralUtility.GetAttribute(session, geoID, partID, attributeData._name, ref attributeInfo, ref data, session.GetAttributeStringData); for (int i = 0; i < attributeCount; ++i) { for (int tuple = 0; tuple < tupleSize; ++tuple) { HAPI_StringHandle stringHandle = data[i * tupleSize + tuple]; attributeData._stringValues[i * tupleSize + tuple] = HEU_SessionManager.GetString(stringHandle, session); } } } } SetAttributeDataSyncd(attributeData); }
/// <summary> /// Get the name of the given node's input. This will return a string handle for the name /// which will persisst until the next call to this function. /// </summary> /// <param name="nodeID">Node's ID</param> /// <param name="inputIndex">Index of the input</param> /// <param name="nodeNameIndex">Input name string handle</param> /// <returns>True if successfully queried the node</returns> public virtual bool GetNodeInputName(HAPI_NodeId nodeID, int inputIndex, out HAPI_StringHandle nodeNameIndex) { nodeNameIndex = 0; return false; }
/// <summary> /// Creates a node inside a node network. /// </summary> /// <param name="parentNodeID">Parent node network's node ID or -1 if at top level</param> /// /// <param name="operatorName">Name of the node operator type</param> /// <param name="nodeLabel">Label for newly created node</param> /// <param name="bCookOnCreation">Whether should cook on creation or not</param> /// <param name="newNodeID">New node's ID</param> /// <returns>True if successfully created a new node</returns> public virtual bool CreateNode(HAPI_StringHandle parentNodeID, string operatorName, string nodeLabel, bool bCookOnCreation, out HAPI_NodeId newNodeID) { newNodeID = -1; return false; }
// ASSETS ----------------------------------------------------------------------------------------------------- /// <summary> /// Load given asset file in Houdini Engine. /// </summary> /// <param name="assetPath">Path to the asset</param> /// <param name="bAllowOverwrite">Whether to overwrite an existing matching asset definition</param> /// <param name="libraryID">ID of the asset in the library</param> /// <returns>True if successfully loaded the asset.</returns> public virtual bool LoadAssetLibraryFromFile(string assetPath, bool bAllowOverwrite, out HAPI_StringHandle libraryID) { libraryID = 0; return false; }
/// <summary> /// Returns the length of the string value for the given handle. /// </summary> /// <param name="stringHandle">Handle of the string to query</param> /// <returns>Buffer of the length of the queried string.</returns> public virtual int GetStringBufferLength(HAPI_StringHandle stringHandle) { return 0; }
/// <summary> /// Get the string value for the associated string handle. /// </summary> /// <param name="stringHandle">Handle to look up.</param> /// <param name="stringBuilder">Container for return value.</param> /// <param name="bufferLength">Length of return value</param> /// <returns>True if it has successfully populated the string value.</returns> public virtual bool GetString(HAPI_StringHandle stringHandle, StringBuilder stringBuilder, int bufferLength) { return false; }
public virtual bool GetParmStringValue(HAPI_NodeId nodeID, string parmName, int index, bool evaluate, out HAPI_StringHandle value) { value = 0; return false; }
public virtual bool GetImagePlanes(HAPI_NodeId nodeID, [Out] HAPI_StringHandle[] imagePlanes, int numImagePlanes) { imagePlanes = new HAPI_StringHandle[0]; return false; }
public void PopulateUnityMaterialData(HEU_SessionBase session) { // First we look for Unity and Substance material attributes on faces. // We fill up the following dictionary with unique Unity + Substance material information _unityMaterialInfos = new Dictionary<int, HEU_UnityMaterialInfo>(); _unityMaterialAttrInfo = new HAPI_AttributeInfo(); _unityMaterialAttrName = new HAPI_StringHandle[0]; HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_PluginSettings.UnityMaterialAttribName, ref _unityMaterialAttrInfo, ref _unityMaterialAttrName, session.GetAttributeStringData); // Store a local copy of the actual string values since the indices get overwritten by the next call to session.GetAttributeStringData. // Using a dictionary to only query the unique strings, as doing all of them is very slow and unnecessary. _unityMaterialAttrStringsMap = new Dictionary<HAPI_StringHandle, string>(); foreach (HAPI_StringHandle strHandle in _unityMaterialAttrName) { if (!_unityMaterialAttrStringsMap.ContainsKey(strHandle)) { string materialName = HEU_SessionManager.GetString(strHandle, session); if (string.IsNullOrEmpty(materialName)) { // Warn user of empty string, but add it anyway to our map so we don't keep trying to parse it Debug.LogWarningFormat("Found empty material attribute value for part {0}.", _partName); } _unityMaterialAttrStringsMap.Add(strHandle, materialName); //Debug.LogFormat("Added Unity material: " + materialName); } } _substanceMaterialAttrNameInfo = new HAPI_AttributeInfo(); _substanceMaterialAttrName = new HAPI_StringHandle[0]; HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_PluginSettings.UnitySubMaterialAttribName, ref _substanceMaterialAttrNameInfo, ref _substanceMaterialAttrName, session.GetAttributeStringData); _substanceMaterialAttrStringsMap = new Dictionary<HAPI_StringHandle, string>(); foreach (HAPI_StringHandle strHandle in _substanceMaterialAttrName) { if (!_substanceMaterialAttrStringsMap.ContainsKey(strHandle)) { string substanceName = HEU_SessionManager.GetString(strHandle, session); if (string.IsNullOrEmpty(substanceName)) { // Warn user of empty string, but add it anyway to our map so we don't keep trying to parse it Debug.LogWarningFormat("Found invalid substance material attribute value ({0}) for part {1}.", _partName, substanceName); } _substanceMaterialAttrStringsMap.Add(strHandle, substanceName); //Debug.LogFormat("Added Substance material: " + substanceName); } } _substanceMaterialAttrIndexInfo = new HAPI_AttributeInfo(); _substanceMaterialAttrIndex = new int[0]; HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_PluginSettings.UnitySubMaterialIndexAttribName, ref _substanceMaterialAttrIndexInfo, ref _substanceMaterialAttrIndex, session.GetAttributeIntData); if (_unityMaterialAttrInfo.exists) { if (_unityMaterialAttrInfo.owner == HAPI_AttributeOwner.HAPI_ATTROWNER_DETAIL && _unityMaterialAttrName.Length > 0) { CreateMaterialInfoEntryFromAttributeIndex(this, 0); // Detail unity material attribute means we can treat it as single material _singleFaceUnityMaterial = true; } else { for(HAPI_StringHandle i = 0; i < _unityMaterialAttrName.Length; ++i) { CreateMaterialInfoEntryFromAttributeIndex(this, i); } } } }