How to create a multipatch using a series of triangles


Creating a multipatch using a series of triangles

The following code example shows how to construct a textured MultiPatch geometry using a TriangleStrip that resembles a vertical polygon, assuming it is 300 (width) x 100 (height) in size:
[C#]
public IMultiPatch CreateMultipatch()
{
    //Prepare the geometry material list.
    IGeometryMaterial texture = new GeometryMaterialClass();
    texture.TextureImage = "C:\\Temp\\MyImage.bmp";

    IGeometryMaterialList materialList = new GeometryMaterialListClass();
    materialList.AddMaterial(texture);

    //Create the multipatch.
    IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreatorClass()
        ;
    multiPatchCreator.Init(4, 1, false, false, false, 4, materialList);

    //Set up part.

    //Could also use a Ring or a TriangleFan.
    multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip);
    multiPatchCreator.SetMaterialIndex(0, 0);
    multiPatchCreator.SetPatchPointIndex(0, 0);
    multiPatchCreator.SetPatchTexturePointIndex(0, 0);

    //Set real-world points.
    WKSPointZ upperLeft = new WKSPointZ();
    WKSPointZ lowerLeft = new WKSPointZ();
    WKSPointZ upperRight = new WKSPointZ();
    WKSPointZ lowerRight = new WKSPointZ();

    upperLeft.X = 0;
    upperLeft.Y = 0;
    upperLeft.Z = 0;
    upperRight.X = 300;
    upperRight.Y = 0;
    upperRight.Z = 0;
    lowerLeft.X = 0;
    lowerLeft.Y = 0;
    lowerLeft.Z =  - 100;
    lowerRight.X = 300;
    lowerRight.Y = 0;
    lowerRight.Z =  - 100;

    multiPatchCreator.SetWKSPointZ(0, ref upperRight);
    multiPatchCreator.SetWKSPointZ(1, ref lowerRight);
    multiPatchCreator.SetWKSPointZ(2, ref upperLeft);
    multiPatchCreator.SetWKSPointZ(3, ref lowerLeft);

    //Set texture points.
    //Set the texture coordinates for a panel.
    WKSPoint textureUpperLeft = new WKSPoint();
    WKSPoint textureLowerLeft = new WKSPoint();
    WKSPoint textureUpperRight = new WKSPoint();
    WKSPoint textureLowerRight = new WKSPoint();

    textureUpperLeft.X = 0;
    textureUpperLeft.Y = 0;
    textureUpperRight.X = 1;
    textureUpperRight.Y = 0;
    textureLowerLeft.X = 0;
    textureLowerLeft.Y = 1;
    textureLowerRight.X = 1;
    textureLowerRight.Y = 1;

    multiPatchCreator.SetTextureWKSPoint(0, ref textureUpperRight);
    multiPatchCreator.SetTextureWKSPoint(1, ref textureLowerRight);
    multiPatchCreator.SetTextureWKSPoint(2, ref textureUpperLeft);
    multiPatchCreator.SetTextureWKSPoint(3, ref textureLowerLeft);
    IMultiPatch multiPatch = multiPatchCreator.CreateMultiPatch()as IMultiPatch;

    return multiPatch;
}
[VB.NET]
Private Function CreateMultipatch() As IMultiPatch
    'Prepare the geometry material list.
    Dim texture As IGeometryMaterial = New GeometryMaterialClass()
    texture.TextureImage = "C:\\Temp\\MyImage.bmp"
    Dim materialList As IGeometryMaterialList = New GeometryMaterialListClass()
    materialList.AddMaterial(texture)
    
    'Create the multipatch.
    Dim multiPatchCreator As IGeneralMultiPatchCreator = New GeneralMultiPatchCreatorClass()
    multiPatchCreator.Init(4, 1, False, False, False, 4, materialList)
    
    'Set up part.
    'Could also use a Ring or a TriangleFan.
    multiPatchCreator.SetPatchType(0, esriPatchType.esriPatchTypeTriangleStrip)
    multiPatchCreator.SetMaterialIndex(0, 0)
    multiPatchCreator.SetPatchPointIndex(0, 0)
    multiPatchCreator.SetPatchTexturePointIndex(0, 0)
    
    'Set real-world points.
    Dim upperLeft As WKSPointZ = New WKSPointZ()
    Dim lowerLeft As WKSPointZ = New WKSPointZ()
    Dim upperRight As WKSPointZ = New WKSPointZ()
    Dim lowerRight As WKSPointZ = New WKSPointZ()
    upperLeft.X = 0
    upperLeft.Y = 0
    upperLeft.Z = 0
    upperRight.X = 300
    upperRight.Y = 0
    upperRight.Z = 0
    lowerLeft.X = 0
    lowerLeft.Y = 0
    lowerLeft.Z = -100
    lowerRight.X = 300
    lowerRight.Y = 0
    lowerRight.Z = -100
    multiPatchCreator.SetWKSPointZ(0, upperRight)
    multiPatchCreator.SetWKSPointZ(1, lowerRight)
    multiPatchCreator.SetWKSPointZ(2, upperLeft)
    multiPatchCreator.SetWKSPointZ(3, lowerLeft)
    
    'Set texture points.
    'Set the texture coordinates for a panel.
    Dim textureUpperLeft As WKSPoint = New WKSPoint()
    Dim textureLowerLeft As WKSPoint = New WKSPoint()
    Dim textureUpperRight As WKSPoint = New WKSPoint()
    Dim textureLowerRight As WKSPoint = New WKSPoint()
    textureUpperLeft.X = 0
    textureUpperLeft.Y = 0
    textureUpperRight.X = 1
    textureUpperRight.Y = 0
    textureLowerLeft.X = 0
    textureLowerLeft.Y = 1
    textureLowerRight.X = 1
    textureLowerRight.Y = 1
    multiPatchCreator.SetTextureWKSPoint(0, textureUpperRight)
    multiPatchCreator.SetTextureWKSPoint(1, textureLowerRight)
    multiPatchCreator.SetTextureWKSPoint(2, textureUpperLeft)
    multiPatchCreator.SetTextureWKSPoint(3, textureLowerLeft)
    Dim multiPatch As IMultiPatch = CType(multiPatchCreator.CreateMultiPatch(), IMultiPatch)
    Return multiPatch
End Function


See Also:

Sample: 3D multipatch examples




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine