// SESSION DEBUG ----------------------------------------------------------------------------------------------

	/// <summary>
	/// Load a HIP file into given session.
	/// The user will be prompted to choose a HIP file via Unity's file dialog.
	/// </summary>
	/// <param name="bCookNodes">True if nodes should be cooked on load</param>
	/// <param name="session">Session to load into. If null, will use default session</param>
	/// <returns>True if successfully loaded the HIP file</returns>
	public static bool LoadSessionFromHIP(bool bCookNodes, HEU_SessionBase session = null)
	{
	    if (session == null || !session.IsSessionValid())
	    {
		session = GetOrCreateDefaultSession();
		if (session == null || !session.IsSessionValid())
		{
		    session.SetSessionErrorMsg("No valid session found. Unable to load session!", true);
		    return false;
		}
	    }

#if UNITY_EDITOR
	    string lastPath = HEU_PluginSettings.LastLoadHIPPath;
	    string fileExt = "hip;*.hiplc;*.hipnc";
	    string filePath = UnityEditor.EditorUtility.OpenFilePanel("Open Houdini HIP", lastPath, fileExt);
	    if (!string.IsNullOrEmpty(filePath))
	    {
		HEU_PluginSettings.LastLoadHIPPath = filePath;

		bool bResult = session.LoadHIPFile(filePath, bCookNodes);
		if (bResult)
		{
		    // TODO
		    HEU_Logger.LogWarning("This is currently not supported in the plugin!");
		}
	    }
#else
            session.SetSessionErrorMsg("Load session only supported in Unity Editor!", true);
#endif
	    return false;
	}
	public static HEU_SessionBase CreateSessionFromType(System.Type type)
	{
#if !UNITY_5_6_OR_NEWER
            HEU_Logger.LogError("Houdini Engine for Unity only supports Unity version 5.6.0 and newer!");
#elif HOUDINIENGINEUNITY_ENABLED
	    if (type == null || type == typeof(HEU_SessionHAPI))
	    {
		// By default, we use HAPI if Houdini Engine is enabled
		return new HEU_SessionHAPI();
	    }
	    else if (_createSessionFromTypeDelegate != null)
	    {
		// For custom HEU_SessionBase classes

		System.Delegate[] delegates = _createSessionFromTypeDelegate.GetInvocationList();
		foreach (System.Delegate del in delegates)
		{
		    CreateSessionFromTypeDelegate createDelegate = del as CreateSessionFromTypeDelegate;
		    HEU_SessionBase newSession = createDelegate.Invoke(type);
		    if (newSession != null)
		    {
			return newSession;
		    }
		}
	    }
#endif
	    // Fallback to empty session
	    return new HEU_SessionBase();
	}
        /// <summary>
        /// Writes out the TerrainLayer file path as a string attribute (primitive-owned) for the specified heightfield volume.
        /// </summary>
        /// <param name="session">Current Houdini session</param>
        /// <param name="geoNodeID">Geometry object ID</param>
        /// <param name="partID">Part ID (volume)</param>
        /// <param name="terrainLayer">The TerrainLayer's file path is set as attribute</param>
        /// <returns>True if successfully added the attribute.</returns>
        public bool SetTerrainLayerAttributesToHeightField(HEU_SessionBase session, HAPI_NodeId geoNodeID, HAPI_PartId partID, TerrainLayer terrainLayer)
        {
            string assetPath = HEU_AssetDatabase.GetAssetPath(terrainLayer);

            if (string.IsNullOrEmpty(assetPath))
            {
                return(false);
            }

            HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo();

            attrInfo.exists        = true;
            attrInfo.owner         = HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM;
            attrInfo.storage       = HAPI_StorageType.HAPI_STORAGETYPE_STRING;
            attrInfo.count         = 1;
            attrInfo.tupleSize     = 1;
            attrInfo.originalOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_INVALID;

            if (!session.AddAttribute(geoNodeID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TERRAINLAYER_FILE_ATTR, ref attrInfo))
            {
                HEU_Logger.LogError("Failed to add TerrainLayer file attribute to input heightfield.");
                return(false);
            }

            string[] pathData = new string[] { assetPath };
            if (!session.SetAttributeStringData(geoNodeID, partID, HEU_Defines.DEFAULT_UNITY_HEIGHTFIELD_TERRAINLAYER_FILE_ATTR, ref attrInfo, pathData, 0, 1))
            {
                HEU_Logger.LogError("Failed to set TerrainLayer file name to input heightfield");
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Create the main heightfield network for input.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="idt"></param>
        /// <returns>True if successfully created the network</returns>
        public bool CreateHeightFieldInputNode(HEU_SessionBase session, HEU_InputDataTerrain idt)
        {
            idt._heightfieldNodeID = HEU_Defines.HEU_INVALID_NODE_ID;
            idt._heightNodeID      = HEU_Defines.HEU_INVALID_NODE_ID;
            idt._maskNodeID        = HEU_Defines.HEU_INVALID_NODE_ID;
            idt._mergeNodeID       = HEU_Defines.HEU_INVALID_NODE_ID;
            idt._parentNodeID      = HEU_Defines.HEU_INVALID_NODE_ID; // Heightfields should have its own objects.

            // Create the HeightField node network
            bool bResult = session.CreateHeightFieldInput(idt._parentNodeID, idt._heightFieldName, idt._numPointsX, idt._numPointsY, idt._voxelSize,
                                                          HAPI_HeightFieldSampling.HAPI_HEIGHTFIELD_SAMPLING_CORNER,
                                                          out idt._heightfieldNodeID, out idt._heightNodeID, out idt._maskNodeID, out idt._mergeNodeID);

            if (!bResult ||
                idt._heightfieldNodeID == HEU_Defines.HEU_INVALID_NODE_ID ||
                idt._heightNodeID == HEU_Defines.HEU_INVALID_NODE_ID ||
                idt._maskNodeID == HEU_Defines.HEU_INVALID_NODE_ID ||
                idt._mergeNodeID == HEU_Defines.HEU_INVALID_NODE_ID)
            {
                HEU_Logger.LogError("Failed to create new heightfield node in Houdini session!");
                return(false);
            }

            if (!session.CookNode(idt._heightNodeID, false))
            {
                HEU_Logger.LogError("New input node failed to cook!");
                return(false);
            }

            return(true);
        }
	/// <summary>
	/// Populate TOP data from linked HDA
	/// </summary>
	private void PopulateFromHDA()
	{
	    if (!_heu.IsAssetValid())
	    {
		_linkState = LinkState.ERROR_NOT_LINKED;
		return;
	    }

	    if (_heu != null)
	    {
		_assetID = _heu.AssetID;
		_assetName = _heu.AssetName;
	    }

	    if (PopulateTOPNetworks())
	    {
		_linkState = LinkState.LINKED;
	    }
	    else
	    {
		_linkState = LinkState.ERROR_NOT_LINKED;
		HEU_Logger.LogErrorFormat("Failed to populate TOP network info for asset {0}!", _assetName);
	    }

	    RepaintUI();
	}
예제 #6
0
	/// <summary>
	/// Creates all folders in the given path if they don't exist.
	/// </summary>
	/// <param name="inPath">The path to create folders for</param>
	public static void CreatePathWithFolders(string inPath)
	{
#if UNITY_EDITOR
	    string pathBuild = "";
	    string[] folders = inPath.Split(HEU_Platform.DirectorySeparator);
	    foreach (string folder in folders)
	    {
		if (string.IsNullOrEmpty(folder))
		{
		    break;
		}

		string nextPath = "";
		if (string.IsNullOrEmpty(pathBuild))
		{
		    nextPath = folder;
		}
		else
		{
		    nextPath = HEU_Platform.BuildPath(pathBuild, folder);
		}

		if (!AssetDatabase.IsValidFolder(nextPath))
		{
		    //HEU_Logger.LogFormat("{0}: Creating folder: {1}/{2}", HEU_Defines.HEU_NAME, pathBuild, folder);
		    AssetDatabase.CreateFolder(pathBuild, folder);
		}

		pathBuild = nextPath;
	    }
#else
	    HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
#endif
	}
        /// <summary>
        /// Cook the PDG graph of the specified TOP network
        /// </summary>
        /// <param name="topNetwork"></param>
        public void CookTOPNetworkOutputNode(HEU_TOPNetworkData topNetwork, System.Action <HEU_PDGCookedEventData> OnCook = null)
        {
#if HOUDINIENGINEUNITY_ENABLED
            ClearEventMessages();

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

            // Cancel all cooks. This is required as otherwise the graph gets into an infinite cook
            // state (bug?)
            if (_pdgContextIDs != null)
            {
                foreach (HAPI_PDG_GraphContextId contextID in _pdgContextIDs)
                {
                    session.CancelPDGCook(contextID);
                }
            }

            if (!session.CookPDG(topNetwork._nodeID, 0, 0))
            {
                HEU_Logger.LogErrorFormat("Cook node failed!");
            }

            _cookedDataEvent = OnCook;

            ResetCallbackVariables();
#endif
        }
예제 #8
0
	public void OnGUI()
	{
	    using (new GUILayout.VerticalScope())
	    {
		_shelfName = EditorGUILayout.TextField("New Shelf Name", _shelfName);
		using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(_shelfName) || _shelfName.Trim().Length == 0))
		{
		    if (GUILayout.Button("Create"))
		    {
			//HEU_Logger.Log("Shelf name: " + _shelfName);
			HEU_Shelf newShelf = HEU_ShelfTools.AddShelf(_shelfName, _shelfPath);
			if (newShelf != null)
			{
			    HEU_ShelfTools.SaveShelf();
			    HEU_ShelfTools.SetReloadShelves();
			    this.Close();
			}
			else
			{
			    HEU_Logger.LogError("Invalid Shelf! Please check if the name or path is valid.");
			}
		    }
		}

		if (GUILayout.Button("Cancel"))
		{
		    this.Close();
		}
	    }
	}
예제 #9
0
	/// <summary>
	/// Loads a copy of the srcAsset at copyPath. Creates a copy if not found.
	/// </summary>
	/// <param name="srcAsset">The source asset object</param>
	/// <param name="copyPath">The full path to the copy</param>
	/// <param name="type">The type of source asset</param>
	/// <param name="bOverwriteExisting">Whether to overwrite existing copy if found</param>
	/// <returns>Returns loaded copy if exists or created, otherwise null</returns>
	public static Object CopyAndLoadAssetAtAnyPath(Object srcAsset, string copyPath, System.Type type, bool bOverwriteExisting)
	{
#if UNITY_EDITOR
	    string srcAssetPath = GetAssetPath(srcAsset);
	    if (!string.IsNullOrEmpty(srcAssetPath))
	    {
		CreatePathWithFolders(copyPath);

		string fileName = HEU_Platform.GetFileName(srcAssetPath);
		string fullCopyPath = HEU_Platform.BuildPath(copyPath, fileName);

		if ((!bOverwriteExisting && HEU_Platform.DoesFileExist(fullCopyPath)) || CopyAsset(srcAssetPath, fullCopyPath))
		{
		    // Refresh database as otherwise we won't be able to load it in the next line.
		    SaveAndRefreshDatabase();

		    return LoadAssetAtPath(fullCopyPath, type);
		}
		else
		{
		    HEU_Logger.LogErrorFormat("Failed to copy and load asset from {0} to {1}!", srcAssetPath, fullCopyPath);
		}
	    }
	    return null;
#else
			// TODO RUNTIME: AssetDatabase is not supported at runtime. Do we need to support this for runtime?
			HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
			return null;
#endif
	}
예제 #10
0
	/// <summary>
	/// Copy the file of the given srcAsset into the given targetPath, which must be absolute.
	/// If targetPath doesn't have a file name, the srcAsset's file name will be used.
	/// </summary>
	/// <param name="srcAsset">Source asset to copy</param>
	/// <param name="targetPath">Absolute path of destination</param>
	/// <param name="type">Type of the asset</param>
	/// <returns></returns>
	public static Object CopyAndLoadAssetAtGivenPath(Object srcAsset, string targetPath, System.Type type)
	{
#if UNITY_EDITOR
	    string srcAssetPath = GetAssetPath(srcAsset);
	    if (!string.IsNullOrEmpty(srcAssetPath))
	    {
		string targetFolderPath = HEU_Platform.GetFolderPath(targetPath);
		CreatePathWithFolders(targetFolderPath);

		string targetFileName = HEU_Platform.GetFileName(targetPath);
		if (string.IsNullOrEmpty(targetFileName))
		{
		    HEU_Logger.LogErrorFormat("Copying asset failed. Destination path must end with a file name: {0}!", targetPath);
		    return null;
		}

		if (CopyAsset(srcAssetPath, targetPath))
		{
		    // Refresh database as otherwise we won't be able to load it in the next line.
		    SaveAndRefreshDatabase();

		    return LoadAssetAtPath(targetPath, type);
		}
		else
		{
		    HEU_Logger.LogErrorFormat("Failed to copy and load asset from {0} to {1}!", srcAssetPath, targetPath);
		}
	    }
	    return null;
#else
			// TODO RUNTIME: AssetDatabase is not supported at runtime. Do we need to support this for runtime?
			HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
			return null;
#endif
	}
예제 #11
0
	public static string GetAssetRootPath(Object asset)
	{
#if UNITY_EDITOR
	    string assetPath = GetAssetPath(asset);
	    if (!string.IsNullOrEmpty(assetPath))
	    {
		// We'll strip the path until we're under AssetCache/Baked/assetName or AssetCache/Working/assetName

		string assetTypePath = GetAssetBakedPath();
		if (!assetPath.StartsWith(assetTypePath))
		{
		    assetTypePath = GetAssetWorkingPath();
		    if (!assetPath.StartsWith(assetTypePath))
		    {
			return null;
		    }
		}

		string removedBakedPath = assetPath.Replace(assetTypePath + HEU_Platform.DirectorySeparator, "");
		string[] splits = removedBakedPath.Split(HEU_Platform.DirectorySeparator);
		if (!string.IsNullOrEmpty(splits[0]))
		{
		    string rootPath = HEU_Platform.BuildPath(assetTypePath, splits[0]);
		    Debug.AssertFormat(AssetDatabase.IsValidFolder(rootPath), "Calculated root path {0} is invalid for asset at {1}.", rootPath, assetPath);
		    return rootPath;
		}
	    }
	    return null;
#else
			HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
			return null; 
#endif
	}
 private GameObject GetGameObjectFromType(Object obj, System.Type type)
 {
     if (type == typeof(GameObject))
     {
         return(obj as GameObject);
     }
     else if (type == typeof(HEU_HoudiniAssetRoot))
     {
         HEU_HoudiniAssetRoot heuRoot = obj as HEU_HoudiniAssetRoot;
         return(heuRoot.gameObject);
     }
     else if (type == typeof(Terrain))
     {
         Terrain terrain = obj as Terrain;
         return(terrain.gameObject);
     }
     else if (type == typeof(HEU_BoundingVolume))
     {
         HEU_BoundingVolume volume = obj as HEU_BoundingVolume;
         return(volume.gameObject);
     }
     else if (type == typeof(Tilemap))
     {
         Tilemap tilemap = obj as Tilemap;
         return(tilemap.gameObject);
     }
     else
     {
         HEU_Logger.LogErrorFormat("Unsupported type {0} for Selection Window.", type);
         return(null);
     }
 }
	public bool IsEquivalentTo(HEU_AttributesStore other)
	{

	    bool bResult = true;

	    string header = "HEU_AttributesStore";

	    if (other == null)
	    {
		HEU_Logger.LogError(header + " Not equivalent");
		return false;
	    }

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._geoName, other._geoName, ref bResult, header, "_geoName");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._attributeDatas, other._attributeDatas, ref bResult, header, "_attributeDatas");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._hasColorAttribute, other._hasColorAttribute, ref bResult, header, "_hasColorAttribute");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._localMaterial.ToTestObject(), other._localMaterial.ToTestObject(), ref bResult, header, "_localMaterial");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._outputTransform.ToTestObject(), other._outputTransform.ToTestObject(), ref bResult, header, "_outputTransform");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._positionAttributeValues, other._positionAttributeValues, ref bResult, header, "_positionAttributeValues");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._vertexIndices, other._vertexIndices, ref bResult, header, "_vertexIndices");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._outputGameObject, other._outputGameObject, ref bResult, header, "_outputGameObject");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._outputMesh.ToTestObject(), other._outputMesh.ToTestObject(), ref bResult, header, "_outputMesh");
	    
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._outputMaterials.ToTestObject(), other._outputMaterials.ToTestObject(), ref bResult, header, "_outputMaterials");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._outputCollider.ToTestObject(), other._outputCollider.ToTestObject(), ref bResult, header, "_outputColliders");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._outputColliderMesh.ToTestObject(), other._outputColliderMesh.ToTestObject(), ref bResult, header, "_outputColliderMesh");

	    return bResult;
	}
	public static bool GetParameterColor3Value(HEU_SessionBase session, HAPI_NodeId nodeID, HAPI_ParmInfo[] parameters, string parameterName, Color defaultValue, out Color outputColor)
	{
	    int parameterIndex = GetParameterIndexFromNameOrTag(session, nodeID, parameters, parameterName);
	    if (parameterIndex < 0 || parameterIndex >= parameters.Length)
	    {
		outputColor = defaultValue;
		return false;
	    }

	    if (parameters[parameterIndex].size < 3)
	    {
		HEU_Logger.LogError("Parameter size not large enough to be a Color3");
		outputColor = defaultValue;
		return false;
	    }

	    int valueIndex = parameters[parameterIndex].floatValuesIndex;
	    float[] value = new float[3];

	    if (session.GetParamFloatValues(nodeID, value, valueIndex, 3))
	    {
		outputColor = new Color(value[0], value[1], value[2], 1f);
		return true;
	    }

	    outputColor = defaultValue;
	    return false;
	}
	public static Material LoadSubstanceMaterialWithName(string materialPath, string substanceName)
	{
	    Material material = LoadUnityMaterial(materialPath);
#if UNITY_2017_4_OR_NEWER || UNITY_2018_1_OR_NEWER
	    HEU_Logger.LogErrorFormat("Houdini Engine for Unity does not support the new Substance plugin as of yet!");
#elif UNITY_EDITOR
			if (material != null)
			{
				string assetPath = HEU_AssetDatabase.GetAssetPath(material);
				
				SubstanceImporter substanceImporter = AssetImporter.GetAtPath(assetPath) as SubstanceImporter;

				ProceduralMaterial[] proceduralMaterials = substanceImporter.GetMaterials();
				for(int i = 0; i < proceduralMaterials.Length; ++i)
				{
					if(proceduralMaterials[i].name.Equals(substanceName))
					{
						material = proceduralMaterials[i];
						break;
					}
				}
			}
#endif

	    if (material != null)
	    {
		HEU_Logger.LogFormat("Loaded Substance material with name {0} from path {1}.", substanceName, materialPath);
	    }
	    else
	    {
		HEU_Logger.LogWarningFormat("Failed to load Substance material with name {0} from path {1}.", substanceName, materialPath);
	    }

	    return material;
	}
        public bool IsEquivalentTo(HEU_GeoNode other)
        {
            bool bResult = true;

            string header = "HEU_GeoNode";

            if (other == null)
            {
                HEU_Logger.LogError(header + " Not equivalent");
                return(false);
            }

            HEU_TestHelpers.AssertTrueLogEquivalent(this._geoInfo.ToTestObject(), other._geoInfo.ToTestObject(), ref bResult, header, "_geoInfo");

            //HEU_TestHelpers.AssertTrueLogEquivalent(this._geoName, other._geoName, ref bResult, header, "_geoName");

            HEU_TestHelpers.AssertTrueLogEquivalent(this._parts, other._parts, ref bResult, header, "_part");

            // SKip _containerObjectNode/parentAsset stuff

            HEU_TestHelpers.AssertTrueLogEquivalent(this._geoCurve, other._geoCurve, ref bResult, header, "_geoCurve");

            // Skip volumCache

            HEU_TestHelpers.AssertTrueLogEquivalent(this._volumeCaches, other._volumeCaches, ref bResult, header, "_volumeCaches");


            return(bResult);
        }
예제 #17
0
	public bool IsEquivalentTo(HEU_Handle other)
	{
	    bool bResult = true;

	    string header = "HEU_Handle";

	    if (other == null)
	    {
		HEU_Logger.LogError(header + " Not equivalent");
		return false;
	    }

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleName, other._handleName, ref bResult, header, "_handleName");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleType,other._handleType, ref bResult, header, "_handleType");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleIndex, other._handleIndex, ref bResult, header, "_handleIndex");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleParamTranslateBinding, other._handleParamTranslateBinding, ref bResult, header, "_handleParamTranslateBinding");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleParamRotateBinding, other._handleParamRotateBinding, ref bResult, header, "_handleParamRotateBinding");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleParamScaleBinding, other._handleParamScaleBinding, ref bResult, header, "_handleParamScaleBinding");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handlePosition, other._handlePosition, ref bResult, header, "_handlePosition");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleRotation, other._handleRotation, ref bResult, header, "_handleRotation");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._handleScale, other._handleScale, ref bResult, header, "_handleScale");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._rstOrder, other._rstOrder, ref bResult, header, "_rstOrder");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._xyzOrder, other._xyzOrder, ref bResult, header, "_xyzOrder");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._convertedTransformEuler.ToTestObject(), other._convertedTransformEuler.ToTestObject(), ref bResult, header, "_convertedTransformEuler");
	    

	    // Skip _materialKey
	 
	    return bResult;
	}
	public static Material GetNewMaterialWithShader(string assetCacheFolderPath, string shaderName, string materialName = "", bool bWriteToFile = true)
	{
	    Material material = null;
	    Shader shader = FindShader(shaderName);
	    if (shader != null)
	    {
		material = new Material(shader);
		if (materialName == null || materialName.Length == 0)
		{
		    material.name = shaderName;
		}
		else
		{
		    material.name = materialName;
		}

		if (bWriteToFile && !string.IsNullOrEmpty(assetCacheFolderPath))
		{
		    string materialFileName = materialName + HEU_Defines.HEU_EXT_MAT;
		    HEU_AssetDatabase.CreateObjectInAssetCacheFolder(material, assetCacheFolderPath, HEU_Defines.HEU_FOLDER_MATERIALS, materialFileName, typeof(Material), bOverwriteExisting: true);
		}
	    }
	    else
	    {
		HEU_Logger.LogWarningFormat("Shader with name {0} not found!", shaderName);
	    }
	    return material;
	}
	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)
	    {
		HEU_Logger.LogErrorFormat("Parsing JSON files in directory caused exception: {0}", ex);
		return false;
	    }

	    return bResult;
	}
예제 #20
0
	/// <summary>
	/// Returns the path to the given asset, with subasset tagging if it is
	/// a subasset. Unity doesn't have a way to query subasset paths directly
	/// nor load them directly. Instead have to load the main asset first then
	/// traverse through all assets to find the subasset.
	/// </summary>
	/// <param name="asset">Asset to get path for</param>
	/// <returns>Path of given asset</returns>
	public static string GetAssetPathWithSubAssetSupport(Object asset)
	{
#if UNITY_EDITOR
	    string assetPath = AssetDatabase.GetAssetPath(asset);

	    bool isSubAsset = HEU_AssetDatabase.IsSubAsset(asset);
	    if (isSubAsset)
	    {
		Object[] subAssets = HEU_AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
		int numSubAssets = subAssets.Length;
		for (int i = 0; i < numSubAssets; ++i)
		{
		    if (subAssets[i] == asset)
		    {
			assetPath = string.Format("{0}{1}/{2}", HEU_Defines.HEU_SUBASSET, assetPath, subAssets[i].name);
			break;
		    }
		}
	    }

	    return assetPath;
#else
	    HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
	    return null;
#endif
	}
	public static Material LoadSubstanceMaterialWithIndex(string materialPath, int substanceMaterialIndex)
	{
	    Material material = LoadUnityMaterial(materialPath);
#if UNITY_2017_4_OR_NEWER || UNITY_2018_1_OR_NEWER
	    HEU_Logger.LogErrorFormat("Houdini Engine for Unity does not support the new Substance plugin as of yet!");
#elif UNITY_EDITOR
			if (material != null)
			{
				string assetPath = HEU_AssetDatabase.GetAssetPath(material);
				SubstanceImporter substanceImporter = AssetImporter.GetAtPath(assetPath) as SubstanceImporter;

				if(substanceMaterialIndex >= 0 && substanceMaterialIndex < substanceImporter.GetMaterialCount())
				{
					material = substanceImporter.GetMaterials()[substanceMaterialIndex];
				}
			}
#endif
	    if (material != null)
	    {
		HEU_Logger.LogFormat("Loaded Substance material with index {0} from path {1}.", substanceMaterialIndex, materialPath);
	    }
	    else
	    {
		HEU_Logger.LogWarningFormat("Failed to load Substance material with index {0} from path {1}.", substanceMaterialIndex, materialPath);
	    }

	    return material;
	}
	public void SyncDirtyAttributesToHoudini(HEU_SessionBase session)
	{
	    if (!UploadAttributeViaMeshInput(session, _geoID, _partID))
	    {
		HEU_Logger.LogError("Unable to upload custom attribute edits!");
	    }
	}
	public bool IsEquivalentTo(HEU_AttributeData other)
	{

	    bool bResult = true;

	    string header = "HEU_AttributeData";

	    if (other == null)
	    {
		HEU_Logger.LogError(header + " Not equivalent");
		return false;
	    }

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._attributeInfo.ToTestObject(), other._attributeInfo.ToTestObject(), ref bResult, header, "_attributeInfo");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._name, other._name, ref bResult, header, "_name");
	    HEU_TestHelpers.AssertTrueLogEquivalent(this._attributeType, other._attributeType, ref bResult, header, "_attributeType");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._intValues, other._intValues, ref bResult, header, "_intValues");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._floatValues, other._floatValues, ref bResult, header, "_floatValues");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._stringValues, other._stringValues, ref bResult, header, "_stringValues");

	    HEU_TestHelpers.AssertTrueLogEquivalent(this._attributeState, other._attributeState, ref bResult, header, "_attributeState");

	    return bResult;
	}
예제 #24
0
	public static void CreatePDGAssetLink()
	{
	    GameObject selectedGO = Selection.activeGameObject;
	    if (selectedGO != null)
	    {
		HEU_HoudiniAssetRoot assetRoot = selectedGO.GetComponent<HEU_HoudiniAssetRoot>();
		if (assetRoot != null)
		{
		    if (assetRoot._houdiniAsset != null)
		    {
			string name = string.Format("{0}_PDGLink", assetRoot._houdiniAsset.AssetName);

			GameObject go = HEU_GeneralUtility.CreateNewGameObject(name);
			HEU_PDGAssetLink assetLink = go.AddComponent<HEU_PDGAssetLink>();
			assetLink.Setup(assetRoot._houdiniAsset);

			Selection.activeGameObject = go;
		    }
		    else
		    {
			HEU_Logger.LogError("Selected gameobject is not an instantiated HDA. Failed to create PDG Asset Link.");
		    }
		}
		else
		{
		    HEU_Logger.LogError("Selected gameobject is not an instantiated HDA. Failed to create PDG Asset Link.");
		}
	    }
	    else
	    {
		//HEU_Logger.LogError("Nothing selected. Select an instantiated HDA first.");
		HEU_EditorUtility.DisplayErrorDialog("PDG Asset Link", "No HDA selected. You must select an instantiated HDA first.", "OK");
	    }
	}
예제 #25
0
	public static void CreateAsset(Object asset, string path)
	{
#if UNITY_EDITOR
	    AssetDatabase.CreateAsset(asset, path);
#else
			HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
#endif
	}
예제 #26
0
 /// <summary>
 /// Add the given attribute to the internal map by name.
 /// </summary>
 /// <param name="attribute">Attribute data to store</param>
 public void SetAttribute(HEU_OutputAttribute attribute)
 {
     if (string.IsNullOrEmpty(attribute._name))
     {
         HEU_Logger.LogWarningFormat("Unable to store attribute with empty name!", attribute._name);
         return;
     }
     _attributes.Add(attribute._name, attribute);
 }
예제 #27
0
	public static void AddObjectToAsset(UnityEngine.Object objectToAdd, UnityEngine.Object assetObject)
	{
#if UNITY_EDITOR
	    AssetDatabase.AddObjectToAsset(objectToAdd, assetObject);
#else
			// TODO RUNTIME: AssetDatabase is not supported at runtime. Do we need to support this for runtime?
			HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
#endif
	}
예제 #28
0
	public static string GetAssetPath(Object asset)
	{
#if UNITY_EDITOR
	    return AssetDatabase.GetAssetPath(asset);
#else
	    HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
	    return null;
#endif
	}
예제 #29
0
	public static Vector2[] GeneratePerTriangle(Mesh meshSrc)
	{
#if UNITY_EDITOR
	    return Unwrapping.GeneratePerTriangleUV(meshSrc);
#else
			HEU_Logger.LogWarning("GeneratePerTriangle is unavailable at runtime!");
			return null;
#endif
	}
예제 #30
0
	public static Object[] LoadAllAssetRepresentationsAtPath(string assetPath)
	{
#if UNITY_EDITOR
	    return AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
#else
	    HEU_Logger.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
	    return null;
#endif
	}