Пример #1
0
		public static bool LoadToolsFromDirectory(string folderPath, out List<HEU_ShelfToolData> tools)
		{
			tools = new List<HEU_ShelfToolData>();

			string[] filePaths = HEU_Platform.GetFilesInFolder(folderPath, "*.json", true);
			bool bResult = false;
			try
			{
				if (filePaths != null)
				{
					foreach (string fileName in filePaths)
					{
						HEU_ShelfToolData tool = LoadToolFromJsonFile(fileName);
						if(tool != null)
						{
							tools.Add(tool);
						}
					}

					bResult = true;
				}
			}
			catch(System.Exception ex)
			{
				Debug.LogErrorFormat("Parsing JSON files in directory caused exception: {0}", ex);
				return false;
			}

			return bResult;
		}
Пример #2
0
		public static string GetToolResourcePath(HEU_ShelfToolData tool, string inPath, string ext)
		{
			if(string.IsNullOrEmpty(inPath) || inPath.Equals("."))
			{
				// Use same path as where json file was
				//inPath = shelf._shelfPath + HEU_Platform.DirectorySeparatorStr + 

				if (!string.IsNullOrEmpty(tool._jsonPath))
				{
					inPath = tool._jsonPath.Replace(".json", "." + ext);
				}
			}

			return inPath;
		}
Пример #3
0
		public static string GetToolAssetPath(HEU_ShelfToolData tool, string inPath)
		{
			if (string.IsNullOrEmpty(inPath) || inPath.Equals("."))
			{
				// Use same path as where json file was
				//inPath = shelf._shelfPath + HEU_Platform.DirectorySeparatorStr + 

				if (!string.IsNullOrEmpty(tool._jsonPath))
				{
					string filePath = tool._jsonPath.Replace(".json", "");
					inPath = HEU_HAPIUtility.FindHoudiniAssetFileInPathWithExt(filePath);
				}
			}

			return inPath;
		}
Пример #4
0
	public static void ExecuteTool(int toolSlot)
	{
	    if (_currentSelectedShelf < 0 && _currentSelectedShelf >= _shelves.Count)
	    {
		Debug.LogWarning("Invalid shelf selected. Unable to apply tool.");
		return;
	    }

	    if (toolSlot < 0 || toolSlot >= _shelves[_currentSelectedShelf]._tools.Count)
	    {
		Debug.LogWarning("Invalid tool selected. Unable to apply tool.");
		return;
	    }

	    HEU_ShelfToolData toolData = _shelves[_currentSelectedShelf]._tools[toolSlot];

	    GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

	    string assetPath = toolData._assetPath;

	    if (toolData._toolType == HEU_ShelfToolData.ToolType.GENERATOR)
	    {
		Matrix4x4 targetMatrix = HEU_EditorUtility.GetSelectedObjectsMeanTransform();
		Vector3 position = HEU_HAPIUtility.GetPosition(ref targetMatrix);
		Quaternion rotation = HEU_HAPIUtility.GetQuaternion(ref targetMatrix);
		Vector3 scale = HEU_HAPIUtility.GetScale(ref targetMatrix);
		scale = Vector3.one;

		ExecuteToolGenerator(toolData._name, assetPath, position, rotation, scale);
	    }
	    else if (selectedObjects.Length == 0)
	    {
		ExecuteToolNoInput(toolData._name, assetPath);
	    }
	    else if (toolData._toolType == HEU_ShelfToolData.ToolType.OPERATOR_SINGLE)
	    {
		ExecuteToolOperatorSingle(toolData._name, assetPath, selectedObjects);
	    }
	    else if (toolData._toolType == HEU_ShelfToolData.ToolType.OPERATOR_MULTI)
	    {
		ExecuteToolOperatorMultiple(toolData._name, assetPath, selectedObjects);
	    }
	    else if (toolData._toolType == HEU_ShelfToolData.ToolType.BATCH)
	    {
		ExecuteToolBatch(toolData._name, assetPath, selectedObjects);
	    }
	}
Пример #5
0
		public static HEU_ShelfToolData LoadToolFromJsonFile(string jsonFilePath)
		{
			string json = null;
			try
			{
				StreamReader fileReader = new StreamReader(jsonFilePath);
				json = fileReader.ReadToEnd();
				fileReader.Close();
			}
			catch(System.Exception ex)
			{
				Debug.LogErrorFormat("Exception while reading {0}: {1}", jsonFilePath, ex);
				return null;
			}

			HEU_ShelfToolData tool = LoadToolFromJsonString(json, jsonFilePath);
			return tool;
		}
Пример #6
0
		public static void ExecuteTool(int toolSlot)
		{
			if(toolSlot < 0 || toolSlot >= _tools.Count)
			{
				Debug.LogWarning("Invalid tool selection!");
				return;
			}

			HEU_ShelfToolData toolData = _tools[toolSlot];
			if(toolData.toolType == HEU_ShelfToolData.ToolType.GENARATOR)
			{
				Matrix4x4 targetMatrix = HEU_EditorUtility.GetSelectedObjectsMeanTransform();
				Vector3 position = HEU_HAPIUtility.GetPosition(ref targetMatrix);
				Quaternion rotation = HEU_HAPIUtility.GetQuaternion(ref targetMatrix);
				Vector3 scale = HEU_HAPIUtility.GetScale(ref targetMatrix);
				scale = Vector3.one;

				ExecuteToolGenerator(toolData.name, toolData.assetPath, position, rotation, scale);
			}
			else if(toolData.toolType == HEU_ShelfToolData.ToolType.OPERATOR_SINGLE)
			{
				GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

				ExecuteToolOperatorSingle(toolData.name, toolData.assetPath, selectedObjects);
			}
			else if (toolData.toolType == HEU_ShelfToolData.ToolType.OPERATOR_MULTI)
			{
				GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

				ExecuteToolOperatorMultiple(toolData.name, toolData.assetPath, selectedObjects);
			}
			else if (toolData.toolType == HEU_ShelfToolData.ToolType.BATCH)
			{
				GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

				ExecuteToolBatch(toolData.name, toolData.assetPath, selectedObjects);
			}
		}
Пример #7
0
		public static string GetToolIconPath(HEU_ShelfToolData tool, string inPath)
		{
			if (string.IsNullOrEmpty(inPath) || inPath.Equals("."))
			{
				// Use same path as where json file was
				if (!string.IsNullOrEmpty(tool._jsonPath))
				{
					inPath = tool._jsonPath.Replace(".json", ".png");
				}
			}

			// Replace the HFS path with <HFS>
			if (!string.IsNullOrEmpty(inPath))
			{
				string hpath = HEU_Platform.GetHoudiniEnginePath();
				if (inPath.StartsWith(hpath))
				{
					inPath = inPath.Replace(hpath, HEU_Defines.HEU_PATH_KEY_HFS);
				}
			}

			return inPath;
		}
Пример #8
0
		public static HEU_ShelfToolData LoadToolFromJsonString(string json, string jsonFilePath)
		{
			//Debug.Log("Loading json: " + jsonFilePath);

			// Get environment variable for tool path
			string envValue = HEU_Platform.GetEnvironmentValue(HEU_Defines.HEU_PATH_KEY_TOOL);
			string envKey = string.Format("<{0}>", HEU_Defines.HEU_PATH_KEY_TOOL);

			HEU_ShelfToolData toolData = null;

			if (!string.IsNullOrEmpty(json))
			{
				try
				{
					JSONNode jsonShelfNode = JSON.Parse(json);
					if (jsonShelfNode != null)
					{
						bool isObject = jsonShelfNode.IsObject;
						bool isArray = jsonShelfNode.IsArray;

						toolData = new HEU_ShelfToolData();

						toolData._name = jsonShelfNode["name"];

						toolData._toolType = (HEU_ShelfToolData.ToolType)System.Enum.Parse(typeof(HEU_ShelfToolData.ToolType), jsonShelfNode["toolType"]);

						toolData._toolTip = jsonShelfNode["toolTip"];

						toolData._iconPath = jsonShelfNode["iconPath"];

						toolData._assetPath = jsonShelfNode["assetPath"];

						toolData._helpURL = jsonShelfNode["helpURL"];

						JSONArray targetArray = jsonShelfNode["target"].AsArray;
						if(targetArray != null)
						{
							int targetCount = targetArray.Count;
							toolData._targets = new string[targetCount];
							for(int j = 0; j < targetCount; ++j)
							{
								toolData._targets[j] = targetArray[j];
							}
						}
	}
				}
				catch (System.Exception ex)
				{
					Debug.LogErrorFormat("Exception when trying to parse shelf json file at path: {0}. Exception: {1}", jsonFilePath, ex.ToString());
					return null;
				}

				toolData._jsonPath = jsonFilePath;

				if (toolData != null && !string.IsNullOrEmpty(toolData._name))
				{
					// Make sure this tool targets Unity (must have "all" or "unity" set in target field)
					bool bCompatiple = false;
					if(toolData._targets != null)
					{
						int numTargets = toolData._targets.Length;
						for(int i = 0; i < numTargets; ++i)
						{
							if (toolData._targets[i].Equals(TARGET_ALL) || toolData._targets[i].Equals(TARGET_UNITY))
							{
								bCompatiple = true;
								break;
							}
						}
					}

					if (bCompatiple)
					{
						if (!string.IsNullOrEmpty(toolData._assetPath))
						{
							toolData._assetPath = toolData._assetPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");
							if (toolData._assetPath.Contains(envKey))
							{
								if (string.IsNullOrEmpty(envValue))
								{
									Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
								}
								else
								{
									toolData._assetPath = toolData._assetPath.Replace(envKey, envValue);
								}
							}
						}
						else
						{
							toolData._assetPath = GetToolAssetPath(toolData, toolData._assetPath);
						}

						string realPath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(toolData._assetPath);
						if (!HEU_Platform.DoesFileExist(realPath))
						{
							Debug.LogErrorFormat("Houdini Engine shelf tool at {0} does not exist!", realPath);
							return null;
						}

						if (!string.IsNullOrEmpty(toolData._iconPath))
						{
							toolData._iconPath = toolData._iconPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");
							if (toolData._iconPath.Contains(envKey))
							{
								if (string.IsNullOrEmpty(envValue))
								{
									Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
								}
								else
								{
									toolData._iconPath = toolData._iconPath.Replace(envKey, envValue);
								}
							}
						}
						else
						{
							toolData._iconPath = GetToolIconPath(toolData, toolData._iconPath);
						}

						return toolData;
					}
				}
			}

			return null;
		}
Пример #9
0
		public static bool LoadToolFromJsonString(string json)
		{
			// Get environment variable for tool path
			string envValue = HEU_Platform.GetEnvironmentValue(HEU_Defines.HEU_PATH_KEY_TOOL);
			string envKey = string.Format("<{0}>", HEU_Defines.HEU_PATH_KEY_TOOL);

			if (!string.IsNullOrEmpty(json))
			{
				HEU_ShelfToolData toolData = JsonUtility.FromJson<HEU_ShelfToolData>(json);

				if(toolData != null 
					&& !string.IsNullOrEmpty(toolData.name) 
					&& !string.IsNullOrEmpty(toolData.assetPath)
					&& !string.IsNullOrEmpty(toolData.iconPath))
				{
					// Make sure this tool targets Unity (must have "all" or "unity" set in target field)
					bool bCompatiple = false;
					if(toolData.target != null)
					{
						int numTargets = toolData.target.Length;
						for(int i = 0; i < numTargets; ++i)
						{
							if (toolData.target[i].Equals(TARGET_ALL))
							{
								bCompatiple = true;
								break;
							}
							else if(toolData.target[i].Equals(TARGET_UNITY))
							{
								bCompatiple = true;
								break;
							}
						}
					}

					if (bCompatiple)
					{
						toolData.assetPath = toolData.assetPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");
						toolData.iconPath = toolData.iconPath.Replace(HEU_Defines.HEU_PATH_KEY_PROJECT + "/", "");

						if(toolData.assetPath.Contains(envKey))
						{
							if(string.IsNullOrEmpty(envValue))
							{
								Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
							}
							else
							{
								toolData.assetPath = toolData.assetPath.Replace(envKey, envValue);
							}
						}

						if (toolData.iconPath.Contains(envKey))
						{
							if (string.IsNullOrEmpty(envValue))
							{
								Debug.LogErrorFormat("Environment value {0} used but not set in environment.", HEU_Defines.HEU_PATH_KEY_TOOL);
							}
							else
							{
								toolData.iconPath = toolData.iconPath.Replace(envKey, envValue);
							}
						}

						_tools.Add(toolData);
						Debug.LogFormat("Added tool: {0}", toolData.name);
					}
				}

				return true;
			}

			return false;
		}