예제 #1
0
        //--------------------------------------------------------------------
        //
        //--------------------------------------------------------------------

        void AddQuery(string resourceKey)
        {
            if (renderQueryPool.ContainsKey(resourceKey))
            {
                Console.WriteLine("D&D: " + resourceKey);
                var _q = renderQueryPool[resourceKey];
                var q  = new RenderQuery(PatchSkeletalMesh.Copy(_q.patch), _q.patchTree, _q.patchKeys);
                resources.DuplicateResources(_q.patch.Mesh, q.patch.Mesh);

                // 初めて登録される場合、ARAP変形を有効にしてスケルトにフィットさせる
                if (!renderQueries.Contains(q))
                {
                    q.patch.Mesh.BeginDeformation();
                    PatchSkeletonFitting.Fitting(q.patch, refSkeleton);
                }

                if (renderQueries.Contains(q))
                {
                    renderQueries.Remove(q);
                }
                renderQueries.Add(q);

                // 追加したパッチを選択モードにする
                selectingQueries.Add(q);

                UpdateConnectablePatchView(renderQueryPool, selectingQueries, refSkeleton);
            }
        }
예제 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //            FLib.FileManager.OpenExplorer("output");

            canvas.AllowDrop = true;

            renderer = new PatchMeshRenderer(canvas.Handle, canvas.ClientSize, true);

            // Magic2Dで作ったセグメントをロードしてパッチに変換
            Dictionary <string, PatchSkeletalMesh> dict;
            Dictionary <string, Bitmap>            bitmaps = new Dictionary <string, Bitmap>();

//            dict = Magic2D.SegmentToPatch.LoadPatches("../../../../..", "Patchwork_resources/GJ_ED3/3_segmentation", bitmaps, 2);
            // dict = Magic2D.SegmentToPatch.LoadPatches(@"C:\Users\furaga\Documents\Research\Patchwork\gj_kirara2", "3_segmentation", bitmaps, 4);
            dict = Magic2D.SegmentToPatch.LoadPatches("./settings", "3_segmentation", bitmaps, 4);

            System.Diagnostics.Debug.Assert(dict.Count == bitmaps.Count);


            // テクスチャをアセットに登録
            foreach (var kv in bitmaps)
            {
                var tex = SharpDXHelper.BitmapToTexture(kv.Value);
                resources.Add(kv.Key, tex);
                tex2bmp[tex] = kv.Value;
            }
            // パッチをキューに入れる
            for (int i = 0; i < dict.Count; i++)
            {
                string            resourceKey = bitmaps.Keys.ElementAt(i);
                string            textureKey  = dict.Keys.ElementAt(i);
                PatchSkeletalMesh patch       = dict.Values.ElementAt(i);
                renderQueryPool[resourceKey] = new RenderQuery(patch, new PatchTree(resourceKey), new List <string>()
                {
                    textureKey
                });
            }


            // パッチをリストに表示する
            foreach (var kv in bitmaps)
            {
                var patch = dict[kv.Key.Split(':')[1]];
                var skl   = patch.CopySkeleton();
                var bmp   = kv.Value;
                var bmp2  = DrawSkeltonOnBmp(skl, bmp);
                patchImageList.Images.Add(kv.Key, bmp2);
                patchView.Items.Add(kv.Key, kv.Key, kv.Key);
            }

            refSkeleton = PatchSkeleton.Load("./settings/refSkeleton.skl");

            canvas.MouseWheel += canvas_MouseWheel;
        }
예제 #3
0
        // seg.bmpはどこに格納する?patchmesh?pathcmeshrenderer?
        // => pathcMeshRendererResourcesに格納する
        static PatchSkeletalMesh ToPatchSkeletalMesh(Segment seg, Dictionary <string, Bitmap> bitmaps, int pathPointInterval)
        {
            PatchMesh           patchMesh     = ToPatchMesh(seg, pathPointInterval);
            PatchSkeleton       patchSkeleton = ToPatchSkeleton(seg);
            List <PatchSection> patchSections = ToPatchSections(seg, patchMesh.pathIndices.Select(i => patchMesh.vertices[i].position).ToList());

            // セグメントが使用するビットマップ画像をすべてコピーする。
            // この関数外でSharpDXHelper.ToTexture(bmp)を使って各画像をSharpDX描画用のテクスチャに変換する
            if (seg.bmp != null)
            {
                bitmaps[PatchMeshRenderResources.GenerateResourceKey(patchMesh, seg.name)] = new Bitmap(seg.bmp);
            }

            PatchSkeletalMesh skeletalMesh = new PatchSkeletalMesh(patchMesh, patchSkeleton, patchSections);

            return(skeletalMesh);
        }
예제 #4
0
        // selectingPatchesをすべて結合する
        private void combineCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string newKey = "combined" + combinedCount;

            HashSet <string> patchKeySet = new HashSet <string>();

            for (int i = 0; i < selectingQueries.Count; i++)
            {
                foreach (string k in selectingQueries[i].patchKeys)
                {
                    patchKeySet.Add(k);
                }
            }

            PatchSkeletalMesh newMesh = PatchConnector.Connect(selectingQueries.Select(q => q.patch).ToList(), refSkeleton, resources);


            PatchTree newTree = new PatchTree(null, null);

            if (newMesh == null)
            {
                return;
            }

            newMesh.Mesh.BeginDeformation();

            renderQueryPool.Add(newKey, new RenderQuery(newMesh, newTree, patchKeySet.ToList()));
            combinedCount++;


            foreach (var q in selectingQueries)
            {
                renderQueries.Remove(q);
            }
            renderQueries.Add(renderQueryPool[newKey]);

            selectingQueries.Clear();
        }
예제 #5
0
 public RenderQuery(PatchSkeletalMesh patch, PatchTree patchTree, List <string> patchKeys)
 {
     this.patch     = patch;
     this.patchKeys = new List <string>(patchKeys);
 }