ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Geometry Namespace / MultipatchBuilderEx Class / ToGeometry Method
Example

In This Topic
    ToGeometry Method (MultipatchBuilderEx)
    In This Topic
    Returns a Multipatch instance representing the current state of this builder.
    Syntax
    public new Multipatch ToGeometry()
    Public Shadows Function ToGeometry() As Multipatch
    Exceptions
    ExceptionDescription
    The number of patches or points is greater than Int32.MaxValue.
    Total number of materials cannot be greater than 65534.
    The texture buffer is invalid.
    Remarks
    The result multipatch will have - all ring patches properly closed, - any null patches or patches with less than 3 vertices will be skipped, - any triangle patch PatchType.Triangles will have the number of vertices adjusted to be divisible by 3, - any missing attributes in the patches will be set to default values. The method does not modify the builder.
    Example
    Construct Multipatch via MultipatchBuilderEx
    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),
    };
    
    // 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 blueTransparent = new BasicMaterial(materialTransparent);
    blueTransparent.Color = System.Windows.Media.Colors.SkyBlue;
    
    // 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(PatchType.Triangles);
    patch.Coords = coords_face1;
    patches.Add(patch);
    
    patch = mpb.MakePatch(PatchType.Triangles);
    patch.Coords = coords_face2;
    patches.Add(patch);
    
    patch = mpb.MakePatch(PatchType.Triangles);
    patch.Coords = coords_face3;
    patches.Add(patch);
    
    patch = mpb.MakePatch(PatchType.Triangles);
    patch.Coords = coords_face4;
    patches.Add(patch);
    
    patch = mpb.MakePatch(PatchType.Triangles);
    patch.Coords = coords_face5;
    patches.Add(patch);
    
    patch = mpb.MakePatch(PatchType.Triangles);
    patch.Coords = coords_face6;
    patches.Add(patch);
    
    patches[0].Material = materialRed;
    patches[1].Material = materialTransparent;
    patches[2].Material = materialRed;
    patches[3].Material = materialRed;
    patches[4].Material = materialRed;
    patches[5].Material = blueTransparent;
    
    // assign the patches to the multipatchBuilder
    mpb.Patches = patches;
    
    // check which patches currently contain the material
    var red = mpb.QueryPatchIndicesWithMaterial(materialRed);
    //   red should be [0, 2, 3, 4]
    
    
    // call ToGeometry to get the multipatch
    multipatch = mpb.ToGeometry() as Multipatch;
    
    Construct Multipatch from another Multipatch
    // create the multipatchBuilderEx object
    var builder = new ArcGIS.Core.Geometry.MultipatchBuilderEx(multipatch);
    
    // check some properties
    bool hasM = builder.HasM;
    bool hasZ = builder.HasZ;
    bool hasID = builder.HasID;
    bool isEmpty = builder.IsEmpty;
    bool hasNormals = builder.HasNormals;
    
    var patches = builder.Patches;
    int patchCount = patches.Count;
    
    // if there's some patches
    if (patchCount > 0)
    {
      int pointCount = builder.GetPatchPointCount(0);
    
      // replace the first point in the first patch
      if (pointCount > 0)
      {
        // get the first point
        var pt = builder.GetPoint(0, 0);
        builder.SetPoint(0, 0, newPoint);
      }
    
      // check which patches currently contain the texture
      var texture = builder.QueryPatchIndicesWithTexture(brickTextureResource);
    
      // assign a texture material
      patches[0].Material = brickMaterialTexture;
    }
    
    // update the builder for M awareness
    builder.HasM = true;
    // synchronize the patch attributes to match the builder attributes
    //   in this instance because we just set HasM to true on the builder, each patch will now get a default M value for it's set of coordinates
    builder.SynchronizeAttributeAwareness();
    
    // call ToGeometry to get the multipatch
    multipatch = builder.ToGeometry() as Multipatch;
    
    // multipatch.HasM will be true
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also