Example #1
0
        /// <summary>
        /// 绘制网格
        /// </summary>
        /// <param name="mesh"></param>
        public void DrawMesh(Mesh mesh)
        {
            int[] PaintSortList = new int[mesh.Surface.Count];
            for (int i = 0; i < PaintSortList.Length; i++)
            {
                PaintSortList[i] = i;
            }

            System.Array.Sort(//对mesh中的网格绘制顺序排序,先绘制远处,再绘制近处
                PaintSortList,
                delegate(int i, int j) {
                return
                ((ToWatcher(mesh.Vertex[mesh.Surface[i].VIndex[0]]) + ToWatcher(mesh.Vertex[mesh.Surface[i].VIndex[1]]) + ToWatcher(mesh.Vertex[mesh.Surface[i].VIndex[2]])
                  >
                  ToWatcher(mesh.Vertex[mesh.Surface[j].VIndex[0]]) + ToWatcher(mesh.Vertex[mesh.Surface[j].VIndex[1]]) + ToWatcher(mesh.Vertex[mesh.Surface[j].VIndex[2]])) ? -1 : 1);
            }
                );
            RGB_D dcolor;

            for (int i = 0; i < PaintSortList.Length; i++)
            {
                dcolor = new RGB_D(0, 0, 0);
                foreach (ParallelLight amblight in AmbientLight)
                {
                    dcolor += WorldModelRender.GetSurfaceLight(
                        mesh.Surface[PaintSortList[i]], amblight,
                        (camera.OPoint - mesh.Surface[PaintSortList[i]].Axis.OPoint).UnitVector()
                        );
                }
                FillTriangle(dcolor.ToColorRGB(), mesh.Vertex[mesh.Surface[PaintSortList[i]].VIndex[0]], mesh.Vertex[mesh.Surface[PaintSortList[i]].VIndex[1]], mesh.Vertex[mesh.Surface[PaintSortList[i]].VIndex[2]]);
            }
        }
Example #2
0
 public PolygonSurfaceType(List <int> _vIndex, RGB_D _BaseColor, BRDFunction _BRDFunc, ref List <Vector3> _Vertex)
 {
     VIndex = new int[_vIndex.Count];
     _vIndex.CopyTo(VIndex, 0);
     Axis          = new FrameofAxis(_Vertex[VIndex[0]], _Vertex[VIndex[1]], _Vertex[VIndex[2]]);
     BaseColor     = _BaseColor;
     BRDFunc       = _BRDFunc;
     IsIlluminated = false;
 }