예제 #1
0
		/// <summary>
		/// Returns a valid session by either reconnecting to an existing session, or creating a new session.
		/// Note that this will display error (once) if unable to get a valid session.
		/// </summary>
		/// <returns>A session object (new or existing). Session might not actually have connected successfully. Check IsSessionValid() and error message./returns>
		public static HEU_SessionBase GetOrCreateDefaultSession(bool bNotifyUserError = true)
		{			
			if(_defaultSession == null)
			{
				// After a code refresh, _defaultSession might be null. So try loading stored plugin data to see if we can get it back.
				HEU_PluginStorage.InstantiateAndLoad();
			}

			if(_defaultSession != null && _defaultSession.IsSessionValid())
			{
				return _defaultSession;
			}
			else if(_defaultSession == null || _defaultSession.ConnectedState == HEU_SessionBase.SessionConnectionState.NOT_CONNECTED)
			{
				// Try creating it if we haven't tried yet
				bNotifyUserError &= !CreateThriftPipeSession(HEU_PluginSettings.Session_PipeName, HEU_PluginSettings.Session_AutoClose, HEU_PluginSettings.Session_Timeout, bNotifyUserError);
			}
			 
			if(bNotifyUserError && !_defaultSession.UserNotifiedSessionInvalid)
			{
				_defaultSession.UserNotifiedSessionInvalid = true;

				HEU_EditorUtility.DisplayErrorDialog(HEU_Defines.HEU_ERROR_TITLE, HEU_SessionManager.GetLastSessionError(), "OK");
				HEU_EditorUtility.DisplayDialog(HEU_Defines.HEU_INSTALL_INFO, HEU_HAPIUtility.GetHoudiniEngineInstallationInfo(), "OK");
			}

			return _defaultSession;
		}
	/// <summary>
	/// Convert environment mapped path to real path, if there is a mapping for it.
	/// For example, if inPath is $HEU_ENVPATH_HDAS/trees/tree1.hda and mapping is
	/// HEU_ENVPATH_HDAS=C:\temp\hdas\ then the result will be C:\temp\hdas\trees/tree1.
	/// </summary>
	/// <param name="inPath"></param>
	/// <returns></returns>
	public string ConvertEnvKeyedPathToReal(string inPath)
	{
	    if (string.IsNullOrEmpty(inPath))
	    {
		return inPath;
	    }

	    if (inPath.StartsWith(HEU_Defines.HEU_PATH_KEY_HFS, System.StringComparison.InvariantCulture))
	    {
		return HEU_HAPIUtility.GetRealPathFromHFSPath(inPath);
	    }

	    if (_envPathMap == null)
	    {
		LoadAssetEnvironmentPaths();
	    }

	    if (_envPathMap != null && inPath.StartsWith(HEU_Defines.HEU_ENVPATH_KEY))
	    {
		foreach (KeyValuePair<string, string> pair in _envPathMap)
		{
		    string key = HEU_Defines.HEU_ENVPATH_KEY + pair.Key;
		    if (inPath.StartsWith(key, System.StringComparison.InvariantCulture))
		    {
			inPath = inPath.Replace(key, pair.Value);
			break;
		    }
		}
	    }

	    return inPath;
	}
		public void SetupMeshAndMaterials(HEU_HoudiniAsset asset, HAPI_PartType partType, GameObject outputGameObject)
		{
			_outputMesh = null;
			_outputGameObject = null;

			if (HEU_HAPIUtility.IsSupportedPolygonType(partType))
			{
				// Get the generated mesh. If mesh is missing, nothing we can do.
				MeshFilter meshFilter = outputGameObject.GetComponent<MeshFilter>();
				if (meshFilter != null && meshFilter.sharedMesh != null)
				{
					_outputMesh = meshFilter.sharedMesh;
				}
				else
				{
					// Without a valid mesh, we won't be able to paint so nothing else to do
					return;
				}

				_outputGameObject = outputGameObject;

				if (_localMaterial == null)
				{
					MeshRenderer meshRenderer = _outputGameObject.GetComponent<MeshRenderer>();
					if(meshRenderer != null)
					{
						_localMaterial = HEU_MaterialFactory.GetNewMaterialWithShader(null, HEU_PluginSettings.DefaultVertexColorShader, HEU_Defines.EDITABLE_MATERIAL, false);
					}
				}
			}
		}
예제 #4
0
		private void DisconnectAndDestroyInputAssets(HEU_SessionBase session)
		{
			DisconnectInputAssetActor(session);

			_inputAsset = null;

			if (session != null)
			{
				foreach (HAPI_NodeId nodeID in _inputObjectsConnectedAssetIDs)
				{
					session.DeleteNode(nodeID);
				}

				if (_connectedNodeID != HEU_Defines.HEU_INVALID_NODE_ID && HEU_HAPIUtility.IsNodeValidInHoudini(session, _connectedNodeID))
				{
					// We'll delete the parent Object because we presume to have created the SOP/merge ourselves.
					// If the parent Object doesn't get deleted, it sticks around unused.
					HAPI_NodeInfo parentNodeInfo = new HAPI_NodeInfo();
					if(session.GetNodeInfo(_connectedNodeID, ref parentNodeInfo))
					{
						if (parentNodeInfo.parentId != HEU_Defines.HEU_INVALID_NODE_ID)
						{
							session.DeleteNode(parentNodeInfo.parentId);
						}
					}
				}
			}

			_inputObjectsConnectedAssetIDs.Clear();
			_connectedNodeID = HEU_Defines.HEU_INVALID_NODE_ID;
		}
예제 #5
0
		public bool HasInputNodeTransformChanged()
		{
			if (_inputObjectType == InputObjectType.UNITY_MESH)
			{
				for (int i = 0; i < _inputObjects.Count; ++i)
				{
					if (_inputObjects[i]._gameObject != null)
					{
						if (_inputObjects[i]._useTransformOffset)
						{
							if (!HEU_HAPIUtility.IsSameTransform(ref _inputObjects[i]._syncdTransform, ref _inputObjects[i]._translateOffset, ref _inputObjects[i]._rotateOffset, ref _inputObjects[i]._scaleOffset))
							{
								return true;
							}
						}
						else if (_inputObjects[i]._gameObject.transform.localToWorldMatrix != _inputObjects[i]._syncdTransform)
						{
							return true;
						}
					}
				}
			}

			return false;
		}
예제 #6
0
		public void UploadParameterPreset(HEU_SessionBase session, HAPI_NodeId geoID, HEU_HoudiniAsset parentAsset)
		{
			// TODO FIXME
			// This fixes up the geo IDs for curves, and upload parameter values to Houdini.
			// This is required for curves in saved scenes, as its parameter data is not part of the parent asset's
			// parameter preset. Also the _geoID and parameters._nodeID could be different so uploading the
			// parameter values before cooking would not be valid for those IDs. This waits until after cooking
			// to then upload and cook just the curve.
			// Admittedly this is a temporary solution until a proper workaround is in place. Ideally for an asset reload
			// the object node and geo node names can be used to match up the IDs and then parameter upload can happen
			// before cooking.

			_geoID = geoID;

			if(_parameters != null)
			{
				_parameters._nodeID = geoID;

				if(_bUploadParameterPreset)
				{
					_parameters.UploadPresetData(session);
					_parameters.UploadValuesToHoudini(session, parentAsset);

					HEU_HAPIUtility.CookNodeInHoudini(session, geoID, false, _curveName);

					_bUploadParameterPreset = false;
				}
			}
		}
		private void CreateNewInstanceFromObject(GameObject assetSourceGO, int instanceIndex, Transform parentTransform, 
			ref HAPI_Transform hapiTransform, string[] instancePrefixes, string instanceName, GameObject collisionSourceGO)
		{
			GameObject newInstanceGO = null;

			if (HEU_EditorUtility.IsPrefabAsset(assetSourceGO))
			{
				newInstanceGO = HEU_EditorUtility.InstantiatePrefab(assetSourceGO) as GameObject;
				newInstanceGO.transform.parent = parentTransform;
			}
			else
			{
				newInstanceGO = HEU_EditorUtility.InstantiateGameObject(assetSourceGO, parentTransform, false, false);
			}

			if (collisionSourceGO != null)
			{
				HEU_GeneralUtility.ReplaceColliderMeshFromMeshFilter(newInstanceGO, collisionSourceGO);
			}

			// To get the instance output name, we pass in the instance index. The actual name will be +1 from this.
			newInstanceGO.name = HEU_GeometryUtility.GetInstanceOutputName(instanceName, instancePrefixes, instanceIndex);
			newInstanceGO.isStatic = assetSourceGO.isStatic;

			Transform instanceTransform = newInstanceGO.transform;
			HEU_HAPIUtility.ApplyLocalTransfromFromHoudiniToUnityForInstance(ref hapiTransform, instanceTransform);

			// When cloning, the instanced part might have been made invisible, so re-enable renderer to have the cloned instance display it.
			HEU_GeneralUtility.SetGameObjectRenderVisiblity(newInstanceGO, true);
			HEU_GeneralUtility.SetGameObjectChildrenRenderVisibility(newInstanceGO, true);
			HEU_GeneralUtility.SetGameObjectColliderState(newInstanceGO, true);
			HEU_GeneralUtility.SetGameObjectChildrenColliderState(newInstanceGO, true);
		}
예제 #8
0
        public static bool CreateAndCookCurveAsset(HEU_SessionBase session, string assetName, bool bCookTemplatedGeos, out HAPI_NodeId newAssetID)
        {
            newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;
            if (!session.CreateNode(HEU_Defines.HEU_INVALID_NODE_ID, "SOP/curve", "Curve", true, out newAssetID))
            {
                return(false);
            }

            // Make sure cooking is successfull before proceeding. Any licensing or file data issues will be caught here.
            if (!HEU_HAPIUtility.ProcessHoudiniCookStatus(session, assetName))
            {
                return(false);
            }

            // In case the cooking wasn't done previously, force it now.
            bool bResult = HEU_HAPIUtility.CookNodeInHoudini(session, newAssetID, bCookTemplatedGeos, assetName);

            if (!bResult)
            {
                // When cook failed, delete the node created earlier
                session.DeleteNode(newAssetID);
                newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;
                return(false);
            }

            return(true);
        }
예제 #9
0
	private void SelectShelf(int index)
	{
	    int numShelves = HEU_ShelfTools.GetNumShelves();
	    if (index >= 0 && index < numShelves)
	    {
		HEU_Shelf shelf = HEU_ShelfTools.GetShelf(index);
		if (shelf != null)
		{
		    int numTools = shelf._tools.Count;
		    _guiContents = new GUIContent[numTools];

		    for (int i = 0; i < numTools; ++i)
		    {
			_guiContents[i] = new GUIContent();
			_guiContents[i].text = shelf._tools[i]._name;

			if (HEU_HAPIUtility.DoesMappedPathExist(shelf._tools[i]._iconPath))
			{
			    string realPath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(shelf._tools[i]._iconPath);
			    _guiContents[i].image = HEU_GeneralUtility.LoadTextureFromFile(realPath);
			}

			_guiContents[i].tooltip = shelf._tools[i]._toolTip;
		    }
		}
	    }
	}
        /// <summary>
        /// Load a NodeSync file and create its construct in Unity.
        /// </summary>
        /// <param name="filePath">Path to the NodeSync file</param>
        /// <param name="name">Name of the NodeSync node</param>
        void CreateNodeSyncFromFile(string filePath, string name)
        {
            HEU_SessionBase session = HEU_SessionManager.GetDefaultSession();

            if (session == null || !session.IsSessionValid())
            {
                return;
            }

            HAPI_NodeId parentNodeID = -1;
            string      nodeName     = name;
            HAPI_NodeId newNodeID    = -1;

            // This loads the node network from file, and returns the node that was created
            // with newNodeID. It is either a SOP object, or a subnet object.
            // The actual loader (HEU_ThreadedTaskLoadGeo) will deal with either case.
            if (!session.LoadNodeFromFile(filePath, parentNodeID, nodeName, true, out newNodeID))
            {
                Log(string.Format("Failed to load node network from file: {0}.", filePath));
                return;
            }

            // Wait until finished
            if (!HEU_HAPIUtility.ProcessHoudiniCookStatus(session, nodeName))
            {
                Log(string.Format("Failed to cook loaded node with name: {0}.", nodeName));
                return;
            }

            GameObject newGO = new GameObject(nodeName);

            HEU_NodeSync nodeSync = newGO.AddComponent <HEU_NodeSync>();

            nodeSync.InitializeFromHoudini(session, newNodeID, nodeName, filePath);
        }
        public override bool CreateInputNodeWithDataUpload(HEU_SessionBase session, int connectNodeID, GameObject inputObject, out int inputNodeID)
        {
            inputNodeID = HEU_Defines.HEU_INVALID_NODE_ID;
            if (!HEU_HAPIUtility.IsNodeValidInHoudini(session, connectNodeID))
            {
                Debug.LogError("Connection node is invalid.");
                return false;
            }

            HEU_InputDataTilemap inputTilemap = GenerateTilemapDataFromGameObject(inputObject);

            string inputName = null;
            HAPI_NodeId newNodeID = HEU_Defines.HEU_INVALID_NODE_ID;
            session.CreateInputNode( out newNodeID, inputName );

            if (newNodeID == HEU_Defines.HEU_INVALID_NODE_ID || !HEU_HAPIUtility.IsNodeValidInHoudini(session, newNodeID))
            {
                Debug.LogError("Failed to create new input node in Houdini session!");
                return false;
            }

            inputNodeID = newNodeID;
            if (!session.CookNode(inputNodeID, false))
            {
                Debug.LogError("New input node failed to cook!");
                return false;
            }

            return UploadData(session, inputNodeID, inputTilemap);
        }
예제 #12
0
		private static bool GetArray<ARG2, T>(
			int arg1, ARG2 arg2,
			GetArray1ArgDel<T> func1,
			GetArray2ArgDel<ARG2, T> func2,
			[Out] T[] data, int start, int count, int tupleSize)
		{
			int maxArraySize = HEU_Defines.HAPI_MAX_PAGE_SIZE / (Marshal.SizeOf(typeof(T)) * tupleSize);
			int localCount = count;
			int currentIndex = start;

			bool bResult = true;
			while (localCount > 0)
			{
				int length = 0;
				if (localCount > maxArraySize)
				{
					length = maxArraySize;
					localCount -= maxArraySize;
				}
				else
				{
					length = localCount;
					localCount = 0;
				}

				T[] localArray = new T[length * tupleSize];

				if (func1 != null)
				{
					bResult = func1(arg1, localArray, currentIndex, length);
				}
				else if (func2 != null)
				{
					bResult = func2(arg1, arg2, localArray, currentIndex, length);
				}
				else
				{
					HEU_HAPIUtility.LogError("No valid delegates given to GetArray< T >!");
					return false;
				}

				if (!bResult)
				{
					break;
				}

				// Copy from temporary array
				for (int i = currentIndex; i < (currentIndex + length); ++i)
				{
					for (int j = 0; j < tupleSize; ++j)
					{
						data[i * tupleSize + j] = localArray[(i - currentIndex) * tupleSize + j];
					}
				}

				currentIndex += length;
			}

			return bResult;
		}
예제 #13
0
	public static void LoadGeoFile()
	{
	    GameObject newGO = HEU_HAPIUtility.LoadGeoWithNewGeoSync();
	    if (newGO != null)
	    {
		HEU_EditorUtility.SelectObject(newGO);
	    }
	}
예제 #14
0
	public static void CreateNewInputAsset()
	{
	    GameObject newCurveGO = HEU_HAPIUtility.CreateNewInputAsset();
	    if (newCurveGO != null)
	    {
		HEU_EditorUtility.SelectObject(newCurveGO);
	    }
	}
예제 #15
0
        private static void ProcessDragEvent(Event dragEvent, SceneView sceneView)
        {
            if (dragEvent != null && (dragEvent.type == EventType.DragUpdated || dragEvent.type == EventType.DragPerform))
            {
                bool          dragHDAs = false;
                List <string> hdaList  = new List <string>();
                foreach (string file in DragAndDrop.paths)
                {
                    if (HEU_HAPIUtility.IsHoudiniAssetFile(file))
                    {
                        dragHDAs = true;
                        DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                        hdaList.Add(file);
                        break;
                    }
                }

                if (dragHDAs)
                {
                    if (dragEvent.type == EventType.DragPerform)
                    {
                        if (HEU_SessionManager.ValidatePluginSession())
                        {
                            Vector3 dropPos = Vector3.zero;
                            if (sceneView != null)
                            {
                                Camera  camera   = sceneView.camera;
                                Vector3 mousePos = HEU_EditorUI.GetMousePosition(ref dragEvent, camera);

                                Ray ray = camera.ScreenPointToRay(mousePos);
                                ray.origin = camera.transform.position;
                                Plane plane = new Plane();
                                plane.SetNormalAndPosition(Vector3.up, Vector3.zero);
                                float enter = 0f;
                                plane.Raycast(ray, out enter);
                                enter   = Mathf.Clamp(enter, camera.nearClipPlane, camera.farClipPlane);
                                dropPos = ray.origin + ray.direction * enter;
                            }

                            List <GameObject> createdGOs = new List <GameObject>();
                            foreach (string file in hdaList)
                            {
                                GameObject go = HEU_HAPIUtility.InstantiateHDA(file, dropPos, HEU_SessionManager.GetOrCreateDefaultSession(), true);
                                if (go != null)
                                {
                                    createdGOs.Add(go);
                                }
                            }

                            // Select the created assets
                            HEU_EditorUtility.SelectObjects(createdGOs.ToArray());
                        }
                    }

                    dragEvent.Use();
                }
            }
        }
예제 #16
0
		/// <summary>
		/// Generates heightfield/terrain data from the given object relevant for uploading to Houdini.
		/// </summary>
		/// <param name="inputObject"></param>
		/// <returns>Valid input object or null if given object is not supported</returns>
		public HEU_InputDataTerrain GenerateTerrainDataFromGameObject(GameObject inputObject)
		{
			HEU_InputDataTerrain inputData = null;

			Terrain terrain = inputObject.GetComponent<Terrain>();
			if (terrain != null)
			{
				TerrainData terrainData = terrain.terrainData;

				Vector3 terrainSize = terrainData.size;
				if (terrainSize.x != terrainSize.z)
				{
					Debug.LogError("Only square sized terrains are supported for input! Change to square size and try again.");
					return null;
				}

				inputData = new HEU_InputDataTerrain();
				inputData._inputObject = inputObject;
				inputData._terrain = terrain;
				inputData._terrainData = terrainData;

				// Height values in Unity are normalized between 0 and 1, so this height scale
				// will multiply them before uploading to Houdini.
				inputData._heightScale = terrainSize.y;

				// Terrain heightMapResolution is the pixel resolution, which we set to the number of voxels
				// by dividing the terrain size with it. In Houdini, this is the Grid Spacing.
				inputData._voxelSize = terrainSize.x / inputData._terrainData.heightmapResolution;

				// This is the number of heightfield voxels on each dimension.
				inputData._numPointsX = Mathf.RoundToInt(inputData._terrainData.heightmapResolution * inputData._voxelSize);
				inputData._numPointsY = Mathf.RoundToInt(inputData._terrainData.heightmapResolution * inputData._voxelSize);

				Matrix4x4 transformMatrix = inputObject.transform.localToWorldMatrix;
				HAPI_TransformEuler transformEuler = HEU_HAPIUtility.GetHAPITransformFromMatrix(ref transformMatrix);

				// Volume transform used for all heightfield layers
				inputData._transform = new HAPI_Transform(false);

				// Unity terrain pivots are at bottom left, but Houdini uses centered heightfields so
				// apply local position offset by half sizes and account for coordinate change
				inputData._transform.position[0] = terrainSize.z * 0.5f;
				inputData._transform.position[1] = -terrainSize.x * 0.5f;
				inputData._transform.position[2] = 0;

				// Volume scale controls final size, but requires to be divided by 2
				inputData._transform.scale[0] = terrainSize.x * 0.5f;
				inputData._transform.scale[1] = terrainSize.z * 0.5f;
				inputData._transform.scale[2] = 0.5f;

				inputData._transform.rotationQuaternion[0] = 0f;
				inputData._transform.rotationQuaternion[1] = 0f;
				inputData._transform.rotationQuaternion[2] = 0f;
				inputData._transform.rotationQuaternion[3] = 1f;
			}

			return inputData;
		}
예제 #17
0
        /// <summary>
        /// Create a new Input SOP with given name.
        /// </summary>
        void CreateInput(string name)
        {
            GameObject newCurveGO = HEU_HAPIUtility.CreateNewInputAsset(name: name);

            if (newCurveGO != null)
            {
                HEU_EditorUtility.SelectObject(newCurveGO);
            }
        }
예제 #18
0
	public static void CreateNewCurveAsset()
	{
	    GameObject newCurveGO = HEU_HAPIUtility.CreateNewCurveAsset();
	    if (newCurveGO != null)
	    {
		HEU_Curve.PreferredNextInteractionMode = HEU_Curve.Interaction.ADD;
		HEU_EditorUtility.SelectObject(newCurveGO);
	    }
	}
예제 #19
0
        /// <summary>
        /// Create a new Curve SOP with given name.
        /// </summary>
        void CreateCurve(string name)
        {
            GameObject newCurveGO = HEU_HAPIUtility.CreateNewCurveAsset(name: name);

            if (newCurveGO != null)
            {
                HEU_Curve.PreferredNextInteractionMode = HEU_Curve.Interaction.ADD;
                HEU_EditorUtility.SelectObject(newCurveGO);
            }
        }
예제 #20
0
        /// <summary>
        /// Cooks node and returns true if successfull.
        /// </summary>
        /// <param name="nodeID">The node to cook</param>
        /// <param name="bCookTemplatedGeos">Whether to cook templated geos</param>
        /// <returns>True if successfully cooked node</returns>
        public static bool CookNodeInHoudini(HEU_SessionBase session, HAPI_NodeId nodeID, bool bCookTemplatedGeos, string assetName)
        {
            bool bResult = session.CookNode(nodeID, bCookTemplatedGeos);

            if (bResult)
            {
                return(HEU_HAPIUtility.ProcessHoudiniCookStatus(session, assetName));
            }

            return(bResult);
        }
예제 #21
0
		public static void ExecuteToolNoInput(string toolName, string toolPath)
		{
			GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), false);
			if (go == null)
			{
				Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
			}
			else
			{
				HEU_EditorUtility.SelectObject(go);
			}
		}
예제 #22
0
        public static bool CreateAndCookInputAsset(HEU_SessionBase session, string assetName, bool bCookTemplatedGeos, out HAPI_NodeId newAssetID)
        {
            newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;
            if (!session.CreateInputNode(out newAssetID, null))
            {
                return(false);
            }

            // Make sure cooking is successfull before proceeding. Any licensing or file data issues will be caught here.
            if (!HEU_HAPIUtility.ProcessHoudiniCookStatus(session, assetName))
            {
                return(false);
            }

            // In case the cooking wasn't done previously, force it now.
            bool bResult = HEU_HAPIUtility.CookNodeInHoudini(session, newAssetID, bCookTemplatedGeos, assetName);

            if (!bResult)
            {
                // When cook failed, deleted the node created earlier
                session.DeleteNode(newAssetID);
                newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;
                return(false);
            }

            // After cooking, set an empty partinfo
            HAPI_GeoInfo inputGeoInfo = new HAPI_GeoInfo();

            if (!session.GetDisplayGeoInfo(newAssetID, ref inputGeoInfo))
            {
                return(false);
            }

            HAPI_PartInfo newPart = new HAPI_PartInfo();

            newPart.init();
            newPart.id          = 0;
            newPart.vertexCount = 0;
            newPart.faceCount   = 0;
            newPart.pointCount  = 0;
            // TODO: always set to mesh type?
            newPart.type = HAPI_PartType.HAPI_PARTTYPE_MESH;

            if (!session.SetPartInfo(inputGeoInfo.nodeId, 0, ref newPart))
            {
                Debug.LogErrorFormat(HEU_Defines.HEU_NAME + ": Failed to set partinfo for input node!");
                return(false);
            }

            return(true);
        }
		private static void LoadHoudiniAssetFromPath(string hdaPath)
		{
			if (!string.IsNullOrEmpty(hdaPath))
			{
				// Store HDA path for next time
				HEU_PluginSettings.LastLoadHDAPath = Path.GetDirectoryName(hdaPath);

				GameObject go = HEU_HAPIUtility.InstantiateHDA(hdaPath, Vector3.zero, HEU_SessionManager.GetOrCreateDefaultSession(), true);
				if (go != null)
				{
					HEU_EditorUtility.SelectObject(go);
				}
			}
		}
예제 #24
0
	public void DestroyAllData()
	{
	    if (_parameters != null)
	    {
		_parameters.CleanUp();
		_parameters = null;
	    }

	    if (_isGeoCurve && _targetGameObject != null)
	    {
		HEU_HAPIUtility.DestroyGameObject(_targetGameObject);
		_targetGameObject = null;
	    }
	}
예제 #25
0
		//	LOGIC -----------------------------------------------------------------------------------------------------

		private void Awake()
		{
#if HOUDINIENGINEUNITY_ENABLED
			if (_sessionID != HEU_SessionData.INVALID_SESSION_ID)
			{
				HEU_SessionBase session = HEU_SessionManager.GetSessionWithID(_sessionID);
				if (session == null || !HEU_HAPIUtility.IsNodeValidInHoudini(session, _fileNodeID))
				{
					// Reset session and file node IDs if these don't exist (could be from scene load).
					_sessionID = HEU_SessionData.INVALID_SESSION_ID;
					_fileNodeID = HEU_Defines.HEU_INVALID_NODE_ID;
				}
			}
#endif
		}
예제 #26
0
		public static void ExecuteToolGenerator(string toolName, string toolPath, Vector3 targetPosition, Quaternion targetRotation, Vector3 targetScale)
		{
			GameObject go = HEU_HAPIUtility.InstantiateHDA(toolPath, targetPosition, HEU_SessionManager.GetOrCreateDefaultSession(), true);
			if (go != null)
			{
				go.transform.rotation = targetRotation;
				go.transform.localScale = targetScale;

				HEU_EditorUtility.SelectObject(go);
			}
			else
			{
				Debug.LogWarningFormat("Failed to instantiate tool: {0}", toolName);
			}
		}
예제 #27
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;
		}
예제 #28
0
        public static bool LoadHDAFile(HEU_SessionBase session, string assetPath, out HAPI_NodeId assetLibraryID, out string[] assetNames)
        {
            assetLibraryID = HEU_Defines.HEU_INVALID_NODE_ID;
            assetNames     = new string[0];

            // Load the file
            string validAssetPath = HEU_HAPIUtility.LocateValidFilePath(assetPath, assetPath);

            if (validAssetPath != null)
            {
                assetPath = validAssetPath;

                HAPI_AssetLibraryId libraryID = 0;
                bool bResult = session.LoadAssetLibraryFromFile(assetPath, false, out libraryID);
                if (!bResult)
                {
                    return(false);
                }

                int assetCount = 0;
                bResult = session.GetAvailableAssetCount(libraryID, out assetCount);
                if (!bResult)
                {
                    return(false);
                }
                Debug.AssertFormat(assetCount > 0, "Houdini Engine: Invalid Asset Count of {0}", assetCount);

                HAPI_StringHandle[] assetNameLengths = new HAPI_StringHandle[assetCount];
                bResult = session.GetAvailableAssets(libraryID, ref assetNameLengths, assetCount);
                if (!bResult)
                {
                    return(false);
                }
                // Sanity check that our array hasn't changed size
                Debug.Assert(assetNameLengths.Length == assetCount, "Houdini Engine: Invalid Asset Names");

                assetNames = new string[assetCount];
                for (int i = 0; i < assetCount; ++i)
                {
                    assetNames[i] = HEU_SessionManager.GetString(assetNameLengths[i]);
                }

                return(true);
            }

            return(false);
        }
예제 #29
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);
	    }
	}
예제 #30
0
	/// <summary>
	/// Set the input node's transform.
	/// </summary>
	/// <param name="session">Session that the input node exists in</param>
	/// <param name="inputObject">The input object info containing data about the input</param>
	/// <param name="inputNodeID">The input node ID</param>
	/// <param name="bKeepWorldTransform">Whether to use world transform or not</param>
	/// <returns></returns>
	internal static bool UploadInputObjectTransform(HEU_SessionBase session, HEU_InputObjectInfo inputObject, HAPI_NodeId inputNodeID, bool bKeepWorldTransform)
	{
	    Matrix4x4 inputTransform = Matrix4x4.identity;
	    if (inputObject._useTransformOffset)
	    {
		if (bKeepWorldTransform)
		{
		    // Add offset tranform to world transform
		    Transform inputObjTransform = inputObject._gameObject.transform;
		    Vector3 position = inputObjTransform.position + inputObject._translateOffset;
		    Quaternion rotation = inputObjTransform.rotation * Quaternion.Euler(inputObject._rotateOffset);
		    Vector3 scale = Vector3.Scale(inputObjTransform.localScale, inputObject._scaleOffset);

		    Vector3 rotVector = rotation.eulerAngles;
		    inputTransform = HEU_HAPIUtility.GetMatrix4x4(ref position, ref rotVector, ref scale);
		}
		else
		{
		    // Offset from origin.
		    inputTransform = HEU_HAPIUtility.GetMatrix4x4(ref inputObject._translateOffset, ref inputObject._rotateOffset, ref inputObject._scaleOffset);
		}
	    }
	    else
	    {
		inputTransform = inputObject._gameObject.transform.localToWorldMatrix;
	    }

	    HAPI_TransformEuler transformEuler = HEU_HAPIUtility.GetHAPITransformFromMatrix(ref inputTransform);

	    HAPI_NodeInfo inputNodeInfo = new HAPI_NodeInfo();
	    if (!session.GetNodeInfo(inputNodeID, ref inputNodeInfo))
	    {
		return false;
	    }

	    if (session.SetObjectTransform(inputNodeInfo.parentId, ref transformEuler))
	    {
		inputObject._syncdTransform = inputTransform;

		inputObject._syncdChildTransforms.Clear();

		GetChildrenTransforms(inputObject._gameObject.transform, ref inputObject._syncdChildTransforms);
	    }

	    return true;
	}