Esempio n. 1
0
        public void OnPolymesh(PolymeshTopology node)
        {
            int nPts    = node.NumberOfPoints;
            int nFacets = node.NumberOfFacets;

            Debug.Print($"Polymesh : {nPts} vertices {nFacets} facets");

            IList <XYZ> vertices = node.GetPoints();
            IList <XYZ> normals  = node.GetNormals();

            DistributionOfNormals distrib = node.DistributionOfNormals;

            VERTEX[]  vertexs = new VERTEX[nPts];
            XYZ       p;
            Transform t = CurrentTransform;

            for (int i = 0; i < nPts; i++)
            {
                p = t.OfPoint(node.GetPoint(i));
                //vertexs[i] = new VERTEX((float)(p.Y*_foot_to_m), (float)(p.Z*_foot_to_m), (float)(p.X*_foot_to_m));
                vertexs[i] = new VERTEX((float)(p.Y), (float)(p.Z), (float)(p.X));
            }

            var prim = _mesh.UsePrimitive(_material);

            PolymeshFacet f;

            for (int i = 0; i < nFacets; i++)
            {
                f = node.GetFacet(i);
                prim.AddTriangle(vertexs[f.V1], vertexs[f.V2], vertexs[f.V3]);
            }
        }
Esempio n. 2
0
        public void OnPolymesh(PolymeshTopology node)
        {
            int nPts    = node.NumberOfPoints;
            int nFacets = node.NumberOfFacets;

            DistributionOfNormals distrib
                = node.DistributionOfNormals;

            Debug.Print(string.Format(
                            "Polymesh {0} vertices {1} facets",
                            nPts, nFacets));

            int iFacet = 0;
            int iPoint = 0;

            IList <XYZ> vertices = node.GetPoints();
            IList <XYZ> normals  = node.GetNormals();
            XYZ         normal;

            foreach (PolymeshFacet triangle in node.GetFacets())
            {
                // Just grab one normal per facet; ignore the
                // three normals per point if they differ.

                if (DistributionOfNormals.OnePerFace == distrib)
                {
                    normal = node.GetNormal(0);
                }
                else if (DistributionOfNormals.OnEachFacet
                         == distrib)
                {
                    normal = node.GetNormal(iFacet++);
                }
                else
                {
                    Debug.Assert(DistributionOfNormals
                                 .AtEachPoint == distrib, "what else?");

                    normal = node.GetNormal(triangle.V1)
                             + node.GetNormal(triangle.V2)
                             + node.GetNormal(triangle.V3);
                    normal /= 3.0;
                }

                StoreTriangle(vertices, triangle, normal);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 计算法线
 /// </summary>
 /// <param name="mirrored">镜像</param>
 public void CalculateNormals(bool mirrored)
 {
     Normals = new List <XYZ>(Points.Count);
     for (int i = 0; i < Points.Count; i++)
     {
         Normals.Add(XYZ.Zero);
     }
     for (int j = 0; j < Points.Count; j++)
     {
         for (int k = 0; k < Indices.Count; k += 3)
         {
             if (Indices[k + 0] == j || Indices[k + 1] == j || Indices[k + 2] == j)
             {
                 XYZ xYZ;
                 XYZ xYZ2;
                 XYZ xYZ3;
                 if (mirrored)
                 {
                     xYZ  = Points[Indices[k + 0]];
                     xYZ2 = Points[Indices[k + 2]];
                     xYZ3 = Points[Indices[k + 1]];
                 }
                 else
                 {
                     xYZ  = Points[Indices[k + 0]];
                     xYZ2 = Points[Indices[k + 1]];
                     xYZ3 = Points[Indices[k + 2]];
                 }
                 XYZ K    = xYZ2 - xYZ;
                 XYZ xYZ4 = xYZ3 - xYZ;
                 XYZ xYZ5 = K.CrossProduct(xYZ4);
                 if (!xYZ5.IsZeroLength())
                 {
                     xYZ5 = xYZ5.Normalize();
                     if (Normals[j].IsZeroLength())
                     {
                         IList <XYZ> normals = Normals;
                         int         index   = j;
                         normals[index] += xYZ5;
                     }
                     else if (Normals[j].DotProduct(xYZ5) > 0.1)
                     {
                         IList <XYZ> normals = Normals;
                         int         index   = j;
                         normals[index] += xYZ5;
                     }
                     else
                     {
                         Points.Add(Points[j]);
                         Normals.Add(xYZ5);
                         int value = Points.Count - 1;
                         if (Indices[k + 0] == j)
                         {
                             Indices[k + 0] = value;
                         }
                         if (Indices[k + 1] == j)
                         {
                             Indices[k + 1] = value;
                         }
                         if (Indices[k + 2] == j)
                         {
                             Indices[k + 2] = value;
                         }
                     }
                 }
             }
         }
     }
     for (int l = 0; l < Normals.Count; l++)
     {
         Normals[l] = Normals[l].Normalize();
     }
     DistributionOfNormals = 0;
 }