/// <inheritdoc/> /// <exception cref="ArgumentNullException"> /// <paramref name="value"/> or <paramref name="property"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// The value of <paramref name="property"/> must not be <see langword="null"/>. /// </exception> public void Set(ref SkeletonPose value, IAnimatableProperty <SkeletonPose> property) { if (value == null) { throw new ArgumentNullException("value"); } if (property == null) { throw new ArgumentNullException("property"); } var animationValue = property.AnimationValue; if (animationValue == null) { if (property.HasBaseValue) { // The SkeletonPose will be recycled in Reset(). Create(ref value, out animationValue); property.AnimationValue = animationValue; } else { throw new ArgumentException("The value of the property must not be null. This exception usually occurs when an IAnimatableProperty<SkeletonPose> is being animated, but the value of the property is null. A SkeletonPose must be set before the property can be animated."); } } SkeletonHelper.Copy(value, animationValue); }
public override void Update(GameTime gameTime) { _debugRenderer.Clear(); if (_avatarPose == null) { // Must wait till renderer is ready. Before that we do not get skeleton info. if (_avatarRenderer.State == AvatarRendererState.Ready) { // Create AvatarPose. _avatarPose = new AvatarPose(_avatarRenderer); // A 'bone transform' is the transformation of a bone relative to its bind pose. // Bone transforms define the pose of a skeleton. // Rotate arm of avatar. SkeletonPose skeletonPose = _avatarPose.SkeletonPose; int shoulderIndex = skeletonPose.Skeleton.GetIndex("ShoulderLeft"); skeletonPose.SetBoneTransform(shoulderIndex, new SrtTransform(QuaternionF.CreateRotationZ(-0.9f))); // The class SkeletonHelper provides some useful extension methods. // One is SetBoneRotationAbsolute() which sets the orientation of a bone relative // to model space. // Rotate elbow to make the lower arm point forward. int elbowIndex = skeletonPose.Skeleton.GetIndex("ElbowLeft"); SkeletonHelper.SetBoneRotationAbsolute(skeletonPose, elbowIndex, QuaternionF.CreateRotationY(ConstantsF.PiOver2)); // Draw avatar skeleton for debugging. _debugRenderer.DrawSkeleton(skeletonPose, _pose, Vector3F.One, 0.02f, Color.Orange, true); } } }
public MixingSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); var animations = _meshNode.Mesh.Animations; _runAnimation = new AnimationClip <SkeletonPose>(animations["Run"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _idleAnimation = new AnimationClip <SkeletonPose>(animations["Idle"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Create a 'Shoot' animation that only affects the upper body. var shootAnimation = animations["Shoot"]; // The SkeletonKeyFrameAnimations allows to set a weight for each bone channel. // For the 'Shoot' animation, we set the weight to 0 for all bones that are // not descendants of the second spine bone (bone index 2). That means, the // animation affects only the upper body bones and is disabled on the lower // body bones. for (int i = 0; i < _meshNode.Mesh.Skeleton.NumberOfBones; i++) { if (!SkeletonHelper.IsAncestorOrSelf(_meshNode.SkeletonPose, 2, i)) { shootAnimation.SetWeight(i, 0); } } var loopedShootingAnimation = new AnimationClip <SkeletonPose>(shootAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Start 'Idle' animation. _idleAnimationController = AnimationService.StartAnimation(_idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose); _idleAnimationController.AutoRecycle(); // Start looping the 'Shoot' animation. We use a Compose transition. This will add the // 'Shoot' animation to the animation composition chain and keeping all other playing // animations. // The 'Idle' animation animates the whole skeleton. The 'Shoot' animation replaces // the 'Idle' animation on the bones of the upper body. AnimationService.StartAnimation(loopedShootingAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Compose() ).AutoRecycle(); }
private void RiderSkeletonChanges(GameSkeleton newValue) { if (newValue == null) { ActiveOutputFragment.UpdatePossibleValues(null); SelectedRiderBone.UpdatePossibleValues(null); } else { ActiveOutputFragment.UpdatePossibleValues(MountLinkController.LoadFragmentsForSkeleton(newValue.SkeletonName, true)); SelectedRiderBone.UpdatePossibleValues(SkeletonHelper.CreateFlatSkeletonList(newValue)); } SelectedRiderBone.SelectedItem = SelectedRiderBone.PossibleValues.FirstOrDefault(x => string.Equals("root", x.BoneName, StringComparison.OrdinalIgnoreCase)); MountLinkController.ReloadFragments(true, false); UpdateCanSaveAndPreviewStates(); }
public override void Update(GameTime gameTime) { base.Update(gameTime); float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; // Change rotation angle. if (_moveArmDown) { _upperArmAngle -= 0.3f * deltaTime; } else { _upperArmAngle += 0.3f * deltaTime; } // Change direction when a certain angle is reached. if (Math.Abs(_upperArmAngle) > 0.5f) { _moveArmDown = !_moveArmDown; } // Get the bone index of the upper arm bone. var skeleton = _meshNode.Mesh.Skeleton; int upperArmIndex = skeleton.GetIndex("L_UpperArm"); // Define the desired bone transform. SrtTransform boneTransform = new SrtTransform(QuaternionF.CreateRotationY(_upperArmAngle)); // Set the new bone transform. var skeletonPose = _meshNode.SkeletonPose; skeletonPose.SetBoneTransform(upperArmIndex, boneTransform); // The class SkeletonHelper provides some useful extension methods. // One is SetBoneRotationAbsolute() which sets the orientation of a bone relative // to model space. int handIndex = skeleton.GetIndex("L_Hand"); SkeletonHelper.SetBoneRotationAbsolute(skeletonPose, handIndex, QuaternionF.CreateRotationX(ConstantsF.Pi)); }
/// <inheritdoc/> /// <exception cref="ArgumentNullException"> /// <paramref name="source"/> or <paramref name="target"/> is <see langword="null"/>. /// </exception> public void Copy(ref SkeletonPose source, ref SkeletonPose target) { SkeletonHelper.Copy(source, target); }