private void CalculateAnimations() { CalculateDefaultPose(); var expectedAnchorCount = _epicModel.GetAnchors().Count(); foreach (var animation in _epicModel.Animations) { if (!animation.HasInitialFrame()) { throw new Exception("Animation must have frame at t=0"); } var duration = animation.Duration; var frameCount = (int) (EpicModelFrameRate * duration); Logger.Write(string.Format( "Compiling animation `{0}` - Duration: {1:0.00} Frames: {2}", animation.AnimationType, duration, frameCount)); var compiledAnimation = new CompiledModel.Animation(frameCount, duration); var frameTime = 0.0f; while (frameTime < duration) { animation.ApplyAtTime(frameTime); var frame = new CompiledModel.Frame(_modelPartsInMaterialOrder.Count); // Calculate model part states foreach (var modelPart in _modelPartsInMaterialOrder) { if (!animation.Ignores(modelPart)) { var modelPartState = new CompiledModel.ModelPartState( modelPart.GetAbsolutePosition(), modelPart.GetAbsoluteRotation()); frame.ModelPartStates.Add(modelPartState); } else { frame.ModelPartStates.Add(null); } } // Calculate anchor states foreach (var modelPart in _epicModel.ModelParts) { if (!animation.Ignores(modelPart)) { foreach (var anchor in modelPart.Anchors) { var anchorState = new CompiledModel.AnchorState( anchor.GetAbsolutePosition(), anchor.GetAbsoluteRotation()); frame.AnchorStates.Add(anchorState); } } else { foreach (var anchor in modelPart.Anchors) { frame.AnchorStates.Add(null); } } } Debug.Assert(frame.AnchorStates.Count == expectedAnchorCount, "Compiled animation frame has incorrect number of anchors"); compiledAnimation.Frames.Add(frame); frameTime += 1.0f / EpicModelFrameRate; } _compiledModel.Animations[animation.AnimationType] = compiledAnimation; } }
private void CalculateDefaultPose() { var defaultPoseAnimation = new CompiledModel.Animation(1, 0); var frame = new CompiledModel.Frame(_modelPartsInMaterialOrder.Count); foreach (var modelPart in _modelPartsInMaterialOrder) { frame.ModelPartStates.Add(new CompiledModel.ModelPartState(modelPart.GetAbsolutePosition(), modelPart.GetAbsoluteRotation())); foreach (var anchor in modelPart.Anchors) { frame.AnchorStates.Add(new CompiledModel.AnchorState(anchor.GetAbsolutePosition(), anchor.GetAbsoluteRotation())); } } defaultPoseAnimation.Frames.Add(frame); _compiledModel.Animations[AnimationType.None] = defaultPoseAnimation; }