public static void ExportFbx([DefaultVar] Animator animator, object[] meshes, object[] animationClips, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, float boneSize, bool morphs, bool flatInbetween, bool compatibility) { List <MeshRenderer> meshList = null; List <int[]> morphList = null; if (meshes != null) { MeshRenderer[] meshArray = Utility.Convert <MeshRenderer>(meshes); meshList = new List <MeshRenderer>(meshArray); if (morphs) { morphList = new List <int[]>(meshes.Length); for (int i = 0; i < meshes.Length; i++) { morphList.Add(null); } } } ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); Operations.UnityConverter imp = new Operations.UnityConverter(animator, meshList, skins, morphList, flatInbetween, preferredUncompressedFormat); if (animationClips != null) { AnimationClip[] clipArray = Utility.Convert <AnimationClip>(animationClips); List <AnimationClip> clipList = new List <AnimationClip>(clipArray); imp.ConvertAnimations(clipList); } FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, boneSize, flatInbetween, compatibility); }
public static void ExportFbx([DefaultVar] UnityParser parser, object[] skinnedMeshRendererIDs, object[] animationParsers, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, bool compatibility) { List <double> sMeshIDList = new List <double>(Utility.Convert <double>(skinnedMeshRendererIDs)); List <MeshRenderer> sMeshes = new List <MeshRenderer>(sMeshIDList.Count); for (int i = 0; i < sMeshIDList.Count; i++) { int sMeshID = (int)sMeshIDList[i]; if (i > 0 && sMeshID < 0) { for (sMeshID = (int)sMeshIDList[i - 1] + 1; sMeshID < -(int)sMeshIDList[i]; sMeshID++) { SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID); if (sMesh == null) { continue; } sMeshes.Add(sMesh); } } else { SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID); if (sMesh == null) { continue; } sMeshes.Add(sMesh); } } UnityConverter imp = new UnityConverter(parser, sMeshes, skins); FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, compatibility); }
public static Transform CreateTransformTree(Animator parser, ImportedFrame frame, Transform parent) { Transform trans = new Transform(parser.file); GameObject gameObj = new GameObject(parser.file); gameObj.m_Name = (string)frame.Name.Clone(); UniqueName(parser, gameObj); gameObj.AddLinkedComponent(trans); parser.m_Avatar.instance.AddBone(parent, trans); Vector3 t, s; Quaternion r; frame.Matrix.Decompose(out s, out r, out t); t.X *= -1; Vector3 euler = FbxUtility.QuaternionToEuler(r); euler.Y *= -1; euler.Z *= -1; trans.m_LocalRotation = FbxUtility.EulerToQuaternion(euler); trans.m_LocalPosition = t; trans.m_LocalScale = s; trans.InitChildren(frame.Count); for (int i = 0; i < frame.Count; i++) { trans.AddChild(CreateTransformTree(parser, frame[i], trans)); } return(trans); }
private void ConvertFrames(Transform trans, ImportedFrame parent) { ImportedFrame frame = new ImportedFrame(); frame.Name = trans.m_GameObject.instance.m_Name; frame.InitChildren(trans.Count); Vector3 euler = FbxUtility.QuaternionToEuler(trans.m_LocalRotation); euler.Y *= -1; euler.Z *= -1; Quaternion mirroredRotation = FbxUtility.EulerToQuaternion(euler); frame.Matrix = Matrix.Scaling(trans.m_LocalScale) * Matrix.RotationQuaternion(mirroredRotation) * Matrix.Translation(-trans.m_LocalPosition.X, trans.m_LocalPosition.Y, trans.m_LocalPosition.Z); if (parent == null) { FrameList = new List <ImportedFrame>(); FrameList.Add(frame); } else { parent.AddChild(frame); } foreach (Transform child in trans) { ConvertFrames(child, frame); } }
public static List <PPtr <Transform> > CreateBoneList(Transform root, Matrix meshTransform, List <ImportedBone> boneList, List <Matrix> poseMatrices) { List <PPtr <Transform> > uBoneList = new List <PPtr <Transform> >(boneList.Count); string message = string.Empty; for (int i = 0; i < boneList.Count; i++) { Transform boneFrame = FindFrame(boneList[i].Name, root); if (boneFrame == null) { message += " " + boneList[i].Name; } Vector3 s, t; Quaternion q; boneList[i].Matrix.Decompose(out s, out q, out t); t.X *= -1; Vector3 euler = FbxUtility.QuaternionToEuler(q); euler.Y *= -1; euler.Z *= -1; q = FbxUtility.EulerToQuaternion(euler); Matrix m = Matrix.Scaling(s) * Matrix.RotationQuaternion(q) * Matrix.Translation(t); poseMatrices.Add(Matrix.Transpose(meshTransform * m)); uBoneList.Add(new PPtr <Transform>(boneFrame)); } if (message != string.Empty) { throw new Exception("Boneframe(s) not found:" + message); } return(uBoneList); }
public static void ExportMorphFbx([DefaultVar] Animator animator, object[] meshes, object[] morphs, bool flatInbetween, string path, string exportFormat, bool morphMask, bool skins, float boneSize, bool compatibility) { MeshRenderer[] meshArray = Utility.Convert <MeshRenderer>(meshes); List <MeshRenderer> meshList = new List <MeshRenderer>(meshArray); object[][] morphArray = Utility.Convert <object[]>(morphs); List <int[]> morphList = new List <int[]>(morphs.Length); for (int i = 0; i < morphArray.Length; i++) { int[] morphIndices = null; if (morphArray[i] != null) { double[] doubles = Utility.Convert <double>(morphArray[i]); morphIndices = new int[doubles.Length]; for (int j = 0; j < doubles.Length; j++) { morphIndices[j] = (int)doubles[j]; } } morphList.Add(morphIndices); } ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); Operations.UnityConverter imp = new Operations.UnityConverter(animator, meshList, skins, morphList, flatInbetween, preferredUncompressedFormat); FbxUtility.ExportMorph(path, imp, exportFormat, morphMask, flatInbetween, skins, boneSize, compatibility); }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, odfParser parser, int resampleCount, bool linear, ReplaceAnimationMethod replaceMethod, string clip, int insertPos, bool negateQuaternionFlips) { if (parser.AnimSection == null) { Report.ReportLog(Path.GetFileName(parser.ODFPath) + " doesn't have an animation section. Skipping this animation"); return; } if (!(wsAnimation.importedAnimation is ImportedKeyframedAnimation)) { Report.ReportLog("The animation has incompatible keyframes."); return; } Report.ReportLog("Replacing animation ..."); List <KeyValuePair <string, ImportedAnimationKeyframe[]> > newTrackList = FbxUtility.CopyKeyframedAnimation(wsAnimation, resampleCount, linear); List <odfTrack> animationNodeList = odf.FindClip(clip, parser).ChildList; ImportedKeyframedAnimation iAnim = new ImportedKeyframedAnimation(); iAnim.TrackList = new List <ImportedAnimationKeyframedTrack>(animationNodeList.Count); Dictionary <string, ImportedAnimationKeyframedTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary <string, ImportedAnimationKeyframedTrack>(); foreach (odfTrack animationNode in animationNodeList) { ImportedAnimationKeyframedTrack iTrack = new ImportedAnimationKeyframedTrack(); iTrack.Name = odf.FindFrame(animationNode.BoneFrameId, parser.FrameSection.RootFrame).Name; iTrack.Keyframes = Plugins.ODFConverter.ConvertTrack(animationNode.KeyframeList); animationNodeDic.Add(odf.FindFrame(animationNode.BoneFrameId, parser.FrameSection.RootFrame).Name, iTrack); iAnim.TrackList.Add(iTrack); } } foreach (var newTrack in newTrackList) { ImportedAnimationKeyframe[] keyframes = newTrack.Value; Quaternion q = keyframes[0].Rotation; keyframes[0].Rotation *= -1; /* if (keyframes[0].Rotation.Angle == 0 || q.Angle == 0) * { * Report.ReportLog("track " + newTrack.Key + " r=" + keyframes[0].Rotation.Angle + " q=" + q.Angle); * }*/ } FbxUtility.ReplaceAnimation(replaceMethod, insertPos, newTrackList, iAnim, animationNodeDic, negateQuaternionFlips); animationNodeList.Clear(); foreach (var newTrack in iAnim.TrackList) { ImportedAnimationKeyframe[] keyframes = ((ImportedAnimationKeyframedTrack)newTrack).Keyframes; odfTrack animationNode = new odfTrack(keyframes.Length); odf.CreateUnknowns(animationNode); animationNodeList.Add(animationNode); animationNode.KeyframeList = Plugins.ODFConverter.ConvertTrack(keyframes); animationNode.BoneFrameId = odf.FindFrame(newTrack.Name, parser.FrameSection.RootFrame).Id; } }
public void SetBoneSRT(int meshIdx, int boneIdx, double sX, double sY, double sZ, double rX, double rY, double rZ, double tX, double tY, double tZ) { remMesh mesh = Parser.MESC[meshIdx]; remSkin skin = rem.FindSkin(mesh.name, Parser.SKIC); remBoneWeights boneWeights = skin[boneIdx]; boneWeights.matrix = FbxUtility.SRTToMatrix(new Vector3((float)sX, (float)sY, (float)sZ), new Vector3((float)rX, (float)rY, (float)rZ), new Vector3((float)tX, (float)tY, (float)tZ)); }
public static void ExportMorphFbx([DefaultVar] Animator animator, object[] meshes, string path, string exportFormat, bool oneBlendShape, bool compatibility) { MeshRenderer[] meshArray = Utility.Convert <MeshRenderer>(meshes); List <MeshRenderer> meshList = new List <MeshRenderer>(meshArray); UnityConverter imp = new UnityConverter(animator, meshList, false, true); FbxUtility.ExportMorph(path, imp, exportFormat, oneBlendShape, compatibility); }
public static void ExportFbx([DefaultVar] Animator animator, object[] meshes, object[] animationParsers, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, bool compatibility) { MeshRenderer[] meshArray = Utility.Convert <MeshRenderer>(meshes); List <MeshRenderer> meshList = new List <MeshRenderer>(meshArray); UnityConverter imp = new UnityConverter(animator, meshList, skins, false); FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, compatibility); }
public void SetBoneSRT(string boneFrame, double sX, double sY, double sZ, double rX, double rY, double rZ, double tX, double tY, double tZ) { remId boneFrameId = new remId(boneFrame); Matrix m = FbxUtility.SRTToMatrix(new Vector3((float)sX, (float)sY, (float)sZ), new Vector3((float)rX, (float)rY, (float)rZ), new Vector3((float)tX, (float)tY, (float)tZ)); foreach (remSkin skin in Parser.SKIC) { foreach (remBoneWeights boneWeights in skin) { if (boneWeights.bone == boneFrameId) { boneWeights.matrix = m; break; } } } }
public static void ExportFbx([DefaultVar] UnityParser parser, object[] skinnedMeshRendererIDs, object[] animationParsers, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, float boneSize, bool compatibility) { List <double> sMeshIDList = new List <double>(Utility.Convert <double>(skinnedMeshRendererIDs)); List <MeshRenderer> sMeshes = new List <MeshRenderer>(sMeshIDList.Count); for (int i = 0; i < sMeshIDList.Count; i++) { int sMeshID = (int)sMeshIDList[i]; if (i > 0 && sMeshID < 0) { for (sMeshID = (int)sMeshIDList[i - 1] + 1; sMeshID < -(int)sMeshIDList[i]; sMeshID++) { SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID); if (sMesh == null) { continue; } sMeshes.Add(sMesh); } } else { SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID); if (sMesh == null) { continue; } sMeshes.Add(sMesh); } } ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP" ? ImageFileFormat.Bmp : (ImageFileFormat)(-1); Operations.UnityConverter imp = new Operations.UnityConverter(parser, sMeshes, skins, preferredUncompressedFormat); FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, boneSize, false, compatibility); }
public static void ExportFbx([DefaultVar] remParser parser, object[] meshNames, object[] reaParsers, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool skins, bool compatibility) { List <reaParser> reaParserList = null; if (reaParsers != null) { reaParserList = new List <reaParser>(Utility.Convert <reaParser>(reaParsers)); } List <string> meshStrList = new List <string>(Utility.Convert <string>(meshNames)); List <remMesh> meshes = new List <remMesh>(meshStrList.Count); foreach (string meshName in meshStrList) { remMesh mesh = rem.FindMesh(new remId(meshName), parser.MESC); if (mesh != null) { meshes.Add(mesh); } else { Report.ReportLog("Mesh " + meshName + " not found."); } } REMConverter imp = new REMConverter(parser, meshes); if (reaParserList != null) { foreach (reaParser reaParser in reaParserList) { imp.ConvertAnimation(reaParser.ANIC, parser); } } FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, false, skins, compatibility); }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, List <ImportedFrame> wsSkeleton, reaParser parser, int resampleCount, bool linear, ReplaceAnimationMethod replaceMethod, int insertPos, bool negateQuaternionFlips) { Report.ReportLog("Replacing animation ..."); List <KeyValuePair <string, ImportedAnimationSampledTrack> > newTrackList = FbxUtility.CopySampledAnimation(wsAnimation, resampleCount, linear); reaANICsection animationNodeList = parser.ANIC; ImportedSampledAnimation iAnim = new ImportedSampledAnimation(); iAnim.TrackList = new List <ImportedAnimationSampledTrack>(animationNodeList.Count); Dictionary <string, ImportedAnimationSampledTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary <string, ImportedAnimationSampledTrack>(); foreach (reaAnimationTrack animationNode in animationNodeList) { ImportedFrame boneFrame = ImportedHelpers.FindFrame(animationNode.boneFrame, wsSkeleton[0]); bool isTopFrame = boneFrame != null && boneFrame.Parent == wsSkeleton[0]; ImportedAnimationSampledTrack iTrack = Plugins.REMConverter.ConvertTrack(animationNode, isTopFrame); iTrack.Name = animationNode.boneFrame; animationNodeDic.Add(animationNode.boneFrame, iTrack); iAnim.TrackList.Add(iTrack); } } FbxUtility.ReplaceAnimation(replaceMethod, insertPos, newTrackList, iAnim, animationNodeDic, negateQuaternionFlips); animationNodeList.ChildList.Clear(); foreach (var newTrack in iAnim.TrackList) { ImportedFrame boneFrame = ImportedHelpers.FindFrame(newTrack.Name, wsSkeleton[0]); bool isTopFrame = boneFrame != null && boneFrame.Parent == wsSkeleton[0]; reaAnimationTrack animationNode = Plugins.REMConverter.ConvertTrack(newTrack, isTopFrame); animationNodeList.AddChild(animationNode); } }
public void SetFrameSRT(int idx, double sX, double sY, double sZ, double rX, double rY, double rZ, double tX, double tY, double tZ) { Parser.BONC[idx].matrix = FbxUtility.SRTToMatrix(new Vector3((float)sX, (float)sY, (float)sZ), new Vector3((float)rX, (float)rY, (float)rZ), new Vector3((float)tX, (float)tY, (float)tZ)); }
public void SetBoneSRT(int boneListIdx, int boneIdx, double sX, double sY, double sZ, double rX, double rY, double rZ, double tX, double tY, double tZ) { odfBone bone = Parser.EnvelopeSection[boneListIdx][boneIdx]; bone.Matrix = FbxUtility.SRTToMatrix(new Vector3((float)sX, (float)sY, (float)sZ), new Vector3((float)rX, (float)rY, (float)rZ), new Vector3((float)tX, (float)tY, (float)tZ)); }
private void ConvertMeshRenderers(List <MeshRenderer> meshList, bool skins, bool morphs) { MeshList = new List <ImportedMesh>(meshList.Count); MaterialList = new List <ImportedMaterial>(meshList.Count); TextureList = new List <ImportedTexture>(meshList.Count); MorphList = new List <ImportedMorph>(meshList.Count); foreach (MeshRenderer meshR in meshList) { Mesh mesh = Operations.GetMesh(meshR); if (mesh == null) { Report.ReportLog("skipping " + meshR.m_GameObject.instance.m_Name + " - no mesh"); continue; } ImportedMesh iMesh = new ImportedMesh(); Transform meshTransform = meshR.m_GameObject.instance.FindLinkedComponent(UnityClassID.Transform); iMesh.Name = meshTransform.GetTransformPath(); iMesh.SubmeshList = new List <ImportedSubmesh>(mesh.m_SubMeshes.Count); using (BinaryReader vertReader = new BinaryReader(new MemoryStream(mesh.m_VertexData.m_DataSize)), indexReader = new BinaryReader(new MemoryStream(mesh.m_IndexBuffer))) { for (int i = 0; i < mesh.m_SubMeshes.Count; i++) { SubMesh submesh = mesh.m_SubMeshes[i]; ImportedSubmesh iSubmesh = new ImportedSubmesh(); iSubmesh.Index = i; iSubmesh.Visible = true; Material mat = meshR.m_Materials[i].instance; ConvertMaterial(mat); iSubmesh.Material = mat.m_Name; iSubmesh.VertexList = new List <ImportedVertex>((int)submesh.vertexCount); for (int str = 0; str < mesh.m_VertexData.m_Streams.Count; str++) { StreamInfo sInfo = mesh.m_VertexData.m_Streams[str]; if (sInfo.channelMask == 0) { continue; } for (int j = 0; j < mesh.m_SubMeshes[i].vertexCount; j++) { ImportedVertex iVertex; if (iSubmesh.VertexList.Count < mesh.m_SubMeshes[i].vertexCount) { iVertex = new ImportedVertex(); iSubmesh.VertexList.Add(iVertex); } else { iVertex = iSubmesh.VertexList[j]; } for (int chn = 0; chn < mesh.m_VertexData.m_Channels.Count; chn++) { ChannelInfo cInfo = mesh.m_VertexData.m_Channels[chn]; if ((sInfo.channelMask & (1 << chn)) == 0) { continue; } vertReader.BaseStream.Position = sInfo.offset + (submesh.firstVertex + j) * sInfo.stride + cInfo.offset; switch (chn) { case 0: iVertex.Position = new SlimDX.Vector3(-vertReader.ReadSingle(), vertReader.ReadSingle(), vertReader.ReadSingle()); break; case 1: iVertex.Normal = new SlimDX.Vector3(-vertReader.ReadSingle(), vertReader.ReadSingle(), vertReader.ReadSingle()); break; case 3: iVertex.UV = new float[2] { vertReader.ReadSingle(), vertReader.ReadSingle() }; break; case 5: iVertex.Tangent = new SlimDX.Vector4(-vertReader.ReadSingle(), vertReader.ReadSingle(), vertReader.ReadSingle(), -vertReader.ReadSingle()); break; } } if (skins && iVertex.BoneIndices == null && mesh.m_Skin.Count > 0) { BoneInfluence inf = mesh.m_Skin[(int)submesh.firstVertex + j]; iVertex.BoneIndices = new byte[inf.boneIndex.Length]; for (int k = 0; k < iVertex.BoneIndices.Length; k++) { iVertex.BoneIndices[k] = (byte)inf.boneIndex[k]; } iVertex.Weights = (float[])inf.weight.Clone(); } } } int numFaces = (int)(submesh.indexCount / 3); iSubmesh.FaceList = new List <ImportedFace>(numFaces); indexReader.BaseStream.Position = submesh.firstByte; for (int j = 0; j < numFaces; j++) { ImportedFace face = new ImportedFace(); face.VertexIndices = new int[3]; face.VertexIndices[0] = indexReader.ReadUInt16() - (int)submesh.firstVertex; face.VertexIndices[2] = indexReader.ReadUInt16() - (int)submesh.firstVertex; face.VertexIndices[1] = indexReader.ReadUInt16() - (int)submesh.firstVertex; iSubmesh.FaceList.Add(face); } iMesh.SubmeshList.Add(iSubmesh); } } if (skins && meshR is SkinnedMeshRenderer) { SkinnedMeshRenderer sMesh = (SkinnedMeshRenderer)meshR; if (sMesh.m_Bones.Count >= 256) { throw new Exception("Too many bones (" + mesh.m_BindPose.Count + ")"); } if (sMesh.m_Bones.Count != mesh.m_BindPose.Count || sMesh.m_Bones.Count != mesh.m_BoneNameHashes.Count) { throw new Exception("Mismatching number of bones bind pose=" + mesh.m_BindPose.Count + " hashes=" + mesh.m_BoneNameHashes.Count + " numBones=" + sMesh.m_Bones.Count); } iMesh.BoneList = new List <ImportedBone>(sMesh.m_Bones.Count); for (int i = 0; i < sMesh.m_Bones.Count; i++) { ImportedBone bone = new ImportedBone(); uint boneHash = mesh.m_BoneNameHashes[i]; bone.Name = avatar.FindBoneName(boneHash); Matrix m = Matrix.Transpose(mesh.m_BindPose[i]); Vector3 s, t; Quaternion q; m.Decompose(out s, out q, out t); t.X *= -1; Vector3 euler = FbxUtility.QuaternionToEuler(q); euler.Y *= -1; euler.Z *= -1; q = FbxUtility.EulerToQuaternion(euler); bone.Matrix = Matrix.Scaling(s) * Matrix.RotationQuaternion(q) * Matrix.Translation(t); iMesh.BoneList.Add(bone); } } if (morphs && mesh.m_Shapes.shapes.Count > 0) { ImportedMorph morph = new ImportedMorph(); morph.Name = iMesh.Name; morph.ClipName = Operations.BlendShapeName(mesh); morph.KeyframeList = new List <ImportedMorphKeyframe>(mesh.m_Shapes.shapes.Count); for (int i = 0; i < mesh.m_Shapes.shapes.Count; i++) { ImportedMorphKeyframe keyframe = new ImportedMorphKeyframe(); keyframe.Name = Operations.BlendShapeKeyframeName(mesh, i); keyframe.VertexList = new List <ImportedVertex>((int)mesh.m_Shapes.shapes[i].vertexCount); keyframe.MorphedVertexIndices = new List <ushort>((int)mesh.m_Shapes.shapes[i].vertexCount); int lastVertIndex = (int)(mesh.m_Shapes.shapes[i].firstVertex + mesh.m_Shapes.shapes[i].vertexCount); for (int j = (int)mesh.m_Shapes.shapes[i].firstVertex; j < lastVertIndex; j++) { BlendShapeVertex morphVert = mesh.m_Shapes.vertices[j]; ImportedVertex vert = GetSourceVertex(iMesh.SubmeshList, (int)morphVert.index); ImportedVertex destVert = new ImportedVertex(); Vector3 morphPos = morphVert.vertex; morphPos.X *= -1; destVert.Position = vert.Position + morphPos; Vector3 morphNormal = morphVert.normal; morphNormal.X *= -1; destVert.Normal = morphNormal; Vector4 morphTangent = new Vector4(morphVert.tangent, 0); morphTangent.X *= -1; destVert.Tangent = morphTangent; keyframe.VertexList.Add(destVert); keyframe.MorphedVertexIndices.Add((ushort)morphVert.index); } morph.KeyframeList.Add(keyframe); } MorphList.Add(morph); } MeshList.Add(iMesh); } }
public static void ExportFbx([DefaultVar] odfParser parser, object[] meshNames, object[] animations, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool skins, bool odaSkeleton, bool compatibility) { List <string> meshStrList = new List <string>(Utility.Convert <string>(meshNames)); List <odfMesh> meshes = new List <odfMesh>(meshStrList.Count); foreach (string meshName in meshStrList) { odfMesh mesh = odf.FindMeshListSome(meshName, parser.MeshSection); if (mesh != null || (mesh = odf.FindMeshListSome(new ObjectID(meshName), parser.MeshSection)) != null) { meshes.Add(mesh); } else { Report.ReportLog("Mesh " + meshName + " not found."); } } ODFConverter imp = new ODFConverter(parser, meshes); if (animations != null) { for (int i = 0; i < animations.Length; i++) { odfParser odaParser = animations[i] as odfParser; if (odaParser != null) { string animName = animations[++i] as string; if (animName == null) { imp.ConvertAnimations((odfParser)odaParser, odaSkeleton); } else { if (animName == "ANIM") { imp.ConvertAnimation(odaParser.AnimSection, odaParser, odaSkeleton); } else { bool found = false; if (odaParser.BANMList != null) { foreach (odfANIMSection anim in odaParser.BANMList) { if (anim.Name == animName) { imp.ConvertAnimation(anim, odaParser, odaSkeleton); found = true; break; } } } if (!found) { Report.ReportLog("animation \"" + animName + "\" not found"); } } } } else { Report.ReportLog("bad argument type for parameter 'animations' " + odaParser.GetType().ToString()); } } } FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, false, skins, compatibility); }