Example #1
0
        /// <summary>
        /// Copies a transform of each bone in a model relative to all parent bones of the bone into a given array.
        /// </summary>
        /// <param name="destinationBoneTransforms">The array to receive bone transforms.</param>
        /// <exception cref="System.ArgumentNullException">destinationBoneTransforms</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">destinationBoneTransforms</exception>
        public void CopyAbsoluteBoneTransformsTo(Matrix[] destinationBoneTransforms)
        {
            if (destinationBoneTransforms == null)
            {
                throw new ArgumentNullException("destinationBoneTransforms");
            }
            if (destinationBoneTransforms.Length < Bones.Count)
            {
                throw new ArgumentOutOfRangeException("destinationBoneTransforms");
            }
            int count = Bones.Count;

            for (int i = 0; i < count; i++)
            {
                ModelBone bone = Bones[i];
                if (bone.Parent == null)
                {
                    destinationBoneTransforms[i] = bone.Transform;
                }
                else
                {
                    destinationBoneTransforms[i] = bone.Transform * destinationBoneTransforms[bone.Parent.Index];
                }
            }
        }
Example #2
0
        protected virtual void ReadBone(ref ModelBone bone)
        {
            // Read ModelBone index
            bone.Index = Reader.ReadInt32();

            // Read Parent Index
            int parentIndex = Reader.ReadInt32();

            if (parentIndex > Model.Bones.Count)
            {
                throw new InvalidOperationException("Invalid index for parent bone");
            }
            bone.Parent = parentIndex >= 0 ? Model.Bones[parentIndex] : null;

            // Transform
            Serialize(ref bone.Transform);

            // Name
            string boneName = null;

            Serialize(ref boneName, false, SerializeFlags.Nullable);
            bone.Name = boneName;

            // Indices
            List <int> indices = null;

            Serialize(ref indices, Serialize, SerializeFlags.Nullable);
            if (indices != null)
            {
                bone.Children = CreateModelBoneCollection(indices.Count);
                bone.Children.ChildIndices = indices;
            }
        }
Example #3
0
        public Windmill(LarvContent lContent, Vector3 location)
            : base(lContent.TextureEffect)
        {
            World = Matrix.Scaling(0.004f)*Matrix.RotationY(1)*Matrix.Translation(location);
            _model = lContent.Load<Model>("models/windmillf");
            _texture = lContent.Load<Texture2D>("models/windmill_diffuse");

            _animatedBone = _model.Meshes.Single(mesh => mesh.Name == "Fan").ParentBone;
            _originalBoneTransformation = Matrix.Translation(0, 850, 0);
        }
Example #4
0
        /// <summary>
        /// Copies a transform of each bone in a model relative to all parent bones of the bone into a given array.
        /// </summary>
        /// <param name="destinationBoneTransformsPtr">The array to receive bone transforms. Length of the allocated array must be at least == sizeof(Matrix) * Bones.Count</param>
        /// <exception cref="System.ArgumentNullException">destinationBoneTransforms</exception>
        public unsafe void CopyAbsoluteBoneTransformsTo(IntPtr destinationBoneTransformsPtr)
        {
            if (destinationBoneTransformsPtr == IntPtr.Zero)
            {
                throw new ArgumentNullException("destinationBoneTransforms");
            }

            var destinationBoneTransforms = (Matrix *)destinationBoneTransformsPtr;

            int count = Bones.Count;

            for (int i = 0; i < count; i++)
            {
                ModelBone bone = Bones[i];
                if (bone.Parent == null)
                {
                    destinationBoneTransforms[i] = bone.Transform;
                }
                else
                {
                    destinationBoneTransforms[i] = bone.Transform * destinationBoneTransforms[bone.Parent.Index];
                }
            }
        }