forked from donkeyProgramming/TheAssetEditor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request donkeyProgramming#202 from mr-phazer/ImportExport-…
…Phazer-03 Updates and Fixes
- Loading branch information
Showing
19 changed files
with
405 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Editors/ImportExportEditor/Editors.ImportExport/Common/VectorConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Numerics; | ||
|
||
namespace Editors.ImportExport.Common | ||
{ | ||
class VecConv | ||
{ | ||
public static Vector4 NormalizeTangentVector4(Vector4 tangent) | ||
{ | ||
// normalize only the xyz components of the tangent, the w component is the handedness (1 or -1) in sharpGLTF | ||
var tempTangent = Vector3.Normalize(new Vector3(tangent.X, tangent.Y, tangent.Z)); | ||
return new Vector4(tempTangent.X, tempTangent.Y, tempTangent.Z, tangent.W); | ||
} | ||
|
||
public static Quaternion GetSys(Microsoft.Xna.Framework.Quaternion q) => new Quaternion(q.X, q.Y, q.Z, q.W); | ||
public static Vector4 GetSys(Microsoft.Xna.Framework.Vector4 v) => new Vector4(v.X, v.Y, v.Z, v.W); | ||
public static Vector3 GetSys(Microsoft.Xna.Framework.Vector3 v) => new Vector3(v.X, v.Y, v.Z); | ||
public static Microsoft.Xna.Framework.Vector4 GetXna(Vector4 v) => new Microsoft.Xna.Framework.Vector4(v.X, v.Y, v.Z, v.W); | ||
public static Microsoft.Xna.Framework.Vector3 GetXna(Vector3 v) => new Microsoft.Xna.Framework.Vector3(v.X, v.Y, v.Z); | ||
public static Microsoft.Xna.Framework.Vector2 GetXna(Vector2 v) => new Microsoft.Xna.Framework.Vector2(v.X, v.Y); | ||
public static Microsoft.Xna.Framework.Vector4 GetXnaVector4(Vector3 v) => new Microsoft.Xna.Framework.Vector4(v.X, v.Y, v.Z, 0); | ||
public static Microsoft.Xna.Framework.Vector3 GetXnaVector3(Vector4 v) => new Microsoft.Xna.Framework.Vector3(v.X, v.Y, v.Z); | ||
public static Matrix4x4 GetSys(Microsoft.Xna.Framework.Matrix invMatrices) => | ||
new(invMatrices.M11, invMatrices.M12, invMatrices.M13, invMatrices.M14, | ||
invMatrices.M21, invMatrices.M22, invMatrices.M23, invMatrices.M24, | ||
invMatrices.M31, invMatrices.M32, invMatrices.M33, invMatrices.M34, | ||
invMatrices.M41, invMatrices.M42, invMatrices.M43, invMatrices.M44); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...Editor/Editors.ImportExport/Exporting/Exporters/RmvToGltf/Helpers/GltfAnimationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Automation; | ||
using Editors.ImportExport.Common; | ||
using GameWorld.Core.Animation; | ||
using Shared.Core.PackFiles; | ||
using Shared.Core.PackFiles.Models; | ||
using Shared.GameFormats.Animation; | ||
using SharpGLTF.Schema2; | ||
using SysNum = System.Numerics; | ||
|
||
namespace Editors.ImportExport.Exporting.Exporters.RmvToGltf.Helpers | ||
{ | ||
public class GltfAnimationBuilder | ||
{ | ||
private readonly IPackFileService _packFileService; | ||
|
||
|
||
public GltfAnimationBuilder(IPackFileService packFileServoce) | ||
{ | ||
_packFileService = packFileServoce; | ||
} | ||
|
||
public void Build(AnimationFile animSkeleton, RmvToGltfExporterSettings settings, ProcessedGltfSkeleton gltfSkeleton, ModelRoot outputScene) | ||
{ | ||
foreach (var animationPackFile in settings.InputAnimationFiles) | ||
{ | ||
var animationToExport = AnimationFile.Create(animationPackFile); | ||
CreateFromTWAnim(animationPackFile.Name, gltfSkeleton, animSkeleton, animationToExport, outputScene, settings); | ||
} | ||
} | ||
|
||
private void CreateFromTWAnim(string animationName, ProcessedGltfSkeleton gltfSkeleton, AnimationFile skeletonAnimFile, AnimationFile animationToExport, ModelRoot modelRoot, RmvToGltfExporterSettings settings) | ||
{ | ||
var doMirror = settings.MirrorMesh; | ||
var gameSkeleton = new GameSkeleton(skeletonAnimFile, null); | ||
var animationClip = new AnimationClip(animationToExport, gameSkeleton); | ||
|
||
var secondsPerFrame = animationClip.PlayTimeInSec / animationClip.DynamicFrames.Count; | ||
|
||
var gltfAnimation = modelRoot.CreateAnimation(animationName); | ||
|
||
for (var boneIndex = 0; boneIndex < animationClip.AnimationBoneCount; boneIndex++) | ||
{ | ||
var translationKeyFrames = new Dictionary<float, SysNum.Vector3>(); | ||
var rotationKeyFrames = new Dictionary<float, SysNum.Quaternion>(); | ||
var scaleKeyFrames = new Dictionary<float, SysNum.Vector3>(); | ||
|
||
// populate the bone track containers with the key frames from the .ANIM animation file | ||
for (var frameIndex = 0; frameIndex < animationClip.DynamicFrames.Count; frameIndex++) | ||
{ | ||
translationKeyFrames.Add(secondsPerFrame * (float)frameIndex, VecConv.GetSys(GlobalSceneTransforms.FlipVector(animationClip.DynamicFrames[frameIndex].Position[boneIndex], doMirror))); | ||
rotationKeyFrames.Add(secondsPerFrame * (float)frameIndex, VecConv.GetSys(GlobalSceneTransforms.FlipQuaternion(animationClip.DynamicFrames[frameIndex].Rotation[boneIndex], doMirror))); | ||
scaleKeyFrames.Add(secondsPerFrame * (float)frameIndex, new SysNum.Vector3(1, 1, 1)); | ||
} | ||
|
||
// add the transformations | ||
var boneNode = gltfSkeleton.Data[boneIndex].Item1; | ||
gltfAnimation.CreateRotationChannel(boneNode, rotationKeyFrames); | ||
gltfAnimation.CreateTranslationChannel(boneNode, translationKeyFrames); | ||
gltfAnimation.CreateScaleChannel(boneNode, scaleKeyFrames); | ||
} | ||
} | ||
} | ||
} |
138 changes: 0 additions & 138 deletions
138
...Editor/Editors.ImportExport/Exporting/Exporters/RmvToGltf/Helpers/GltfAnimationCreator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.