// 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 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); }); }
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); }); }