网格面集合类。

命名空间:  SuperMap.Data
程序集:  SuperMap.Data (in SuperMap.Data)
版本: dll

语法

C#
public class Meshes : IEnumerable

备注

该类是网格面对象(Mesh对象)的集合。主要用来对三维模型几何对象中的网格面集合对象进行设置,我们可以将定义的多个网格面对象加入到该集合中并显示在三维场景中。

示例

以下代码示范了如何定义网格面对象,并将该对象添加到三维模型几何对象的网格面集合中,最后加入三维场景显示在三维球体上。

CopyC#
public void TestMeshes(SceneControl m_sceneControl)
    {
       //新建GeoModel对象,设置Position为(110, 39, 0);
        GeoModel geoModel = new GeoModel();
        geoModel.Position = new Point3D(110, 39, 0);

        //获取Meshes;
        Meshes meshes = geoModel.Meshes;

        //构造Mesh对象mesh;
        Mesh mesh = new Mesh();
        Double[] vertexes = new Double[12];
        Double[] normals = new Double[12];
        Int32[] indexes = new Int32[8];
        Double[] textureCoords = new Double[8];
        Color[] colors = new Color[] { Color.Red, Color.SkyBlue, Color.Black, Color.Blue };

        //设置顶点坐标,每三个一组,对应坐标系的X,Y,Z数值
        vertexes[0] = 0.0; vertexes[1] = 0.0; vertexes[2] = 0.0;
        vertexes[3] = 36000; vertexes[4] = -48000; vertexes[5] = 0.0;
        vertexes[6] = 100000; vertexes[7] = 0.0; vertexes[8] = 0.0;
        vertexes[9] = 64000; vertexes[10] = 0; vertexes[11] = 48000;

        //设置顶点索引,用于绘制图形时应用
        indexes[0] = 0; indexes[1] = 1; indexes[2] = 2;
        indexes[3] = 0; indexes[4] = 2; indexes[5] = 3;

        //设置顶点的法向量方向,设置法向量可以突出Mesh的阴影效果,更加逼真。
        normals[0] = 0.0; normals[1] = 0.0; normals[2] = 1.0;
        for (int i = 3; i < 7; i++)
        {
            normals[i] = normals[0]; normals[i + 1] = normals[1]; normals[i + 2] = normals[2];
        }
        normals[9] = 0.0; normals[10] = -1.0; normals[11] = 0.0;


        //设置纹理坐标,用于设置贴图的显示效果
        for (int i = 0; i < 8;i += 2 )
        {
            textureCoords[i] = 0.0 + 0.125 * i;
            textureCoords[i + 1] = textureCoords[i];
        }

        mesh.Vertices = vertexes;
        mesh.Indexes = indexes;
        mesh.Normals = normals;
        mesh.Colors = colors;
        mesh.TextureCoords = textureCoords;
        Material material = new Material();
        material.TextureFile = "C:/green.jpg";
        mesh.Material = material;
        meshes.Add(mesh);

        //新建Scene,关联m_sceneControl;
        Scene scene = m_sceneControl.Scene;

        //MeoModel.ComputeBoundingBos()一定要调用否则不显示,再调用setBoundingBox(模型的BoundingBox);
        geoModel.ComputeBoundingBox();
        geoModel.SetBoundingBox(geoModel.BoundingBox);

        //添加GeoModel到Scene的TrackingLayer中;
        scene.TrackingLayer.Add(geoModel, "Model");
        //Meshes.ToArrary()构造meshs2;(先调用Thread.Sleep(500),让场景控件关闭后不占用meshes资源)
        Thread.Sleep(500);
        Mesh[] meshs2 = meshes.ToArray();

        //将meshs2添加到Meshes集合中;
        meshes.AddRange(meshs2);

        //移除索引为0的Mesh对象,移除从索引0处开始的1个Mesh对象;
        meshes.Remove(0);
        meshes.RemoveRange(0, 1);

        //Clear()清除Meshes中全部Mesh对象;
        meshes.Clear();
    }

继承层次

System..::.Object
  SuperMap.Data..::.Meshes

请参见