Example #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)); //创建完成
        }
Example #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);
        }
Example #3
0
        void aaa(IFeatureClass fc, int index, IResourceManager resourceM)
        {
            //无条件查询,即全选
            IFdeCursor sourceCursor = fc.Update(null);
            IRowBuffer row          = null;

            //遍历feature
            while ((row = sourceCursor.NextRow()) != null)
            {
                //从feature中拿到几何属性
                IGeometry geom = (IGeometry)row.GetValue(index);
                //确定是模型
                if (geom.GeometryType == gviGeometryType.gviGeometryModelPoint)
                {
                    //转换为modelPoint
                    IModelPoint mp = (IModelPoint)geom;

                    //mp 的转换矩阵
                    IMatrix mx = mp.AsMatrix();

                    //获取模型实例
                    //注意:
                    //model可以被不同的modelPoint多次引用,需要修改模型时
                    //需要通过modelName判断一下,这个模型被修改过没有
                    IModel model = resourceM.GetModel(mp.ModelName);

                    //提取模型节点属性
                    if (model != null)
                    {
                        #region modelInside
                        //遍历DrawGroup
                        for (int dgrpi = 0; dgrpi < model.GroupCount; dgrpi++)
                        {
                            IDrawGroup dgrp = model.GetGroup(dgrpi);
                            if (dgrp != null)
                            {
                                //遍历DrawPrimitive
                                for (int dpri = 0; dpri < dgrp.PrimitiveCount; dpri++)
                                {
                                    IDrawPrimitive dpr = dgrp.GetPrimitive(dpri);
                                    if (dpr != null)
                                    {
                                        //获取顶点数组
                                        float[] verArray = dpr.VertexArray.Array;
                                        //创建新的顶点数组,替换原来的
                                        IFloatArray newArr = new FloatArray();

                                        //遍历数组,转为点,三个成员为一组,xyz
                                        for (int veri = 0; veri < verArray.Length; veri += 3)
                                        {
                                            Vector3 vec = new Vector3();
                                            vec.X = verArray[veri];
                                            vec.Y = verArray[veri + 1];
                                            vec.Z = verArray[veri + 2];

                                            //用矩阵转到决对坐标,并修改
                                            IVector3 refVec = mx.MultiplyVector(vec);

                                            //修改部份
                                            refVec.X = 3.3;
                                            refVec.Y = 4.4;
                                            refVec.Z = 5.5;

                                            //修改完,减掉mp中的位移,准备塞回modle
                                            newArr.Append((float)(refVec.X - mp.X));
                                            newArr.Append((float)(refVec.Y - mp.Y));
                                            newArr.Append((float)(refVec.Z - mp.Z));
                                        }
                                        //把新顶点数组塞入Primitive
                                        dpr.VertexArray = newArr;
                                        //再把Primitive更新到当前Group
                                        dgrp.SetPrimitive(dpri, dpr);
                                    }
                                }
                                //把组更新到当前model
                                model.SetGroup(dgrpi, dgrp);
                            }
                        }
                        //更新数据源
                        resourceM.UpdateModel(mp.ModelName, model);
                        resourceM.RebuildSimplifiedModel(mp.ModelName);//重建简模
                        //释放资源
                        model.Dispose();
                        model = null;
                        #endregion
                    }

                    //修改mp
                    mp.SetCoords(3.3, 4.4, 5.5, mp.M, mp.Id);
                    //塞回row
                    row.SetValue(index, mp);
                }
            }
        }
Example #4
0
        /// <summary>
        /// 参数化建模
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDriveModel_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (polyline != null)
                {
                    center = polyline.Envelope.Center;
                    IModelPoint mp = new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    mp.SpatialCRS = datasetCRS;
                    mp.Position   = center;

                    IModel         model     = new ResourceFactory().CreateModel();
                    IDrawGroup     group     = new DrawGroup();
                    IDrawPrimitive primitive = new DrawPrimitive();
                    IDrawMaterial  material  = new DrawMaterial();
                    material.TextureName = (strMediaPath + @"\shp\road\textrure.jpg");
                    material.CullMode    = gviCullFaceMode.gviCullNone;
                    material.WrapModeS   = gviTextureWrapMode.gviTextureWrapRepeat;
                    material.WrapModeT   = gviTextureWrapMode.gviTextureWrapRepeat;
                    IFloatArray va = new FloatArray();
                    IFloatArray ta = new FloatArray();
                    // 逐点外扩
                    for (int i = 0; i < polyline.PointCount; i++)
                    {
                        #region 单独处理最后一个点
                        if (i == polyline.PointCount - 1)
                        {
                            curPoint  = polyline.GetPoint(i);
                            vecCurPos = curPoint.Position;
                            // 最后一个点重用最后的方向向量
                            vecTarget = vecDirect.CrossProduct(vecZ);
                            vecTarget.Normalize();
                            vecTarget.MultiplyByScalar(width / 2);
                            vecP = vecCurPos.Add(vecTarget);
                            vecTarget.MultiplyByScalar(-1);
                            vecQ = vecCurPos.Add(vecTarget);
                            // 设置外扩点
                            P          = curPoint.Clone() as IPoint;
                            P.Position = vecP;
                            Q          = curPoint.Clone() as IPoint;
                            Q.Position = vecQ;
                            // 把点坐标加进顶点数组
                            va.Append((float)(vecP.X - center.X));
                            va.Append((float)(vecP.Y - center.Y));
                            va.Append((float)(vecP.Z - center.Z));
                            va.Append((float)(vecQ.X - center.X));
                            va.Append((float)(vecQ.Y - center.Y));
                            va.Append((float)(vecQ.Z - center.Z));
                            // 加纹理坐标
                            ta.Append(0);  //P点纹理
                            if (i == 0)
                            {
                                lastV = 0.0;
                            }
                            else
                            {
                                lastV = lastV + length / 10;  //v方向上每隔10米重复一次
                            }
                            ta.Append((float)lastV);
                            ta.Append(1);  //Q点纹理
                            ta.Append((float)lastV);

                            {
                                ISimplePointSymbol ps = new SimplePointSymbol();
                                ps.FillColor = System.Drawing.Color.Yellow;
                                ps.Size      = 5;
                                rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId));
                                rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId));
                            }

                            break;
                        }
                        #endregion

                        // 当不是最后一个点时:
                        curPoint   = polyline.GetPoint(i);
                        nextPoint  = polyline.GetPoint(i + 1);
                        vecCurPos  = curPoint.Position;
                        vecNextPos = nextPoint.Position;
                        // 运算
                        vecNextPos.MultiplyByScalar(-1);
                        vecDirect = vecCurPos.Add(vecNextPos);  //方向向量
                        vecZ.Set(0, 0, 1);
                        vecTarget = vecDirect.CrossProduct(vecZ);
                        vecTarget.Normalize();
                        vecTarget.MultiplyByScalar(width / 2);
                        vecP = vecCurPos.Add(vecTarget);
                        vecTarget.MultiplyByScalar(-1);
                        vecQ = vecCurPos.Add(vecTarget);
                        // 设置外扩点
                        P          = curPoint.Clone() as IPoint;
                        P.Position = vecP;
                        Q          = curPoint.Clone() as IPoint;
                        Q.Position = vecQ;
                        // 把点坐标加进顶点数组
                        va.Append((float)(vecP.X - center.X));
                        va.Append((float)(vecP.Y - center.Y));
                        va.Append((float)(vecP.Z - center.Z));
                        va.Append((float)(vecQ.X - center.X));
                        va.Append((float)(vecQ.Y - center.Y));
                        va.Append((float)(vecQ.Z - center.Z));
                        // 加纹理坐标
                        ta.Append(0);  //P点纹理
                        if (i == 0)
                        {
                            lastV = 0.0;
                        }
                        else
                        {
                            lastV = lastV + length / 5; //v方向上每隔10米重复一次
                        }
                        length = vecDirect.Length;      //计算长度给奇数点用
                        ta.Append((float)lastV);
                        ta.Append(1);                   //Q点纹理
                        ta.Append((float)lastV);

                        {
                            ISimplePointSymbol ps = new SimplePointSymbol();
                            ps.FillColor = System.Drawing.Color.Yellow;
                            ps.Size      = 5;
                            rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId));
                            rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId));
                        }
                    }
                    // 计算索引坐标
                    IUInt16Array ia = new UInt16Array();
                    for (int i = 0; i < va.Length / 6 - 1; i++)
                    {
                        ia.Append((ushort)(2 * i));
                        ia.Append((ushort)(2 * i + 1));
                        ia.Append((ushort)(2 * i + 2));
                        ia.Append((ushort)(2 * i + 1));
                        ia.Append((ushort)(2 * i + 3));
                        ia.Append((ushort)(2 * i + 2));
                    }
                    primitive.VertexArray   = va;
                    primitive.TexcoordArray = ta;
                    primitive.IndexArray    = ia;
                    primitive.Material      = material;
                    group.AddPrimitive(primitive);
                    model.AddGroup(group);

                    // 在内存中临时存储模型
                    string modelName = fid.ToString();
                    this.axRenderControl1.ObjectManager.AddModel(modelName, model);
                    mp.ModelName     = modelName;
                    mp.ModelEnvelope = model.Envelope;
                    // 可视化临时模型
                    IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId);
                    rmp.MaxVisibleDistance = 100000;
                    rmp.MouseSelectMask    = gviViewportMask.gviViewNone;
                    rModelpointToDelList.Add(rmp);
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }