Пример #1
0
        public static bool ConvertPolygon(double[] vtx, double height, int flag, out IDoubleArray VArray, out IUInt16Array IndexArray, out IFloatArray TextureArrayU1V1, out IDoubleArray Norms)
        {
            bool flag2;

            VArray           = new DoubleArrayClass();
            IndexArray       = new UInt16ArrayClass();
            TextureArrayU1V1 = new FloatArrayClass();
            IFloatArray array = null;

            Norms = new DoubleArrayClass();
            IPolygon polygon = null;
            ITriMesh o       = null;

            try
            {
                if (((vtx == null) || ((vtx.Length % 2) != 0)) || (vtx.Length < 8))
                {
                    return(false);
                }
                polygon = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                if (polygon == null)
                {
                    return(false);
                }
                int num = vtx.Length / 2;
                for (int i = 0; i < num; i++)
                {
                    IPoint pointValue = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                    if (flag == 1)
                    {
                        pointValue.X = vtx[i * 2];
                        pointValue.Y = vtx[(i * 2) + 1];
                        pointValue.Z = height;
                    }
                    else
                    {
                        pointValue.X = vtx[((num - i) - 1) * 2];
                        pointValue.Y = vtx[(((num - i) - 1) * 2) + 1];
                        pointValue.Z = height;
                    }
                    polygon.ExteriorRing.AppendPoint(pointValue);
                }
                if (!polygon.IsClosed)
                {
                    polygon.Close();
                }
                o = geoConvertor.PolygonToTriMesh(polygon);
                if (o == null)
                {
                    return(false);
                }
                if (!o.BatchExport(ref VArray, ref IndexArray, ref TextureArrayU1V1, ref array, ref Norms))
                {
                    return(false);
                }
                flag2 = true;
            }
            catch (Exception)
            {
                flag2 = false;
            }
            finally
            {
                if (polygon != null)
                {
                    Marshal.ReleaseComObject(polygon);
                }
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                }
            }
            return(flag2);
        }
Пример #2
0
        private bool MergeModels(IFeatureClass fc, string geometryField, int[] oidList, IResourceManager resMgr, ref IModelPoint desModelPoint)
        {
            bool flag = true;
            bool result;

            try
            {
                if (fc == null || oidList == null)
                {
                    result = false;
                    return(result);
                }
                Gvitech.CityMaker.Resource.IModel model = resMgr.GetModel(desModelPoint.ModelName);
                IMatrix matrix = desModelPoint.AsMatrix().Clone();
                matrix.Inverse();
                int        position = fc.GetFields().IndexOf(geometryField);
                IFdeCursor rows     = fc.GetRows(oidList, false);
                IVector3   src      = new Vector3Class();
                IVector3   vector   = new Vector3Class();
                System.Collections.Generic.Dictionary <IMatrix, string> dictionary = new System.Collections.Generic.Dictionary <IMatrix, string>();
                IRowBuffer rowBuffer;
                while ((rowBuffer = rows.NextRow()) != null)
                {
                    IModelPoint modelPoint = rowBuffer.GetValue(position) as IModelPoint;
                    if (modelPoint != null)
                    {
                        dictionary[modelPoint.AsMatrix().Clone()] = modelPoint.ModelName;
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(modelPoint);
                    }
                }
                foreach (IMatrix current in dictionary.Keys)
                {
                    string name = dictionary[current];
                    Gvitech.CityMaker.Resource.IModel model2 = resMgr.GetModel(name);
                    for (int i = 0; i < model2.GroupCount; i++)
                    {
                        Gvitech.CityMaker.Resource.IDrawGroup drawGroup = new DrawGroupClass();
                        Gvitech.CityMaker.Resource.IDrawGroup group     = model2.GetGroup(i);
                        for (int j = 0; j < group.PrimitiveCount; j++)
                        {
                            Gvitech.CityMaker.Resource.IDrawPrimitive primitive = group.GetPrimitive(j);
                            if (primitive.PrimitiveType == Gvitech.CityMaker.Resource.gviPrimitiveType.gviPrimitiveBillboardZ)
                            {
                                flag   = false;
                                result = flag;
                                return(result);
                            }
                            Gvitech.CityMaker.Resource.IDrawPrimitive drawPrimitive = new DrawPrimitiveClass();
                            IFloatArray vertexArray = primitive.VertexArray;
                            IFloatArray floatArray  = new FloatArrayClass();
                            int         num         = 0;
                            while ((long)num < (long)((ulong)vertexArray.Length))
                            {
                                vector.X = (double)vertexArray.Get(num);
                                vector.Y = (double)vertexArray.Get(num + 1);
                                vector.Z = (double)vertexArray.Get(num + 2);
                                current.MultiplyVector(vector, ref src);
                                matrix.MultiplyVector(src, ref vector);
                                floatArray.Append((float)vector.X);
                                floatArray.Append((float)vector.Y);
                                floatArray.Append((float)vector.Z);
                                num += 3;
                            }
                            drawPrimitive.VertexArray        = floatArray;
                            drawPrimitive.BakedTexcoordArray = primitive.BakedTexcoordArray;
                            drawPrimitive.ColorArray         = primitive.ColorArray;
                            drawPrimitive.IndexArray         = primitive.IndexArray;
                            drawPrimitive.Material           = primitive.Material;
                            drawPrimitive.NormalArray        = primitive.NormalArray;
                            drawPrimitive.PrimitiveMode      = primitive.PrimitiveMode;
                            drawPrimitive.PrimitiveType      = primitive.PrimitiveType;
                            drawPrimitive.TexcoordArray      = primitive.TexcoordArray;
                            drawGroup.AddPrimitive(drawPrimitive);
                        }
                        drawGroup.CompleteMapFactor      = group.CompleteMapFactor;
                        drawGroup.CompleteMapTextureName = group.CompleteMapTextureName;
                        drawGroup.LightMapTextureName    = group.LightMapTextureName;
                        model.AddGroup(drawGroup);
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(model2);
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rows);
                desModelPoint.ModelEnvelope = model.Envelope.Clone();
                resMgr.UpdateModel(desModelPoint.ModelName, model);
                resMgr.RebuildSimplifiedModel(desModelPoint.ModelName);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(matrix);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(model);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                flag = false;
                XtraMessageBox.Show(ex.Message);
            }
            catch (System.Exception e)
            {
                flag = false;
                LoggingService.Error(e);
            }
            result = flag;
            return(result);
        }
Пример #3
0
        public override bool Draw(out IModelPoint mp, out IModel fmodel, out IModel smodel)
        {
            List <ushort>  list2      = new List <ushort>();
            IPolygon       polygon    = null;
            IPolygon       polygon2   = null;
            IPolygon       polygon3   = null;
            IPoint         pointValue = null;
            ITriMesh       mesh       = null;
            IDoubleArray   vArray     = null;
            IUInt16Array   indexArray = null;
            IFloatArray    array3     = null;
            IFloatArray    array4     = null;
            IDoubleArray   norms      = null;
            IDrawGroup     group      = null;
            IDrawPrimitive primitive  = null;
            IDrawPrimitive primitive2 = null;
            IDrawPrimitive primitive3 = null;
            double         naN        = double.NaN;
            double         ty         = double.NaN;

            base.Draw(out mp, out fmodel, out smodel);
            try
            {
                int           num;
                int           num2;
                List <Vector> list;
                polygon  = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon2 = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon3 = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                if (this._route.Count > 2)
                {
                    list = Maths.DisperseLine(this._route, this._pillarSection.Diameter);
                }
                else
                {
                    list = this._route;
                }
                double[] vtxs = this._pillarSection.GetVtxs();
                SystemLog.Instance.Log("顶点个数:" + vtxs.Length);
                double[] numArray = new double[list.Count];
                for (num = 0; num < list.Count; num++)
                {
                    if (num == 0)
                    {
                        numArray[num] = 0.0;
                    }
                    else
                    {
                        numArray[num] = (list[num] - list[num - 1]).Length + numArray[num - 1];
                    }
                }
                object renderInfo = (this._renderType == RenderType.Texture) ? ((object)this._tcNames) : ((object)this._colors);
                int[]  index      = new int[3];
                index[1] = 1;
                index[2] = 2;
                if (!base.NewEmptyModel(index, this._renderType, renderInfo, out fmodel))
                {
                    return(false);
                }
                group = fmodel.GetGroup(0);
                SystemLog.Instance.Log("开始计算正交向量:" + DateTime.Now.ToLongTimeString());
                primitive = group.GetPrimitive(0);
                for (num = 0; num < list.Count; num++)
                {
                    Vector vector;
                    Vector vector2;
                    Vector vector3;
                    if (num == 0)
                    {
                        vector = list[num + 1] - list[num];
                    }
                    else if (num == (list.Count - 1))
                    {
                        vector = list[num] - list[num - 1];
                    }
                    else
                    {
                        vector = ((list[num] - list[num - 1])).UnitVector() + ((list[num + 1] - list[num])).UnitVector();
                    }
                    Maths.GenerateComplementBasis(vector, out vector2, out vector3);
                    vector2 = -vector2;
                    num2    = 0;
                    while (num2 <= this._pillarSection.SegCount)
                    {
                        Vector vector6;
                        Vector vector7;
                        (((vtxs[num2 * 2] - this._pillarSection.OffsetX) * vector2) + ((vtxs[(num2 * 2) + 1] - this._pillarSection.OffsetY) * vector3)).UnitVector();
                        Vector vector4 = list[num] + ((Vector)((vtxs[num2 * 2] * vector2) + (vtxs[(num2 * 2) + 1] * vector3)));
                        Vector vector5 = (Vector)(vector4 * 1.01);
                        if (num == 0)
                        {
                            pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pointValue.SetCoords(vector4.X, vector4.Y, vector4.Z, 0.0, 0);
                            polygon.ExteriorRing.AppendPoint(pointValue);
                            pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pointValue.SetCoords(vector5.X, vector5.Y, vector5.Z, 0.0, 0);
                            polygon3.ExteriorRing.AppendPoint(pointValue);
                        }
                        else if (num == (list.Count - 1))
                        {
                            pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pointValue.SetCoords(vector4.X, vector4.Y, vector4.Z, 0.0, 0);
                            polygon2.ExteriorRing.AppendPoint(pointValue);
                        }
                        primitive.VertexArray.Append((float)vector4.X);
                        primitive.VertexArray.Append((float)vector4.Y);
                        primitive.VertexArray.Append((float)vector4.Z);
                        list2.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                        primitive.VertexArray.Append((float)vector4.X);
                        primitive.VertexArray.Append((float)vector4.Y);
                        primitive.VertexArray.Append((float)vector4.Z);
                        list2.Add((ushort)((primitive.VertexArray.Length / 3) - 1));
                        if (this._renderType == RenderType.Texture)
                        {
                            primitive.TexcoordArray.Append((float)(num2 * 1.0));
                            primitive.TexcoordArray.Append((float)(num * 1.0));
                            primitive.TexcoordArray.Append((float)(num2 * 1.0));
                            primitive.TexcoordArray.Append((float)(num * 1.0));
                        }
                        if (num2 == 0)
                        {
                            vector6 = new Vector(vtxs[num2 * 2] - vtxs[(this._pillarSection.SegCount - 1) * 2], vtxs[(num2 * 2) + 1] - vtxs[((this._pillarSection.SegCount - 1) * 2) + 1], 0.0).UnitVector();
                            vector7 = new Vector(vtxs[(num2 + 1) * 2] - vtxs[num2 * 2], vtxs[((num2 + 1) * 2) + 1] - vtxs[(num2 * 2) + 1], 0.0).UnitVector();
                        }
                        else if (num2 == this._pillarSection.SegCount)
                        {
                            vector6 = new Vector(vtxs[num2 * 2] - vtxs[(num2 - 1) * 2], vtxs[(num2 * 2) + 1] - vtxs[((num2 - 1) * 2) + 1], 0.0).UnitVector();
                            vector7 = new Vector(vtxs[2] - vtxs[num2 * 2], vtxs[3] - vtxs[(num2 * 2) + 1], 0.0).UnitVector();
                        }
                        else
                        {
                            vector6 = new Vector(vtxs[num2 * 2] - vtxs[(num2 - 1) * 2], vtxs[(num2 * 2) + 1] - vtxs[((num2 - 1) * 2) + 1], 0.0).UnitVector();
                            vector7 = new Vector(vtxs[(num2 + 1) * 2] - vtxs[num2 * 2], vtxs[((num2 + 1) * 2) + 1] - vtxs[(num2 * 2) + 1], 0.0).UnitVector();
                        }
                        Vector vector8 = new Vector(vector6.Y, -vector6.X, vector6.Z);
                        primitive.NormalArray.Append((float)vector8.X);
                        primitive.NormalArray.Append((float)vector8.Y);
                        primitive.NormalArray.Append((float)vector8.Z);
                        vector8 = new Vector(vector7.Y, -vector7.X, vector7.Z);
                        primitive.NormalArray.Append((float)vector8.X);
                        primitive.NormalArray.Append((float)vector8.Y);
                        primitive.NormalArray.Append((float)vector8.Z);
                        num2++;
                    }
                }
                SystemLog.Instance.Log("结束计算正交向量:" + DateTime.Now.ToLongTimeString());
                SystemLog.Instance.Log("开始添加索引数组:" + DateTime.Now.ToLongTimeString());
                for (num = 0; num < (list.Count - 1); num++)
                {
                    for (num2 = 0; num2 < this._pillarSection.SegCount; num2++)
                    {
                        primitive.IndexArray.Append(list2[((num * ((this._pillarSection.SegCount + 1) * 2)) + (num2 * 2)) + 1]);
                        primitive.IndexArray.Append(list2[((num + 1) * ((this._pillarSection.SegCount + 1) * 2)) + ((num2 + 1) * 2)]);
                        primitive.IndexArray.Append(list2[(((num + 1) * ((this._pillarSection.SegCount + 1) * 2)) + (num2 * 2)) + 1]);
                        primitive.IndexArray.Append(list2[((num * ((this._pillarSection.SegCount + 1) * 2)) + (num2 * 2)) + 1]);
                        primitive.IndexArray.Append(list2[(num * ((this._pillarSection.SegCount + 1) * 2)) + ((num2 + 1) * 2)]);
                        primitive.IndexArray.Append(list2[((num + 1) * ((this._pillarSection.SegCount + 1) * 2)) + ((num2 + 1) * 2)]);
                    }
                }
                SystemLog.Instance.Log("结束添加索引数组:" + DateTime.Now.ToLongTimeString());
                SystemLog.Instance.Log("开始画底面顶面和线框:" + DateTime.Now.ToLongTimeString());
                vArray     = new DoubleArrayClass();
                indexArray = new UInt16ArrayClass();
                array3     = new FloatArrayClass();
                norms      = new DoubleArrayClass();
                primitive2 = group.GetPrimitive(1);
                polygon.ExteriorRing.ReverseOrientation();
                mesh = DrawGeometry.geoConvertor.PolygonToTriMesh(polygon);
                if ((mesh != null) && mesh.BatchExport(ref vArray, ref indexArray, ref array3, ref array4, ref norms))
                {
                    for (num = 0; num < vArray.Length; num++)
                    {
                        primitive2.VertexArray.Append((float)vArray.Array[num]);
                    }
                    for (num = 0; num < indexArray.Length; num++)
                    {
                        primitive2.IndexArray.Append(indexArray.Array[num]);
                    }
                    for (num = 0; num < norms.Length; num++)
                    {
                        primitive2.NormalArray.Append((float)norms.Array[num]);
                    }
                    if (this._renderType == RenderType.Texture)
                    {
                        for (num = 0; num < (vArray.Length / 3); num++)
                        {
                            this.GetTexcoord(vArray.Array[num * 3], vArray.Array[(num * 3) + 1], out naN, out ty);
                            primitive2.TexcoordArray.Append((float)naN);
                            primitive2.TexcoordArray.Append((float)ty);
                        }
                    }
                }
                vArray     = new DoubleArrayClass();
                indexArray = new UInt16ArrayClass();
                array3     = new FloatArrayClass();
                norms      = new DoubleArrayClass();
                primitive3 = group.GetPrimitive(2);
                mesh       = DrawGeometry.geoConvertor.PolygonToTriMesh(polygon2);
                if ((mesh != null) && mesh.BatchExport(ref vArray, ref indexArray, ref array3, ref array4, ref norms))
                {
                    for (num = 0; num < vArray.Length; num++)
                    {
                        primitive3.VertexArray.Append((float)vArray.Array[num]);
                    }
                    for (num = 0; num < indexArray.Length; num++)
                    {
                        primitive3.IndexArray.Append(indexArray.Array[num]);
                    }
                    for (num = 0; num < norms.Length; num++)
                    {
                        primitive3.NormalArray.Append((float)norms.Array[num]);
                    }
                    if (this._renderType == RenderType.Texture)
                    {
                        for (num = 0; num < (vArray.Length / 3); num++)
                        {
                            this.GetTexcoord(vArray.Array[num * 3], vArray.Array[(num * 3) + 1], out naN, out ty);
                            primitive3.TexcoordArray.Append((float)naN);
                            primitive3.TexcoordArray.Append((float)ty);
                        }
                    }
                }
                SystemLog.Instance.Log("结束画底面顶面和线框:" + DateTime.Now.ToLongTimeString());
                SystemLog.Instance.Log("结束调用Draw:" + DateTime.Now.ToLongTimeString());
                return(true);
            }
            catch (Exception exception)
            {
                SystemLog.Instance.Log(exception);
                return(false);
            }
        }