Esempio n. 1
0
        public static bool CreateAndCookAssetNode(HEU_SessionBase session, string assetName, bool bCookTemplatedGeos, out HAPI_NodeId newAssetID)
        {
            newAssetID = HEU_Defines.HEU_INVALID_NODE_ID;

            // Create top level node. Note that CreateNode will cook the node if HAPI was initialized with threaded cook setting on.
            bool bResult = session.CreateNode(-1, assetName, "", false, out newAssetID);

            if (!bResult)
            {
                return(false);
            }

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

            // In case the cooking wasn't done previously, force it now.
            bResult = 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);
            }

            // Get the asset ID
            HAPI_AssetInfo assetInfo = new HAPI_AssetInfo();

            bResult = session.GetAssetInfo(newAssetID, ref assetInfo);
            if (bResult)
            {
                // Check for any errors
                HAPI_ErrorCodeBits errors = session.CheckForSpecificErrors(newAssetID, (HAPI_ErrorCodeBits)HAPI_ErrorCode.HAPI_ERRORCODE_ASSET_DEF_NOT_FOUND);
                if (errors > 0)
                {
                    // TODO: revisit for UI improvement
                    HEU_EditorUtility.DisplayDialog("Asset Missing Sub-asset Definitions",
                                                    "There are undefined nodes. This is due to not being able to find specific " +
                                                    "asset definitions.", "Ok");
                    return(false);
                }
            }

            return(true);
        }
	// GEOMETRY GETTERS -------------------------------------------------------------------------------------------

	public static string GetUniqueMaterialShopName(HAPI_NodeId assetID, HAPI_NodeId materialID)
	{
	    HEU_SessionBase sessionBase = GetOrCreateDefaultSession();
	    if (sessionBase != null)
	    {
		HAPI_AssetInfo assetInfo = new HAPI_AssetInfo();
		if (!sessionBase.GetAssetInfo(assetID, ref assetInfo))
		{
		    return "";
		}

		HAPI_MaterialInfo materialInfo = new HAPI_MaterialInfo();
		if (!sessionBase.GetMaterialInfo(materialID, ref materialInfo))
		{
		    return "";
		}

		HAPI_NodeInfo assetNodeInfo = new HAPI_NodeInfo();
		if (!sessionBase.GetNodeInfo(assetID, ref assetNodeInfo))
		{
		    return "";
		}

		HAPI_NodeInfo materialNodeInfo = new HAPI_NodeInfo();
		if (!sessionBase.GetNodeInfo(materialInfo.nodeId, ref materialNodeInfo))
		{
		    return "";
		}

		string assetNodeName = HEU_SessionManager.GetString(assetNodeInfo.internalNodePathSH, sessionBase);
		string materialNodeName = HEU_SessionManager.GetString(materialNodeInfo.internalNodePathSH, sessionBase);
		if (assetNodeName.Length > 0 && materialNodeName.Length > 0)
		{
		    // Remove assetNodeName from materialNodeName. Extra position is for separator.
		    string materialName = materialNodeName.Substring(assetNodeName.Length + 1);
		    return materialName.Replace("/", "_");
		}
	    }
	    return "";
	}