コード例 #1
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
        public bool ExportSkinnedMeshToFBX(SkeletonAsset skeleton, MeshAsset mesh, int lodIndex, String targetdir, bool asOne)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot     = lScene.GetRootNode();
            FBXNode lSkeletonRoot = CreateFbxSkeleton(skeleton, lScene);

            SceneRoot.AddChild(lSkeletonRoot);
            if (asOne)
            {
                FBXNode fbxMesh = CreateFbxMesh(mesh.lods[lodIndex], lScene);
                CreateMeshSkinning(skeleton, mesh.lods[lodIndex], fbxMesh, lSkeletonRoot, lScene);
                SceneRoot.AddChild(fbxMesh);
                StoreRestPose(lScene, lSkeletonRoot, skeleton);
            }
            else
            {
                for (int i = 0; i < mesh.lods[lodIndex].sections.Count; i++)
                {
                    FBXNode CurrentSectionMesh = CreateFbxMesh(mesh.lods[lodIndex].sections[i], lScene);
                    CreateMeshSkinning(skeleton, mesh.lods[lodIndex].sections[i], CurrentSectionMesh, lSkeletonRoot, lScene);
                    SceneRoot.AddChild(CurrentSectionMesh);
                    StoreBindPose(lScene, CurrentSectionMesh);
                }
            }
            return(SaveScene(targetdir, lSdkManager, lScene));
        }
コード例 #2
0
 public void ApplyMorphToMesh(MeshAsset mesh)
 {
     for (int i = 0; i < LodCount; i++)
     {
         ApplyMorphToMeshLod(i, mesh);
     }
 }
コード例 #3
0
        private void ApplyMorphToMeshLod(int lodIndex, MeshAsset mesh)
        {
            List <Vector> LodVertices = GetVerticesForLod(lodIndex, mesh);
            MeshLOD       lod         = mesh.lods[lodIndex];
            int           offset      = 0;

            foreach (MeshLodSection section in lod.sections)
            {
                if (section.vertices != null)
                {
                    for (int i = 0; i < section.vertices.Count; i++)
                    {
                        section.vertices[i].position.members[0] = LodVertices[offset].members[0];
                        section.vertices[i].position.members[1] = LodVertices[offset].members[1];
                        section.vertices[i].position.members[2] = LodVertices[offset].members[2];
                        offset++;
                    }
                }
                else
                {
                    // if the lod is not completely loaded, we abort
                    break;
                }
            }
        }
コード例 #4
0
 public void ExportAllLods(MeshAsset mesh, string targetdir)
 {
     for (int i = 0; i < mesh.lods.Count; i++)
     {
         string targetFile = Path.Combine(targetdir, mesh.lods[i].shortName + ".fbx");
         ExportMesh(mesh, i, targetFile);
     }
 }
コード例 #5
0
 public void ExportAllLods(MeshAsset mesh, string targetdir)
 {
     foreach (MeshLOD lod in mesh.lods)
     {
         string targetFile = Path.Combine(targetdir, lod.shortName + ".obj");
         byte[] data       = ExportAsObj(mesh, lod);
         File.WriteAllBytes(targetFile, data);
     }
 }
コード例 #6
0
 public void ExportAllLods(MeshAsset mesh, string targetdir)
 {
     foreach (MeshLOD lod in mesh.lods)
     {
         string targetFile = Path.Combine(targetdir, lod.shortName + ".psk");
         byte[] data       = ExportSkinnedMeshToPsk(Skeleton, lod);
         File.WriteAllBytes(targetFile, data);
     }
 }
コード例 #7
0
 public void ExportAllLodsWithMorph(MeshAsset mesh, MorphStaticAsset morph, string targetdir, float scale = 1.0f, bool bake = false)
 {
     for (int morphLod = 0; morphLod < morph.LodCount; morphLod++)
     {
         string fileName   = string.Format("{0}_lod{1}.obj", morph.MorphName, morphLod);
         string targetFile = Path.Combine(targetdir, fileName);
         ExportLodWithMorph(mesh, morphLod, morph, targetFile, scale, bake);
     }
 }
コード例 #8
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
 public void ExportMesh(MeshAsset mesh, int lodIndex, string targetFile)
 {
     if (Skeleton != null && mesh.header.type == MeshType.MeshType_Skinned)
     {
         ExportSkinnedMeshToFBX(Skeleton, mesh, lodIndex, targetFile, true);
     }
     else
     {
         ExportStaticMeshToFBX(mesh, lodIndex, targetFile, true);
     }
 }
コード例 #9
0
 public void Apply(MeshAsset mesh, SkeletonAsset skeleton)
 {
     if (mesh != null)
     {
         ApplyMorphToMesh(mesh);
     }
     if (skeleton != null)
     {
         ApplyMorphToSkeleton(skeleton);
     }
 }
コード例 #10
0
 public void ExportMesh(MeshAsset mesh, int lodIndex, string targetFile)
 {
     if (Skeleton != null)
     {
         ExportSkinnedMeshToFBX(Skeleton, mesh, lodIndex, targetFile, true);
     }
     else
     {
         ExportStaticMeshToFBX(mesh, lodIndex, targetFile, true);
     }
 }
コード例 #11
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
 public void ExportLodWithMorph(MeshAsset mesh, int lodIndex, MorphStaticAsset morph, string targetFile, float scale = 100f, bool bake = false)
 {
     exportScale = scale;
     if (bake)
     {
         morph.ApplyMorphToMesh(mesh);
         ExportMeshWithMorph(Skeleton, mesh, lodIndex, morph.BonesMorph, targetFile);
     }
     else
     {
         ExportMeshWithMorph(Skeleton, mesh, lodIndex, morph.GetVerticesForLod(lodIndex, mesh), morph.BonesMorph, targetFile);
     }
 }
コード例 #12
0
        public List <Vector> GetVerticesForLod(int lodIndex, MeshAsset presetMesh)
        {
            int startOffset = 0;

            for (int i = 0; i < lodIndex; i++)
            {
                startOffset = startOffset + presetMesh.lods[i].GetLODTotalVertCount();
            }

            var VerticesForLod = new List <Vector>();

            VerticesForLod.AddRange(Vertices.GetRange(startOffset, presetMesh.lods[lodIndex].GetLODTotalVertCount()));
            return(VerticesForLod);
        }
コード例 #13
0
        ///
        private byte[] ExportAsObj(MeshAsset mesh, MeshLOD lod)
        {
            string[]   subMeshNames = new string[lod.sections.Count];
            float[][]  verts        = new float[lod.sections.Count][];
            float[][]  uvcords      = new float[lod.sections.Count][];
            ushort[][] indices      = new ushort[lod.sections.Count][];

            for (int i = 0; i < lod.sections.Count; i++)
            {
                subMeshNames[i] = lod.sections[i].matName;
                verts[i]        = GetVerticesPositionsArray(lod.sections[i].vertices);
                uvcords[i]      = GetUVCoordsArray(lod.sections[i].vertices);
                indices[i]      = lod.sections[i].indicies.ToArray();
            }

            return(convertToOBJ(mesh.header.shortName, subMeshNames, verts, uvcords, indices));
        }
コード例 #14
0
        public void ExportLodWithMorph(MeshAsset mesh, int lodIndex, MorphStaticAsset morph, string targetfile, float scale = 1.0f, bool bake = false)
        {
            morph.ApplyMorphToMesh(mesh);
            ExportLod(mesh, lodIndex, targetfile, scale);

            // export psa file holding a pose corresponding to the skeleton morph
            string psaFileName   = Path.GetFileNameWithoutExtension(targetfile) + ".psa";
            string targetPsaFile = Path.Combine(Path.GetDirectoryName(targetfile), psaFileName);

            try
            {
                byte[] psaData = ExportPoseToPsa(Skeleton, morph.BonesMorph, scale);
                File.WriteAllBytes(targetPsaFile, psaData);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Unable to export pose as psa : skeleton not provided");
            }
        }
コード例 #15
0
        public bool ExportMeshWithMorph(SkeletonAsset Skeleton, MeshAsset mesh, int lodIndex, List <Vector> morphVertex, List <Vector> morphBones, String targetdir)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot = lScene.GetRootNode();
            FBXNode fbxMesh   = CreateFbxMesh(mesh.lods[lodIndex], lScene);

            AddMorphToMesh(lScene, fbxMesh, morphVertex);
            SceneRoot.AddChild(fbxMesh);
            if (Skeleton != null)
            {
                FBXNode lSkeletonRoot = CreateFbxSkeleton(Skeleton, lScene);
                CreateMeshSkinning(Skeleton, mesh.lods[lodIndex], fbxMesh, lSkeletonRoot, lScene);
                UpdateSkeletonWithMorph(Skeleton, lSkeletonRoot, morphBones);
                SceneRoot.AddChild(lSkeletonRoot);
                StoreBindPose(lScene, fbxMesh);
            }
            return(SaveScene(targetdir, lSdkManager, lScene));
        }
コード例 #16
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
        public bool ExportStaticMeshToFBX(MeshAsset mesh, int lodIndex, String targetdir, bool asOne)
        {
            FBXManager lSdkManager = new FBXManager();
            FBXScene   lScene      = new FBXScene();

            FBXHelper.InitializeSdkObjects(lSdkManager, lScene);
            FBXNode SceneRoot = lScene.GetRootNode();

            if (asOne)
            {
                FBXNode fbxMesh = CreateFbxMesh(mesh.lods[lodIndex], lScene);
                SceneRoot.AddChild(fbxMesh);
            }
            else
            {
                for (int i = 0; i < mesh.lods[lodIndex].sections.Count; i++)
                {
                    FBXNode CurrentSectionMesh = CreateFbxMesh(mesh.lods[lodIndex].sections[i], lScene);
                    SceneRoot.AddChild(CurrentSectionMesh);
                }
            }
            return(SaveScene(targetdir, lSdkManager, lScene));
        }
コード例 #17
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
 public bool ExportSkinnedMeshToFBX(SkeletonAsset skeleton, MeshAsset mesh, int lodIndex, String targetdir)
 {
     return(ExportSkinnedMeshToFBX(skeleton, mesh, lodIndex, targetdir, false));
 }
コード例 #18
0
 public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile)
 {
     byte[] pskData = ExportSkinnedMeshToPsk(Skeleton, mesh.lods[0]);
     File.WriteAllBytes(targetFile, pskData);
 }
コード例 #19
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
 private bool ExportMeshWithMorph(SkeletonAsset Skeleton, MeshAsset mesh, int lodIndex, List <Vector> morphBones, String targetdir)
 {
     return(ExportMeshWithMorph(Skeleton, mesh, lodIndex, null, morphBones, targetdir));
 }
コード例 #20
0
ファイル: FBXExporter.cs プロジェクト: gabbyh/MEAExplorerWV
 public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile, float scale = 100f)
 {
     exportScale = scale;
     ExportMesh(mesh, lodIndex, targetFile);
 }
コード例 #21
0
 public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile)
 {
     ExportMesh(mesh, lodIndex, targetFile);
 }
コード例 #22
0
 public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile)
 {
     byte[] data = ExportAsObj(mesh, mesh.lods[lodIndex]);
     File.WriteAllBytes(targetFile, data);
 }
コード例 #23
0
 public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile, float scale = 1.0f)
 {
     exportScale = scale;
     byte[] data = ExportAsObj(mesh, mesh.lods[lodIndex]);
     File.WriteAllBytes(targetFile, data);
 }
コード例 #24
0
 public void ExportLodWithMorph(MeshAsset mesh, int lodIndex, MorphStaticAsset morph, string targetfile, float scale = 1.0f, bool bake = false)
 {
     morph.ApplyMorphToMesh(mesh);
     ExportLod(mesh, lodIndex, targetfile, scale);
 }