Exemple #1
0
        static PatchMesh ToPatchMesh(Segment seg, int pathPointInterval)
        {
            List <PointF> rawPath = new List <PointF>(seg.path);

            // 輪郭からメッシュを生成
            var shiftPath      = FLib.FMath.ShiftPath(seg.path, -seg.offset.X, -seg.offset.Y);
            var subdividedPath = PathSubdivision.Subdivide(shiftPath, pathPointInterval);

            subdividedPath.RemoveAt(subdividedPath.Count - 1); // 終点(始点と同じ)は消す

            List <PointF> vertices   = new List <PointF>();
            List <int>    triIndices = new List <int>();

            FLib.Triangle.Triangulate(subdividedPath, vertices, triIndices, FLib.Triangle.Parameters.Default);

            List <int> path = Enumerable.Range(0, subdividedPath.Count).ToList();

            //
            // seg.partingLineから各頂点が属すpartを計算
            //
            List <int> vert2part   = new List <int>();
            var        partingLine = new List <PointF>();

            if (seg.partingLine != null)
            {
                partingLine = FLib.FMath.ShiftPath(seg.partingLine, -seg.offset.X, -seg.offset.Y);
            }
            PartingMeshes(vertices, triIndices, partingLine, vert2part);


            string patchKey    = seg.name;
            SizeF  textureSize = seg.bmp.Size;

            var patch = new PatchMesh(vertices, triIndices, path, vert2part, patchKey, textureSize);

            return(patch);
        }
        public SegmentMeshInfo(Segment seg, bool initControlPoints)
        {
            if (seg == null)
            {
                return;
            }

            if (seg.path != null && seg.path.Count > 3)
            {
                // メッシュを生成
                var shiftPath = ShiftPath(seg.path, -seg.offset.X, -seg.offset.Y);
                var sdPath    = PathSubdivision.Subdivide(shiftPath, 10);
                sdPath.RemoveAt(sdPath.Count - 1); // 終点(始点と同じ)は消す

                var partingLine = new List <PointF>();
                if (seg.partingLine != null)
                {
                    partingLine = ShiftPath(seg.partingLine, -seg.offset.X, -seg.offset.Y);
                }

                arap = new ARAPDeformation(sdPath, partingLine);

                // 接合面の情報をコピー
                if (seg.section != null || seg.section.Count > 0)
                {
                    var _sections = FMath.SplitPathRange(ShiftPath(seg.section, -seg.offset.X, -seg.offset.Y), shiftPath, true);
                    sections = new List <CharacterRange>();
                    foreach (var r in _sections)
                    {
                        int i1 = r.First;
                        int i2 = r.First + r.Length - 1;
                        try
                        {
                            int j1 = sdPath.IndexOf(shiftPath[i1]);
                            int j2 = sdPath.IndexOf(shiftPath[i2]);
                            sections.Add(new CharacterRange(j1, j2 - j1 + 1));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e + e.StackTrace);
                        }
                    }
                }
            }

            if (seg.an != null)
            {
                // スケルトンをコピー
                an = new SkeletonAnnotation(seg.an, false);
                foreach (var j in an.joints)
                {
                    j.position = new PointF(j.position.X - seg.offset.X, j.position.Y - seg.offset.Y);
                }
            }

            // 接合面とボーンの交差情報
            if (sections != null && sections.Count >= 1 && seg.an != null && seg.an.bones != null)
            {
                crossDict = GetBoneSectionCrossDict(GetPath(), sections, an);
            }

            if (initControlPoints && arap != null)
            {
                // 制御点を初期
                InitializeControlPoints(arap, an, 30, sections, boneToControls);
                arap.BeginDeformation();
            }
        }