Contains all the attributes for an editable node (part). Addtionally contains attribute-editing tools data such as temporary mesh and collider.
Inheritance: ScriptableObject
Ejemplo n.º 1
0
		private void SetSelectedAttributeStore(HEU_AttributesStore newStore)
		{
			if (_selectedAttributesStore == newStore)
			{
				return;
			}

			if (_selectedAttributesStore != null)
			{
				_selectedAttributesStore.DisablePaintCollider();
			}

			_selectedAttributesStore = null;
			DestroyEditPointBoxMesh();

			if (newStore != null)
			{
				SerializedObject serializedObject = GetOrCreateSerializedAttributesStore(newStore);
				_selectedAttributesStore = serializedObject.targetObject as HEU_AttributesStore;
			}

			if (_interactionMode == ToolInteractionMode.EDIT)
			{
				UpdateShowOnlyEditGeometry();
			}
			else if (_interactionMode == ToolInteractionMode.PAINT)
			{
				if (_selectedAttributesStore != null)
				{
					_selectedAttributesStore.EnablePaintCollider();
				}
			}
		}
Ejemplo n.º 2
0
		private void ClearCache()
		{
			if (_toolsInfoSerializedObject != null)
			{
				SerializedProperty isPaintingProperty = HEU_EditorUtility.GetSerializedProperty(_toolsInfoSerializedObject, "_isPainting");
				PaintingFinished(isPaintingProperty);
			}

			_selectedAttributesStore = null;
			_selectedAttributeData = null;

			_attributesStores.Clear();
			_serializedAttributesStoresCache.Clear();

			if(_editPointBoxMaterial != null)
			{
				HEU_MaterialFactory.DestroyNonAssetMaterial(_editPointBoxMaterial, false);
				_editPointBoxMaterial = null;
			}

			DestroyEditPointBoxMesh();

			_dragMouseDown = false;

			_asset = null;

			_toolsInfo = null;
		}
Ejemplo n.º 3
0
	private void ChangePaintMeshVisiblity(HEU_ToolsInfo.PaintMeshVisibility visiblity)
	{
	    _toolsInfo._paintMeshVisiblity = visiblity;
	    UpdatePaintMeshVisibility();

	    _GUIChanged = true;
	    HEU_AttributesStore.SetAttributeDataDirty(_selectedAttributeData);
	}
Ejemplo n.º 4
0
		private SerializedObject GetOrCreateSerializedAttributesStore(HEU_AttributesStore attributesStore)
		{
			SerializedObject serializedAttributesStore = null;
			if (!_serializedAttributesStoresCache.TryGetValue(attributesStore, out serializedAttributesStore))
			{
				serializedAttributesStore = new SerializedObject(attributesStore);
				_serializedAttributesStoresCache.Add(attributesStore, serializedAttributesStore);
			}
			return serializedAttributesStore;
		}
Ejemplo n.º 5
0
		public void CopyAttributeValuesTo(HEU_AttributesStore destAttrStore)
		{
			foreach(HEU_AttributeData attrData in _attributeDatas)
			{
				HEU_AttributeData destAttrData = destAttrStore.GetAttributeData(attrData._name);
				if(destAttrStore != null)
				{
					attrData.CopyValuesTo(destAttrData);
					SetAttributeDataDirty(destAttrData);
				}
			}
		}
Ejemplo n.º 6
0
		public void CacheAttributesStores()
		{
			_attributesStores.Clear();
			foreach (Object targetObject in targets)
			{
				HEU_AttributesStore attributeStore = targetObject as HEU_AttributesStore;
				if (attributeStore != null)
				{
					_attributesStores.Add(attributeStore);
				}
			}
		}
Ejemplo n.º 7
0
		public void FillAttribute(HEU_AttributeData attributeData, HEU_ToolsInfo sourceTools)
		{
			if(attributeData._attributeState == HEU_AttributeData.AttributeState.INVALID)
			{
				return;
			}

			HEU_AttributesStore.SetAttributeValueFunc setAttrFunc = HEU_AttributesStore.GetAttributeSetValueFunction(attributeData._attributeType, sourceTools._paintMergeMode);
			if (setAttrFunc == null)
			{
				return;
			}

			int tupleSize = attributeData._attributeInfo.tupleSize;
			int count = attributeData._attributeInfo.count;
			for (int pt = 0; pt < count; ++pt)
			{
				setAttrFunc(attributeData, pt * tupleSize, sourceTools, 0, sourceTools._paintBrushOpacity);
			}

			SetAttributeDataDirty(attributeData);
		}
Ejemplo n.º 8
0
		private void DrawEditAttributeValues()
		{
			if(_selectedAttributeData == null)
			{
				return;
			}

			if(_editPointsSelectedIndices.Count == 0)
			{
				return;
			}

			int arraySize = _selectedAttributeData._attributeInfo.tupleSize;

			// Use first values found as current values
			int ptIndex = _editPointsSelectedIndices[0] * arraySize;

			// Display values of selected pts which can be edited
			if (_selectedAttributeData._attributeType == HEU_AttributeData.AttributeType.INT)
			{
				// Copy values to display
				int[] values = new int[arraySize];
				for (int i = 0; i < arraySize; ++i)
				{
					values[i] = _selectedAttributeData._intValues[ptIndex + i];
				}

				// Display values and update attribute if changed
				bool bChanged = HEU_EditorUI.DrawArray<int>(_editValuesLabel, ref values, HEU_EditorUI.DrawFieldInt);
				if (bChanged)
				{
					int numPts = _editPointsSelectedIndices.Count;
					for (int i = 0; i < numPts; ++i)
					{
						ptIndex = _editPointsSelectedIndices[i] * arraySize;

						HEU_AttributesStore.SetAttributeEditValueInt(_selectedAttributeData, ptIndex, values);
					}

					_GUIChanged = true;

					HEU_AttributesStore.SetAttributeDataDirty(_selectedAttributeData);
				}
			}
			else if (_selectedAttributeData._attributeType == HEU_AttributeData.AttributeType.FLOAT)
			{
				// Copy values to display
				float[] values = new float[arraySize];
				for(int i = 0; i < arraySize; ++i)
				{
					values[i] = _selectedAttributeData._floatValues[ptIndex + i];
				}

				// Display values and update attribute if changed
				bool bChanged = HEU_EditorUI.DrawArray<float>(_editValuesLabel, ref values, HEU_EditorUI.DrawFieldFloat);
				if (bChanged)
				{
					int numPts = _editPointsSelectedIndices.Count;
					for (int i = 0; i < numPts; ++i)
					{
						ptIndex = _editPointsSelectedIndices[i] * arraySize;

						HEU_AttributesStore.SetAttributeEditValueFloat(_selectedAttributeData, ptIndex, values);
					}

					_GUIChanged = true;

					HEU_AttributesStore.SetAttributeDataDirty(_selectedAttributeData);
				}
			}
			else if (_selectedAttributeData._attributeType == HEU_AttributeData.AttributeType.STRING)
			{
				// Copy values to display
				string[] values = new string[arraySize];
				for (int i = 0; i < arraySize; ++i)
				{
					values[i] = _selectedAttributeData._stringValues[ptIndex + i];
				}

				// Display values and update attribute if changed
				bool bChanged = HEU_EditorUI.DrawArray<string>(_editValuesLabel, ref values, HEU_EditorUI.DrawFieldString);
				if (bChanged)
				{
					int numPts = _editPointsSelectedIndices.Count;
					for (int i = 0; i < numPts; ++i)
					{
						ptIndex = _editPointsSelectedIndices[i] * arraySize;

						HEU_AttributesStore.SetAttributeEditValueString(_selectedAttributeData, ptIndex, values);
					}

					_GUIChanged = true;

					HEU_AttributesStore.SetAttributeDataDirty(_selectedAttributeData);
				}
			}
		}
Ejemplo n.º 9
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;
				}
			}
		}
Ejemplo n.º 10
0
		private void HandlePaintEvent(RaycastHit hit, float brushRadius, HEU_ToolsInfo.PaintMergeMode paintMergeMode)
		{
			if(_selectedAttributesStore == null || _selectedAttributeData == null)
			{
				return;
			}

			HEU_AttributesStore.SetAttributeValueFunc setAttrFunc = HEU_AttributesStore.GetAttributeSetValueFunction(_selectedAttributeData._attributeType, paintMergeMode);
			if(setAttrFunc == null)
			{
				return;
			}

			Vector3[] positionArray = new Vector3[0];
			_selectedAttributesStore.GetPositionAttributeValues(out positionArray);

			int[] indices = new int[0];
			_selectedAttributesStore.GetVertexIndices(out indices);

			int numPositions = positionArray.Length;
			if (positionArray != null && numPositions > 0 && indices != null && indices.Length > 0)
			{
				Vector3 localHitPoint = _selectedAttributesStore.OutputTransform.InverseTransformPoint(hit.point);

				Mesh mesh = _selectedAttributesStore.OutputMesh;
				Color[] colors = mesh.colors;

				for (int posIndex = 0; posIndex < numPositions; ++posIndex)
				{
					float distance = Vector3.Distance(localHitPoint, positionArray[posIndex]);
					if (distance <= brushRadius)
					{
						float paintFactor = Mathf.Abs((brushRadius - distance) / brushRadius) * _toolsInfo._paintBrushOpacity;

						// Update the attribute
						_selectedAttributesStore.PaintAttribute(_selectedAttributeData, _toolsInfo, posIndex, paintFactor, setAttrFunc);

						// Get the paint color
						Color paintColor = _toolsInfo._affectedAreaPaintColor;
						if (_selectedAttributeData.IsColorAttribute())
						{
							if (_selectedAttributeData._attributeInfo.tupleSize >= 3 && _toolsInfo._paintFloatValue.Length >= 3)
							{
								paintColor.r = _toolsInfo._paintFloatValue[0];
								paintColor.g = _toolsInfo._paintFloatValue[1];
								paintColor.b = _toolsInfo._paintFloatValue[2];

								if (_selectedAttributeData._attributeInfo.tupleSize >= 4 && _toolsInfo._paintFloatValue.Length >= 4)
								{
									paintColor.a = _toolsInfo._paintFloatValue[3];
								}
							}
						}

						// Update local temporary mesh to show area of effect.
						// The position index, a point attribute, must be mapped to the vertex color,
						// which is a vertex attribute, via the vertex index
						int numIndices = indices.Length;
						for(int i = 0; i < numIndices; ++i)
						{
							if(indices[i] == posIndex && i < colors.Length)
							{
								colors[i] = Color.Lerp(colors[i], paintColor, paintFactor);
							}
						}
					}
				}

				mesh.colors = colors;
			}
		}