コード例 #1
0
		private static void SetAttributeDataSyncd(HEU_AttributeData attributeData)
		{
			attributeData._attributeState = HEU_AttributeData.AttributeState.SYNCED;
		}
コード例 #2
0
		public static void SetAttributeDataDirty(HEU_AttributeData attributeData)
		{
			attributeData._attributeState = HEU_AttributeData.AttributeState.LOCAL_DIRTY;
		}
コード例 #3
0
		private void UpdateAttribute(HEU_SessionBase session, HAPI_NodeId geoID, HAPI_PartId partID, HEU_AttributeData attributeData)
		{
			int attrCount = attributeData._attributeInfo.count;

			// Presuming we are working with point attributes
			HAPI_AttributeInfo newAttrInfo = new HAPI_AttributeInfo();
			newAttrInfo.exists = true;
			newAttrInfo.owner = attributeData._attributeInfo.owner;
			newAttrInfo.storage = attributeData._attributeInfo.storage;
			newAttrInfo.count = attributeData._attributeInfo.count;
			newAttrInfo.tupleSize = attributeData._attributeInfo.tupleSize;
			newAttrInfo.originalOwner = attributeData._attributeInfo.originalOwner;

			if (!session.AddAttribute(geoID, partID, attributeData._name, ref newAttrInfo))
			{
				Debug.LogErrorFormat("Failed to add attribute: {0}", attributeData._name);
				return;
			}

			if (newAttrInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_INT)
			{
				int[] pointData = new int[attrCount * newAttrInfo.tupleSize];
				for (int j = 0; j < attrCount; ++j)
				{
					for (int tuple = 0; tuple < newAttrInfo.tupleSize; ++tuple)
					{
						pointData[j * newAttrInfo.tupleSize + tuple] = attributeData._intValues[j * newAttrInfo.tupleSize + tuple];
					}
				}
				HEU_GeneralUtility.SetAttributeArray(geoID, partID, attributeData._name, ref newAttrInfo, pointData, session.SetAttributeIntData, attrCount);
			}
			else if (newAttrInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_FLOAT)
			{
				float[] pointData = new float[attrCount * newAttrInfo.tupleSize];
				for (int j = 0; j < attrCount; ++j)
				{
					for (int tuple = 0; tuple < newAttrInfo.tupleSize; ++tuple)
					{
						pointData[j * newAttrInfo.tupleSize + tuple] = attributeData._floatValues[j * newAttrInfo.tupleSize + tuple];
					}
				}
				HEU_GeneralUtility.SetAttributeArray(geoID, partID, attributeData._name, ref newAttrInfo, pointData, session.SetAttributeFloatData, attrCount);
			}
			else if (newAttrInfo.storage == HAPI_StorageType.HAPI_STORAGETYPE_STRING)
			{
				string[] pointData = new string[attrCount * newAttrInfo.tupleSize];
				for (int j = 0; j < attrCount; ++j)
				{
					for (int tuple = 0; tuple < newAttrInfo.tupleSize; ++tuple)
					{
						pointData[j * newAttrInfo.tupleSize + tuple] = attributeData._stringValues[j * newAttrInfo.tupleSize + tuple];
					}
				}
				HEU_GeneralUtility.SetAttributeArray(geoID, partID, attributeData._name, ref newAttrInfo, pointData, session.SetAttributeStringData, attrCount);
			}
		}
コード例 #4
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);
		}
コード例 #5
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;
		}
コード例 #6
0
		private void SetSelectedAttributeData(HEU_AttributeData newAttr)
		{
			_selectedAttributeData = newAttr;
		}
コード例 #7
0
		private void DrawAttributeSelection()
		{
			// Try to re-use the last selected node
			string lastSelectedNodeName = null;
			SerializedProperty lastSelectedNodeNameProperty = HEU_EditorUtility.GetSerializedProperty(_toolsInfoSerializedObject, "_lastAttributeNodeName");
			if (lastSelectedNodeNameProperty != null)
			{
				lastSelectedNodeName = lastSelectedNodeNameProperty.stringValue;
			}

			HEU_AttributesStore foundAttributeStore = null;

			// Get the names of the all editable nodes having an attribute store for this asset
			// While doing that, we'll find the last selected attribute store
			int lastSelectedIndex = 0;
			List<string> nodeNames = new List<string>();
			foreach (HEU_AttributesStore attributeStore in _attributesStores)
			{
				string geoName = attributeStore.GeoName;
				if (!nodeNames.Contains(geoName))
				{
					nodeNames.Add(geoName);

					// Either re-select last selected node, or select the first one found
					if (string.IsNullOrEmpty(lastSelectedNodeName) || lastSelectedNodeName.Equals(geoName))
					{
						lastSelectedNodeName = geoName;
						lastSelectedIndex = nodeNames.Count - 1;
						foundAttributeStore = attributeStore;
					}
				}
			}

			// Try to re-use the last selected attribute
			string lastSelectedAttributeName = null;
			SerializedProperty lastSelectedAttributeProperty = HEU_EditorUtility.GetSerializedProperty(_toolsInfoSerializedObject, "_lastAttributeName");
			if (lastSelectedAttributeProperty != null)
			{
				lastSelectedAttributeName = lastSelectedAttributeProperty.stringValue;
			}

			// Display a dropdown list of editable nodes with attribute stores
			int currentSelectedIndex = EditorGUILayout.Popup(_editableNodeLabel, lastSelectedIndex, nodeNames.ToArray());
			if (currentSelectedIndex != lastSelectedIndex)
			{
				// User changed node selection, so update it
				lastSelectedNodeName = nodeNames[currentSelectedIndex];

				foundAttributeStore = null;

				foreach (HEU_AttributesStore attributeStore in _attributesStores)
				{
					string geoName = attributeStore.GeoName;
					if (geoName.Equals(lastSelectedNodeName))
					{
						foundAttributeStore = attributeStore;
						break;
					}
				}

				SetSelectedAttributeStore(foundAttributeStore);

				// Reset selected attribute to first attribute
				SetSelectedAttributeData(_selectedAttributesStore.GetAttributeData(0));
				lastSelectedAttributeName = _selectedAttributeData._name;
				lastSelectedAttributeProperty.stringValue = lastSelectedAttributeName;

				lastSelectedNodeNameProperty.stringValue = lastSelectedNodeName;

				_GUIChanged = true;
			}
			else
			{
				// Since selected node hasn't changed, re-use the last selected attribute

				SetSelectedAttributeStore(foundAttributeStore);

				SetSelectedAttributeData(_selectedAttributesStore.GetAttributeData(lastSelectedAttributeName));
			}

			// Get attribute names for selected node
			List<string> attributeNames = _selectedAttributesStore.GetAttributeNames();

			// Find the last selected attribute index
			int lastAttributeIndex = -1;
			if (!string.IsNullOrEmpty(lastSelectedAttributeName))
			{
				for(int i = 0; i < attributeNames.Count; ++i)
				{
					if (lastSelectedAttributeName.Equals(attributeNames[i]))
					{
						lastAttributeIndex = i;
						break;
					}
				}
			}

			// Use first attribute as default if none selected last time
			if(lastAttributeIndex == -1)
			{
				lastAttributeIndex = 0;
				HEU_AttributeData data = _selectedAttributesStore.GetAttributeData(0);
				if (data != null)
				{
					lastSelectedAttributeProperty.stringValue = data._name;
				}
			}

			// Display attributes as dropdown
			if (attributeNames.Count > 0)
			{
				int currentAttributeIndex = EditorGUILayout.Popup(_attributeLabel, lastAttributeIndex, attributeNames.ToArray());
				if (currentAttributeIndex != lastAttributeIndex)
				{
					// User changed attribute selection, so update it
					SetSelectedAttributeData(_selectedAttributesStore.GetAttributeData(attributeNames[currentAttributeIndex]));
					lastSelectedAttributeProperty.stringValue = _selectedAttributeData._name;
				}
			}
		}