How to create a multipatch using a series of triangles


Creating a multipatch using a series of triangles

The following shows a simple code example of constructing a textured MultiPatch geometry using a TriangleStrip that resembles a vertical polygon, assuming it is 300 (width) x 100 (height) in size:
[Java]
static IMultiPatch createMultipatch()throws Exception{
    //Prepare the geometry material list.
    IGeometryMaterial texture = new GeometryMaterial();
    texture.setTextureImage("C:\\Temp\\MyImage.bmp");

    IGeometryMaterialList materialList = new GeometryMaterialList();
    materialList.addMaterial(texture);

    //Create the multipatch.
    IGeneralMultiPatchCreator multiPatchCreator = new GeneralMultiPatchCreator();
    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 = 1;
    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.
    _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, textureUpperRight);
    multiPatchCreator.setTextureWKSPoint(1, textureLowerRight);
    multiPatchCreator.setTextureWKSPoint(2, textureUpperLeft);
    multiPatchCreator.setTextureWKSPoint(3, textureLowerLeft);
    IMultiPatch multiPatch = (IMultiPatch)multiPatchCreator.createMultiPatch();

    return multiPatch;
}






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