Пример #1
0
		private void GetAttributesList(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, List<HEU_AttributeData> attributesList, HAPI_AttributeOwner ownerType, int attributeCount)
		{
			if (attributeCount > 0)
			{
				string[] attributeNames = new string[attributeCount];
				if (session.GetAttributeNames(geoID, partID, ownerType, ref attributeNames, attributeCount))
				{
					for (int i = 0; i < attributeNames.Length; ++i)
					{
						HEU_AttributeData attrData = GetAttributeData(attributeNames[i]);
						if (attrData == null)
						{
							// New attribute, so create and populate

							HAPI_AttributeInfo attributeInfo = new HAPI_AttributeInfo();
							if (!session.GetAttributeInfo(geoID, partID, attributeNames[i], ownerType, ref attributeInfo))
							{
								return;
							}

							attrData = CreateAttribute(attributeNames[i], ref attributeInfo);

							PopulateAttributeData(session, geoID, partID, attrData, ref attributeInfo);

							attributesList.Add(attrData);
						}
						else
						{
							// Existing, so just add it
							attributesList.Add(attrData);
						}
					}
				}
			}
		}
		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 static bool GetAttribute<T>(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string name, ref HAPI_AttributeInfo info, ref T[] data, GetAttributeArrayInputFunc<T> getFunc)
		{
			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 false;
			}

			if (originalTupleSize > 0)
			{
				info.tupleSize = originalTupleSize;
			}

			data = new T[info.count * info.tupleSize];
			return GetAttributeArray(geoID, partID, name, ref info, data, getFunc, info.count);
		}
        public static bool VolumeLayerHasAttributes(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID)
        {
            string[] layerAttrNames =
            {
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_DIFFUSE_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_MASK_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_NORMAL_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_NORMAL_SCALE_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_METALLIC_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SMOOTHNESS_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SPECULAR_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_OFFSET_ATTR,
                HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_SIZE_ATTR
            };

            // Check if any of the layer attribute names show up in the existing primitive attributes
            HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
            bool bResult = false;
            foreach (string layerAttr in layerAttrNames)
            {
                bResult = session.GetAttributeInfo(geoID, partID, layerAttr, HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM, ref attrInfo);
                if (bResult && attrInfo.exists)
                {
                    return true;
                }
            }

            return false;
        }
		public static bool CheckAttributeExists(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attribName, HAPI_AttributeOwner attribOwner)
		{
			HAPI_AttributeInfo attribInfo = new HAPI_AttributeInfo();
			if(session.GetAttributeInfo(geoID, partID, attribName, attribOwner, ref attribInfo))
			{
				return attribInfo.exists;
			}
			return false;
		}
Пример #6
0
 public static bool DoesGeoPartHaveAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attrName, HAPI_AttributeOwner owner, ref HAPI_AttributeInfo attributeInfo)
 {
     if (session.GetAttributeInfo(geoID, partID, attrName, owner, ref attributeInfo))
     {
         return(attributeInfo.exists);
         //Debug.LogFormat("Attr {0} exists={1}, with count={2}, type={3}, storage={4}, tuple={5}", "Cd", colorAttrInfo.exists, colorAttrInfo.count, colorAttrInfo.typeInfo, colorAttrInfo.storage, colorAttrInfo.tupleSize);
     }
     return(false);
 }
Пример #7
0
		/// <summary>
		/// Returns true if specified geometry and part has the given atttribute name.
		/// </summary>
		/// <param name="session">Houdini session to check</param>
		/// <param name="geoID">Geometry object ID</param>
		/// <param name="partID">Part ID</param>
		/// <param name="attrName">The name of the attribute to check</param>
		/// <param name="attrOwner">The owner type for the attribute</param>
		/// <returns></returns>
		public static bool HasAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attrName, HAPI_AttributeOwner attrOwner)
		{
			if (string.IsNullOrEmpty(attrName))
			{
				return false;
			}

			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			bool bResult = session.GetAttributeInfo(geoID, partID, attrName, attrOwner, ref attrInfo);
			return (bResult && attrInfo.exists);
		}
		public static bool GetAttributeInfo(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, string attribName, ref HAPI_AttributeInfo attribInfo)
		{
			bool bResult = false;
			for (HAPI_AttributeOwner type = 0; type < HAPI_AttributeOwner.HAPI_ATTROWNER_MAX; ++type)
			{
				bResult = session.GetAttributeInfo(geoID, partID, attribName, type, ref attribInfo);
				if (!bResult)
				{
					attribInfo.exists = false;
					return false;
				}
				else if(attribInfo.exists)
				{
					break;
				}
			}
			return true;
		}
		private void GetPartLayerAttributes(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_NodeId partID, HEU_VolumeLayer layer)
		{
			// Get the tile index, if it exists, for this part
			HAPI_AttributeInfo tileAttrInfo = new HAPI_AttributeInfo();
			int[] tileAttrData = new int[0];
			HEU_GeneralUtility.GetAttribute(session, geoID, partID, HEU_Defines.HAPI_HEIGHTFIELD_TILE_ATTR, ref tileAttrInfo, ref tileAttrData, session.GetAttributeIntData);
			if (tileAttrData != null && tileAttrData.Length > 0)
			{
				layer._tile = tileAttrData[0];
				//Debug.LogFormat("Tile: {0}", tileAttrData[0]);
			}
			else
			{
				layer._tile = 0;
			}


			string[] layerAttrNames =
			{
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_DIFFUSE_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_MASK_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TEXTURE_NORMAL_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_NORMAL_SCALE_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_METALLIC_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SMOOTHNESS_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_SPECULAR_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_OFFSET_ATTR,
				HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TILE_SIZE_ATTR
			};

			// Check if any of the layer attribute names show up in the existing primitive attributes
			layer._hasLayerAttributes = false;
			HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();
			bool bResult = false;
			foreach (string layerAttr in layerAttrNames)
			{
				bResult = session.GetAttributeInfo(geoID, partID, layerAttr, HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM, ref attrInfo);
				if (bResult && attrInfo.exists)
				{
					layer._hasLayerAttributes = true;
					break;
				}
			}
		}
Пример #10
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;
		}