Esempio n. 1
0
        protected override void OnClick()
        {
            // find footprint layer
            var buildingLyr = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "BuildingStructure") as FeatureLayer;

            if (buildingLyr == null)
            {
                MessageBox.Show("Can't find layer: BuildingStructure");
                return;
            }

            // create new structural features
            _ = QueuedTask.Run(() =>
            {
                // get all selected lines and use them as the building footprint
                var bldgSelection = buildingLyr.GetSelection();
                Multipatch mp     = null;
                #region Get MultiPatch
                foreach (var footprintOid in bldgSelection.GetObjectIDs())
                {
                    // get the multipatch shape using the Inspector
                    var insp = new Inspector();
                    insp.Load(buildingLyr, footprintOid);
                    mp = insp.Shape.Clone() as Multipatch;
                    break;
                }
                #endregion
                if (mp == null)
                {
                    MessageBox.Show("No multipatch selected");
                    return;
                }

                // create a builder
                var mpb = new ArcGIS.Core.Geometry.MultipatchBuilderEx(mp);

                // apply the texture materials to the patches
                var patches = mpb.Patches;
                foreach (var patch in patches)
                {
                    System.Diagnostics.Debug.WriteLine(patch.Material);
                    MyMultipatchBuilder.ShowPatchLabels(patch);
                    foreach (var coord in patch.TextureCoords2D)
                    {
                        System.Diagnostics.Debug.WriteLine($@"new Coordinate2D({coord.X},{coord.Y}),");
                    }
                    break;
                }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the structure (multipatch) from a given footprint and the number of floors
        /// building a multipatch geometry using the new 2.5 MultipatchBuilderEx class
        /// Must be called from MCT !!!
        /// </summary>
        /// <param name="floorFootPrint">footprint line features of wall</param>
        /// <param name="floorLevels">Number of floors (4 meters/floor)</param>
        /// <returns></returns>
        public static MultipatchBuilderEx CreateTriangleMultipatchBuilder(Polygon floorFootPrint,
                                                                          int floorLevels)
        {
            var heightInMeters = floorLevels * 7;
            // create the multipatchBuilderEx object
            var mpb = new ArcGIS.Core.Geometry.MultipatchBuilderEx();
            // create a list of patch objects
            var patches = new List <Patch>();
            var coords  = new List <Coordinate3D>();

            // each line in the polygon makes up one 'face' (patch) for the multipatch
            // the floor footprint is the baseline
            // heightInMeters is the elevation
            coords.AddRange(CoordsWithHeight(floorFootPrint, heightInMeters));
            // to drape the faces with textures we have to using triangle patches
            // with one patch for each wall and each wall with the following coordinates
            // making two triangles per wall:
            // upper right, upper left, lower left
            // upper right, lower left, lower right
            // the coords list contains for each wall:
            // lower left, upper left, lower right, upper right
            // process each wall:
            for (var idx = 0; idx < coords.Count - 3; idx += 2)
            {
                var patch      = mpb.MakePatch(esriPatchType.Triangles);
                var wallCoords = GetWallCoordinates(coords, idx);
                patch.Coords = wallCoords;
                // if (idx == 0) ShowPatchLabels(patch);
                patches.Add(patch);
            }
            // add the roof
            var roofPatch  = mpb.MakePatch(esriPatchType.TriangleFan);
            var roofCoords = GetRoofCoordinates(coords);

            roofPatch.Coords = roofCoords;
            patches.Add(roofPatch);

            // assign the patches to the multipatchBuilder
            mpb.Patches = patches;

            // call ToGeometry to get the multipatch
            return(mpb);
        }
        protected override async void OnClick()
        {
            // make sure there's an OID from a created feature
            if (Module1.MultipatchOID == -1)
            {
                return;
            }

            if (MapView.Active?.Map == null)
            {
                return;
            }

            // find layer
            var member = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "MultipatchWithTextureSimple") as FeatureLayer;

            if (member == null)
            {
                return;
            }


            // create the textures
            esriTextureCompressionType compressionType = esriTextureCompressionType.CompressionJPEG;

            byte[] brickImageBuffer     = GetBufferImage("pack://application:,,,/MultipatchBuilderEx;component/Textures/Brick.jpg", compressionType);
            var    brickTextureResource = new TextureResource(new JPEGTexture(brickImageBuffer));

            BasicMaterial brickMaterialTexture = new BasicMaterial();

            brickMaterialTexture.TextureResource = brickTextureResource;

            byte[] blocksImageBuffer     = GetBufferImage("pack://application:,,,/MultipatchBuilderEx;component/Textures/Retaining_Blocks.jpg", compressionType);
            var    blocksTextureResource = new TextureResource(new JPEGTexture(blocksImageBuffer));

            BasicMaterial blockskMaterialTexture = new BasicMaterial();

            blockskMaterialTexture.TextureResource = blocksTextureResource;

            byte[] waterImageBuffer     = GetBufferImage("pack://application:,,,/MultipatchBuilderEx;component/Textures/water.jpg", compressionType);
            var    waterTextureResource = new TextureResource(new JPEGTexture(waterImageBuffer));

            BasicMaterial waterMaterialTexture = new BasicMaterial();

            waterMaterialTexture.TextureResource = waterTextureResource;

            // set up a set of TextureCoordinates - these determine how the texture is draped over a face
            //  In this scenario we will use the same textureCoordinates for each face
            var textureCoords = new List <Coordinate2D>()
            {
                new Coordinate2D(0, 0),
                new Coordinate2D(1, 0),
                new Coordinate2D(1, -1),
                new Coordinate2D(0, 0),
                new Coordinate2D(1, -1),
                new Coordinate2D(0, -1),
            };

            bool result = await QueuedTask.Run(() =>
            {
                // get the multipatch shape using the Inspector
                var insp = new Inspector();
                insp.Load(member, Module1.MultipatchOID);
                var origMultipatch = insp.Shape as Multipatch;

                // create a builder
                var mpb = new ArcGIS.Core.Geometry.MultipatchBuilderEx(origMultipatch);

                // apply the texture materials to the patches
                var patches = mpb.Patches;

                patches[0].Material        = brickMaterialTexture;
                patches[0].TextureCoords2D = textureCoords;

                patches[1].Material        = blockskMaterialTexture;
                patches[1].TextureCoords2D = textureCoords;

                patches[2].Material        = brickMaterialTexture;
                patches[2].TextureCoords2D = textureCoords;

                patches[3].Material        = waterMaterialTexture;
                patches[3].TextureCoords2D = textureCoords;

                patches[4].Material        = blockskMaterialTexture;
                patches[4].TextureCoords2D = textureCoords;

                patches[5].Material        = waterMaterialTexture;
                patches[5].TextureCoords2D = textureCoords;

                // use this method to determine patches which contain the specified texture
                //var texture = mpb.QueryPatchIndicesWithTexture(brickTextureResource);

                // get the modified multipatch geometry
                var newMultipatch = mpb.ToGeometry() as Multipatch;

                // modify operation
                var modifyOp  = new EditOperation();
                modifyOp.Name = "Apply textures to multipatch";
                modifyOp.Modify(member, Module1.MultipatchOID, newMultipatch);

                if (modifyOp.Execute())
                {
                    return(true);
                }

                return(false);
            });
        }
        // static method to hold the coordinates and code for building a multipatch geometry using the new 2.5 MultipatchBuilderEx class
        public static Multipatch CreateTriangleMultipatchGeometry()
        {
            #region Coordinates

            var coords_face1 = new List <Coordinate3D>()
            {
                new Coordinate3D(12.495461061000071, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 62.552700000000186),
            };

            var coords_face2 = new List <Coordinate3D>()
            {
                new Coordinate3D(12.495461061000071, 41.902576344000067, 62.552700000000186),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 62.552700000000186),
            };

            var coords_face3 = new List <Coordinate3D>()
            {
                new Coordinate3D(12.495488442000067, 41.902576344000067, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 62.552700000000186),
            };

            var coords_face4 = new List <Coordinate3D>()
            {
                new Coordinate3D(12.495488442000067, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 59.504700000004959),
            };

            var coords_face5 = new List <Coordinate3D>()
            {
                new Coordinate3D(12.495488442000067, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 59.504700000004959),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 62.552700000000186),
            };

            var coords_face6 = new List <Coordinate3D>()
            {
                new Coordinate3D(12.495488442000067, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495461061000071, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902603910000039, 62.552700000000186),
                new Coordinate3D(12.495461061000071, 41.902576344000067, 62.552700000000186),
                new Coordinate3D(12.495488442000067, 41.902576344000067, 62.552700000000186),
            };
            #endregion

            // create a list of patch objects
            var patches = new List <Patch>();

            // create the multipatchBuilderEx object
            var mpb = new ArcGIS.Core.Geometry.MultipatchBuilderEx();

            // make each patch using the appropriate coordinates and add to the patch list
            var patch = mpb.MakePatch(esriPatchType.Triangles);
            patch.Coords = coords_face1;
            patches.Add(patch);

            patch        = mpb.MakePatch(esriPatchType.Triangles);
            patch.Coords = coords_face2;
            patches.Add(patch);

            patch        = mpb.MakePatch(esriPatchType.Triangles);
            patch.Coords = coords_face3;
            patches.Add(patch);

            patch        = mpb.MakePatch(esriPatchType.Triangles);
            patch.Coords = coords_face4;
            patches.Add(patch);

            patch        = mpb.MakePatch(esriPatchType.Triangles);
            patch.Coords = coords_face5;
            patches.Add(patch);

            patch        = mpb.MakePatch(esriPatchType.Triangles);
            patch.Coords = coords_face6;
            patches.Add(patch);

            // assign the patches to the multipatchBuilder
            mpb.Patches = patches;

            // call ToGeometry to get the multipatch
            var multipatch = mpb.ToGeometry() as Multipatch;

            return(multipatch);
        }
        protected override async void OnClick()
        {
            // make sure there's an OID from a created feature
            if (Module1.MultipatchOID == -1)
            {
                return;
            }

            if (MapView.Active?.Map == null)
            {
                return;
            }

            // find layer
            var member = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "MultipatchWithTextureSimple") as FeatureLayer;

            if (member == null)
            {
                return;
            }

            // create some materials
            var materialRed = new BasicMaterial();

            materialRed.Color = System.Windows.Media.Colors.Red;

            var materialTransparent = new BasicMaterial();

            materialTransparent.Color = System.Windows.Media.Colors.White;
            materialTransparent.TransparencyPercent = 80;

            var materialBlue = new BasicMaterial();

            materialBlue.Color = System.Windows.Media.Colors.SkyBlue;

            bool result = await QueuedTask.Run(() =>
            {
                // get the multipatch shape using the Inspector
                var insp = new Inspector();
                insp.Load(member, Module1.MultipatchOID);
                var origMultipatch = insp.Shape as Multipatch;

                // create a builder
                var mpb = new ArcGIS.Core.Geometry.MultipatchBuilderEx(origMultipatch);
                // apply the materials to the patches
                var patches         = mpb.Patches;
                patches[0].Material = materialRed;
                patches[1].Material = materialTransparent;
                patches[2].Material = materialRed;
                patches[3].Material = materialBlue;
                patches[4].Material = materialRed;
                patches[5].Material = materialRed;

                // use the QueryPatchIndicesWithMaterial method to determine patches which contain the specified material
                //var red = mpb.QueryPatchIndicesWithMaterial(materialRed);
                //var blue = mpb.QueryPatchIndicesWithMaterial(materialBlue);

                // get the modified multipatch geometry
                var newMultipatch = mpb.ToGeometry() as Multipatch;

                // modify operation
                var modifyOp  = new EditOperation();
                modifyOp.Name = "Apply materials to multipatch";
                modifyOp.Modify(member, Module1.MultipatchOID, newMultipatch);

                if (modifyOp.Execute())
                {
                    return(true);
                }

                return(false);
            });
        }