Ejemplo n.º 1
0
        /// <summary>
        /// 创建并加载点云
        /// </summary>
        /// <returns></returns>
        IRenderModelPoint CreatePointCloud()
        {
            //准备容器
            IModel         model         = new ResourceFactory().CreateModel();
            IDrawGroup     drawGroup     = new DrawGroup();
            IDrawPrimitive drawPrimitive = new DrawPrimitive();
            IFloatArray    verList       = new FloatArray();  //点集
            IUInt32Array   colorList     = new UInt32Array(); //点色

            //点坐标
            float x = 3.3f, y = 4.4f, z = 5.5f;
            //点色
            byte a = 128, r = 255, g = 255, b = 255;
            uint col = (uint)(b | g << 8 | r << 16 | a << 24); //argb => uint

            for (int i = 0; i < 10; i++)
            {
                verList.Append(x);
                verList.Append(y);
                verList.Append(z);
                colorList.Append(col);
            }

            //塞入容器
            drawPrimitive.VertexArray          = verList;
            drawPrimitive.ColorArray           = colorList;
            drawPrimitive.Material.EnableBlend = false;                                     //关闭融合
            drawPrimitive.Material.EnableLight = false;                                     //关闭光照
            drawPrimitive.PrimitiveMode        = gviPrimitiveMode.gviPrimitiveModeLineList; //设置绘制模式为点
            drawGroup.AddPrimitive(drawPrimitive);                                          //塞入渲染组
            model.AddGroup(drawGroup);                                                      //塞入model
            axRenderControl.ObjectManager.AddModel("modelName", model);                     //塞入三维对象,与modelPoint通过名称匹配

            //创建modelPoint,用于索引模型
            IModelPoint mp = (IModelPoint) new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);

            mp.SpatialCRS    = (SpatialCRS)CRSFactory.CreateFromWKT("wkt");                     //设置坐标系
            mp.ModelEnvelope = model.Envelope;                                                  // 排除不显示BUG
            mp.SetCoords(3.3, 4.4, 5.5, 0, 0);
            mp.ModelName = "modelName";                                                         //匹配模型
            return(axRenderControl.ObjectManager.CreateRenderModelPoint(mp, null, Guid.Empty)); //创建完成
        }
Ejemplo n.º 2
0
        private IModel CreateModel(float lenght, float width, float height, uint color)
        {
            IModel         model        = new ResourceFactory().CreateModel();
            IDrawGroup     group        = new DrawGroup();
            IDrawPrimitive primitive    = new DrawPrimitive();
            IFloatArray    vertexArray  = new FloatArray();
            IFloatArray    textureArray = new FloatArray();
            IUInt32Array   colorArray   = new UInt32Array();

            #region
            //顶点数组3个为一组(三角面1)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            //顶点数组3个为一组(三角面2)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            //顶点数组3个为一组(三角面3)
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面4)
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面5)
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面6)
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面7)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f);
            //顶点数组3个为一组(三角面8)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面9)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面10)
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面11)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            //顶点数组3个为一组(三角面12)
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f);
            vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght);
            vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght);

            #endregion

            #region
            //颜色数组1个为一组
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            colorArray.Append(color);
            #endregion

            #region
            //纹理数组2个为一组
            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(0.0f);

            textureArray.Append(1.0f);
            textureArray.Append(1.0f);

            textureArray.Append(0.0f);
            textureArray.Append(1.0f);
            #endregion

            primitive.ColorArray    = colorArray;
            primitive.TexcoordArray = textureArray;
            primitive.VertexArray   = vertexArray;

            IDrawMaterial material = new DrawMaterial();
            material.EnableLight = true;
            primitive.Material   = material;
            group.AddPrimitive(primitive);
            //光照效果,跟法向有关
            group.ComputeNormal();
            model.AddGroup(group);
            return(model);
        }