Exemplo n.º 1
0
        private void DoImportColors()
        {
            int resolution = LPTCommon.PAINTER_MAP_RESOLUTION;

            DesData.Shading.AlbedoMapResolution = resolution;
            Color[] colors = new Color[resolution * resolution];
            Vector2 uv     = Vector2.zero;
            Color   c      = Color.clear;

            for (int z = 0; z < resolution; ++z)
            {
                for (int x = 0; x < resolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, resolution - 1, x),
                        Mathf.InverseLerp(0, resolution - 1, z));
                    c = SrcData.SurfaceSettings.GetColor(uv);
                    colors[GUtilities.To1DIndex(x, z, resolution)] = c;
                }
            }

            DesData.Shading.Internal_AlbedoMap.SetPixels(colors);
            DesData.Shading.Internal_AlbedoMap.Apply();
            DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
        }
        private void DoExportGeometry()
        {
            DesData.heightmapResolution = SrcData.Geometry.HeightMapResolution + 1;
            int resolution = DesData.heightmapResolution;

            float[,] heightSample = new float[resolution, resolution];
            Vector2 uv  = Vector2.zero;
            Vector2 enc = Vector2.zero;
            float   h   = 0;

            for (int z = 0; z < resolution; ++z)
            {
                for (int x = 0; x < resolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, resolution - 1, x),
                        Mathf.InverseLerp(0, resolution - 1, z));
                    enc = (Vector4)SrcData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                    h   = GCommon.DecodeFloatRG(enc);
                    heightSample[z, x] = h;
                }
            }

            DesData.SetHeights(0, 0, heightSample);

            if (ExportTerrainSize)
            {
                DesData.size = new Vector3(SrcData.Geometry.Width, SrcData.Geometry.Height, SrcData.Geometry.Length);
            }
        }
Exemplo n.º 3
0
        private void DoImportGrasses()
        {
            if (!ImportGrassInstancesOnly)
            {
                GGrassPrototypeGroup grassesGroup = DesData.Foliage.Grasses;
                if (grassesGroup == null ||
                    grassesGroup == GRuntimeSettings.Instance.foliageDefault.grasses)
                {
                    CreateNewGrassPrototypesGroup = true;
                }

                if (CreateNewGrassPrototypesGroup)
                {
                    grassesGroup = ScriptableObject.CreateInstance <GGrassPrototypeGroup>();

#if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        string path      = AssetDatabase.GetAssetPath(DesData);
                        string directory = Path.GetDirectoryName(path);
                        string filePath  = Path.Combine(directory, string.Format("Grasses_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks));
                        AssetDatabase.CreateAsset(grassesGroup, filePath);
                    }
#endif
                    DesData.Foliage.Grasses = grassesGroup;
                }

                grassesGroup.Prototypes.Clear();

                DetailPrototype[] detailPrototypes = SrcData.detailPrototypes;
                for (int i = 0; i < detailPrototypes.Length; ++i)
                {
                    GGrassPrototype proto = (GGrassPrototype)detailPrototypes[i];
                    grassesGroup.Prototypes.Add(proto);
                }
                GCommon.SetDirty(grassesGroup);
            }

            List <GGrassInstance> grasses = new List <GGrassInstance>();
            int detailResolution          = SrcData.detailResolution;
            int detailLayerCount          = SrcData.detailPrototypes.Length;
            for (int layer = 0; layer < detailLayerCount; ++layer)
            {
                int[,] density = SrcData.GetDetailLayer(0, 0, detailResolution, detailResolution, layer);
                DoImportDetailLayer(layer, density, grasses);
            }

            DesData.Foliage.ClearGrassInstances();
            DesData.Foliage.AddGrassInstances(grasses);
            if (DesTerrain != null)
            {
                DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect);
                DesTerrain.UpdateGrassPatches(-1, true);
                DesData.Foliage.ClearGrassDirtyRegions();
            }

            DesData.SetDirty(GTerrainData.DirtyFlags.Foliage);
            //GC.Collect();
        }
Exemplo n.º 4
0
        private void ImportRaw16()
        {
            byte[] data          = File.ReadAllBytes(FilePath);
            int    rawResolution = Mathf.FloorToInt(Mathf.Sqrt(data.Length / sizeof(UInt16)));

            if (rawResolution * rawResolution != data.Length / sizeof(UInt16))
            {
                throw new Exception("Error on populate data, RAW file doesn't have squared size or bit depth has been mis-configured!");
            }

            if (UseRawResolution)
            {
                DesData.Geometry.HeightMapResolution = rawResolution;
            }

            float[] heightData = new float[rawResolution * rawResolution];
            for (int i = 0; i < heightData.Length; ++i)
            {
                UInt16 pixelValue = BitConverter.ToUInt16(data, i * 2);
                heightData[i] = pixelValue * 1.0f / UInt16.MaxValue;
            }

            Vector2 uv  = Vector2.zero;
            Vector2 enc = Vector2.zero;
            float   h   = 0;

            Color[] heightMapColors    = DesData.Geometry.HeightMap.GetPixels();
            Color[] oldHeightMapColors = new Color[heightMapColors.Length];
            Array.Copy(heightMapColors, oldHeightMapColors, heightMapColors.Length);

            int heightMapResolution = DesData.Geometry.HeightMapResolution;

            for (int z = 0; z < heightMapResolution; ++z)
            {
                for (int x = 0; x < heightMapResolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, heightMapResolution - 1, x),
                        1 - Mathf.InverseLerp(0, heightMapResolution - 1, z));

                    Color c = heightMapColors[GUtilities.To1DIndex(x, z, heightMapResolution)];
                    h   = GUtilities.GetValueBilinear(heightData, rawResolution, rawResolution, uv);
                    enc = GCommon.EncodeTerrainHeight(h);
                    c.r = enc.x;
                    c.g = enc.y;
                    heightMapColors[GUtilities.To1DIndex(x, z, heightMapResolution)] = c;
                }
            }

            DesData.Geometry.HeightMap.SetPixels(heightMapColors);
            DesData.Geometry.HeightMap.Apply();

            IEnumerable <Rect> dirtyRects = GCommon.CompareTerrainTexture(DesData.Geometry.ChunkGridSize, oldHeightMapColors, heightMapColors);

            DesData.Geometry.SetRegionDirty(dirtyRects);
            DesData.SetDirty(GTerrainData.DirtyFlags.Geometry);
        }
Exemplo n.º 5
0
        private void DoImportTrees()
        {
            if (!ImportTreeInstancesOnly)
            {
                GTreePrototypeGroup treeGroup = DesData.Foliage.Trees;
                if (treeGroup == null ||
                    treeGroup == GRuntimeSettings.Instance.foliageDefault.trees)
                {
                    CreateNewTreePrototypesGroup = true;
                }

                if (CreateNewTreePrototypesGroup)
                {
                    treeGroup = ScriptableObject.CreateInstance <GTreePrototypeGroup>();

#if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        string path      = AssetDatabase.GetAssetPath(DesData);
                        string directory = Path.GetDirectoryName(path);
                        string filePath  = Path.Combine(directory, string.Format("Trees_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks));
                        AssetDatabase.CreateAsset(treeGroup, filePath);
                    }
#endif
                    DesData.Foliage.Trees = treeGroup;
                }

                treeGroup.Prototypes.Clear();
                TreePrototype[] treePrototypes = SrcData.treePrototypes;
                for (int i = 0; i < treePrototypes.Length; ++i)
                {
                    GTreePrototype proto = (GTreePrototype)treePrototypes[i];
                    treeGroup.Prototypes.Add(proto);
                }
                GCommon.SetDirty(treeGroup);
            }

            DesData.Foliage.TreeInstances.Clear();
            TreeInstance[] treeInstances = SrcData.treeInstances;
            for (int i = 0; i < treeInstances.Length; ++i)
            {
                GTreeInstance t = (GTreeInstance)treeInstances[i];
                DesData.Foliage.TreeInstances.Add(t);
            }

            if (DesTerrain != null)
            {
                DesData.Foliage.SetTreeRegionDirty(GCommon.UnitRect);
                DesTerrain.UpdateTreesPosition();
                DesData.Foliage.ClearTreeDirtyRegions();
            }

            DesData.SetDirty(GTerrainData.DirtyFlags.Foliage);
            //GC.Collect();
        }
Exemplo n.º 6
0
        private void DoImportSplats()
        {
            GSplatPrototypeGroup splatGroup = DesData.Shading.Splats;

            if (splatGroup == null ||
                splatGroup == GGriffinSettings.Instance.TerrainDataDefault.Shading.Splats)
            {
                CreateNewSplatPrototypesGroup = true;
            }

            if (CreateNewSplatPrototypesGroup)
            {
                splatGroup = ScriptableObject.CreateInstance <GSplatPrototypeGroup>();

#if UNITY_EDITOR
                string path      = AssetDatabase.GetAssetPath(DesData);
                string directory = Path.GetDirectoryName(path);
                string filePath  = Path.Combine(directory, string.Format("Splats_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks));
                AssetDatabase.CreateAsset(splatGroup, filePath);
#endif
                DesData.Shading.Splats = splatGroup;
            }

            List <LPTSplatInfo> layers     = SrcData.SurfaceSettings.Splats;
            GSplatPrototype[]   prototypes = new GSplatPrototype[layers.Count];
            for (int i = 0; i < layers.Count; ++i)
            {
                GSplatPrototype p = (GSplatPrototype)layers[i];
                prototypes[i] = p;
            }
            splatGroup.Prototypes = new List <GSplatPrototype>(prototypes);

            int controlResolution = SrcData.SurfaceSettings.ControlResolution;
            DesData.Shading.SplatControlResolution = controlResolution;

            Texture[]     alphaMaps       = SrcData.SurfaceSettings.GetSplatControlTextures();
            int           maxControlCount = Mathf.Min(alphaMaps.Length, DesData.Shading.SplatControlMapCount);
            RenderTexture rt = new RenderTexture(controlResolution, controlResolution, 0, RenderTextureFormat.ARGB32);

            for (int i = 0; i < maxControlCount; ++i)
            {
                Texture2D controlMap = DesData.Shading.Internal_GetSplatControl(i);
                GCommon.CopyToRT(alphaMaps[i], rt);
                GCommon.CopyFromRT(controlMap, rt);
                controlMap.filterMode = alphaMaps[i].filterMode;
            }

            rt.Release();
            GUtilities.DestroyObject(rt);

            DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
            GC.Collect();
        }
Exemplo n.º 7
0
        private void DoImportGeometry()
        {
            if (UseUnityTerrainSize)
            {
                DesData.Geometry.Width  = SrcData.size.x;
                DesData.Geometry.Height = SrcData.size.y;
                DesData.Geometry.Length = SrcData.size.z;
            }
            int hmResolution = SrcData.heightmapResolution - 1;

            DesData.Geometry.HeightMapResolution = hmResolution;

            float[,] heightSample = SrcData.GetHeights(0, 0, DesData.Geometry.HeightMapResolution, DesData.Geometry.HeightMapResolution);
            Color[] heightMapColor = new Color[DesData.Geometry.HeightMapResolution * DesData.Geometry.HeightMapResolution];
            float   h = 0;
            Vector2 enc;

            int length = heightSample.GetLength(0);
            int width  = heightSample.GetLength(1);

            for (int z = 0; z < length; ++z)
            {
                for (int x = 0; x < width; ++x)
                {
                    h   = Mathf.Clamp(heightSample[z, x], 0f, 0.99999f);
                    enc = GCommon.EncodeTerrainHeight(h);
                    heightMapColor[GUtilities.To1DIndex(x, z, width)] = new Color(enc.x, enc.y, 0, 0);
                }
            }

            DesData.Geometry.HeightMap.SetPixels(heightMapColor);
            DesData.Geometry.HeightMap.Apply();
            DesData.Geometry.SetRegionDirty(GCommon.UnitRect);
            DesData.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);

            if (!SkipFoliageSnap)
            {
                if (DesTerrain != null)
                {
                    DesData.Foliage.SetTreeRegionDirty(GCommon.UnitRect);
                    DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect);
                    DesTerrain.UpdateTreesPosition();
                    DesTerrain.UpdateGrassPatches();
                    DesData.Foliage.ClearTreeDirtyRegions();
                    DesData.Foliage.ClearGrassDirtyRegions();
                }
            }

            //GC.Collect();
        }
        private void DoExportGrasses()
        {
            DesData.detailPrototypes = new DetailPrototype[0];

            if (SrcData.Foliage.Grasses == null)
            {
                return;
            }

            DetailPrototype[] detailPrototypes = new DetailPrototype[SrcData.Foliage.Grasses.Prototypes.Count];
            for (int i = 0; i < detailPrototypes.Length; ++i)
            {
                detailPrototypes[i] = (DetailPrototype)SrcData.Foliage.Grasses.Prototypes[i];
            }
            DesData.detailPrototypes = detailPrototypes;
            DesData.RefreshPrototypes();

            List <GGrassInstance> instances = SrcData.Foliage.GetGrassInstances();

            if (DesData.detailResolution <= 0)
            {
                DesData.SetDetailResolution(512, 32);
                Debug.Log("Detail Resolution is invalid, set to default value (512/32)");
            }

            int resolution = DesData.detailResolution;

            for (int layer = 0; layer < detailPrototypes.Length; ++layer)
            {
                int x = 0;
                int z = 0;
                int[,] density = new int[resolution, resolution];
                for (int i = 0; i < instances.Count; ++i)
                {
                    if (instances[i].PrototypeIndex != layer)
                    {
                        continue;
                    }
                    GGrassInstance g = instances[i];
                    x = Mathf.FloorToInt(Mathf.Lerp(0, resolution - 1, g.Position.x));
                    z = Mathf.FloorToInt(Mathf.Lerp(0, resolution - 1, g.Position.z));

                    density[z, x] += 1;
                }

                DesData.SetDetailLayer(0, 0, layer, density);
            }
        }
Exemplo n.º 9
0
        private void DoImportGeometry()
        {
            if (UsePolarisV1TerrainSize)
            {
                Vector3 size = SrcData.OverallShapeSettings.ScaledSize;
                DesData.Geometry.Width  = size.x;
                DesData.Geometry.Height = size.y;
                DesData.Geometry.Length = size.z;
            }

            SrcData.SurfaceSettings.InitHeightMapColors();
            if (SrcData.SurfaceSettings.UseMedianSmooth)
            {
                for (int i = 0; i < SrcData.SurfaceSettings.MedianSmoothPassCount; ++i)
                {
                    SrcData.SurfaceSettings.SmoothHeightMapColorAdditionalPass();
                }
            }

            int resolution = LPTCommon.PAINTER_MAP_RESOLUTION;

            DesData.Geometry.HeightMapResolution = resolution;
            Color[] heightMapColor = new Color[resolution * resolution];
            Vector2 uv             = Vector2.zero;
            float   h = 0;

            for (int z = 0; z < resolution; ++z)
            {
                for (int x = 0; x < resolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, resolution - 1, x),
                        Mathf.InverseLerp(0, resolution - 1, z));
                    h = SrcData.SurfaceSettings.GetHeightSample(uv);
                    heightMapColor[GUtilities.To1DIndex(x, z, resolution)] = new Color(h, 0, 0, 0);
                }
            }

            DesData.Geometry.Internal_HeightMap.SetPixels(heightMapColor);
            DesData.Geometry.Internal_HeightMap.Apply();
            DesData.Geometry.SetRegionDirty(GCommon.UnitRect);
            DesData.SetDirty(GTerrainData.DirtyFlags.Geometry);
            GC.Collect();
        }
Exemplo n.º 10
0
        private void DoImportSplats()
        {
            if (!ImportSplatControlMapsOnly)
            {
                GSplatPrototypeGroup splatGroup = DesData.Shading.Splats;
                if (splatGroup == null ||
                    splatGroup == GRuntimeSettings.Instance.shadingDefault.splats)
                {
                    CreateNewSplatPrototypesGroup = true;
                }

                if (CreateNewSplatPrototypesGroup)
                {
                    splatGroup = ScriptableObject.CreateInstance <GSplatPrototypeGroup>();

#if UNITY_EDITOR
                    if (!Application.isPlaying)
                    {
                        string path      = AssetDatabase.GetAssetPath(DesData);
                        string directory = Path.GetDirectoryName(path);
                        string filePath  = Path.Combine(directory, string.Format("Splats_{0}_{1}.asset", DesData.Id, System.DateTime.Now.Ticks));
                        AssetDatabase.CreateAsset(splatGroup, filePath);
                    }
#endif
                    DesData.Shading.Splats = splatGroup;
                }

                TerrainLayer[]    layers     = SrcData.terrainLayers;
                GSplatPrototype[] prototypes = new GSplatPrototype[layers.Length];
                for (int i = 0; i < layers.Length; ++i)
                {
                    if (layers[i] != null)
                    {
                        GSplatPrototype p = (GSplatPrototype)layers[i];
                        prototypes[i] = p;
                    }
                    else
                    {
                        prototypes[i] = new GSplatPrototype();
                    }
                }
                splatGroup.Prototypes = new List <GSplatPrototype>(prototypes);
                GCommon.SetDirty(splatGroup);
            }

            if (ImportSplatControlMapResolution)
            {
                DesData.Shading.SplatControlResolution = SrcData.alphamapResolution;
            }

            Texture2D[] alphaMaps     = SrcData.alphamapTextures;
            int         alphaMapCount = Mathf.Min(alphaMaps.Length, DesData.Shading.SplatControlMapCount);
            for (int i = 0; i < alphaMapCount; ++i)
            {
                try
                {
                    Texture2D controlMap = DesData.Shading.GetSplatControl(i);
                    //controlMap.SetPixels(alphaMaps[i].GetPixels());
                    //controlMap.Apply();
                    GCommon.CopyTexture(alphaMaps[i], controlMap);
                    controlMap.filterMode = alphaMaps[i].filterMode;
                }
                catch (System.Exception e)
                {
                    Debug.LogError(string.Format("Skip import splat alpha map {0}, error: {1}", alphaMaps[i].name, e.ToString()));
                }
            }

            if (ImportSplatsAsAlbedo)
            {
                DesData.Shading.ConvertSplatsToAlbedo();
            }

            DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
            //GC.Collect();
        }
Exemplo n.º 11
0
        public override void OnClick()
        {
            /*  执行接边要素的搜索
             *  基本过程:
             *    1.获取基本参数信息:图幅结合表的图层、参与接边图层列表、接边参数(从配置xml文件中获取);
             *    2.实现IMapframe接口,通过接口获取接边的源、目标缓冲区域、接边边界;
             *    3.(接边要素粗选)实现IDestinatDataset接口,使用(2)返回的缓冲区域通过接口获取待接边源要素、目标要素的OID集合;
             *    4.(接边要素精选)实现ICheckOperation接口,通过接口在步骤(3)的OID集合中判断接边情况和属性匹配情况(若FieldsControlList不赋值,则不进行属性控制);
             *    5.将接口ICheckOperation返回的信息反映到界面上。
             */
            frmJoinFeaSearch FeaSearch      = new frmJoinFeaSearch();
            List <string>    JoinFeaClsName = null;
            Dictionary <string, List <string> > JoinField = new Dictionary <string, List <string> >();//////接边控制字段
            string MapFrameName  = string.Empty;
            string MapFrameField = "";

            if (System.Windows.Forms.DialogResult.OK == FeaSearch.ShowDialog())
            {
                JoinFeaClsName = FeaSearch.JoinLayerName;
                JoinField      = FeaSearch.FieldDic;
                MapFrameName   = FeaSearch.MapFrameName;
                MapFrameField  = FeaSearch.MapFrameField;
                IFeatureClass MapFrameFeaClss = null;
                #region 获取图幅范围
                int layercount = m_Hook.ArcGisMapControl.LayerCount;
                for (int i = 0; i < layercount; i++)
                {
                    ILayer getlayer = m_Hook.ArcGisMapControl.get_Layer(i);
                    if (getlayer.Name == MapFrameName)
                    {
                        IFeatureLayer FeaLayer = getlayer as IFeatureLayer;
                        MapFrameFeaClss = FeaLayer.FeatureClass;
                    }
                }
                #endregion
                List <IFeatureClass> JoinFeaCls = new List <IFeatureClass>();
                m_Hook.PolylineSearchGrid.Tag = JoinFeaCls;//////将待接边的图层列表挂在PolylineSearchGrid.Tag上供使用
                #region 获取接边图层列表
                layercount = m_Hook.ArcGisMapControl.LayerCount;
                for (int i = 0; i < layercount; i++)
                {
                    ILayer getlayer = m_Hook.ArcGisMapControl.get_Layer(i);
                    if (JoinFeaClsName.Contains(getlayer.Name))
                    {
                        IFeatureLayer FeaLayer   = getlayer as IFeatureLayer;
                        IFeatureClass getFeaClss = FeaLayer.FeatureClass;
                        JoinFeaCls.Add(getFeaClss);
                    }
                }
                #endregion
                double dDisTo     = -1;
                double dSeacherTo = -1;
                double dAngleTo   = -1;
                double dLengthTo  = -1;
                #region 获取接边参数
                XmlDocument XmlDoc = new XmlDocument();
                XmlDoc.Load(ModData.v_JoinSettingXML);
                if (null == XmlDoc)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取接边参数配置文件失败!");
                    return;
                }
                XmlElement ele = XmlDoc.SelectSingleNode(".//接边设置") as XmlElement;

                string sDisTo       = ele.GetAttribute("距离容差");
                string sSeacherTo   = ele.GetAttribute("搜索容差");
                string sAngleTo     = ele.GetAttribute("角度容差");
                string sLengthTo    = ele.GetAttribute("长度容差");
                string sJoinType    = ele.GetAttribute("接边类型");
                string sIsRemovePnt = ele.GetAttribute("删除多边形多余点").Trim();
                string sIsSimplify  = ele.GetAttribute("简单化要素").Trim();
                try
                {
                    dDisTo     = Convert.ToDouble(sDisTo);
                    dSeacherTo = Convert.ToDouble(sSeacherTo);
                    dAngleTo   = Convert.ToDouble(sAngleTo);
                    dLengthTo  = Convert.ToDouble(sLengthTo);
                }
                catch
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "接边参数配置文件中参数不正确!");
                    return;
                }
                #endregion
                if (MapFrameFeaClss == null)
                {
                    return;
                }
                int            max          = MapFrameFeaClss.FeatureCount(null);
                IFeatureCursor JoinFrameCur = MapFrameFeaClss.Search(null, false);
                IFeature       MapFrameFea  = JoinFrameCur.NextFeature();

                IMapframe pMapframe = null;//////////接边图幅类初始化(标准图幅接边或非标准图幅接边)
                if (sJoinType == "标准图幅")
                {
                    pMapframe = new ClsMapFrame();
                }
                else
                {
                    pMapframe = new ClsTaskFrame();
                }
                pMapframe.MapFrameFea = MapFrameFeaClss;
                FrmProcessBar ProcessBar = new FrmProcessBar(max);
                ProcessBar.Show();
                ProcessBar.SetFrmProcessBarText("正在搜索接边要素");
                long value = 0;
                this.m_PolyLineSearchTable.Rows.Clear();
                this.m_PolygonSearchTable.Rows.Clear();
                IDestinatDataset DesData = null;
                if (sJoinType == "标准图幅")
                {
                    DesData = new ClsDestinatDataset(true);/////标准图幅接边搜索
                }
                else
                {
                    DesData = new ClsDestinatDataset(false);/////非标准图幅接边搜索
                }
                /////////////////////////////////
                DesData.Angle_to = dAngleTo;
                if (sIsRemovePnt == "Y")//////删除多边形上多余的点
                {
                    DesData.IsRemoveRedundantPnt = true;
                }
                else
                {
                    DesData.IsRemoveRedundantPnt = false;
                }

                if (sIsSimplify == "Y")///////要素简单化(针对有多个geometry的要素)
                {
                    DesData.IsGeometrySimplify = true;
                }
                else
                {
                    DesData.IsGeometrySimplify = false;
                }
                //////////////////////////////////////
                ele = XmlDoc.SelectSingleNode(".//日志设置") as XmlElement;
                string sLogPath = ele.GetAttribute("日志路径").Trim();



                DesData.JoinFeatureClass = JoinFeaCls;
                //////遍历每一个图幅搜索接边要素/////
                if (!string.IsNullOrEmpty(sLogPath))
                {
                    IJoinLOG  JoinLog = new ClsJoinLog();
                    Exception ex      = null;
                    JoinLog.onDataJoin_Start(0, out ex);
                }
                while (MapFrameFea != null)
                {
                    value += 1;
                    ProcessBar.SetFrmProcessBarValue(value);
                    Application.DoEvents();
                    int    index = MapFrameFea.Fields.FindField(MapFrameField);
                    string No    = string.Empty;
                    try
                    {
                        if (index > 0)
                        {
                            No = MapFrameFea.get_Value(index).ToString();
                        }
                    }
                    catch
                    {
                        No = string.Empty;
                    }
                    ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No);
                    Application.DoEvents();
                    pMapframe.OriMapFrame = MapFrameFea;

                    IGeometry OriArea = null;
                    IGeometry DesArea = null;
                    ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + "正在生成缓冲区");
                    Application.DoEvents();
                    try
                    {
                        pMapframe.GetBufferArea(dDisTo, out OriArea, out DesArea);
                    }
                    catch
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示!", "生成接边搜索缓冲区失败!\n请检查图幅范围图层是否设置正确。");
                        ProcessBar.Close();
                        return;
                    }
                    ////////////////////////////////////
                    //IElement ele2 = null;
                    //IPolygonElement pPolElemnt = new PolygonElementClass();
                    //IFillShapeElement pFillShapeElement = (IFillShapeElement)pPolElemnt;
                    //pFillShapeElement.Symbol = GetDrawSymbol(0, 255, 0);
                    //ele2 = pFillShapeElement as IElement;
                    //ele2.Geometry = DesArea;
                    //IGraphicsContainer pMapGraphics = (IGraphicsContainer)m_Hook.ArcGisMapControl.Map;
                    //pMapGraphics.AddElement(ele2, 0);
                    //m_Hook.ArcGisMapControl.ActiveView.Refresh();

                    //IElement ele3 = null;
                    //pPolElemnt = new PolygonElementClass();
                    //pFillShapeElement = (IFillShapeElement)pPolElemnt;
                    //pFillShapeElement.Symbol = GetDrawSymbol(255, 0, 0);
                    //ele3 = pFillShapeElement as IElement;
                    //ele3.Geometry = OriArea;
                    ////IGraphicsContainer pMapGraphics = (IGraphicsContainer)this.axMapControl.Map;
                    //pMapGraphics.AddElement(ele3, 0);

                    /////////////////////////////////////
                    if (!string.IsNullOrEmpty(No))
                    {
                        ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + ",正在获取接边要素");
                    }
                    else
                    {
                        ProcessBar.SetFrmProcessBarText("正在获取接边要素");
                    }
                    Application.DoEvents();
                    Dictionary <string, List <long> > OriOidDic = DesData.GetFeaturesByGeometry(OriArea, true);  ////接边源要素记录
                    Dictionary <string, List <long> > DesOidDic = DesData.GetFeaturesByGeometry(DesArea, false); ////接边目标要素记录
                    ICheckOperation CheckOper = new ClsCheckOperationer();
                    CheckOper.Angel_Tolerrance  = dAngleTo;                                                      /////////////角度容差
                    CheckOper.borderline        = pMapframe.Getborderline();                                     //接边边界
                    CheckOper.Dis_Tolerance     = dDisTo;                                                        //////////////////距离容差
                    CheckOper.Search_Tolerrance = dSeacherTo;                                                    //////////搜索容差
                    CheckOper.Length_Tolerrance = dLengthTo;                                                     ///////////长度容差
                    CheckOper.DesBufferArea     = DesArea;                                                       /////////////////目标搜索缓冲区
                    CheckOper.OriBufferArea     = OriArea;                                                       /////////////////源搜索缓冲区

                    if (!string.IsNullOrEmpty(sLogPath))
                    {
                        CheckOper.CreatLog = true;
                    }
                    else
                    {
                        CheckOper.CreatLog = false;
                    }
                    if (null != OriOidDic)
                    {
                        foreach (KeyValuePair <string, List <long> > item in OriOidDic)
                        {
                            string OriFeaName = item.Key;
                            if (!string.IsNullOrEmpty(No))
                            {
                                ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + ",正在搜索图层:" + OriFeaName);
                            }
                            else
                            {
                                ProcessBar.SetFrmProcessBarText("正在搜索图层:" + OriFeaName);
                            }
                            Application.DoEvents();
                            List <long> OriFeaOIDL = item.Value;
                            List <long> DesFeaOIDL = null;
                            if (DesOidDic == null)
                            {
                                continue;
                            }
                            if (DesOidDic.ContainsKey(OriFeaName))
                            {
                                DesFeaOIDL = DesOidDic[OriFeaName];
                            }
                            if (null != OriFeaOIDL && null != DesFeaOIDL)
                            {
                                CheckOper.DesFeaturesOID = DesFeaOIDL;
                                CheckOper.OriFeaturesOID = OriFeaOIDL;
                                IFeatureClass JoinFea = DesData.TargetFeatureClass(OriFeaName);
                                if (null != JoinFeaCls)
                                {
                                    CheckOper.DestinatFeaCls = JoinFea;
                                    if (null != JoinField)
                                    {
                                        foreach (KeyValuePair <string, List <string> > getitem in JoinField)
                                        {
                                            if (getitem.Key == (JoinFea as IDataset).Name)
                                            {
                                                CheckOper.FieldsControlList = getitem.Value;
                                            }
                                        }
                                    }
                                    esriGeometryType GeoType = CheckOper.GetDatasetGeometryType();
                                    if (GeoType == esriGeometryType.esriGeometryPolyline)
                                    {
                                        if (!string.IsNullOrEmpty(No))
                                        {
                                            ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + ",正在搜索图层:" + OriFeaName + ",操作:线型要素记录");
                                        }
                                        else
                                        {
                                            ProcessBar.SetFrmProcessBarText("正在搜索图层:" + OriFeaName + ",操作:线型要素记录");
                                        }
                                        Application.DoEvents();
                                        DataTable table = CheckOper.GetPolylineDesFeatureOIDByOriFeature();
                                        if (null != table)
                                        {
                                            for (int i = 0; i < table.Rows.Count; i++)
                                            {
                                                if (!string.IsNullOrEmpty(No))
                                                {
                                                    ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + "正在搜索图层:" + OriFeaName + ",操作:添加记录到列表");
                                                }
                                                else
                                                {
                                                    ProcessBar.SetFrmProcessBarText("正在搜索图层:" + OriFeaName + ",操作:添加记录到列表");
                                                }
                                                Application.DoEvents();
                                                this.m_PolyLineSearchTable.Rows.Add(table.Rows[i].ItemArray);
                                            }
                                        }
                                    }
                                    if (GeoType == esriGeometryType.esriGeometryPolygon)
                                    {
                                        if (!string.IsNullOrEmpty(No))
                                        {
                                            ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + "正在搜索图层:" + OriFeaName + ",操作:多边形要素记录");
                                        }
                                        else
                                        {
                                            ProcessBar.SetFrmProcessBarText("正在搜索图层:" + OriFeaName + ",操作:多边形要素记录");
                                        }
                                        Application.DoEvents();
                                        DataTable table = CheckOper.GetPolygonDesFeatureOIDByOriFeature();
                                        if (null != table)
                                        {
                                            for (int i = 0; i < table.Rows.Count; i++)
                                            {
                                                if (!string.IsNullOrEmpty(No))
                                                {
                                                    ProcessBar.SetFrmProcessBarText("正在处理图幅:" + No + "正在搜索图层:" + OriFeaName + ",操作:添加记录到列表");
                                                }
                                                else
                                                {
                                                    ProcessBar.SetFrmProcessBarText("正在搜索图层:" + OriFeaName + ",操作:添加记录到列表");
                                                }
                                                Application.DoEvents();
                                                this.m_PolygonSearchTable.Rows.Add(table.Rows[i].ItemArray);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    MapFrameFea = JoinFrameCur.NextFeature();
                }
                if (!string.IsNullOrEmpty(sLogPath))
                {
                    IJoinLOG  JoinLog = new ClsJoinLog();
                    Exception ex      = null;
                    JoinLog.onDataJoin_Terminate(0, out ex);
                }
                m_Hook.PolygonSearchGrid.DataSource  = null;
                m_Hook.PolylineSearchGrid.DataSource = null;
                m_Hook.PolygonSearchGrid.DataSource  = this.m_PolygonSearchTable;
                m_Hook.PolylineSearchGrid.DataSource = this.m_PolyLineSearchTable;
                SelectALL(m_Hook.PolylineSearchGrid);
                SelectALL(m_Hook.PolygonSearchGrid);
                MessageBox.Show("线记录个数:" + this.m_PolyLineSearchTable.Rows.Count + ";面记录个数:" + this.m_PolygonSearchTable.Rows.Count);
                ProcessBar.Close();
            }
        }
Exemplo n.º 12
0
        public void Import()
        {
            try
            {
#if UNITY_EDITOR
                GCommonGUI.ProgressBar("Working", "Importing textures...", 1f);
#endif
                if (HeightMap != null || VisibilityMap != null)
                {
                    Color[] oldHeightMapColors = DesData.Geometry.HeightMap.GetPixels();

                    Texture2D hm = null;
                    if (HeightMap != null)
                    {
                        hm = GCommon.CloneTexture(HeightMap);
                    }
                    Texture2D vm = null;
                    if (VisibilityMap != null)
                    {
                        vm = GCommon.CloneTexture(VisibilityMap);
                    }

                    int     desResolution = DesData.Geometry.HeightMapResolution;
                    Color[] newColor      = new Color[desResolution * desResolution];
                    Vector2 uv            = Vector2.zero;
                    Vector2 enc           = Vector2.zero;
                    for (int y = 0; y < desResolution; ++y)
                    {
                        for (int x = 0; x < desResolution; ++x)
                        {
                            uv.Set(
                                Mathf.InverseLerp(0, desResolution, x),
                                Mathf.InverseLerp(0, desResolution, y));

                            Color c = Color.clear;
                            if (hm != null)
                            {
                                enc = GCommon.EncodeTerrainHeight(hm.GetPixelBilinear(uv.x, uv.y).r);
                                c.r = enc.x;
                                c.g = enc.y;
                            }
                            else
                            {
                                c = DesData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                            }

                            if (vm != null)
                            {
                                c.a = 1 - vm.GetPixelBilinear(uv.x, uv.y).r;
                            }
                            else
                            {
                                c.a = DesData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y).a;
                            }

                            newColor[GUtilities.To1DIndex(x, y, desResolution)] = c;
                        }
                    }

                    DesData.Geometry.HeightMap.SetPixels(newColor);
                    DesData.Geometry.HeightMap.Apply();

                    if (hm != null || vm != null)
                    {
                        Color[]            newHeightMapColors = DesData.Geometry.HeightMap.GetPixels();
                        IEnumerable <Rect> dirtyRects         = GCommon.CompareTerrainTexture(DesData.Geometry.ChunkGridSize, oldHeightMapColors, newHeightMapColors);
                        DesData.Geometry.SetRegionDirty(dirtyRects);
                        DesData.SetDirty(GTerrainData.DirtyFlags.GeometryTimeSliced);

                        if (Terrain != null)
                        {
                            DesData.Foliage.SetTreeRegionDirty(GCommon.UnitRect);
                            DesData.Foliage.SetGrassRegionDirty(GCommon.UnitRect);
                            Terrain.UpdateTreesPosition(true);
                            Terrain.UpdateGrassPatches(-1, true);
                            DesData.Foliage.ClearTreeDirtyRegions();
                            DesData.Foliage.ClearGrassDirtyRegions();
                        }
                    }

                    if (hm != null)
                    {
                        GUtilities.DestroyObject(hm);
                    }
                    if (vm != null)
                    {
                        GUtilities.DestroyObject(vm);
                    }
                }

                if (MaskMap != null)
                {
                    GCommon.CopyTexture(MaskMap, DesData.Mask.MaskMap);
                }
                if (AlbedoMap != null)
                {
                    GCommon.CopyTexture(AlbedoMap, DesData.Shading.AlbedoMap);
                    DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
                }
                if (MetallicMap != null)
                {
                    GCommon.CopyTexture(MetallicMap, DesData.Shading.MetallicMap);
                    DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
                }
                if (SplatControlMaps != null)
                {
                    int count = Mathf.Min(SplatControlMaps.Length, DesData.Shading.SplatControlMapCount);
                    for (int i = 0; i < count; ++i)
                    {
                        if (SplatControlMaps[i] != null)
                        {
                            GCommon.CopyTexture(SplatControlMaps[i], DesData.Shading.GetSplatControl(i));
                        }
                    }
                    DesData.SetDirty(GTerrainData.DirtyFlags.Shading);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
#if UNITY_EDITOR
                GCommonGUI.ClearProgressBar();
#endif
            }
        }