Exemplo n.º 1
0
        private Multipatch CreateCubeMultipatch()
        {
            double side = 5.0;

            // create the multipatch builder
            MultipatchBuilderEx cubeMultipatchBuilderEx = new MultipatchBuilderEx();

            // make the top face patch
            Patch topFacePatch = cubeMultipatchBuilderEx.MakePatch(PatchType.FirstRing);

            topFacePatch.Coords = new List <Coordinate3D>
            {
                new Coordinate3D(0, 0, side),
                new Coordinate3D(0, side, side),
                new Coordinate3D(side, side, side),
                new Coordinate3D(side, 0, side),
            };

            // make the bottom face patch
            Patch bottomFacePatch = cubeMultipatchBuilderEx.MakePatch(PatchType.FirstRing);

            bottomFacePatch.Coords = new List <Coordinate3D>
            {
                new Coordinate3D(0, 0, 0),
                new Coordinate3D(0, side, 0),
                new Coordinate3D(side, side, 0),
                new Coordinate3D(side, 0, 0),
            };

            // make the sides face patch
            Patch sidesFacePatch = cubeMultipatchBuilderEx.MakePatch(PatchType.TriangleStrip);

            sidesFacePatch.Coords = new List <Coordinate3D>
            {
                new Coordinate3D(0, 0, 0),
                new Coordinate3D(0, 0, side),
                new Coordinate3D(side, 0, 0),
                new Coordinate3D(side, 0, side),
                new Coordinate3D(side, side, 0),
                new Coordinate3D(side, side, side),
                new Coordinate3D(0, side, 0),
                new Coordinate3D(0, side, side),
                new Coordinate3D(0, 0, 0),
                new Coordinate3D(0, 0, side),
            };

            // add to the Patches collection on the builder
            cubeMultipatchBuilderEx.Patches.Add(topFacePatch);
            cubeMultipatchBuilderEx.Patches.Add(bottomFacePatch);
            cubeMultipatchBuilderEx.Patches.Add(sidesFacePatch);

            // create the geometry
            Multipatch cubeMultipatch = cubeMultipatchBuilderEx.ToGeometry() as Multipatch;

            return(cubeMultipatch);
        }
        internal static async Task <Multipatch> MakeFishnetRingMultiPatchAsync(Polygon inputPoly)
        {
            Envelope envPoly  = inputPoly.Extent;
            var      interval = GetFishnetIntervalDistance(envPoly);

            var mColor      = System.Windows.Media.Colors.LightCyan;
            var materialRed = new BasicMaterial
            {
                Color     = mColor,
                EdgeColor = mColor,
                EdgeWidth = 0
            };
            // create the multipatchBuilderEx object
            var mpb = new MultipatchBuilderEx();
            // create a list of patch objects
            var patches = new List <Patch>();
            var first   = true;

            for (var dX = envPoly.XMin; dX < envPoly.XMax + interval; dX += interval)
            {
                for (var dY = envPoly.YMin; dY < envPoly.YMax + interval; dY += interval)
                {
                    var cutEnv = EnvelopeBuilder.CreateEnvelope(dX, dY, dX + interval, dY + interval,
                                                                envPoly.SpatialReference);
                    if (GeometryEngine.Instance.Intersects(cutEnv, inputPoly))
                    {
                        var addPolygonPart = GeometryEngine.Instance.Clip(inputPoly, cutEnv) as Polygon;
                        if (addPolygonPart.Area < 0)
                        {
                            System.Diagnostics.Debug.WriteLine($@"area: {addPolygonPart.Area}");
                        }
                        var result = await Module1.CurrentMapView.Map.GetZsFromSurfaceAsync(addPolygonPart);

                        if (result.Status == SurfaceZsResultStatus.Ok)
                        {
                            addPolygonPart = GeometryEngine.Instance.Move(result.Geometry, 0, 0, Module1.Elevation) as Polygon;
                        }
                        var patch = mpb.MakePatch(first ? esriPatchType.FirstRing : esriPatchType.Ring);
                        first = false;
                        patch.InsertPoints(0, addPolygonPart.Points);
                        patch.Material = materialRed;
                        patches.Add(patch);
                    }
                }
            }      // assign the patches to the multipatchBuilder
            mpb.Patches = patches;
            // call ToGeometry to get the multipatch
            return(mpb.ToGeometry() as Multipatch);
        }
        private Multipatch ApplyMaterialsToMultipatch(Multipatch source)
        {
            // create material for the top face patch
            BasicMaterial topFaceMaterial = new BasicMaterial();

            topFaceMaterial.Color               = Color.FromRgb(203, 65, 84);
            topFaceMaterial.Shininess           = 150;
            topFaceMaterial.TransparencyPercent = 50;
            topFaceMaterial.EdgeWidth           = 20;

            // create material for the bottom face patch
            BasicMaterial bottomFaceMaterial = new BasicMaterial();

            bottomFaceMaterial.Color     = Color.FromRgb(203, 65, 84);
            bottomFaceMaterial.EdgeWidth = 20;

            // create material for the sides face
            BasicMaterial sidesFaceMaterial = new BasicMaterial();

            sidesFaceMaterial.Color     = Color.FromRgb(133, 94, 66);
            sidesFaceMaterial.Shininess = 0;
            sidesFaceMaterial.EdgeWidth = 20;


            // create a builder using the source multipatch
            var cubeMultipatchBuilderEx = new MultipatchBuilderEx(source);

            // set material to the top face patch
            var topFacePatch = cubeMultipatchBuilderEx.Patches[0];

            topFacePatch.Material = topFaceMaterial;

            // set material to the bottom face patch
            var bottomFacePatch = cubeMultipatchBuilderEx.Patches[1];

            bottomFacePatch.Material = bottomFaceMaterial;

            // set material to the sides face patch
            var sidesFacePatch = cubeMultipatchBuilderEx.Patches[2];

            sidesFacePatch.Material = sidesFaceMaterial;

            // create the geometry
            Multipatch cubeMultipatchWithMaterials = cubeMultipatchBuilderEx.ToGeometry() as Multipatch;

            return(cubeMultipatchWithMaterials);
        }
        private Multipatch ApplyTexturesToMultipatch(Multipatch source)
        {
            // read jpeg file into a buffer.  Create a JPEGTexture
            // "C:\Data\xxx\Rubik_cube.jpg
            byte[]      imageBuffer       = GetBufferFromImageFile(@"C:\Data\MultipatchBuilderEx\Textures\Rubik_cube.jpg", esriTextureCompressionType.CompressionJPEG);
            JPEGTexture rubiksCubeTexture = new JPEGTexture(imageBuffer);

            // create a material
            BasicMaterial textureMaterial = new BasicMaterial();

            // create a TextureResource from the JPEGTexture and assign
            textureMaterial.TextureResource = new TextureResource(rubiksCubeTexture);


            // create a builder using the source multipatch
            var cubeMultipatchBuilderExWithTextures = new MultipatchBuilderEx(source);

            // assign texture material to all the patches
            foreach (Patch p in cubeMultipatchBuilderExWithTextures.Patches)
            {
                p.Material = textureMaterial;
            }

            // assign texture coordinate to patches

            // assign texture coordinates to the top face patch
            Patch topFacePatch = cubeMultipatchBuilderExWithTextures.Patches[0];

            topFacePatch.TextureCoords2D = new List <Coordinate2D>
            {
                new Coordinate2D(0.25, 0.33),
                new Coordinate2D(0.25, 0),
                new Coordinate2D(0.5, 0),
                new Coordinate2D(0.5, 0.33),
                new Coordinate2D(0.25, 0.33)
            };

            // assign texture coordinates to the bottom face patch
            Patch bottomFacePatch = cubeMultipatchBuilderExWithTextures.Patches[1];

            bottomFacePatch.TextureCoords2D = new List <Coordinate2D>
            {
                new Coordinate2D(0.25, 1),
                new Coordinate2D(0.25, 0.66),
                new Coordinate2D(0.5, 0.66),
                new Coordinate2D(0.5, 1),
                new Coordinate2D(0.25, 1)
            };

            // assign texture coordinates to the sides face patch
            Patch sidesFacePatch = cubeMultipatchBuilderExWithTextures.Patches[2];

            sidesFacePatch.TextureCoords2D = new List <Coordinate2D>
            {
                new Coordinate2D(0, 0.66),
                new Coordinate2D(0, 0.33),
                new Coordinate2D(0.25, 0.66),
                new Coordinate2D(0.25, 0.33),
                new Coordinate2D(0.5, 0.66),
                new Coordinate2D(0.5, 0.33),
                new Coordinate2D(0.75, 0.66),
                new Coordinate2D(0.75, 0.33),
                new Coordinate2D(1.0, 0.66),
                new Coordinate2D(1.0, 0.33)
            };

            // create the geometry
            Multipatch cubeMultipatchWithTextures = cubeMultipatchBuilderExWithTextures.ToGeometry() as Multipatch;

            return(cubeMultipatchWithTextures);
        }