示例#1
0
        //-----------------------------------------------------------------------------------
        // Deform()
        //-----------------------------------------------------------------------------------

        /// <summary>
        /// 切り口付近で2つのsmeshが重なるように変形する
        /// patch2がdst方向
        /// </summary>
        private static void Deform(PatchSkeletalMesh patch1, PatchSkeletalMesh patch2, PatchSkeleton refSkeleton, PatchSection section1, PatchSection section2, PatchSkeletonBone crossingBone)
        {
            if (patch1 == null || patch2 == null)
            {
                return;
            }

            // 各メッシュを大雑把にスケルトンに合わせる
            PatchSkeletonFitting.Fitting(patch1, refSkeleton);
            PatchSkeletonFitting.Fitting(patch2, refSkeleton);

            // TODO: サイズの修正

            // 回転はFitting()でやってるから必要ない

            // 位置の調整

            float overlap = OverlapWidth(patch1, patch2, refSkeleton, section1, section2, crossingBone, 100, 45);

            AdjustHeight(patch1, patch2, refSkeleton, section1, section2, crossingBone);
            OverlayPatches(patch1, patch2, refSkeleton, section1, section2, crossingBone, overlap);

#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(patch1).Save("output_Connector2/4_patch1.png");
            PatchSkeletalMeshRenderer.ToBitmap(patch2).Save("output_Connector2/4_patch2.png");
#endif
            // メッシュを伸ばして繋げる
            Expand(patch1, patch2, refSkeleton, section1, section2, crossingBone, overlap, overlap);
        }
示例#2
0
        //-----------------------------------------------------------------------------------
        // Deform()
        //-----------------------------------------------------------------------------------

        /// <summary>
        /// 切り口付近で2つのsmeshが重なるように変形する
        /// </summary>
        private static void Deform(PatchSkeletalMesh smesh1, PatchSkeletalMesh smesh2, PatchSkeleton skl, PatchSection section1, PatchSection section2, PatchSkeletonBone crossingBone)
        {
            if (smesh1 == null || smesh2 == null)
            {
                return;
            }

            // 各メッシュを大雑把にスケルトンに合わせる
            PatchSkeletonFitting.Fitting(smesh1, skl);
            PatchSkeletonFitting.Fitting(smesh2, skl);
#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(smesh1, new List <PatchSection>()
            {
                section1
            }).Save("output/5_1_mesh1_fitting.png");
            PatchSkeletalMeshRenderer.ToBitmap(smesh2, new List <PatchSection>()
            {
                section2
            }).Save("output/5_2_mesh2_fitting.png");
#endif

            // サイズの修正は手動でやる
            // 回転はFitting()でやってるから必要ない

            // 位置の調整
            AdjustPosition(smesh1, smesh2, skl, section1, section2, crossingBone);
#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(smesh1, new List <PatchSection>()
            {
                section1
            }).Save("output/5_3_mesh1_AdjustPosition.png");
            PatchSkeletalMeshRenderer.ToBitmap(smesh2, new List <PatchSection>()
            {
                section2
            }).Save("output/5_4_mesh2_AdjustPosition.png");
#endif

            // メッシュを伸ばして繋げる
            Expand(smesh1, smesh2, skl, section1, section2, crossingBone);
#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(smesh1, new List <PatchSection>()
            {
                section1
            }).Save("output/5_5_mesh1_ExpandPatches.png");
            PatchSkeletalMeshRenderer.ToBitmap(smesh2, new List <PatchSection>()
            {
                section2
            }).Save("output/5_6_mesh2_ExpandPatches.png");
#endif
        }
示例#3
0
        /// <summary>
        /// 2つの骨格つきメッシュをスケルトン情報を元に結合する
        /// 1. スケルトンに合わせて各メッシュをざっくり移動・ボーン方向にARAP
        /// 2. メッシュ同士が自然に繋がるように位置・角度・スケールを調整(fitting(), adjustposition())
        /// 3. 繋ぎ目が重なるようにARAP(expand())
        /// 4. 新しいARAP可能なひとつのメッシュを生成(combine)                                                                                                                                                                                                                                                                                          /// </summary>
        /// (5. リソースの更新。これはここでやるべきなのだろうか?)
        /// </summary>
        public static PatchSkeletalMesh Connect(PatchSkeletalMesh smesh1, PatchSkeletalMesh smesh2, PatchSkeleton refSkeleton, PatchMeshRenderResources resources)
        {
            if (refSkeleton == null)
            {
                return(null);
            }

            // メッシュ・骨格データはConnect()内で変更されうるのでコピーしたものを使う
            PatchSkeletalMesh smesh1_t = PatchSkeletalMesh.Copy(smesh1);
            PatchSkeletalMesh smesh2_t = PatchSkeletalMesh.Copy(smesh2);

#if DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(smesh1_t, smesh1_t.sections, alignment: true).Save("smesh1_t.png");
            PatchSkeletalMeshRenderer.ToBitmap(smesh2_t, smesh2_t.sections, alignment: true).Save("smesh2_t.png");
#endif
            var refSkeleton_t = PatchSkeleton.Copy(refSkeleton);

            // smesh1, smesh2で同じボーンを共有している(結合すべき)切り口を探す
            // これらの切り口の付近を変形することでメッシュを繋げる
            PatchSection      section1;
            PatchSection      section2;
            PatchSkeletonBone crossingBone;

            bool canConnect = CanConnect(new List <PatchSkeletalMesh>()
            {
                smesh1, smesh2
            }, refSkeleton);
            bool canConnect_t = CanConnect(new List <PatchSkeletalMesh>()
            {
                smesh1_t, smesh2_t
            }, refSkeleton_t);

            bool found = FindConnectingSections(smesh1_t, smesh2_t, refSkeleton_t, out section1, out section2, out crossingBone);
            if (!found)
            {
                return(null);
            }
#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(smesh1_t, new List <CharacterRange>()
            {
                section1
            }).Save("output/3_mesh1_t_seciton1.png");
            PatchSkeletalMeshRenderer.ToBitmap(smesh2_t, new List <CharacterRange>()
            {
                section2
            }).Save("output/4_mesh2_t_section2.png");
#endif

            // 2つのsmeshが重なるように位置調整およびARAP変形をする
            smesh1_t.mesh.BeginDeformation();
            smesh2_t.mesh.BeginDeformation();
            Deform(smesh1_t, smesh2_t, refSkeleton_t, section1, section2, crossingBone);
            smesh2_t.mesh.EndDeformation();
            smesh1_t.mesh.EndDeformation();
#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(smesh1_t).Save("output/6_mesh1_t_deformed.png");
            PatchSkeletalMeshRenderer.ToBitmap(smesh2_t).Save("output/7_mesh2_t_deformed.png");
#endif

            // 2つの変形済みのsmeshを1つのsmeshに結合して、ARAPできるようにする
            var combinedSMesh = Combine(smesh1_t, smesh2_t, section1, section2);
#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(combinedSMesh, combinedSMesh.sections).Save("output/8_conbinedMesh.png");
#endif

            if (resources != null)
            {
                List <string> textureKeys = resources.GetResourceKeyByPatchMesh(smesh1.mesh);
                textureKeys.AddRange(resources.GetResourceKeyByPatchMesh(smesh2.mesh));

                foreach (var key in textureKeys)
                {
                    string patchKey = key.Split(':').Last();
                    string newKey   = PatchMeshRenderResources.GenerateResourceKey(combinedSMesh.mesh, patchKey);
                    // TODO: テクスチャはコピーしたほうが良い?
                    resources.Add(newKey, resources.GetTexture(key));
                }
            }

            return(combinedSMesh);
        }
示例#4
0
        public static PatchSkeletalMesh Connect(PatchSkeletalMesh patch1, PatchSkeletalMesh patch2, PatchSkeleton refSkeleton, PatchMeshRenderResources resources)
        {
            if (refSkeleton == null)
            {
                return(null);
            }

            if (!System.IO.Directory.Exists("output_Connector2"))
            {
                System.IO.Directory.CreateDirectory("output_Connector2");
            }

            FLib.FileManager.OpenExplorer("output_Connector2");

#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(patch1).Save("output_Connector2/1_patch1.png");
            PatchSkeletalMeshRenderer.ToBitmap(patch2).Save("output_Connector2/1_patch2.png");
#endif
            // 1. パッチをコピー
            PatchSkeletalMesh patch1_t = PatchSkeletalMesh.Copy(patch1);
            PatchSkeletalMesh patch2_t = PatchSkeletalMesh.Copy(patch2);
            var refSkeleton_t          = PatchSkeleton.Copy(refSkeleton);

            // 2. patch1, patch2の接続面および対応するボーンを探す
            PatchSection      section1;
            PatchSection      section2;
            PatchSkeletonBone crossingBone;
            bool swap;
            bool found = ConnectableSections(patch1_t, patch2_t, refSkeleton_t, out section1, out section2, out crossingBone, out swap);
            if (!found)
            {
                return(null);
            }

            if (swap)
            {
                FMath.Swap(ref patch1_t, ref patch2_t);
                FMath.Swap(ref section1, ref section2);
            }

#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(patch1_t, new List <CharacterRange>()
            {
                section1
            }).Save("output_Connector2/2_patch1.png");
            PatchSkeletalMeshRenderer.ToBitmap(patch2_t, new List <CharacterRange>()
            {
                section2
            }).Save("output_Connector2/2_patch2.png");
#endif

            // 3. 2つのパッチが重なるように位置調整およびARAP変形
            patch1_t.mesh.BeginDeformation();
            patch2_t.mesh.BeginDeformation();
            Deform(patch1_t, patch2_t, refSkeleton_t, section1, section2, crossingBone);
            patch2_t.mesh.EndDeformation();
            patch1_t.mesh.EndDeformation();

#if _DEBUG
            PatchSkeletalMeshRenderer.ToBitmap(patch1_t, new List <CharacterRange>()
            {
                section1
            }).Save("output_Connector2/3_patch1.png");
            PatchSkeletalMeshRenderer.ToBitmap(patch2_t, new List <CharacterRange>()
            {
                section2
            }).Save("output_Connector2/3_patch2.png");
#endif

            // 4. 2つのパッチのテクスチャを合成して、新しいパッチを生成

//            TODO:メッシュをビットマップ画像として書き出してリサンプリング

            // todo
            var combinedSMesh = Combine(patch1_t, patch2_t, section1, section2);


            // 5. 新しいパッチに使うテクスチャをリソースに登録

            // todo
            if (resources != null)
            {
                List <string> textureKeys = resources.GetResourceKeyByPatchMesh(patch1.mesh);
                textureKeys.AddRange(resources.GetResourceKeyByPatchMesh(patch2.mesh));

                foreach (var key in textureKeys)
                {
                    string patchKey = key.Split(':').Last();
                    string newKey   = PatchMeshRenderResources.GenerateResourceKey(combinedSMesh.mesh, patchKey);
                    resources.Add(newKey, resources.GetTexture(key));
                }
            }
            return(combinedSMesh);
        }