Beispiel #1
0
        public static HeModel ToHeModel(CadMesh src)
        {
            HeModel m = new HeModel();

            m.VertexStore = src.VertexStore;

            Dictionary <uint, HalfEdge> map = new Dictionary <uint, HalfEdge>();

            for (int fi = 0; fi < src.FaceStore.Count; fi++)
            {
                CadFace f = src.FaceStore[fi];

                int      vi         = f.VList[0];
                HalfEdge head       = m.CreateHalfEdge(vi);
                HalfEdge current_he = head;

                HeFace face      = m.CreateFace(head);
                int    faceIndex = m.FaceStore.Add(face);

                current_he.Face = faceIndex;

                HalfEdge next_he;

                for (int pi = 1; pi < f.VList.Count; pi++)
                {
                    vi      = f.VList[pi];
                    next_he = m.CreateHalfEdge(vi);

                    current_he.Next = next_he;
                    next_he.Prev    = current_he;

                    next_he.Face = faceIndex;

                    current_he = next_he;
                }

                head.Prev       = current_he;
                current_he.Next = head;


                HalfEdge c = head;

                for (; ;)
                {
                    HeConnector.SetHalfEdgePair(c, map);

                    map[HeConnector.GetHeKey(c)] = c;

                    c = c.Next;
                    if (c == head)
                    {
                        break;
                    }
                }
            }

            m.RecreateNormals();

            return(m);
        }
Beispiel #2
0
        // 三角形の追加
        // 左右回り方を統一して追加するようにする
        public void AddTriangle(int v0, int v1, int v2)
        {
            HalfEdge he0 = mHeModel.CreateHalfEdge(v0);
            HalfEdge he1 = mHeModel.CreateHalfEdge(v1);
            HalfEdge he2 = mHeModel.CreateHalfEdge(v2);

            he0.Next = he1;
            he0.Prev = he2;
            he1.Next = he2;
            he1.Prev = he0;
            he2.Next = he0;
            he2.Prev = he1;

            // 法線の設定
            Vector3d normal = CadMath.Normal(
                mHeModel.VertexStore[v0].vector,
                mHeModel.VertexStore[v1].vector,
                mHeModel.VertexStore[v2].vector);

            // Faceの設定
            HeFace face = mHeModel.CreateFace(he0);

            if (!normal.IsInvalid())
            {
                face.Normal = mHeModel.NormalStore.Add(normal);
                he0.Normal  = mHeModel.NormalStore.Add(normal);
                he1.Normal  = mHeModel.NormalStore.Add(normal);
                he2.Normal  = mHeModel.NormalStore.Add(normal);
            }

            int faceIndex = mHeModel.FaceStore.Add(face);

            he0.Face = faceIndex;
            he1.Face = faceIndex;
            he2.Face = faceIndex;

            // Pairの設定
            HeConnector.SetHalfEdgePair(he0, HeMap);
            HeMap[HeConnector.GetHeKey(he0)] = he0;

            HeConnector.SetHalfEdgePair(he1, HeMap);
            HeMap[HeConnector.GetHeKey(he1)] = he1;

            HeConnector.SetHalfEdgePair(he2, HeMap);
            HeMap[HeConnector.GetHeKey(he2)] = he2;
        }