GetGroupNames() public static method

Gets the group names for given group type.
public static GetGroupNames ( HEU_SessionBase session, HAPI_NodeId nodeID, HAPI_PartId partID, HAPI_GroupType groupType, bool isInstanced ) : string[]
session HEU_SessionBase
nodeID HAPI_NodeId The node ID
partID HAPI_PartId
groupType HAPI_GroupType The group type to query
isInstanced bool
return string[]
Ejemplo n.º 1
0
		public bool PopulateGeometryData(HEU_SessionBase session)
		{
			// Get vertex position
			HAPI_AttributeInfo posAttrInfo = new HAPI_AttributeInfo();
			_posAttr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_POSITION, ref posAttrInfo, ref _posAttr, session.GetAttributeFloatData);
			if (!posAttrInfo.exists)
			{
				return false;
			}
			else if (posAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT)
			{
				Debug.LogErrorFormat("{0} only supports position as POINT attribute. Position attribute of {1} type not supported!", HEU_Defines.HEU_PRODUCT_NAME, posAttrInfo.owner);
				return false;
			}

			// Get UV attributes
			_uvAttrInfo = new HAPI_AttributeInfo();
			_uvAttrInfo.tupleSize = 2;
			_uvAttr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_UV, ref _uvAttrInfo, ref _uvAttr, session.GetAttributeFloatData);

			// Get UV2 attributes
			_uv2AttrInfo = new HAPI_AttributeInfo();
			_uv2AttrInfo.tupleSize = 2;
			_uv2Attr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_UV2, ref _uv2AttrInfo, ref _uv2Attr, session.GetAttributeFloatData);

			// Get UV3 attributes
			_uv3AttrInfo = new HAPI_AttributeInfo();
			_uv3AttrInfo.tupleSize = 2;
			_uv3Attr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_UV3, ref _uv3AttrInfo, ref _uv3Attr, session.GetAttributeFloatData);

			// Get normal attributes
			_normalAttrInfo = new HAPI_AttributeInfo();
			_normalAttr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_NORMAL, ref _normalAttrInfo, ref _normalAttr, session.GetAttributeFloatData);

			// Get colour attributes
			_colorAttrInfo = new HAPI_AttributeInfo();
			_colorAttr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_COLOR, ref _colorAttrInfo, ref _colorAttr, session.GetAttributeFloatData);

			// Get alpha attributes
			_alphaAttrInfo = new HAPI_AttributeInfo();
			_alphaAttr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_ALPHA, ref _alphaAttrInfo, ref _alphaAttr, session.GetAttributeFloatData);

			// Get tangent attributes
			_tangentAttrInfo = new HAPI_AttributeInfo();
			_tangentAttr = new float[0];
			HEU_GeneralUtility.GetAttribute(session, GeoID, PartID, HEU_Defines.HAPI_ATTRIB_TANGENT, ref _tangentAttrInfo, ref _tangentAttr, session.GetAttributeFloatData);

			// Warn user since we are splitting points by attributes, might prevent some attrributes
			// to be transferred over properly
			if (_normalAttrInfo.exists && _normalAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT
									&& _normalAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_VERTEX)
			{
				Debug.LogWarningFormat("{0}: Normals are not declared as point or vertex attributes.\nSet them as per point or vertices in HDA.", _partName);
			}

			if (_tangentAttrInfo.exists && _tangentAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT
									&& _tangentAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_VERTEX)
			{
				Debug.LogWarningFormat("{0}: Tangents are not declared as point or vertex attributes.\nSet them as per point or vertices in HDA.", _partName);
			}

			if (_colorAttrInfo.exists && _colorAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_POINT
									&& _colorAttrInfo.owner != HAPI_AttributeOwner.HAPI_ATTROWNER_VERTEX)
			{
				Debug.LogWarningFormat("{0}: Colours are not declared as point or vertex attributes."
					+ "\nCurrently set as owner type {1}. Set them as per point or vertices in HDA.", _partName, _colorAttrInfo.owner);
			}

			_groups = HEU_SessionManager.GetGroupNames(GeoID, HAPI_GroupType.HAPI_GROUPTYPE_PRIM);

			_allCollisionVertexList = new int[_vertexList.Length];
			_allCollisionFaceIndices = new int[_partInfo.faceCount];

			_hasGroupGeometry = false;

			// We go through each group, building up a triangle list of indices that belong to it
			// For strictly colliders (ie. non-rendering), we only create geometry colliders 
			for (int g = 0; g < _groups.Length; ++g)
			{
				string groupName = _groups[g];

				// Query HAPI to get the group membership. 
				// This is returned as an array of 1s for vertices that belong to this group.
				int[] membership = null;
				HEU_SessionManager.GetGroupMembership(session, GeoID, PartID, HAPI_GroupType.HAPI_GROUPTYPE_PRIM, groupName, ref membership);

				bool bIsCollidable = groupName.Contains(HEU_PluginSettings.CollisionGroupName);
				bool bIsRenderCollidable = groupName.Contains(HEU_PluginSettings.RenderedCollisionGroupName);

				if (bIsCollidable || bIsRenderCollidable)
				{
					// Extract vertex indices for this collision group

					int[] groupVertexList = new int[_vertexList.Length];
					groupVertexList.Init<int>(-1);

					int groupVertexListCount = 0;

					List<int> allFaceList = new List<int>();
					for (int f = 0; f < membership.Length; ++f)
					{
						if (membership[f] > 0)
						{
							// This face is a member of the specified group

							allFaceList.Add(f);

							groupVertexList[f * 3 + 0] = _vertexList[f * 3 + 0];
							groupVertexList[f * 3 + 1] = _vertexList[f * 3 + 1];
							groupVertexList[f * 3 + 2] = _vertexList[f * 3 + 2];

							// Mark vertices as used
							_allCollisionVertexList[f * 3 + 0] = 1;
							_allCollisionVertexList[f * 3 + 1] = 1;
							_allCollisionVertexList[f * 3 + 2] = 1;

							// Mark face as used
							_allCollisionFaceIndices[f] = 1;

							groupVertexListCount += 3;
						}
					}

					if (groupVertexListCount > 0)
					{
						_groupSplitVertexIndices.Add(groupName, groupVertexList);
						_groupSplitFaceIndices.Add(groupName, allFaceList);

						_hasGroupGeometry = true;

						//Debug.Log("Adding collision group: " + groupName + " with index count: " + _groupVertexList.Length);
					}
				}
			}

			if (_hasGroupGeometry)
			{
				// Construct vertex list for all other vertices that are not part of collision geometry
				int[] remainingGroupSplitFaces = new int[_vertexList.Length];
				remainingGroupSplitFaces.Init<int>(-1);
				bool bMainSplitGroup = false;

				List<int> remainingGroupSplitFaceIndices = new List<int>();

				for (int cv = 0; cv < _allCollisionVertexList.Length; ++cv)
				{
					if (_allCollisionVertexList[cv] == 0)
					{
						// Unused index, so add it to unused vertex list
						remainingGroupSplitFaces[cv] = _vertexList[cv];
						bMainSplitGroup = true;
					}
				}

				for (int cf = 0; cf < _allCollisionFaceIndices.Length; ++cf)
				{
					if (_allCollisionFaceIndices[cf] == 0)
					{
						remainingGroupSplitFaceIndices.Add(cf);
					}
				}

				if (bMainSplitGroup)
				{
					_groupSplitVertexIndices.Add(HEU_Defines.HEU_DEFAULT_GEO_GROUP_NAME, remainingGroupSplitFaces);
					_groupSplitFaceIndices.Add(HEU_Defines.HEU_DEFAULT_GEO_GROUP_NAME, remainingGroupSplitFaceIndices);

					//Debug.Log("Adding remaining group with index count: " + remainingGroupSplitFaces.Length);
				}
			}
			else
			{
				_groupSplitVertexIndices.Add(HEU_Defines.HEU_DEFAULT_GEO_GROUP_NAME, _vertexList);

				List<int> allFaces = new List<int>();
				for (int f = 0; f < _partInfo.faceCount; ++f)
				{
					allFaces.Add(f);
				}
				_groupSplitFaceIndices.Add(HEU_Defines.HEU_DEFAULT_GEO_GROUP_NAME, allFaces);

				//Debug.Log("Adding single non-group with index count: " + _vertexList.Length);
			}

			// We'll be generating the normals if they're not provided by Houdini
			// For every vertex, we'll hold list of other vertices that it shares faces with (ie. connected to)
			_sharedNormalIndices = null;
			_cosineThreshold = 0f;
			if (!_normalAttrInfo.exists)
			{
				_sharedNormalIndices = new List<VertexEntry>[_vertexList.Length];
				_cosineThreshold = Mathf.Cos(HEU_PluginSettings.NormalGenerationThresholdAngle * Mathf.Deg2Rad);

				for (int i = 0; i < _vertexList.Length; ++i)
				{
					_sharedNormalIndices[i] = new List<VertexEntry>();
				}
			}

			return true;
		}