GetString() public static method

Get the string value of the given string handle.
public static GetString ( int stringHandle, HEU_SessionBase session = null ) : string
stringHandle int String handle to query.
session HEU_SessionBase
return string
Example #1
0
	/// <summary>
	/// Return the file name for the given material node's parameter.
	/// </summary>
	/// <param name="session">Current session</param>
	/// <param name="nodeID">Material node ID</param>
	/// <param name="parmInfo">Parameter on material to query</param>
	/// <returns>Given parameter's string value</returns>
	public static string GetTextureFileNameFromMaterialParam(HEU_SessionBase session, HAPI_NodeId nodeID, HAPI_ParmInfo parmInfo)
	{
	    string textureFileName = "default_texture.png";

	    HAPI_StringHandle stringValue;
	    string paramName = HEU_SessionManager.GetString(parmInfo.nameSH, session);
	    if (session.GetParmStringValue(nodeID, paramName, 0, true, out stringValue))
	    {
		string paramStrValue = HEU_SessionManager.GetString(stringValue, session);

		// The returned string needs to be cleaned up:
		// eg. opdef:/Sop/testgeometry_pighead?lowres.jpg -> Sop_testgeometry_pighead_lowres.jpg
		textureFileName = paramStrValue;

		int lastColon = textureFileName.LastIndexOf(':');
		if (lastColon > 0 && (lastColon + 1) < textureFileName.Length)
		{
		    textureFileName = textureFileName.Substring(lastColon + 1);
		}

		// Remove starting / after removing :: above
		textureFileName = textureFileName.TrimStart('/');

		textureFileName = textureFileName.Replace("?", "_");
		textureFileName = textureFileName.Replace("/", "_");

		//Debug.LogFormat("Texture File Name: {0}, {1}", paramStrValue, textureFileName);
	    }

	    return textureFileName;
	}
Example #2
0
        /// <summary>
        /// Process custom attribute with Unity script name, and attach any scripts found.
        /// </summary>
        /// <param name="session">Session to use</param>
        public void ProcessUnityScriptAttribute(HEU_SessionBase session)
        {
            if (_parts == null || _parts.Count == 0)
            {
                return;
            }

            HAPI_AttributeInfo scriptAttributeInfo = new HAPI_AttributeInfo();

            int[] scriptAttr = new int[0];

            HEU_GeneralUtility.GetAttribute(session, GeoID, 0, HEU_PluginSettings.UnityScriptAttributeName, ref scriptAttributeInfo, ref scriptAttr, session.GetAttributeStringData);
            if (scriptAttributeInfo.exists)
            {
                if (scriptAttributeInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_DETAIL)
                {
                    Debug.LogWarningFormat("Houdini Engine for Unity only supports {0} as detail attributes!", HEU_PluginSettings.UnityScriptAttributeName);
                }
                else if (scriptAttr.Length > 0)
                {
                    string scriptToAttach = HEU_SessionManager.GetString(scriptAttr[0]);
                    AttachScriptWithInvokeFunction(scriptToAttach);
                }
            }
        }
		public static List<HEU_Handle> FindOrGenerateHandles(HEU_SessionBase session, ref HAPI_AssetInfo assetInfo, HAPI_NodeId assetID, string assetName, HEU_Parameters parameters, List<HEU_Handle> currentHandles)
		{
			List<HEU_Handle> newHandles = new List<HEU_Handle>();

			if (assetInfo.handleCount == 0)
			{
				return newHandles;
			}

			HAPI_HandleInfo[] handleInfos = new HAPI_HandleInfo[assetInfo.handleCount];
			HEU_GeneralUtility.GetArray1Arg(assetID, session.GetHandleInfo, handleInfos, 0, assetInfo.handleCount);

			for (int i = 0; i < handleInfos.Length; ++i)
			{
				if (handleInfos[i].bindingsCount <= 0)
				{
					continue;
				}

				string handleName = HEU_SessionManager.GetString(handleInfos[i].nameSH, session);

				HEU_Handle.HEU_HandleType handleType = HEU_Handle.HEU_HandleType.UNSUPPORTED;
				string handleTypeString = HEU_SessionManager.GetString(handleInfos[i].typeNameSH, session);
				if (handleTypeString.Equals(HEU_Defines.HAPI_HANDLE_TRANSFORM))
				{
					handleType = HEU_Handle.HEU_HandleType.XFORM;
				}
				else
				{
					// Commented out warning as it gets annoying, especially with "Curve" handles
					//Debug.LogWarningFormat("Asset {0} has unsupported Handle type {0} for handle {1}", assetName, handleName, handleTypeString);
					continue;
				}

				HEU_Handle newHandle = null;
				foreach (HEU_Handle curHandle in currentHandles)
				{
					if (curHandle.HandleName.Equals(handleName))
					{
						newHandle = curHandle;
						break;
					}
				}

				if (newHandle == null)
				{
					newHandle = ScriptableObject.CreateInstance<HEU_Handle>();
				}

				bool bSuccess = newHandle.SetupHandle(session, assetID, i, handleName, handleType, ref handleInfos[i], parameters);
				if (bSuccess)
				{
					newHandles.Add(newHandle);
					//Debug.LogFormat("Found handle {0} of type {1}", handleName, handleTypeString);
				}
			}

			return newHandles;
		}
        public void Initialize(HEU_SessionBase session, HAPI_GeoInfo geoInfo, HEU_ObjectNode containerObjectNode)
        {
            _containerObjectNode = containerObjectNode;
            _geoInfo             = geoInfo;
            _geoName             = HEU_SessionManager.GetString(_geoInfo.nameSH, session);

            //Debug.Log(string.Format("GeoNode initialized with ID={0}, name={1}, type={2}", GeoID, GeoName, geoInfo.type));
        }
	public virtual bool DoAssetLoad()
	{
	    string assetPath = _filePath;
	    if (!HEU_Platform.DoesFileExist(assetPath))
	    {
		assetPath = HEU_AssetDatabase.GetValidAssetPath(assetPath);
	    }

	    HAPI_NodeId libraryID = -1;
	    HAPI_NodeId newNodeID = -1;

	    byte[] buffer = null;
	    bool bResult = HEU_Platform.LoadFileIntoMemory(assetPath, out buffer);
	    if (bResult)
	    {
		if (!_session.LoadAssetLibraryFromMemory(buffer, true, out libraryID))
		{
		    HEU_Logger.LogErrorFormat("Unable to load asset library.");
		    return false;
		}
		//HEU_Logger.Log("Loaded asset");

		int assetCount = 0;
		bResult = _session.GetAvailableAssetCount(libraryID, out assetCount);
		if (!bResult)
		{
		    return false;
		}

		int[] assetNameLengths = new int[assetCount];
		bResult = _session.GetAvailableAssets(libraryID, ref assetNameLengths, assetCount);
		if (!bResult)
		{
		    return false;
		}

		string[] assetNames = new string[assetCount];
		for (int i = 0; i < assetCount; ++i)
		{
		    assetNames[i] = HEU_SessionManager.GetString(assetNameLengths[i], _session);
		}

		// Create top level node. Note that CreateNode will cook the node if HAPI was initialized with threaded cook setting on.
		string topNodeName = assetNames[0];
		bResult = _session.CreateNode(-1, topNodeName, "", false, out newNodeID);
		if (!bResult)
		{
		    return false;
		}
		//HEU_Logger.Log("Created asset node");

		_loadData._cookNodeID = newNodeID;
	    }

	    return true;
	}
Example #6
0
		public void UpdateLayerFromPart(HEU_SessionBase session, HEU_PartData part)
		{
			HEU_GeoNode geoNode = part.ParentGeoNode;

			HAPI_VolumeInfo volumeInfo = new HAPI_VolumeInfo();
			bool bResult = session.GetVolumeInfo(geoNode.GeoID, part.PartID, ref volumeInfo);
			if (!bResult || volumeInfo.tupleSize != 1 || volumeInfo.zLength != 1 || volumeInfo.storage != HAPI_StorageType.HAPI_STORAGETYPE_FLOAT)
			{
				return;
			}

			string volumeName = HEU_SessionManager.GetString(volumeInfo.nameSH, session);
			part.SetVolumeLayerName(volumeName);

			//Debug.LogFormat("Part name: {0}, GeoName: {1}, Volume Name: {2}, Display: {3}", part.PartName, geoNode.GeoName, volumeName, geoNode.Displayable);

			bool bHeightPart = volumeName.Equals("height");

			HEU_VolumeLayer layer = GetLayer(volumeName);
			if (layer == null)
			{
				layer = new HEU_VolumeLayer();
				layer._layerName = volumeName;

				if (bHeightPart)
				{
					_layers.Insert(0, layer);
				}
				else
				{
					_layers.Add(layer);
				}
			}

			layer._part = part;

			GetPartLayerAttributes(session, geoNode.GeoID, part.PartID, layer);

			if (!bHeightPart)
			{
				part.DestroyAllData();
			}

			if (!_updatedLayers.Contains(layer))
			{
				if (bHeightPart)
				{
					_updatedLayers.Insert(0, layer);
				}
				else
				{
					_updatedLayers.Add(layer);
				}
			}
		}
Example #7
0
	public void SyncFromParameters(HEU_SessionBase session, HEU_HoudiniAsset parentAsset)
	{
	    HAPI_NodeInfo geoNodeInfo = new HAPI_NodeInfo();
	    if (!session.GetNodeInfo(_geoID, ref geoNodeInfo))
	    {
		return;
	    }

	    if (_parameters != null)
	    {
		_parameters.CleanUp();
	    }
	    else
	    {
		_parameters = ScriptableObject.CreateInstance<HEU_Parameters>();
	    }

	    string geoNodeName = HEU_SessionManager.GetString(geoNodeInfo.nameSH, session);
	    _parameters._uiLabel = geoNodeName.ToUpper() + " PARAMETERS";

	    bool bResult = _parameters.Initialize(session, _geoID, ref geoNodeInfo, null, null, parentAsset);
	    if (!bResult)
	    {
		Debug.LogWarningFormat("Parameter generate failed for geo node {0}.", geoNodeInfo.id);
		_parameters.CleanUp();
		return;
	    }

	    _points.Clear();
	    string pointList = _parameters.GetStringFromParameter(HEU_Defines.CURVE_COORDS_PARAM);
	    if (!string.IsNullOrEmpty(pointList))
	    {
		string[] pointSplit = pointList.Split(' ');
		foreach (string str in pointSplit)
		{
		    string[] vecSplit = str.Split(',');
		    if (vecSplit.Length == 3)
		    {
			_points.Add(new Vector3(-System.Convert.ToSingle(vecSplit[0], System.Globalization.CultureInfo.InvariantCulture),
				System.Convert.ToSingle(vecSplit[1], System.Globalization.CultureInfo.InvariantCulture),
				System.Convert.ToSingle(vecSplit[2], System.Globalization.CultureInfo.InvariantCulture)));
		    }
		}
	    }

	    // Since we just reset / created new our parameters and sync'd, we also need to 
	    // get the preset from Houdini session
	    if (!HEU_EditorUtility.IsEditorPlaying() && IsEditable())
	    {
		DownloadPresetData(session);
	    }
	}
Example #8
0
	private void SyncWithObjectInfo(HEU_SessionBase session)
	{
	    string realName = HEU_SessionManager.GetString(_objectInfo.nameSH, session);
	    if (!HEU_PluginSettings.ShortenFolderPaths || realName.Length < 3)
	    {
		_objName = realName;
	    }
	    else
	    {
		_objName = realName.Substring(0, 3) + this.GetHashCode();
	    }
	    
	}
	public static int GetParameterIndexFromName(HEU_SessionBase session, HAPI_ParmInfo[] parameters, string parameterName)
	{
	    if (parameters != null && parameters.Length > 0)
	    {
		int numParameters = parameters.Length;
		for (int i = 0; i < numParameters; ++i)
		{
		    if (HEU_SessionManager.GetString(parameters[i].nameSH, session).Equals(parameterName))
		    {
			return i;
		    }
		}
	    }
	    return -1;
	}
	/// <summary>
	/// Returns null if the given image info supports a Unity friendly image format.
	/// Otherwise returns a file format that we know Unity supports.
	/// </summary>
	/// <param name="imageInfo">Image info containing the current image file format</param>
	/// <returns></returns>
	internal static string GetSupportedFileFormat(HEU_SessionBase session, ref HAPI_ImageInfo imageInfo)
	{
	    string desiredFileFormatName = null;

	    string imageInfoFileFormat = HEU_SessionManager.GetString(imageInfo.imageFileFormatNameSH, session);

	    if (!imageInfoFileFormat.Equals(HEU_HAPIConstants.HAPI_PNG_FORMAT_NAME)
		    && !imageInfoFileFormat.Equals(HEU_HAPIConstants.HAPI_JPEG_FORMAT_NAME)
		    && !imageInfoFileFormat.Equals(HEU_HAPIConstants.HAPI_BMP_FORMAT_NAME)
		    && !imageInfoFileFormat.Equals(HEU_HAPIConstants.HAPI_TGA_FORMAT_NAME))
	    {
		desiredFileFormatName = HEU_HAPIConstants.HAPI_PNG_FORMAT_NAME;
	    }
	    return desiredFileFormatName;
	}
Example #11
0
        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);
        }
Example #12
0
		private void UpdateVolumeLayers(HEU_SessionBase session, HEU_HoudiniAsset houdiniAsset, List<HEU_PartData> volumeParts)
		{
			bool bResult;
			foreach (HEU_PartData part in volumeParts)
			{
				HEU_GeoNode geoNode = part.ParentGeoNode;

				HAPI_VolumeInfo volumeInfo = new HAPI_VolumeInfo();
				bResult = session.GetVolumeInfo(geoNode.GeoID, part.PartID, ref volumeInfo);
				if (!bResult || volumeInfo.tupleSize != 1 || volumeInfo.zLength != 1 || volumeInfo.storage != HAPI_StorageType.HAPI_STORAGETYPE_FLOAT)
				{
					continue;
				}

				string volumeName = HEU_SessionManager.GetString(volumeInfo.nameSH, session);
				part.SetVolumeLayerName(volumeName);

				//Debug.LogFormat("Part name: {0}, GeoName: {1}, Volume Name: {2}, Display: {3}", part.PartName, geoNode.GeoName, volumeName, geoNode.Displayable);

				bool bHeightPart = volumeName.Equals("height");

				HEU_VolumeLayer layer = GetLayer(volumeName);
				if (layer == null)
				{
					layer = new HEU_VolumeLayer();
					layer._layerName = volumeName;

					layer._splatTexture = LoadDefaultSplatTexture();

					if (bHeightPart)
					{
						_layers.Insert(0, layer);
					}
					else
					{
						_layers.Add(layer);
					}
				}

				layer._part = part;

				if (!bHeightPart)
				{
					part.DestroyAllData();
				}
			}
		}
Example #13
0
		/// <summary>
		/// Returns the Unity script attribute value, if found, on the specified geo's part.
		/// The attribute must be of string type, and owned by detail.
		/// </summary>
		/// <param name="session">Session that the asset resides in</param>
		/// <param name="geoID">The geo node's ID</param>
		/// <param name="partID">The part's ID</param>
		/// <returns>The name of the Unity script, or null if not found</returns>
		public static string GetUnityScriptAttributeValue(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID)
		{
			HAPI_AttributeInfo scriptAttributeInfo = new HAPI_AttributeInfo();
			int[] scriptAttr = new int[0];
			string scriptString = null;

			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_PluginSettings.UnityScriptAttributeName, ref scriptAttributeInfo, ref scriptAttr, session.GetAttributeStringData);
			if (scriptAttributeInfo.exists)
			{
				if (scriptAttr.Length > 0)
				{
					scriptString = HEU_SessionManager.GetString(scriptAttr[0]);
				}
			}

			return scriptString;
		}
        internal void Initialize(HEU_SessionBase session, HAPI_GeoInfo geoInfo, HEU_ObjectNode containerObjectNode)
        {
            _containerObjectNode = containerObjectNode;
            _geoInfo             = geoInfo;

            string realName = HEU_SessionManager.GetString(_geoInfo.nameSH, session);

            if (!HEU_PluginSettings.ShortenFolderPaths || realName.Length < 3)
            {
                _geoName = HEU_SessionManager.GetString(_geoInfo.nameSH, session);
            }
            else
            {
                _geoName = realName.Substring(0, 3) + this.GetHashCode();
            }

            //HEU_Logger.Log(string.Format("GeoNode initialized with ID={0}, name={1}, type={2}", GeoID, GeoName, geoInfo.type));
        }
Example #15
0
		public bool GenerateInstancerBuffers(HEU_SessionBase session, HAPI_NodeId nodeID, List<HAPI_PartInfo> instancerParts,
			out List<HEU_LoadBufferInstancer> instancerBuffers)
		{
			instancerBuffers = null;
			if (instancerParts.Count == 0)
			{
				return true;
			}

			instancerBuffers = new List<HEU_LoadBufferInstancer>();

			foreach (HAPI_PartInfo partInfo in instancerParts)
			{
				HAPI_NodeId geoID = nodeID;
				HAPI_PartId partID = partInfo.id;
				string partName = HEU_SessionManager.GetString(partInfo.nameSH, session);

				HEU_LoadBufferInstancer newBuffer = null;
				if (partInfo.instancedPartCount > 0)
				{
					// Part instancer
					newBuffer = GeneratePartsInstancerBuffer(session, geoID, partID, partName, partInfo);
				}
				else if (partInfo.vertexCount == 0 && partInfo.pointCount > 0)
				{
					// Point attribute instancer
					newBuffer = GeneratePointAttributeInstancerBuffer(session, geoID, partID, partName, partInfo);
				}
				else
				{
					SetLog(HEU_LoadData.LoadStatus.ERROR, string.Format("Invalid instanced part count: {0} for part {1}", partInfo.instancedPartCount, partName));
					continue;
				}

				if (newBuffer != null)
				{
					instancerBuffers.Add(newBuffer);
				}
			}

			return true;
		}
		/// <summary>
		/// Returns the Unity script attribute value, if found, on the specified geo's part.
		/// The attribute must be of string type, and owned by detail.
		/// </summary>
		/// <param name="session">Session that the asset resides in</param>
		/// <param name="geoID">The geo node's ID</param>
		/// <param name="partID">The part's ID</param>
		/// <returns>The name of the Unity script, or null if not found</returns>
		public static string GetUnityScriptAttributeValue(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID)
		{
			HAPI_AttributeInfo scriptAttributeInfo = new HAPI_AttributeInfo();
			int[] scriptAttr = new int[0];
			string scriptString = null;

			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_PluginSettings.UnityScriptAttributeName, ref scriptAttributeInfo, ref scriptAttr, session.GetAttributeStringData);
			if (scriptAttributeInfo.exists)
			{
				if (scriptAttributeInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_DETAIL)
				{
					Debug.LogWarningFormat("Houdini Engine for Unity only supports {0} as detail attributes!", HEU_PluginSettings.UnityScriptAttributeName);
				}
				else if (scriptAttr.Length > 0)
				{
					scriptString = HEU_SessionManager.GetString(scriptAttr[0]);
				}
			}

			return scriptString;
		}
	// GEOMETRY GETTERS -------------------------------------------------------------------------------------------

	public static string GetUniqueMaterialShopName(HAPI_NodeId assetID, HAPI_NodeId materialID)
	{
	    HEU_SessionBase sessionBase = GetOrCreateDefaultSession();
	    if (sessionBase != null)
	    {
		HAPI_AssetInfo assetInfo = new HAPI_AssetInfo();
		if (!sessionBase.GetAssetInfo(assetID, ref assetInfo))
		{
		    return "";
		}

		HAPI_MaterialInfo materialInfo = new HAPI_MaterialInfo();
		if (!sessionBase.GetMaterialInfo(materialID, ref materialInfo))
		{
		    return "";
		}

		HAPI_NodeInfo assetNodeInfo = new HAPI_NodeInfo();
		if (!sessionBase.GetNodeInfo(assetID, ref assetNodeInfo))
		{
		    return "";
		}

		HAPI_NodeInfo materialNodeInfo = new HAPI_NodeInfo();
		if (!sessionBase.GetNodeInfo(materialInfo.nodeId, ref materialNodeInfo))
		{
		    return "";
		}

		string assetNodeName = HEU_SessionManager.GetString(assetNodeInfo.internalNodePathSH, sessionBase);
		string materialNodeName = HEU_SessionManager.GetString(materialNodeInfo.internalNodePathSH, sessionBase);
		if (assetNodeName.Length > 0 && materialNodeName.Length > 0)
		{
		    // Remove assetNodeName from materialNodeName. Extra position is for separator.
		    string materialName = materialNodeName.Substring(assetNodeName.Length + 1);
		    return materialName.Replace("/", "_");
		}
	    }
	    return "";
	}
		/// <summary>
		/// Assign the Unity tag to the GameObject if found on the part as attribute.
		/// </summary>
		public static void AssignUnityTag(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, GameObject gameObject)
		{
			HAPI_AttributeInfo tagAttrInfo = new HAPI_AttributeInfo();
			int[] tagAttr = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_PluginSettings.UnityTagAttributeName, ref tagAttrInfo, ref tagAttr, session.GetAttributeStringData);
			if (tagAttrInfo.exists)
			{
				string tag = HEU_SessionManager.GetString(tagAttr[0]);
				if (tag.Length > 0)
				{
					try
					{
						SetTag(gameObject, tag, true);
					}
					catch (Exception ex)
					{
						Debug.LogWarning("Tag exception: " + ex.ToString());
						Debug.LogWarningFormat("Unity tag '{0}' does not exist for current project. Add the tag in order to use it!", tag);
					}
				}
			}
		}
	public static int FindTextureParamByNameOrTag(HEU_SessionBase session, HAPI_NodeId nodeID, HAPI_ParmInfo[] parameters, string parameterName, string useTextureParmName)
	{
	    int outParmId = GetParameterIndexFromNameOrTag(session, nodeID, parameters, parameterName);
	    if (outParmId < 0)
	    {
		return outParmId;
	    }

	    // Check if the matching "use" parameter exists.
	    int foundUseParmId = GetParameterIndexFromNameOrTag(session, nodeID, parameters, useTextureParmName);
	    if (foundUseParmId >= 0)
	    {
		// Found a valid "use" parameter. Check if it is disabled.
		int[] useValue = new int[1];
		int intValuesIndex = parameters[foundUseParmId].intValuesIndex;

		if (session.GetParamIntValues(nodeID, useValue, parameters[foundUseParmId].intValuesIndex, 1))
		{
		    if (useValue.Length > 0 && useValue[0] == 0)
		    {
			// We found the texture, but the use tag is disabled, so don't use it!
			return -1;
		    }
		}
	    }

	    // Finally, make sure that the found texture parm is not empty!
	    int[] parmValueHandle = new int[1];
	    if (session.GetParamStringValues(nodeID, parmValueHandle, parameters[outParmId].stringValuesIndex, 1))
	    {
		string parmValue = HEU_SessionManager.GetString(parmValueHandle[0], session);
		if (string.IsNullOrEmpty(parmValue))
		{
		    return -1;
		}
	    }

	    return outParmId;
	}
		/// <summary>
		/// Assign Unity layer to the GameObject if found on the part as attribute.
		/// </summary>
		/// <param name="session"></param>
		/// <param name="geoID"></param>
		/// <param name="partID"></param>
		/// <param name="gameObject"></param>
		public static void AssignUnityLayer(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, GameObject gameObject)
		{
			HAPI_AttributeInfo layerAttrInfo = new HAPI_AttributeInfo();
			int[] layerAttr = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_PluginSettings.UnityLayerAttributeName, ref layerAttrInfo, ref layerAttr, session.GetAttributeStringData);
			if (layerAttrInfo.exists)
			{
				string layerStr = HEU_SessionManager.GetString(layerAttr[0]);
				if (layerStr.Length > 0)
				{
					int layer = LayerMask.NameToLayer(layerStr);
					if (layer < 0)
					{
						Debug.LogWarningFormat("Unity layer '{0}' does not exist for current project. Add the layer in order to use it!", layerStr);
					}
					else
					{
						HEU_GeneralUtility.SetLayer(gameObject, layer, true);
					}
				}
			}
		}
	/// <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;
	}
Example #22
0
		/// <summary>
		/// Returns the single string value from Attribute with given name and owner type, or null if failed.
		/// </summary>
		/// <param name="session">Houdini Engine session to query</param>
		/// <param name="geoID">The geometry ID in Houdini</param>
		/// <param name="partID">The part ID in Houdini</param>
		/// <param name="attrName">Name of the attribute to query</param>
		/// <param name="attrOwner">Owner type of the attribute</param>
		/// <returns>Valid string if successful, otherwise returns null</returns>
		public static string GetAttributeStringValueSingle(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attrName, HAPI_AttributeOwner attrOwner)
		{
			if (string.IsNullOrEmpty(attrName))
			{
				return null;
			}

			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			int[] stringHandle = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, attrName, ref attrInfo, ref stringHandle, session.GetAttributeStringData);
			if (attrInfo.exists)
			{
				if (attrInfo.owner != attrOwner)
				{
					Debug.LogWarningFormat("Expected {0} attribute owner for attribute {1} but got {2}!", attrOwner, attrName, attrInfo.owner);
				}
				else if (stringHandle.Length > 0)
				{
					return HEU_SessionManager.GetString(stringHandle[0]);
				}
			}
			return null;
		}
Example #23
0
		private void ParseVolumeDatas(HEU_SessionBase session, List<HEU_PartData> volumeParts)
		{
			bool bResult;
			foreach (HEU_PartData part in volumeParts)
			{
				HEU_GeoNode geoNode = part.ParentGeoNode;

				HAPI_VolumeInfo volumeInfo = new HAPI_VolumeInfo();
				bResult = session.GetVolumeInfo(geoNode.GeoID, part.PartID, ref volumeInfo);
				if(!bResult || volumeInfo.tupleSize != 1 || volumeInfo.zLength != 1 || volumeInfo.storage != HAPI_StorageType.HAPI_STORAGETYPE_FLOAT)
				{
					continue;
				}

				string volumeName = HEU_SessionManager.GetString(volumeInfo.nameSH, session);

				//Debug.LogFormat("Part name: {0}, GeoName: {1}, Volume Name: {2}, Display: {3}", part.PartName, geoNode.GeoName, volumeName, geoNode.Displayable);

				if(volumeName.Equals("height"))
				{
					if (_heightMapVolumeData == null)
					{
						_heightMapVolumeData = new HEU_VolumeData();
						_heightMapVolumeData._partData = part;
						_heightMapVolumeData._volumeInfo = volumeInfo;
					}
				}
				else
				{
					HEU_VolumeData volumeData = new HEU_VolumeData();
					volumeData._partData = part;
					volumeData._volumeInfo = volumeInfo;
					_textureVolumeDatas.Add(volumeData);
				}
			}
		}
        /// <summary>
        /// Process the part at the given index, creating its data (geometry),
        /// and adding it to the list of parts.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="partID"></param>
        /// <returns>A valid HEU_PartData if it has been successfully processed.</returns>
        private void ProcessPart(HEU_SessionBase session, int partID, ref HAPI_PartInfo partInfo, ref HEU_PartData partData)
        {
            HEU_HoudiniAsset parentAsset = ParentAsset;
            bool             bResult     = true;

            //Debug.LogFormat("Part: name={0}, id={1}, type={2}, instanced={3}, instance count={4}, instance part count={5}", HEU_SessionManager.GetString(partInfo.nameSH, session), partID, partInfo.type, partInfo.isInstanced, partInfo.instanceCount, partInfo.instancedPartCount);

#if HEU_PROFILER_ON
            float processPartStartTime = Time.realtimeSinceStartup;
#endif

            bool isPartEditable    = IsIntermediateOrEditable();
            bool isAttribInstancer = false;

            if (IsGeoInputType())
            {
                // Setup for input node to accept inputs
                if (_inputNode == null)
                {
                    string partName = HEU_SessionManager.GetString(partInfo.nameSH, session);
                    _inputNode = HEU_InputNode.CreateSetupInput(GeoID, 0, partName, HEU_InputNode.InputNodeType.NODE, ParentAsset);
                    if (_inputNode != null)
                    {
                        ParentAsset.AddInputNode(_inputNode);
                    }
                }

                if (HEU_HAPIUtility.IsSupportedPolygonType(partInfo.type) && partInfo.vertexCount == 0)
                {
                    // No geometry for input asset

                    if (partData != null)
                    {
                        // Clean up existing part
                        HEU_PartData.DestroyPart(partData);
                        partData = null;
                    }

                    // No need to process further since we don't have geometry
                    return;
                }
            }
            else
            {
                // Preliminary check for attribute instancing (mesh type with no verts but has points with instances)
                if (HEU_HAPIUtility.IsSupportedPolygonType(partInfo.type) && partInfo.vertexCount == 0 && partInfo.pointCount > 0)
                {
                    HAPI_AttributeInfo instanceAttrInfo = new HAPI_AttributeInfo();
                    HEU_GeneralUtility.GetAttributeInfo(session, GeoID, partID, HEU_PluginSettings.UnityInstanceAttr, ref instanceAttrInfo);
                    if (instanceAttrInfo.exists && instanceAttrInfo.count > 0)
                    {
                        isAttribInstancer = true;
                    }
                }
            }

            if (partInfo.type == HAPI_PartType.HAPI_PARTTYPE_INVALID)
            {
                // Clean up invalid parts
                if (partData != null)
                {
                    HEU_PartData.DestroyPart(partData);
                    partData = null;
                }
            }
            else if (partInfo.type < HAPI_PartType.HAPI_PARTTYPE_MAX)
            {
                // Process the part based on type. Keep or ignore.

                // We treat parts of type curve as curves, along with geo nodes that are editable and type curves
                if (partInfo.type == HAPI_PartType.HAPI_PARTTYPE_CURVE)
                {
                    if (partData == null)
                    {
                        partData = ScriptableObject.CreateInstance <HEU_PartData>();
                    }

                    partData.Initialize(session, partID, GeoID, _containerObjectNode.ObjectID, this, ref partInfo,
                                        HEU_PartData.PartOutputType.CURVE, isPartEditable, _containerObjectNode.IsInstancer(), false);
                    SetupGameObjectAndTransform(partData, parentAsset);
                    partData.ProcessCurvePart(session);
                }
                else if (partInfo.type == HAPI_PartType.HAPI_PARTTYPE_VOLUME)
                {
                    // We only process "height" volume parts. Other volume parts are ignored for now.

#if TERRAIN_SUPPORTED
                    HAPI_VolumeInfo volumeInfo = new HAPI_VolumeInfo();
                    bResult = session.GetVolumeInfo(GeoID, partID, ref volumeInfo);
                    if (!bResult)
                    {
                        Debug.LogErrorFormat("Unable to get volume info for geo node {0} and part {1} ", GeoID, partID);
                    }
                    else
                    {
                        if (Displayable && !IsIntermediateOrEditable())
                        {
                            if (partData == null)
                            {
                                partData = ScriptableObject.CreateInstance <HEU_PartData>();
                            }
                            else
                            {
                                // Clear volume data (case where switching from polygonal mesh to volume output)
                                partData.ClearGeneratedMeshOutput();
                            }

                            partData.Initialize(session, partID, GeoID, _containerObjectNode.ObjectID, this, ref partInfo,
                                                HEU_PartData.PartOutputType.VOLUME, isPartEditable, _containerObjectNode.IsInstancer(), false);
                            SetupGameObjectAndTransform(partData, ParentAsset);
                        }
                    }
#else
                    Debug.LogWarningFormat("Terrain (heightfield volume) is not yet supported.");
#endif
                }
                else if (partInfo.type == HAPI_PartType.HAPI_PARTTYPE_INSTANCER || isAttribInstancer)
                {
                    if (partData == null)
                    {
                        partData = ScriptableObject.CreateInstance <HEU_PartData>();
                    }
                    else
                    {
                        partData.ClearGeneratedMeshOutput();
                        partData.ClearGeneratedVolumeOutput();
                    }

                    partData.Initialize(session, partID, GeoID, _containerObjectNode.ObjectID, this, ref partInfo,
                                        HEU_PartData.PartOutputType.INSTANCER, isPartEditable, _containerObjectNode.IsInstancer(), isAttribInstancer);
                    SetupGameObjectAndTransform(partData, parentAsset);
                }
                else if (HEU_HAPIUtility.IsSupportedPolygonType(partInfo.type))
                {
                    if (partData == null)
                    {
                        partData = ScriptableObject.CreateInstance <HEU_PartData>();
                    }
                    else
                    {
                        // Clear volume data (case where switching from something other output to mesh)
                        partData.ClearGeneratedVolumeOutput();
                    }

                    partData.Initialize(session, partID, GeoID, _containerObjectNode.ObjectID, this, ref partInfo,
                                        HEU_PartData.PartOutputType.MESH, isPartEditable, _containerObjectNode.IsInstancer(), false);

                    // This check allows to ignore editable non-display nodes by default, but commented out to allow
                    // them for now. Users can also ignore them by turning on IgnoreNonDisplayNodes
                    //if (Displayable || (Editable && ParentAsset.EditableNodesToolsEnabled))
                    {
                        SetupGameObjectAndTransform(partData, parentAsset);
                    }
                }
                else
                {
                    Debug.LogWarningFormat("Unsupported part type {0}", partInfo.type);
                }

                if (partData != null)
                {
                    // Success!
                    _parts.Add(partData);

                    // Set unique name for the part
                    string partName = HEU_PluginSettings.UseFullPathNamesForOutput ? GeneratePartFullName(partData.PartName) : partData.PartName;
                    partData.SetGameObjectName(partName);

                    // For intermediate or default-type editable nodes, setup the HEU_AttributeStore
                    if (isPartEditable)
                    {
                        partData.SyncAttributesStore(session, _geoInfo.nodeId, ref partInfo);
                    }
                    else
                    {
                        // Remove attributes store if it has it
                        partData.DestroyAttributesStore();
                    }
                }
            }

#if HEU_PROFILER_ON
            Debug.LogFormat("PART PROCESS TIME:: NAME={0}, TIME={1}", HEU_SessionManager.GetString(partInfo.nameSH, session), (Time.realtimeSinceStartup - processPartStartTime));
#endif
        }
        public void UpdateGeo(HEU_SessionBase session)
        {
            // Create or recreate parts.

            bool bObjectInstancer = _containerObjectNode.IsInstancer();

            // Save list of old parts. We'll destroy these after creating new parts.
            // The reason for temporarily keeping these is to transfer data (eg. instance overrides, attribute data)
            List <HEU_PartData> oldParts = new List <HEU_PartData>(_parts);

            _parts.Clear();

            try
            {
                if (!_geoInfo.isDisplayGeo)
                {
                    if (ParentAsset.IgnoreNonDisplayNodes)
                    {
                        return;
                    }
                    else if (!_geoInfo.isEditable ||
                             (_geoInfo.type != HAPI_GeoType.HAPI_GEOTYPE_DEFAULT &&
                              _geoInfo.type != HAPI_GeoType.HAPI_GEOTYPE_INTERMEDIATE &&
                              _geoInfo.type != HAPI_GeoType.HAPI_GEOTYPE_CURVE))
                    {
                        return;
                    }
                }

                if (IsGeoCurveType())
                {
                    ProcessGeoCurve(session);
                }
                else
                {
                    int numParts = _geoInfo.partCount;
                    //Debug.Log("Number of parts: " + numParts);
                    //Debug.LogFormat("GeoNode type {0}, isTemplated: {1}, isDisplayGeo: {2}, isEditable: {3}", _geoInfo.type, _geoInfo.isTemplated, _geoInfo.isDisplayGeo, _geoInfo.isEditable);
                    for (int i = 0; i < numParts; ++i)
                    {
                        HAPI_PartInfo partInfo = new HAPI_PartInfo();
                        if (!session.GetPartInfo(GeoID, i, ref partInfo))
                        {
                            Debug.LogErrorFormat("Unable to get PartInfo for geo node {0} and part {1}.", GeoID, i);
                            continue;
                        }

                        // Find the old part for this new part.
                        HEU_PartData part           = null;
                        HEU_PartData oldMatchedPart = null;

                        foreach (HEU_PartData oldPart in oldParts)
                        {
                            string partName = HEU_SessionManager.GetString(partInfo.nameSH, session);
                            if (oldPart.PartName.Equals(partName))
                            {
                                oldMatchedPart = oldPart;
                            }
                        }

                        if (oldMatchedPart != null)
                        {
                            //Debug.Log("Found matched part: " + oldMatchedPart.name);

                            List <HEU_ObjectInstanceInfo> sourceObjectInstanceInfos = null;
                            if (bObjectInstancer)
                            {
                                // ProcessPart will clear out the object instances, so hence why
                                // we keep a copy here, then restore after processing the parts.
                                sourceObjectInstanceInfos = oldMatchedPart.GetObjectInstanceInfos();
                            }

                            // Clear out old generated data
                            oldMatchedPart.ClearGeneratedData();

                            part = oldMatchedPart;
                            oldParts.Remove(oldMatchedPart);

                            ProcessPart(session, i, ref partInfo, ref part);

                            if (part != null && bObjectInstancer && sourceObjectInstanceInfos != null)
                            {
                                // Set object instances from old part into new. This keeps the user set object inputs around.
                                part.SetObjectInstanceInfos(sourceObjectInstanceInfos);
                            }
                        }
                        else
                        {
                            ProcessPart(session, i, ref partInfo, ref part);
                        }
                    }
                }
            }
            finally
            {
                HEU_PartData.DestroyParts(oldParts);
            }
        }
Example #26
0
		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);
		}
Example #27
0
		public void SyncAllAttributesFrom(HEU_SessionBase session, HEU_HoudiniAsset asset, HAPI_NodeId geoID, ref HAPI_PartInfo partInfo, GameObject outputGameObject)
		{
			_geoID = geoID;
			_partID = partInfo.id;

			HAPI_GeoInfo geoInfo = new HAPI_GeoInfo();
			if(session.GetGeoInfo(_geoID, ref geoInfo))
			{
				_geoName = HEU_SessionManager.GetString(geoInfo.nameSH, session);
			}

			if (outputGameObject != null)
			{
				_outputTransform = outputGameObject.transform;
			}

			// Need the vertex list of indices to map the positions to vertex colors
			_vertexIndices = new int[partInfo.vertexCount];
			if (!HEU_GeneralUtility.GetArray2Arg(geoID, partInfo.id, session.GetVertexList, _vertexIndices, 0, partInfo.vertexCount))
			{
				return;
			}

			// Note that this currently only supports point attributes
			int attributePointCount = partInfo.attributeCounts[(int)HAPI_AttributeOwner.HAPI_ATTROWNER_POINT];
			string[] pointAttributeNames = new string[attributePointCount];
			if(!session.GetAttributeNames(geoID, partInfo.id, HAPI_AttributeOwner.HAPI_ATTROWNER_POINT, ref pointAttributeNames, attributePointCount))
			{
				Debug.LogErrorFormat("Failed to sync attributes. Unable to retrieve attribute names.");
				return;
			}

			// Create new list of attributes. We'll move existing attributes that are still in use as we find them.
			List<HEU_AttributeData> newAttributeDatas = new List<HEU_AttributeData>();

			foreach (string pointAttributeName in pointAttributeNames)
			{
				if(string.IsNullOrEmpty(pointAttributeName))
				{
					continue;
				}

				// Get position attribute values separately. Used for painting and editing points in 3D scene.
				HAPI_AttributeInfo pointAttributeInfo = new HAPI_AttributeInfo();
				if(session.GetAttributeInfo(geoID, partInfo.id, pointAttributeName, HAPI_AttributeOwner.HAPI_ATTROWNER_POINT, ref pointAttributeInfo))
				{
					if (pointAttributeName.Equals(HEU_Defines.HAPI_ATTRIB_POSITION))
					{
						if (pointAttributeInfo.storage != HAPI_StorageType.HAPI_STORAGETYPE_FLOAT)
						{
							Debug.LogErrorFormat("Expected float type for position attribute, but got {0}", pointAttributeInfo.storage);
							return;
						}

						_positionAttributeValues = new Vector3[pointAttributeInfo.count];
						float[] data = new float[0];
						HEU_GeneralUtility.GetAttribute(session, geoID, partInfo.id, pointAttributeName, ref pointAttributeInfo, ref data, session.GetAttributeFloatData);
						for (int i = 0; i < pointAttributeInfo.count; ++i)
						{
							_positionAttributeValues[i] = new Vector3(-data[i * pointAttributeInfo.tupleSize + 0], data[i * pointAttributeInfo.tupleSize + 1], data[i * pointAttributeInfo.tupleSize + 2]);
						}

						// We don't let position attributes be editted (for now anyway)
						continue;
					}


					HEU_AttributeData attrData = GetAttributeData(pointAttributeName);
					if (attrData == null)
					{
						// Attribute data not found. Create it.

						attrData = CreateAttribute(pointAttributeName, ref pointAttributeInfo);
						//Debug.LogFormat("Created attribute data: {0}", pointAttributeName);
					}

					// Add to new list.
					newAttributeDatas.Add(attrData);

					// Sync the attribute info to data.
					PopulateAttributeData(session, geoID, partInfo.id, attrData, ref pointAttributeInfo);

					if(pointAttributeName.Equals(HEU_Defines.HAPI_ATTRIB_COLOR) || pointAttributeInfo.typeInfo == HAPI_AttributeTypeInfo.HAPI_ATTRIBUTE_TYPE_COLOR)
					{
						_hasColorAttribute = true;
					}
				}
				else
				{
					// Failed to get point attribute info!
				}
			}

			// Overwriting the old list with the new should automatically remove unused attribute datas.
			_attributeDatas = newAttributeDatas;
		}
Example #28
0
		//  LOGIC -----------------------------------------------------------------------------------------------------

		public bool SetupHandle(HEU_SessionBase session, HAPI_NodeId assetID, int handleIndex, string handleName, 
			HEU_HandleType handleType, ref HAPI_HandleInfo handleInfo, HEU_Parameters parameters)
		{
			_handleIndex = handleIndex;
			_handleName = handleName;
			_handleType = handleType;

			HAPI_HandleBindingInfo[] handleBindingInfos = new HAPI_HandleBindingInfo[handleInfo.bindingsCount];
			if (!session.GetHandleBindingInfo(assetID, _handleIndex, handleBindingInfos, 0, handleInfo.bindingsCount))
			{
				return false;
			}

			HAPI_ParmId translateParmID = -1;
			HAPI_ParmId rotateParmID = -1;
			HAPI_ParmId scaleParmID = -1;
			HAPI_ParmId rstOrderParmID = -1;
			HAPI_ParmId xyzOrderParmID = -1;

			_rstOrder = HAPI_RSTOrder.HAPI_SRT;
			_xyzOrder = HAPI_XYZOrder.HAPI_XYZ;

			_handleParamTranslateBinding = null;
			_handleParamRotateBinding = null;
			_handleParamScaleBinding = null;

			for (int i = 0; i < handleBindingInfos.Length; ++i)
			{
				string parmName = HEU_SessionManager.GetString(handleBindingInfos[i].handleParmNameSH, session);

				//string assetParmName = HEU_SessionManager.GetString(handleBindingInfos[i].assetParmNameSH, session);
				//Debug.LogFormat("Handle {0} has parm {1} with asset parm {2} with asset parm id {3}", handleName, parmName, assetParmName, handleBindingInfos[i].assetParmId);

				if (parmName.Equals("tx") || parmName.Equals("ty") || parmName.Equals("tz"))
				{
					translateParmID = handleBindingInfos[i].assetParmId;

					if(_handleParamTranslateBinding == null)
					{
						HEU_ParameterData parmData = parameters.GetParameterWithParmID(translateParmID);
						if (parmData != null && !parmData._parmInfo.invisible)
						{
							_handleParamTranslateBinding = new HEU_HandleParamBinding();
							_handleParamTranslateBinding._paramType = HEU_HandleParamBinding.HEU_HandleParamType.TRANSLATE;
							_handleParamTranslateBinding._parmID = parmData.ParmID;
							_handleParamTranslateBinding._paramName = parmData._name;
							_handleParamTranslateBinding._bDisabled = parmData._parmInfo.disabled;
						}
					}

					if(_handleParamTranslateBinding != null)
					{
						if(parmName.Equals("tx"))
						{
							_handleParamTranslateBinding._boundChannels[0] = true;
						}
						else if (parmName.Equals("ty"))
						{
							_handleParamTranslateBinding._boundChannels[1] = true;
						}
						else if (parmName.Equals("tz"))
						{
							_handleParamTranslateBinding._boundChannels[2] = true;
						}
					}
				}

				if (parmName.Equals("rx") || parmName.Equals("ry") || parmName.Equals("rz"))
				{
					rotateParmID = handleBindingInfos[i].assetParmId;

					if(_handleParamRotateBinding == null)
					{
						HEU_ParameterData parmData = parameters.GetParameterWithParmID(rotateParmID);
						if (parmData != null && !parmData._parmInfo.invisible)
						{
							_handleParamRotateBinding = new HEU_HandleParamBinding();
							_handleParamRotateBinding._paramType = HEU_HandleParamBinding.HEU_HandleParamType.ROTATE;
							_handleParamRotateBinding._parmID = parmData.ParmID;
							_handleParamRotateBinding._paramName = parmData._name;
							_handleParamRotateBinding._bDisabled = parmData._parmInfo.disabled;
						}
					}

					if (_handleParamRotateBinding != null)
					{
						if (parmName.Equals("rx"))
						{
							_handleParamRotateBinding._boundChannels[0] = true;
						}
						else if (parmName.Equals("ry"))
						{
							_handleParamRotateBinding._boundChannels[1] = true;
						}
						else if (parmName.Equals("rz"))
						{
							_handleParamRotateBinding._boundChannels[2] = true;
						}
					}
				}

				if (parmName.Equals("sx") || parmName.Equals("sy") || parmName.Equals("sz"))
				{
					scaleParmID = handleBindingInfos[i].assetParmId;

					if (_handleParamScaleBinding == null)
					{
						HEU_ParameterData parmData = parameters.GetParameterWithParmID(scaleParmID);
						if (parmData != null && !parmData._parmInfo.invisible)
						{
							_handleParamScaleBinding = new HEU_HandleParamBinding();
							_handleParamScaleBinding._paramType = HEU_HandleParamBinding.HEU_HandleParamType.SCALE;
							_handleParamScaleBinding._parmID = parmData.ParmID;
							_handleParamScaleBinding._paramName = parmData._name;
							_handleParamScaleBinding._bDisabled = parmData._parmInfo.disabled;
						}
					}

					if (_handleParamScaleBinding != null)
					{
						if (parmName.Equals("sx"))
						{
							_handleParamScaleBinding._boundChannels[0] = true;
						}
						else if (parmName.Equals("sy"))
						{
							_handleParamScaleBinding._boundChannels[1] = true;
						}
						else if (parmName.Equals("sz"))
						{
							_handleParamScaleBinding._boundChannels[2] = true;
						}
					}
				}

				if(parmName.Equals("trs_order"))
				{
					rstOrderParmID = handleBindingInfos[i].assetParmId;
				}

				if (parmName.Equals("xyz_order"))
				{
					xyzOrderParmID = handleBindingInfos[i].assetParmId;
				}
			}

			if (rstOrderParmID >= 0)
			{
				HEU_ParameterData parmData = parameters.GetParameter(rstOrderParmID);
				if (parmData != null)
				{
					_rstOrder = (HAPI_RSTOrder)parmData._intValues[0];
				}
			}

			if (xyzOrderParmID >= 0)
			{
				HEU_ParameterData parmData = parameters.GetParameter(xyzOrderParmID);
				if (parmData != null)
				{
					_xyzOrder = (HAPI_XYZOrder)parmData._intValues[0];
				}
			}

			GenerateTransform(session, parameters);

			return true;
		}
	/// <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>
	public void LoadResults(HEU_SessionBase session, HEU_TOPNodeData topNode, HAPI_PDG_WorkitemInfo workItemInfo, HAPI_PDG_WorkitemResultInfo[] resultInfos, HAPI_PDG_WorkitemId workItemID)
	{
	    // Create HEU_GeoSync objects, set results, and sync it

	    string workItemName = HEU_SessionManager.GetString(workItemInfo.nameSH, session);
	    //Debug.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;
	    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);


		//Debug.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 = new GameObject(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 = new GameObject(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);
		geoSync.StartSync();
	    }
	}
	/// <summary>
	/// Given TOP nodes from a TOP network, populate internal state from each TOP node.
	/// </summary>
	/// <param name="session">Houdini Engine session</param>
	/// <param name="topNetwork">TOP network to query TOP nodes from</param>
	/// <param name="topNodeIDs">List of TOP nodes in the TOP network</param>
	/// <param name="useHEngineData">Whether or not to use HEngine data for filtering</param>
	/// <returns>True if successfully populated data</returns>
	public static bool PopulateTOPNodes(HEU_SessionBase session, HEU_TOPNetworkData topNetwork, HAPI_NodeId[] topNodeIDs, bool useHEngineData)
	{
	    // Holds list of found TOP nodes
	    List<HEU_TOPNodeData> newNodes = new List<HEU_TOPNodeData>();

	    foreach (HAPI_NodeId topNodeID in topNodeIDs)
	    {
		// Not necessary. Blocks main thread.
		//session.CookNode(childNodeID, HEU_PluginSettings.CookTemplatedGeos);

		HAPI_NodeInfo childNodeInfo = new HAPI_NodeInfo();
		if (!session.GetNodeInfo(topNodeID, ref childNodeInfo))
		{
		    return false;
		}

		string nodeName = HEU_SessionManager.GetString(childNodeInfo.nameSH, session);
		//Debug.LogFormat("TOP Node: name={0}, type={1}", nodeName, childNodeInfo.type);

		TOPNodeTags tags = new TOPNodeTags();
		if (useHEngineData)
		{
		    ParseHEngineData(session, topNodeID, ref childNodeInfo, ref tags);

		    if (!tags._show)
		    {
			continue;
		    }
		}
		else
		{
		    tags._show = true;
		}

		HEU_TOPNodeData topNodeData = GetTOPNodeByName(nodeName, topNetwork._topNodes);
		if (topNodeData == null)
		{
		    topNodeData = new HEU_TOPNodeData();
		}
		else
		{
		    topNetwork._topNodes.Remove(topNodeData);
		}

		newNodes.Add(topNodeData);

		//topNodeData.Reset();
		topNodeData._nodeID = topNodeID;
		topNodeData._nodeName = nodeName;
		topNodeData._parentName = topNetwork._parentName + "_" + topNetwork._nodeName;
		topNodeData._tags = tags;
	    }

	    // Clear old unused TOP nodes
	    for (int i = 0; i < topNetwork._topNodes.Count; ++i)
	    {
		ClearTOPNodeWorkItemResults(topNetwork._topNodes[i]);
	    }
	    topNetwork._topNodes = newNodes;

	    // Get list of updated TOP node names
	    topNetwork._topNodeNames = new string[topNetwork._topNodes.Count];
	    for (int i = 0; i < topNetwork._topNodes.Count; ++i)
	    {
		topNetwork._topNodeNames[i] = topNetwork._topNodes[i]._nodeName;
	    }

	    return true;
	}