示例#1
0
        private void Enable()
        {
            m_cutoutMaskRenderer = IOC.Resolve <ITerrainCutoutMaskRenderer>();
            m_cutoutMaskRenderer.ObjectImageLayer = m_editor.CameraLayerSettings.ResourcePreviewLayer;

            m_terrainHandlesSelection.Selection.activeGameObject  = null;
            m_terrainHandlesSelection.Selection.SelectionChanged += OnSelectionChanged;
            m_terrainHandlesSelection.CreateCustomHandle         += OnCreateCustomHandle;
            m_terrainHandlesSelection.DestroyCustomHandle        += OnDestroyCustomHandle;
            m_terrainHandlesSelection.Enabled = true;

            m_interpolator = new CachedBicubicInterpolator();

            TerrainData data = TerrainData;

            const float preferredSpace = 10;

            m_state = Terrain.GetComponent <TerrainToolState>();
            if (m_state == null)
            {
                m_additiveHeights     = GetHeightmap();
                m_interpolatedHeights = new float[data.heightmapResolution, data.heightmapResolution];

                m_state = Terrain.gameObject.GetComponent <TerrainToolState>();
                if (m_state == null)
                {
                    m_state = Terrain.gameObject.AddComponent <TerrainToolState>();
                }

                m_state.ZSize = data.size.z;
                m_state.XSize = data.size.x;

                m_zCount = Mathf.RoundToInt(Mathf.Max(2, data.size.z / preferredSpace) + 1);
                m_xCount = Mathf.RoundToInt(Mathf.Max(2, data.size.x / preferredSpace) + 1);

                m_state.ZSpacing = m_state.ZSize / (m_zCount - 1);
                m_state.XSpacing = m_state.XSize / (m_xCount - 1);

                m_state.Grid          = new float[Mathf.FloorToInt(m_zCount) * Mathf.FloorToInt(m_xCount)];
                m_state.HeightMap     = new float[data.heightmapResolution * data.heightmapResolution];
                m_state.CutoutTexture = m_cutoutMaskRenderer.CreateMask(data, null);

                XSpacing = m_state.XSpacing;
                ZSpacing = m_state.ZSpacing;
            }
            else
            {
                InitAdditiveAndInterpolatedHeights();
            }

            CreateHandles();
            EnableZTest = EnableZTest;
        }
示例#2
0
        private void Enable()
        {
            m_editor.ActiveWindowChanged        += OnActiveWindowChanged;
            m_editor.Selection.SelectionChanged += OnSelectionChanged;
            m_interpolator = new CachedBicubicInterpolator();

            TerrainData data = ActiveTerrainData;

            m_additiveHeights     = data.GetHeights(0, 0, data.heightmapWidth, data.heightmapHeight);
            m_interpolatedHeights = new float[data.heightmapHeight, data.heightmapWidth];

            const float preferredSpace = 10;

            m_state = ActiveTerrain.GetComponent <TerrainToolState>();
            if (m_state == null || m_state.HeightMap.Length != data.heightmapWidth * data.heightmapHeight)
            {
                m_state = ActiveTerrain.gameObject.GetComponent <TerrainToolState>();
                if (m_state == null)
                {
                    m_state = ActiveTerrain.gameObject.AddComponent <TerrainToolState>();
                }

                m_state.ZSize = ActiveTerrainData.size.z;
                m_state.XSize = ActiveTerrainData.size.x;

                m_zCount = Mathf.Max(2, Mathf.FloorToInt(ActiveTerrainData.size.z / preferredSpace)) + 1;
                m_xCount = Mathf.Max(2, Mathf.FloorToInt(ActiveTerrainData.size.x / preferredSpace)) + 1;

                m_state.ZSpacing = m_state.ZSize / (m_zCount - 1);
                m_state.XSpacing = m_state.XSize / (m_xCount - 1);

                m_state.Grid          = new float[m_zCount * m_xCount];
                m_state.HeightMap     = new float[data.heightmapWidth * data.heightmapHeight];
                m_state.CutoutTexture = m_cutoutMaskRenderer.CreateMask(ActiveTerrainData, null);
            }
            else
            {
                m_state.ZSize = ActiveTerrainData.size.z;
                m_state.XSize = ActiveTerrainData.size.x;

                m_state.ZSpacing = m_state.ZSize / (m_zCount - 1);
                m_state.XSpacing = m_state.XSize / (m_xCount - 1);

                TryRefreshGrid();
            }

            InitHandles();
            OnActiveWindowChanged(m_editor.ActiveWindow);
            EnableZTest = EnableZTest;
        }
示例#3
0
        private void OnEnable()
        {
            m_editor.Undo.Store();

            m_editor.ActiveWindowChanged        += OnActiveWindowChanged;
            m_editor.Selection.SelectionChanged += OnSelectionChanged;
            m_interpolator  = new CachedBicubicInterpolator();
            m_activeTerrain = Terrain.activeTerrain;
            m_state         = m_activeTerrain.GetComponent <TerrainToolState>();
            if (m_state == null)
            {
                m_state           = m_activeTerrain.gameObject.AddComponent <TerrainToolState>();
                m_state.Size      = (int)m_activeTerrain.terrainData.size.x;
                m_count           = m_state.Size / m_state.Spacing + 1;
                m_state.Grid      = new float[m_count * m_count];
                m_state.HeightMap = new float[m_activeTerrain.terrainData.heightmapWidth * m_activeTerrain.terrainData.heightmapHeight];
                float[,] hmap     = m_activeTerrain.terrainData.GetHeights(0, 0, m_activeTerrain.terrainData.heightmapWidth, m_activeTerrain.terrainData.heightmapHeight);
                for (int i = 0; i < m_activeTerrain.terrainData.heightmapWidth; ++i)
                {
                    for (int j = 0; j < m_activeTerrain.terrainData.heightmapHeight; ++j)
                    {
                        m_state.HeightMap[i * m_activeTerrain.terrainData.heightmapHeight + j] = hmap[i, j];
                    }
                }
                m_state.CutoutTexture = m_cutoutMaskRenderer.CreateMask(null);
            }
            else
            {
                TryRefreshGrid();
            }
            InitHandles();

            OnSelectionChanged(null);
            OnActiveWindowChanged(m_editor.ActiveWindow);
            EnableZTest = EnableZTest;
        }