示例#1
0
        /// <summary>
        /// Returns terrain names of terrains that intersect with the given bounds object
        /// </summary>
        /// <param name="bounds">A bounds object to check against the terrains. Needs to be in absolute world space position, mind the current origin offset!</param>
        /// <returns></returns>
        public static string[] GetTerrainsIntersectingBounds(BoundsDouble bounds)
        {
            //Reduce the bounds size a bit to prevent selecting terrains that are perfectly aligned with the bounds border
            //-this leads to too many terrains being logged as affected by an operation otherwise.
            Bounds intersectingBounds = new BoundsDouble();

            intersectingBounds.center = bounds.center;
            intersectingBounds.size   = bounds.size - new Vector3Double(0.001f, 0.001f, 0.001f);

            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                GaiaSessionManager sessionManager = GaiaSessionManager.GetSessionManager();
                if (sessionManager == null)
                {
                    Debug.LogError("Trying to get terrains that intersect with bounds, but there is no session manager in scene.");
                    return(null);
                }
                return(TerrainLoaderManager.TerrainScenes.Where(x => x.m_bounds.Intersects(intersectingBounds)).Select(x => x.GetTerrainName()).ToArray());
            }
            else
            {
                List <string> affectedTerrainNames = new List <string>();
                foreach (Terrain t in Terrain.activeTerrains)
                {
                    if (intersectingBounds.Intersects(TerrainHelper.GetWorldSpaceBounds(t)))
                    {
                        affectedTerrainNames.Add(t.name);
                    }
                }
                return(affectedTerrainNames.ToArray());
            }
        }
示例#2
0
        /// <summary>
        /// Get current basic scene information
        /// </summary>
        /// <returns></returns>
        public static GaiaSceneInfo GetSceneInfo()
        {
            GaiaSceneInfo sceneInfo = new GaiaSceneInfo();
            Terrain       terrain   = Gaia.TerrainHelper.GetActiveTerrain();

            if (terrain == null)
            {
                Debug.LogWarning("You must have a valid terrain for sceneinfo to work correctly.");
            }
            else
            {
                //Get or create a session in order to get a sea level
                GaiaSessionManager sessionMgr = GaiaSessionManager.GetSessionManager();

                //Get the terrain bounds
                Gaia.TerrainHelper.GetTerrainBounds(terrain, ref sceneInfo.m_sceneBounds);

                //Get the sea level
                sceneInfo.m_seaLevel = sessionMgr.GetSeaLevel();

                //Grab the central point on the terrain - handy for placing player etc
                sceneInfo.m_centrePointOnTerrain = new Vector3(sceneInfo.m_sceneBounds.center.x, terrain.SampleHeight(sceneInfo.m_sceneBounds.center), sceneInfo.m_sceneBounds.center.z);
            }

            return(sceneInfo);
        }
示例#3
0
        /// <summary>
        /// Get current basic scene information
        /// </summary>
        /// <returns></returns>
        public static GaiaSceneInfo GetSceneInfo()
        {
            GaiaSceneInfo sceneInfo = new GaiaSceneInfo();


            //Get or create a session in order to get a sea level
            GaiaSessionManager sessionMgr = GaiaSessionManager.GetSessionManager();

            //Get the sea level
            sceneInfo.m_seaLevel = sessionMgr.GetSeaLevel();


            //Not used anywhere - obsolete?
            //Terrain terrain = Gaia.TerrainHelper.GetActiveTerrain();

            ////Get the terrain bounds
            //Gaia.TerrainHelper.GetTerrainBounds(terrain, ref sceneInfo.m_sceneBounds);


            ////Grab the central point on the terrain - handy for placing player etc
            //sceneInfo.m_centrePointOnTerrain = new Vector3(sceneInfo.m_sceneBounds.center.x, terrain.SampleHeight(sceneInfo.m_sceneBounds.center), sceneInfo.m_sceneBounds.center.z);


            return(sceneInfo);
        }
示例#4
0
        public static void FinalizePlayerObjectEditor(GameObject playerObj, GaiaSettings gaiaSettings)
        {
            if (playerObj != null)
            {
                playerObj.transform.SetParent(GaiaUtils.GetPlayerObject().transform);
                #if UNITY_EDITOR
                //Adjust the scene view to see the camera
                if (SceneView.lastActiveSceneView != null)
                {
                    if (gaiaSettings.m_focusPlayerOnSetup)
                    {
                        SceneView.lastActiveSceneView.LookAtDirect(playerObj.transform.position, playerObj.transform.rotation);
                    }
                }
                #endif
            }

            GaiaSessionManager session = GaiaSessionManager.GetSessionManager();
            if (session != null)
            {
                if (session.m_session != null)
                {
                    if (playerObj.transform.position.y < session.m_session.m_seaLevel)
                    {
                        playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z);
                    }
                }
            }

#if GAIA_PRO_PRESENT
            //Add the simple terrain culling script, useful in any case
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true;
            }
#endif

            bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains();
            if (dynamicLoadedTerrains)
            {
#if GAIA_PRO_PRESENT
                TerrainLoader loader = playerObj.GetComponent <TerrainLoader>();
                if (loader == null)
                {
                    loader = playerObj.AddComponent <TerrainLoader>();
                }
                loader.LoadMode = LoadMode.RuntimeAlways;
                float tileSize = 512;
                if (TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize > 0)
                {
                    tileSize = TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize;
                }
                float size = tileSize * 1.25f * 2f;
                loader.m_loadingBoundsRegular  = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size));
                loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f));
                loader.m_loadingBoundsCollider = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size));
#endif
            }
        }
示例#5
0
 public static string GetTerrainMeshExportDirectory(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(CreatePathIfDoesNotExist(GetExportDirectory(gaiaSession) + TERRAIN_MESH_EXPORT_DIRECTORY));
 }
示例#6
0
 public static string GetMaskMapExportDirectory(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(CreatePathIfDoesNotExist(GetExportDirectory(gaiaSession) + MASK_MAP_EXPORT_DIRECTORY));
 }
示例#7
0
 /// <summary>
 /// Returns the path to store terrain layer files in
 /// </summary>
 /// <param name="gaiaSession">The current session to get / create this directory for</param>
 /// <returns></returns>
 public static string GetTerrainLayerPath(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + TERRAIN_LAYERS_DIRECTORY));
 }
示例#8
0
 /// <summary>
 /// Returns the path to store scene files in, according to the Gaia Session path
 /// </summary>
 /// <param name="gaiaSession">The session to get / create the directory for</param>
 /// <returns></returns>
 public static string GetScenePath(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(GetSessionSubFolderPath(gaiaSession));
 }
示例#9
0
 /// <summary>
 /// Returns the path to store impostor scenes in, according to the session filename
 /// </summary>
 /// <param name="gaiaSession">The session to get / create this path for</param>
 /// <returns></returns>
 public static string GetBackupScenePath(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + BACKUP_SCENES_DIRECTORY));
 }
示例#10
0
 /// <summary>
 /// Returns the path to store collider scenes in, according to the session filename
 /// </summary>
 /// <param name="gaiaSession">The session to get / create this path for</param>
 /// <returns></returns>
 public static string GetColliderScenePath(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + COLLIDER_SCENES_DIRECTORY));
 }
示例#11
0
 /// <summary>
 /// Returns the path to store impostor scenes in, according to the session filename
 /// </summary>
 /// <param name="gaiaSession">The session to get / create this path for</param>
 /// <returns></returns>
 public static string GetImpostorScenePath(GaiaSession gaiaSession = null)
 {
     if (gaiaSession == null)
     {
         gaiaSession = GaiaSessionManager.GetSessionManager().m_session;
     }
     return(CreatePathIfDoesNotExist(GetScenePath(gaiaSession) + IMPOSTOR_SCENES_DIRECTORY));
 }
示例#12
0
        public static void BakeMaskStack(ImageMask[] maskStack, Terrain terrain, Transform transform, float range, int resolution, string path)
        {
            //Simulate an operation to allow the image masks to acces the current terrain data
            GaiaMultiTerrainOperation operation = new GaiaMultiTerrainOperation(terrain, transform, range);

            operation.GetHeightmap();
            operation.GetNormalmap();
            operation.CollectTerrainBakedMasks();

            float maxCurrentTerrainHeight = 0f;
            float minCurrentTerrainHeight = 0f;
            float seaLevel;

            GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();

            gsm.GetWorldMinMax(ref minCurrentTerrainHeight, ref maxCurrentTerrainHeight);
            seaLevel = gsm.GetSeaLevel();

            if (maskStack.Length > 0)
            {
                //We start from a white texture, so we need the first mask action in the stack to always be "Multiply", otherwise there will be no result.
                maskStack[0].m_blendMode = ImageMaskBlendMode.Multiply;

                //Iterate through all image masks and set up the required data that masks might need to function properly
                foreach (ImageMask mask in maskStack)
                {
                    //mask.m_heightmapContext = heightmapContext;
                    //mask.m_normalmapContext = normalmapContext;
                    //mask.m_collisionContext = collisionContext;
                    mask.m_multiTerrainOperation = operation;
                    mask.m_seaLevel       = seaLevel;
                    mask.m_maxWorldHeight = maxCurrentTerrainHeight;
                    mask.m_minWorldHeight = minCurrentTerrainHeight;
                }
            }

            RenderTexture inputTexture = RenderTexture.GetTemporary(resolution, resolution, 0, RenderTextureFormat.ARGBFloat);
            RenderTexture currentRT    = RenderTexture.active;

            RenderTexture.active = inputTexture;
            GL.Clear(true, true, Color.white);
            RenderTexture.active = currentRT;
            RenderTexture localOutputTexture  = RenderTexture.GetTemporary(inputTexture.descriptor);
            RenderTexture globalOutputTexture = RenderTexture.GetTemporary(inputTexture.descriptor);

            localOutputTexture  = ImageProcessing.ApplyMaskStack(inputTexture, localOutputTexture, maskStack, ImageMaskInfluence.Local);
            globalOutputTexture = ImageProcessing.ApplyMaskStack(localOutputTexture, globalOutputTexture, maskStack, ImageMaskInfluence.Global);

            WriteRenderTexture(path, globalOutputTexture);

            RenderTexture.ReleaseTemporary(inputTexture);
            RenderTexture.ReleaseTemporary(localOutputTexture);
            RenderTexture.ReleaseTemporary(globalOutputTexture);
            inputTexture        = null;
            localOutputTexture  = null;
            globalOutputTexture = null;
            operation.CloseOperation();
        }
示例#13
0
        public static void PlayBWSession(string stampName, BWGGaiaExtConst.BWGStampFeatureType featureType, string packShortname)
        {
            // Enable stamp if it isn't already enabled
            MoveBWStamp(stampName, featureType, "Assets/BackwoodsGaming/GaiaPacks/Stamp/" + packShortname + "/Stamps/" + featureType + "/", 1);

            // Check to see if a terrain already exists in the scene.  If so, give user option to flatten.
            Terrain t = Gaia.TerrainHelper.GetActiveTerrain();

            if (t != null)
            {
                if (EditorUtility.DisplayDialog("WARNING", "You have an existing terrain in your scene!  Would you like to flatten it or Quit?", "Quit", "Flatten"))
                {
                    Debug.Log("Quit selected? ");
                    return;
                }

                // User chose to flatten terrain.
                GaiaWorldManager wm = new GaiaWorldManager(Terrain.activeTerrains);
                wm.FlattenWorld();
            }

            // Create Gaia root game object if it doesn't already exist in scene hierarchy.
            GameObject gaiaObj = GameObject.Find("Gaia");

            if (gaiaObj == null)
            {
                gaiaObj = new GameObject("Gaia");
            }

            // Check for Session Manager and create if it doesn't exist.
            GaiaSessionManager sessionMgr = null;
            GameObject         mgrObj     = GameObject.Find("Session Manager");

            if (mgrObj == null)
            {
                mgrObj     = new GameObject("Session Manager");
                sessionMgr = mgrObj.AddComponent <GaiaSessionManager>();
                mgrObj.transform.parent = gaiaObj.transform;
            }
            else
            {
                sessionMgr = mgrObj.GetComponent <GaiaSessionManager>();
            }

            // Find and load the saved session for this stamp
            sessionMgr.m_session = AssetDatabase.LoadAssetAtPath <GaiaSession>("Assets/BackwoodsGaming/GaiaPacks/Stamp/" + packShortname + "/Data/GS-" + stampName + ".asset");

            // Debug.Log("Session: " + sessionMgr.m_session.m_name);

            // Play the session after user confirms
            if (EditorUtility.DisplayDialog("Playback Session ?", "Are you sure you want to playback this session - this can not be undone ?", "Yes", "No"))
            {
                sessionMgr.PlaySession();
            }
        }
示例#14
0
        void OnEnable()
        {
            //Get the settings and update tooltips
            GaiaSettings settings = Gaia.Utils.GetGaiaSettings();

            if (settings != null)
            {
                m_showTooltips = settings.m_showTooltips;
            }

            //Get our resource
            m_manager = (GaiaSessionManager)target;
        }
示例#15
0
        /// <summary>
        /// Create the terrain defined by these settings - and apply the resources to it
        /// </summary>
        public void CreateTerrain(GaiaResource resources)
        {
            Terrain[,] world;

            //Update the resouces ny associating them with their assets
            resources.AssociateAssets();

            //Update the session
            GaiaSessionManager sessionMgr = GaiaSessionManager.GetSessionManager();

            if (sessionMgr != null && sessionMgr.IsLocked() != true)
            {
                //Update terrain settings in session
                sessionMgr.m_session.m_terrainWidth  = m_tilesX * m_terrainSize;
                sessionMgr.m_session.m_terrainDepth  = m_tilesZ * m_terrainSize;
                sessionMgr.m_session.m_terrainHeight = m_terrainHeight;

                //Add the defaults
                sessionMgr.AddDefaults(this);

                //Set the sea level - but only if it is zero - if not zero then its been deliberately set
                if (Gaia.GaiaUtils.Math_ApproximatelyEqual(sessionMgr.m_session.m_seaLevel, 0f))
                {
                    sessionMgr.SetSeaLevel(m_seaLevel);
                }

                //Grab the resources scriptable object
                sessionMgr.AddResource(resources);

                //Adjust them if they are different to the defaults
                resources.ChangeSeaLevel(sessionMgr.m_session.m_seaLevel);

                //Then add the operation
                sessionMgr.AddOperation(GetTerrainCreationOperation(resources));
            }

            //Create the terrains array
            world = new Terrain[m_tilesX, m_tilesZ];

            //And iterate through and create each terrain
            for (int x = 0; x < m_tilesX; x++)
            {
                for (int z = 0; z < m_tilesZ; z++)
                {
                    CreateTile(x, z, ref world, resources);
                }
            }

            //Now join them together and remove their seams
            RemoveWorldSeams(ref world);
        }
示例#16
0
        void OnEnable()
        {
            m_manager = (GaiaSessionManager)target;

            //Init editor utils
            if (m_editorUtils == null)
            {
                // Get editor utils for this
                m_editorUtils = PWApp.GetEditorUtils(this);
            }


            GaiaLighting.SetPostProcessingStatus(false);
        }
示例#17
0
    public void StampButton()
    {
        StamperSettings stamperSettings = ScriptableObject.CreateInstance <StamperSettings>();

        stamperSettings.m_width      = 150;
        stamperSettings.m_imageMasks = new ImageMask[1] {
            new ImageMask()
            {
                m_operation      = ImageMaskOperation.ImageMask,
                ImageMaskTexture = stamperTestTexture
            }
        };
        stamperSettings.m_y = 25;
        GaiaSessionManager.Stamp(stamperSettings, executeStamp, null, true);
    }
示例#18
0
    public void CreateTerrainButton()
    {
        WorldCreationSettings worldCreationSettings = ScriptableObject.CreateInstance <WorldCreationSettings>();

        worldCreationSettings.m_xTiles                = xTiles;
        worldCreationSettings.m_zTiles                = zTiles;
        worldCreationSettings.m_tileSize              = tileSize;
        worldCreationSettings.m_tileHeight            = tileHeight;
        worldCreationSettings.m_seaLevel              = seaLevel;
        worldCreationSettings.m_createInScene         = createTerrainsInScenes;
        worldCreationSettings.m_autoUnloadScenes      = autoUnloadScenes;
        worldCreationSettings.m_applyFloatingPointFix = applyFloatingPointFix;
        //worldCreationSettings.m_gaiaDefaults = new GaiaDefaults();
        //worldCreationSettings.m_spawnerPresetList = new List<BiomeSpawnerListEntry>() { }
        GaiaSessionManager.CreateWorld(worldCreationSettings, executeWorldCreation);
    }
示例#19
0
        /// <summary>
        /// Looks up terrain layer asset files matching a Gaia terrain, and returns them as an array.
        /// </summary>
        /// <param name="terrainName">The Gaia terrain name to look up terrain layer asset files for.</param>
        /// <returns></returns>
        //        private static TerrainLayer[] LookupTerrainLayerAssetFiles(string terrainName)
        //        {
        //#if UNITY_EDITOR

        //            string gaiaDirectory = "";
        //            string terrainLayerDirectory = gaiaDirectory + "Profiles/TerrainLayers";
        //            DirectoryInfo info = new DirectoryInfo(terrainLayerDirectory);
        //            FileInfo[] fileInfo = info.GetFiles(terrainName + "*.asset");

        //            TerrainLayer[] returnArray = new TerrainLayer[fileInfo.Length];

        //            for (int i = 0; i < fileInfo.Length; i++)
        //            {
        //                returnArray[i] = (TerrainLayer)AssetDatabase.LoadAssetAtPath("Assets" + fileInfo[i].FullName.Substring(Application.dataPath.Length), typeof(TerrainLayer));
        //            }
        //            return returnArray;
        //#else
        //            Debug.LogError("Runtime Gaia operation is not supported");
        //            return new TerrainLayer[0];
        //#endif
        //        }

        /// <summary>
        /// Saves a unity terrain layer as asset file and returns a reference to the newly created Terrain Layerfile.
        /// </summary>
        /// <param name="terrainName">The name of the current Gaia terrain (for the filename).</param>
        /// <param name="layerId">The layer ID of the layer that is to be saved (for the filename).</param>
        /// <param name="terrainLayer">The terrain layer object to save.</param>
        /// <returns>Reference to the created TerrainLayer</returns>
        public static TerrainLayer SaveTerrainLayerAsAsset(string terrainName, string layerId, TerrainLayer terrainLayer)
        {
#if UNITY_EDITOR
            GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager();

            //The combination of terrain name and layer id should be unique enough so that users don't overwrite layers between terrains.
            string path = GaiaDirectories.GetTerrainLayerPath(gsm.m_session) + "/" + terrainName + "_" + layerId + ".asset";

            AssetDatabase.CreateAsset(terrainLayer, path);
            AssetDatabase.ImportAsset(path);

            return(AssetDatabase.LoadAssetAtPath <TerrainLayer>(path));
#else
            Debug.LogError("Runtime Gaia operation is not supported");
            return(new TerrainLayer());
#endif
        }
示例#20
0
        /// <summary>
        /// Get the terrain scene that matches this location, otherwise return null
        /// </summary>
        /// <param name="locationWU">Location to check in world units</param>
        /// <returns>Terrain here or null</returns>
        public static TerrainScene GetDynamicLoadedTerrain(Vector3 locationWU, GaiaSessionManager gsm = null)
        {
            if (gsm == null)
            {
                gsm = GaiaSessionManager.GetSessionManager(false);
            }

            foreach (TerrainScene terrainScene in TerrainLoaderManager.TerrainScenes)
            {
                if (terrainScene.m_bounds.min.x <= locationWU.x && terrainScene.m_bounds.min.z <= locationWU.z && terrainScene.m_bounds.max.x >= locationWU.x && terrainScene.m_bounds.max.z >= locationWU.z)
                {
                    return(terrainScene);
                }
            }

            return(null);
        }
示例#21
0
        private void AddNewCollisionMaskCacheEntry(RenderTexture texture, Terrain terrain, string fileName)
        {
            BakedMaskCacheEntry[] newArray = new BakedMaskCacheEntry[m_cacheEntries.Length + 1];
            int length2 = m_cacheEntries.Length;

            for (int i = 0; i < length2; i++)
            {
                newArray[i] = m_cacheEntries[i];
            }
            newArray[newArray.Length - 1] = new BakedMaskCacheEntry();
            WriteCacheEntry(newArray[newArray.Length - 1], texture, terrain, fileName);
            m_cacheEntries = newArray;
            //EditorUtility.SetDirty(this);
#if UNITY_EDITOR
            EditorUtility.SetDirty(GaiaSessionManager.GetSessionManager(false));
#endif
        }
示例#22
0
        /// <summary>
        /// Create the terrain defined by these settings
        /// </summary>
        public void CreateTerrain()
        {
            Terrain[,] world;

            //Update the session
            GaiaSessionManager sessionMgr = GaiaSessionManager.GetSessionManager();

            if (sessionMgr != null && sessionMgr.IsLocked() != true)
            {
                //Update terrain settings in session
                sessionMgr.m_session.m_terrainWidth  = m_tilesX * m_terrainSize;
                sessionMgr.m_session.m_terrainDepth  = m_tilesZ * m_terrainSize;
                sessionMgr.m_session.m_terrainHeight = m_terrainHeight;
                sessionMgr.AddDefaults(this);

                sessionMgr.SetSeaLevel(m_seaLevel);

                //Then add the operation
                GaiaOperation op = new GaiaOperation();
                op.m_description       = "Creating terrain";
                op.m_generatedByID     = m_defaultsID;
                op.m_generatedByName   = this.name;
                op.m_generatedByType   = this.GetType().ToString();
                op.m_isActive          = true;
                op.m_operationDateTime = DateTime.Now.ToString();
                op.m_operationType     = GaiaOperation.OperationType.CreateTerrain;
                sessionMgr.AddOperation(op);
            }

            //Create the terrains array
            world = new Terrain[m_tilesX, m_tilesZ];

            //And iterate through and create each terrain
            for (int x = 0; x < m_tilesX; x++)
            {
                for (int z = 0; z < m_tilesZ; z++)
                {
                    CreateTile(x, z, ref world, null);
                }
            }

            //Now join them together and remove their seams
            RemoveWorldSeams(ref world);
        }
示例#23
0
        private void ExportMask()
        {
            GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);

            if (mgr.TileCount > 0)
            {
                GaiaSessionManager gsm  = GaiaSessionManager.GetSessionManager();
                string             path = GaiaDirectories.GetExportDirectory(gsm.m_session);
                path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));
                mgr.ExportSplatmapAsPng(path, m_selectedMask);
                Debug.Log("Created " + path);
                AssetDatabase.Refresh();
                EditorUtility.FocusProjectWindow();
                EditorUtility.DisplayDialog("Export complete", " Your texture mask has been saved to : " + path, "OK");
            }
            else
            {
                EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain!!", "OK");
            }
        }
示例#24
0
        public static void FinalizePlayerObjectRuntime(GameObject playerObj)
        {
            GaiaSessionManager session = GaiaSessionManager.GetSessionManager();

            if (session != null)
            {
                if (session.m_session != null)
                {
                    if (playerObj.transform.position.y < session.m_session.m_seaLevel)
                    {
                        playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z);
                    }
                }
            }

#if GAIA_PRO_PRESENT
            //Add the simple terrain culling script, useful in any case
            if (GaiaUtils.CheckIfSceneProfileExists())
            {
                GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true;
            }
#endif

            bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains();
            if (dynamicLoadedTerrains)
            {
#if GAIA_PRO_PRESENT
                Terrain       terrain = TerrainHelper.GetActiveTerrain();
                TerrainLoader loader  = playerObj.GetComponent <TerrainLoader>();
                if (loader == null)
                {
                    loader = playerObj.AddComponent <TerrainLoader>();
                }
                loader.LoadMode = LoadMode.RuntimeAlways;
                float size = terrain.terrainData.size.x * 1.25f * 2f;
                loader.m_loadingBoundsRegular  = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size));
                loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f));
#endif
            }
        }
示例#25
0
        /// <summary>
        /// Returns a folder that is named as the session asset, to store session related data into.
        /// </summary>
        /// <param name="gaiaSession">The session to create the directory for</param>
        /// <returns></returns>
        public static string GetSessionSubFolderPath(GaiaSession gaiaSession, bool create = true)
        {
#if UNITY_EDITOR
            string masterScenePath = AssetDatabase.GetAssetPath(gaiaSession).Replace(".asset", "");
            if (String.IsNullOrEmpty(masterScenePath))
            {
                GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false);
                gsm.SaveSession();
                masterScenePath = AssetDatabase.GetAssetPath(gsm.m_session).Replace(".asset", "");
            }
            if (create)
            {
                return(CreatePathIfDoesNotExist(masterScenePath));
            }
            else
            {
                return(masterScenePath);
            }
#else
            return("");
#endif
        }
示例#26
0
        private void ExportNormal()
        {
            if (Terrain.activeTerrain == null)
            {
                EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain in your scene!!", "OK");
                return;
            }

            GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);

            if (mgr.TileCount > 0)
            {
                GaiaSessionManager gsm  = GaiaSessionManager.GetSessionManager();
                string             path = GaiaDirectories.GetExportDirectory(gsm.m_session);
                mgr.LoadFromWorld();
                path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));
                mgr.ExportNormalmapAsPng(path);
                AssetDatabase.Refresh();

                EditorUtility.DisplayDialog("Export complete", " Your normal map has been saved to : " + path, "OK");
            }
        }
示例#27
0
        void OnGUI()
        {
            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle           = new GUIStyle(GUI.skin.label);
                m_wrapStyle.fontStyle = FontStyle.Normal;
                m_wrapStyle.wordWrap  = true;
            }

            //Text intro
            GUILayout.BeginVertical("Gaia WaterFlow Mask Exporter", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("The Gaia waterflow exporter allows you to calculate and export a water flow mask from your terrain.", m_wrapStyle);
            GUILayout.EndVertical();

            if (string.IsNullOrEmpty(m_maskName))
            {
                m_maskName = string.Format("TerrainWaterFlow-{0:yyyyMMdd-HHmmss}", DateTime.Now);
            }
            m_maskName = EditorGUILayout.TextField(GetLabel("Mask Name"), m_maskName);

            m_waterFlowMap.m_dropletVolume             = EditorGUILayout.Slider(GetLabel("Droplet Volume"), m_waterFlowMap.m_dropletVolume, 0.1f, 2f);
            m_waterFlowMap.m_dropletAbsorbtionRate     = EditorGUILayout.Slider(GetLabel("Droplet Absorbtion Rate"), m_waterFlowMap.m_dropletAbsorbtionRate, 0.01f, 1f);
            m_waterFlowMap.m_waterflowSmoothIterations = EditorGUILayout.IntSlider(GetLabel("Smooth Iterations"), m_waterFlowMap.m_waterflowSmoothIterations, 0, 10);

            GUILayout.Space(5);

            EditorGUI.indentLevel++;
            if (DisplayButton(GetLabel("Create Mask")))
            {
                Terrain terrain = Gaia.TerrainHelper.GetActiveTerrain();
                if (terrain == null)
                {
                    EditorUtility.DisplayDialog("OOPS!", "You must have a valid terrain!!", "OK");
                    return;
                }
                GaiaSessionManager gsm  = GaiaSessionManager.GetSessionManager();
                string             path = GaiaDirectories.GetExportDirectory(gsm.m_session);

                path = Path.Combine(path, PWCommon4.Utils.FixFileName(m_maskName));

                m_waterFlowMap.CreateWaterFlowMap(terrain);
                m_waterFlowMap.ExportWaterMapToPath(path);


                GaiaWorldManager mgr = new GaiaWorldManager(Terrain.activeTerrains);
                mgr.LoadFromWorld();

                path += "WaterFlow";
                mgr.ExportWaterflowMapAsPng(m_waterFlowMap.m_waterflowSmoothIterations, path);

                AssetDatabase.Refresh();
                EditorUtility.DisplayDialog("Done!", "Your mask is available at " + path, "OK");
            }
            EditorGUI.indentLevel--;
        }
示例#28
0
        /// <summary>
        /// Crate post processing instance profile
        /// </summary>
        /// <param name="sceneProfile"></param>
        public static void CreatePostFXProfileInstance(SceneProfile sceneProfile, GaiaLightingProfileValues profile)
        {
            try
            {
                if (sceneProfile == null)
                {
                    return;
                }

#if UPPipeline
                VolumeProfile volumeProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaUtils.GetAssetPath("URP Global Post Processing Profile.asset"));
                if (profile.PostProcessProfileURP != null)
                {
                    volumeProfile = profile.PostProcessProfileURP;
                }
                if (volumeProfile == null)
                {
                    return;
                }

                GaiaSessionManager session = GaiaSessionManager.GetSessionManager();
                if (session != null)
                {
                    string path = GaiaDirectories.GetSceneProfilesFolderPath(session.m_session);
                    if (!string.IsNullOrEmpty(path))
                    {
                        if (EditorSceneManager.GetActiveScene() != null)
                        {
                            if (!string.IsNullOrEmpty(EditorSceneManager.GetActiveScene().path))
                            {
                                path = path + "/" + EditorSceneManager.GetActiveScene().name + " " + volumeProfile.name + " Profile.asset";
                            }
                            else
                            {
                                path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
                            }
                        }
                        else
                        {
                            path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
                        }

                        if (sceneProfile.m_universalPostFXProfile != null)
                        {
                            if (!sceneProfile.m_isUserProfileSet)
                            {
                                if (!sceneProfile.m_universalPostFXProfile.name.Contains(volumeProfile.name))
                                {
                                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(sceneProfile.m_universalPostFXProfile));
                                    sceneProfile.m_universalPostFXProfile = null;
                                }
                            }
                        }

                        if (AssetDatabase.LoadAssetAtPath <VolumeProfile>(path) == null)
                        {
                            FileUtil.CopyFileOrDirectory(AssetDatabase.GetAssetPath(volumeProfile), path);
                            AssetDatabase.ImportAsset(path);
                        }

                        sceneProfile.m_universalPostFXProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(path);
                    }
                }
#endif
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
示例#29
0
        /// <summary>
        /// Clear all the trees on all the terrains
        /// </summary>
        public static void ClearSpawns(SpawnerResourceType resourceType, ClearSpawnFor clearSpawnFor, ClearSpawnFrom clearSpawnFrom, List <string> terrainNames = null, Spawner spawner = null)
        {
            if (terrainNames == null)
            {
                if (clearSpawnFor == ClearSpawnFor.AllTerrains)
                {
                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        GaiaSessionManager sessionManager = GaiaSessionManager.GetSessionManager();
                        terrainNames = TerrainLoaderManager.TerrainScenes.Select(x => x.GetTerrainName()).ToList();
                    }
                    else
                    {
                        terrainNames = Terrain.activeTerrains.Select(x => x.name).ToList();
                    }
                }
                else
                {
                    terrainNames = new List <string> {
                        spawner.GetCurrentTerrain().name
                    };
                }
            }

            string progressBarTitle = "Clearing...";

            Action <Terrain> act = null;

            switch (resourceType)
            {
            case SpawnerResourceType.TerrainTexture:
                progressBarTitle = "Clearing Textures";
                //Not supported, should not be required
                throw new NotSupportedException("Clearing of Textures is currently not supported via the terrain helper");

            case SpawnerResourceType.TerrainDetail:
                progressBarTitle = "Clearing Terrain Details";
                act = (t) => ClearDetailsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.TerrainTree:
                progressBarTitle = "Clearing Trees";
                act = (t) => ClearTreesOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.GameObject:
                progressBarTitle = "Clearing Game Objects";
                act = (t) => ClearGameObjectsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.Probe:
                progressBarTitle = "Clearing Probes";
                act = (t) => ClearGameObjectsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.SpawnExtension:
                progressBarTitle = "Clearing Spawn Extensions";
                act = (t) => ClearSpawnExtensionsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.StampDistribution:
                //Not supported, should not be required
                throw new NotSupportedException("Clearing of Stamps is currently not supported via the terrain helper");
            }

            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                GaiaUtils.CallFunctionOnDynamicLoadedTerrains(act, true, terrainNames);
            }
            else
            {
                for (int idx = 0; idx < terrainNames.Count; idx++)
                {
                    ProgressBar.Show(ProgressBarPriority.Spawning, progressBarTitle, progressBarTitle, idx + 1, terrainNames.Count(), true);

                    GameObject go = GameObject.Find(terrainNames[idx]);
                    if (go != null)
                    {
                        Terrain terrain = go.GetComponent <Terrain>();
                        act(terrain);
                    }
                    ProgressBar.Clear(ProgressBarPriority.Spawning);
                }
            }
        }
示例#30
0
        /// <summary>
        /// Get the bounds of the terrain at this location or fail with a null
        /// </summary>
        /// <param name="locationWU">Location to check and get terrain for</param>
        /// <returns>Bounds of selected terrain or null if invalid for some reason</returns>
        public static bool GetTerrainBounds(ref BoundsDouble bounds, bool activeTerrainsOnly = false)
        {
            //Terrain terrain = GetTerrain(locationWU);
            //if (terrain == null)
            //{
            //    return false;
            //}
            //bounds.center = terrain.transform.position;
            //bounds.size = terrain.terrainData.size;
            //bounds.center += bounds.extents;

            Vector3Double accumulatedCenter = new Vector3Double();

            //Do we use dynamic loaded terrains in the scene?
            if (GaiaUtils.HasDynamicLoadedTerrains() && !activeTerrainsOnly)
            {
#if GAIA_PRO_PRESENT
                //we do have dynamic terrains -> calculate the bounds according to the terrain scene data in the session
                GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false);

                foreach (TerrainScene t in TerrainLoaderManager.TerrainScenes)
                {
                    accumulatedCenter += t.m_bounds.center;
                }

                bounds.center = accumulatedCenter / TerrainLoaderManager.TerrainScenes.Count;

                foreach (TerrainScene t in TerrainLoaderManager.TerrainScenes)
                {
                    bounds.Encapsulate(t.m_bounds);
                }
#endif
            }
            else
            {
                //no placeholder -> calculate bounds according to the active terrains in the scene
                if (Terrain.activeTerrains.Length > 0)
                {
                    foreach (Terrain t in Terrain.activeTerrains)
                    {
                        if (!TerrainHelper.IsWorldMapTerrain(t))
                        {
                            if (t.terrainData != null)
                            {
                                accumulatedCenter += new Vector3Double(t.transform.position) + new Vector3Double(t.terrainData.bounds.extents);
                            }
                            else
                            {
                                Debug.LogWarning("Terrain " + t.name + " in the scene is missing the terrain data object!");
                            }
                        }
                    }
                    bounds.center = accumulatedCenter / Terrain.activeTerrains.Length;

                    foreach (Terrain t in Terrain.activeTerrains)
                    {
                        if (!TerrainHelper.IsWorldMapTerrain(t))
                        {
                            if (t.terrainData != null)
                            {
                                Bounds newBounds = new Bounds();
                                newBounds.center  = t.transform.position;
                                newBounds.size    = t.terrainData.size;
                                newBounds.center += t.terrainData.bounds.extents;
                                bounds.Encapsulate(newBounds);
                            }
                        }
                    }
                }
                else
                {
                    bounds = new BoundsDouble(Vector3Double.zero, Vector3Double.zero);
                    //No active terrains? There might be mesh terrains we can use then
                    GameObject meshTerrainExportObject = GaiaUtils.GetTerrainExportObject(false);
                    if (meshTerrainExportObject != null)
                    {
                        foreach (Transform t in meshTerrainExportObject.transform)
                        {
                            MeshRenderer mr = t.GetComponent <MeshRenderer>();
                            if (mr != null)
                            {
                                bounds.Encapsulate(mr.bounds);
                            }
                        }
                    }
                }
            }


            return(true);
        }