コード例 #1
0
        /// <summary>
        /// Create the mask and put it in the root assets directory
        /// </summary>
        public void CreateMask()
        {
            // Check to see if we have an active terrain
            if (Terrain.activeTerrain == null)
            {
                Debug.LogError("You need an active terrain!");
                return;
            }

            // Get the terrain
            UnityHeightMap hm = new UnityHeightMap(Terrain.activeTerrain);

            // Create a heightmap for the mask
            HeightMap maskHm = new HeightMap(hm.Width(), hm.Depth());

            //Iterate though our terrain, at the resolution of the heightmap and pick up the height
            float testHeight;
            float nrmSeaLevel = m_seaLevel / Terrain.activeTerrain.terrainData.size.y;

            for (int x = 0; x < hm.Width(); x++)
            {
                for (int z = 0; z < hm.Depth(); z++)
                {
                    testHeight = hm[x, z];
                    if (testHeight < nrmSeaLevel)
                    {
                        continue;
                    }
                    else if (Gaia.GaiaUtils.Math_ApproximatelyEqual(testHeight, nrmSeaLevel))
                    {
                        //We have a shoreline, lets mask it
                        maskHm[x, z] = m_aboveWaterStrength;
                        MakeMask(x, z, nrmSeaLevel, m_maskSize, hm, maskHm);
                    }
                    else
                    {
                        maskHm[x, z] = m_aboveWaterStrength;
                    }
                }
            }

            maskHm.Flip();
            //maskHm.Smooth(1);
            string path = GaiaDirectories.GetExportDirectory();

            path = Path.Combine(path, PWCommon4.Utils.FixFileName(string.Format("TerrainShoreLineMask-{0:yyyyMMdd-HHmmss}", DateTime.Now)));
            Gaia.GaiaUtils.CompressToSingleChannelFileImage(maskHm.Heights(), path, TextureFormat.RGBA32, false, true);

            EditorUtility.DisplayDialog("Shoreline Masker", "Your shorline mask has been created at " + path, "OK");
        }
コード例 #2
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");
            }
        }
コード例 #3
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");
            }
        }
コード例 #4
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--;
        }