/* * SkinInfo.cs * Copyright (c) 2006 David Astle * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework; using System.Collections.ObjectModel; using Microsoft.Xna.Framework.Graphics; namespace Xclna.Xna.Animation { /// /// A structure that contains information for a bindpose skin offset. /// Represents the inverse bind pose for a bone. /// public struct SkinInfo { /// /// Creates a new SkinInfo. /// /// The name of the bone attached to the transform. /// The inverse bind pose transform for the bone. /// The index in the MatrixPalette for the bone. /// The index of the bone. public SkinInfo(string name, Matrix inverseBindPoseTransform, int paletteIndex, int boneIndex) { BoneName = name; InverseBindPoseTransform = inverseBindPoseTransform; PaletteIndex = paletteIndex; BoneIndex = boneIndex; } /// /// The name of the bone attached to the transform. /// public readonly string BoneName; /// /// The transform for the bone. /// public readonly Matrix InverseBindPoseTransform; /// /// The index in the MatrixPalette for the bone. /// public readonly int PaletteIndex; /// /// The index of the bone. /// public readonly int BoneIndex; } /// /// A collection of SkinInfo objects. /// public class SkinInfoCollection : ReadOnlyCollection { private SkinInfoCollection(Model model, SkinInfo[] info) : base(info) { } internal SkinInfoCollection(IList info) : base(info) { } /// /// Finds the skinning info for the model and calculates the inverse /// reference poses required for animation. /// /// The model that contains the skinning info. /// A collection of SkinInfo objects. public static SkinInfoCollection FromModel(Model model) { // This is created in the content pipeline Dictionary modelTagData = (Dictionary)model.Tag; // An array of bone names that are used by the palette SkinInfoCollection[] info = (SkinInfoCollection[])modelTagData["SkinInfo"]; return info[0]; } } }