public override void OnFrameRender(Device device, double totalTime, float elapsedTime) { device.RenderState.Lighting = true; // Advance the animation by the time elapsed since last time. if (elapsedTime > 0) { animationController.AdvanceTime((double)elapsedTime); } if (GameObject != null) { this.RenderFrame(this.animationRoot.FrameHierarchy, GameObject.TransformMatrix); } else { this.RenderFrame(this.animationRoot.FrameHierarchy, Matrix.Identity); } }
public void Update(Model9 model, float dtime, Matrix world) { if (model != null && model.SkinnedMesh != null) { #if PROFILE_ANIMATIONS if (ResetMatricesStart != null) { ResetMatricesStart(); } #endif ((CustomFrame)model.SkinnedMesh.RootFrame).ResetMatrices(); #if PROFILE_ANIMATIONS if (ResetMatricesStop != null) { ResetMatricesStop(); } if (SetupACStrat != null) { SetupACStrat(); } #endif if (TrackFadeTime[CurrentTrack] > 0) { #if DEBUG_ANIMATIONS if (i % 15 == 0 && Entity.Name != "MainCharacter") { Console.WriteLine("Previous: " + (TrackFadeTime[CurrentTrack] / FadeTime)); Console.WriteLine("Current: " + (FadeTime - TrackFadeTime[CurrentTrack]) / FadeTime); } i++; #endif AnimationController.SetTrackWeight(previousTrack, TrackFadeTime[CurrentTrack] / FadeTime); AnimationController.SetTrackWeight(CurrentTrack, (FadeTime - TrackFadeTime[CurrentTrack]) / FadeTime); TrackFadeTime[CurrentTrack] -= dtime; } else { AnimationController.DisableTrack(previousTrack); AnimationController.SetTrackSpeed(previousTrack, 0); AnimationController.SetTrackWeight(previousTrack, 0); AnimationController.SetTrackWeight(CurrentTrack, 1); } if (!TrackPaused[CurrentTrack] && !Looping[CurrentTrack]) { if (TrackDurations[CurrentTrack] - dtime > 0) { TrackDurations[CurrentTrack] -= dtime; } else { TrackDurations[CurrentTrack] = 0; AnimationController.SetTrackPosition(CurrentTrack, TrackDurations[CurrentTrack] - 0.01f); AnimationController.SetTrackSpeed(CurrentTrack, 0); TrackPaused[CurrentTrack] = true; if (AnimationDone != null) { AnimationDone(0); } } } #if PROFILE_ANIMATIONS if (SetupACStop != null) { SetupACStop(); } if (AdvanceTimeStart != null) { AdvanceTimeStart(); } #endif AnimationController.AdvanceTime(dtime, null); #if PROFILE_ANIMATIONS if (AdvanceTimeStop != null) { AdvanceTimeStop(); } if (AdjustFrameMatricesStrat != null) { AdjustFrameMatricesStrat(); } #endif foreach (var v in FrameCustomValues) { #if DEBUG if (v.Value.M22 == float.NaN || v.Value.M21 == float.NaN || v.Value.M23 == float.NaN || v.Value.M24 == float.NaN) { throw new Exception("Matrix contains NaN"); } #endif model.SkinnedMesh.ForEachFrame((f) => { if (f.Name == v.Key) { f.TransformationMatrix *= v.Value; } }); } #if PROFILE_ANIMATIONS if (AdjustFrameMatricesStop != null) { AdjustFrameMatricesStop(); } if (UpdateMatricesStart != null) { UpdateMatricesStart(); } #endif model.SkinnedMesh.UpdateFrameMatrices(model.SkinnedMesh.RootFrame, world); #if PROFILE_ANIMATIONS if (UpdateMatricesStop != null) { UpdateMatricesStop(); } if (StoreMatricesStart != null) { StoreMatricesStart(); } #endif foreach (var frame in SkinnedMesh.Frames) { if (frame.Name == "sword1" || frame.Name == "rifle" || frame.Name == "joint3") { FrameTransformation[frame] = frame.CombinedTransform; } } foreach (Common.Tuple <CustomFrame, CustomMeshContainer> meshContainer in SkinnedMesh.MeshContainers) { string name = meshContainer.First.Name; if (meshContainer.Second != null) { if (meshContainer.Second.SkinInfo != null) { BoneCombination[] combinations = meshContainer.Second.BoneCombinations; Matrix[][] combinationMatrices = new Matrix[combinations.Length][]; for (int i = 0; i < combinations.Length; i++) { Matrix[] boneMatrices = new Matrix[meshContainer.Second.PaletteEntries]; for (int pe = 0; pe < meshContainer.Second.PaletteEntries; pe++) { int index = combinations[i].BoneIds[pe]; if (index != -1) { boneMatrices[pe] = meshContainer.Second.BoneOffsets[index] * meshContainer.Second.BoneMatricesLookup[index].CombinedTransform; } } combinationMatrices[i] = boneMatrices; } StoredFrameMatrices[meshContainer.Second.MeshData.Mesh] = combinationMatrices; } else { Matrix[][] combinedTransform = new Matrix[1][]; combinedTransform[0] = new Matrix[] { meshContainer.First.CombinedTransform }; StoredFrameMatrices[meshContainer.Second.MeshData.Mesh] = combinedTransform; } } } #if PROFILE_ANIMATIONS if (StoreMatricesStop != null) { StoreMatricesStop(); } #endif //model.SkinnedMesh.ForEachFrame((frame) => //{ // FrameTransformation[frame] = frame.CombinedTransform; // frame.ForEachMeshContainer((mc) => // { // if (mc.SkinInfo != null) // { // BoneCombination[] combinations = mc.BoneCombinations; // Common.Tuple<Matrix[], Matrix[]>[] combinationMatrices = // new Common.Tuple<Matrix[], Matrix[]>[combinations.Length]; // for (int i = 0; i < combinations.Length; i++) // { // Matrix[] boneMatrices = new Matrix[mc.PaletteEntries]; // Matrix[] normalMatrices = new Matrix[mc.PaletteEntries]; // for (int pe = 0; pe < mc.PaletteEntries; pe++) // { // int index = combinations[i].BoneIds[pe]; // if (index != -1) // { // boneMatrices[pe] = mc.BoneOffsets[index] * // mc.BoneMatricesLookup[index].CombinedTransform; // normalMatrices[pe] = SlimDX.Matrix.Transpose( // SlimDX.Matrix.Invert(boneMatrices[pe])); // } // } // combinationMatrices[i] = new Common.Tuple<Matrix[], Matrix[]>( // boneMatrices, normalMatrices); // } // StoredFrameMatrices[mc.MeshData.Mesh] = combinationMatrices; // } // else // { // Common.Tuple<Matrix[], Matrix[]>[] combinedTransform = // new Common.Tuple<Matrix[], Matrix[]>[1]; // combinedTransform[0] = new Common.Tuple<Matrix[], Matrix[]>( // new Matrix[1] { frame.CombinedTransform }, // new Matrix[1] { Matrix.Transpose(Matrix.Invert(frame.CombinedTransform)) }); // StoredFrameMatrices[mc.MeshData.Mesh] = combinedTransform; // } // }); //}); } }