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)); }
public void ApplyMorphToMesh(MeshAsset mesh) { for (int i = 0; i < LodCount; i++) { ApplyMorphToMeshLod(i, mesh); } }
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; } } }
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); } }
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); } }
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); } }
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); } }
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); } }
public void Apply(MeshAsset mesh, SkeletonAsset skeleton) { if (mesh != null) { ApplyMorphToMesh(mesh); } if (skeleton != null) { ApplyMorphToSkeleton(skeleton); } }
public void ExportMesh(MeshAsset mesh, int lodIndex, string targetFile) { if (Skeleton != null) { ExportSkinnedMeshToFBX(Skeleton, mesh, lodIndex, targetFile, true); } else { ExportStaticMeshToFBX(mesh, lodIndex, targetFile, true); } }
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); } }
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); }
/// 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)); }
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"); } }
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)); }
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)); }
public bool ExportSkinnedMeshToFBX(SkeletonAsset skeleton, MeshAsset mesh, int lodIndex, String targetdir) { return(ExportSkinnedMeshToFBX(skeleton, mesh, lodIndex, targetdir, false)); }
public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile) { byte[] pskData = ExportSkinnedMeshToPsk(Skeleton, mesh.lods[0]); File.WriteAllBytes(targetFile, pskData); }
private bool ExportMeshWithMorph(SkeletonAsset Skeleton, MeshAsset mesh, int lodIndex, List <Vector> morphBones, String targetdir) { return(ExportMeshWithMorph(Skeleton, mesh, lodIndex, null, morphBones, targetdir)); }
public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile, float scale = 100f) { exportScale = scale; ExportMesh(mesh, lodIndex, targetFile); }
public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile) { ExportMesh(mesh, lodIndex, targetFile); }
public void ExportLod(MeshAsset mesh, int lodIndex, string targetFile) { byte[] data = ExportAsObj(mesh, mesh.lods[lodIndex]); File.WriteAllBytes(targetFile, data); }
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); }
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); }