Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                ConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                ci.Database       = "../XXX.FDB";
                IDataSource      dataSouce  = new DataSourceFactory().OpenDataSource(ci);
                string[]         names      = (string[])dataSouce.GetFeatureDatasetNames();
                IFeatureDataSet  fds        = dataSouce.OpenFeatureDataset(names[0]);
                IResourceManager resManager = fds as IResourceManager;

                //没有锁时这句会报错
                IEnumResName myEnumNames = resManager.GetModelNames();
                while (myEnumNames.MoveNext())
                {
                    string modelName = myEnumNames.Current;
                    IModel myModel   = resManager.GetModel(modelName);
                    if (myModel != null)
                    {
                        for (int i = 0; i < myModel.GroupCount; i++)
                        {
                            IDrawGroup myGroup = myModel.GetGroup(i);
                            for (int j = 0; j < myGroup.PrimitiveCount; j++)
                            {
                                IDrawPrimitive myPv = myGroup.GetPrimitive(j);
                                IDrawMaterial  myDM = myPv.Material;
                                if (myDM != null)
                                {
                                    myDM.EnableLight = false;
                                }
                                myPv.Material = myDM;
                                myGroup.SetPrimitive(j, myPv);
                            }
                            myModel.SetGroup(i, myGroup);
                        }
                        resManager.UpdateModel(modelName, myModel);
                    }
                }

                //手动释放COM对象
                Marshal.ReleaseComObject(fds);
                MessageBox.Show("完成!");
            }
            catch { MessageBox.Show("必须插入加密锁!必须安装CityMaker Builder 7.1"); }
        }
Пример #2
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);
                }
            }
        }