示例#1
0
        /// <summary>
        /// Отрисовка модели
        /// </summary>
        /// <param name="drawSurface"></param>
        /// <param name="drawingSide"></param>
        /// <returns></returns>
        public int ShowModel(IDrawingSurface surface, PolygonSides drawingSide = PolygonSides.AllSides)
        {
            try
            {
                if (collection.Length == 1)
                {
                    if (collection[0] != null)
                    {
                        if (collection[0].ShowModel(surface, drawingSide) != 0)
                        {
                            throw new Exception(ErrorLog.GetLastError());
                        }
                    }
                }
                else
                {
                    if (drawingSide == PolygonSides.Auto)
                    {
                        if (ShowModel(surface, PolygonSides.RearSide) != 0)
                        {
                            throw new Exception(Graph3DLibrary.ErrorLog.GetLastError());
                        }
                        if (ShowModel(surface, PolygonSides.FrontSide) != 0)
                        {
                            throw new Exception(Graph3DLibrary.ErrorLog.GetLastError());
                        }
                    }
                    else
                    {
                        int PolygonPartSize = ActivePolygonCount / surface.BufferCount;
                        Parallel.For(0, surface.BufferCount, (int partIndex) =>
                        {
                            int sideIdx;
                            Pen pen          = new Pen(Color.White);
                            SolidBrush brush = new SolidBrush(Color.White);

                            PointF[] poly = new PointF[3] {
                                new PointF(), new PointF(), new PointF()
                            };

                            for (int i = partIndex * PolygonPartSize; (i < ActivePolygonCount) && (i < (partIndex + 1) * PolygonPartSize); i++)
                            {
                                if (collection[ActivePolygon[i].ModelIndex] != null)
                                {
                                    sideIdx = (collection[ActivePolygon[i].ModelIndex].Polygon[ActivePolygon[i].PolygonIndex].NormalZ <= 0) ? 0 : 1;

                                    if (drawingSide != PolygonSides.AllSides)
                                    {
                                        if ((drawingSide == PolygonSides.FrontSide) & (sideIdx == 1))
                                        {
                                            continue;
                                        }
                                        if ((drawingSide == PolygonSides.RearSide) & (sideIdx == 0))
                                        {
                                            continue;
                                        }
                                    }

                                    if (Engine3D.BuiltStaticPolygon(ref collection[ActivePolygon[i].ModelIndex].ScreenVertex3D, ref collection[ActivePolygon[i].ModelIndex].Polygon[ActivePolygon[i].PolygonIndex], ref poly) != 0)
                                    {
                                        throw new Exception(Graph3DLibrary.ErrorLog.GetLastError());
                                    }

                                    switch (collection[ActivePolygon[i].ModelIndex].Polygon[ActivePolygon[i].PolygonIndex].FillType)
                                    {
                                    case PolygonFillType.Solid:
                                        brush.Color = collection[ActivePolygon[i].ModelIndex].Polygon[ActivePolygon[i].PolygonIndex].LightingColor[sideIdx];
                                        surface.FillPolygon(brush, poly, partIndex);
                                        break;

                                    case PolygonFillType.Wide:
                                        pen.Color = collection[ActivePolygon[i].ModelIndex].Polygon[ActivePolygon[i].PolygonIndex].LightingColor[sideIdx];
                                        surface.DrawPolygon(pen, poly, partIndex);
                                        break;
                                    }
                                }
                            }
                            pen.Dispose();
                        });
                    }
                }
                return(0);
            }
            catch (Exception er)
            {
                Graph3DLibrary.ErrorLog.AddErrorMessage("ModelCollectionController", "ShowModel", er.Message, -1);
                return(-1);
            }
        }