/*! * Binds this geometry to a list of bones. Creates and attatches a * NiSkinInstance and NiSkinData class. The bones must have a common * ancestor in the scenegraph. This becomes the skeleton root. */ public void BindSkinWith(IList <NiNode> bone_nodes, Action <NiObject> skinInstConstructor) { if (skinInstConstructor == null) { skinInstConstructor = NiSkinInstance.Create; } //Ensure skin is not aleady bound if (skinInstance != null) { throw new Exception("You have attempted to re-bind a skin that is already bound. Unbind it first."); } //Ensure that some bones are given if (bone_nodes.Count == 0) { throw new Exception("You must specify at least one bone node."); } //--Find a suitable skeleton root--// //The skeleton root will be the common ancestor of all bones which influence this skin, //and the skin object itself. var objects = new List <NiAVObject>(); objects.Add(this); for (var i = 0; i < bone_nodes.Count; ++i) { objects.Add(bone_nodes[i]); } var skeleton_root = Nif.FindCommonAncestor(objects); if (skeleton_root == null) { throw new Exception("Failed to find suitable skeleton root."); } //Create a skin instance using the bone and root data skinInstance = skinInstConstructor() as NiSkinInstance; if (skinInstance == null) { throw new Exception("Failed to construct NiSkinInstance"); } skinInstance.BindSkin(skeleton_root, bone_nodes); //Create a NiSkinData object based on this mesh skinInstance.SkinData = new NiSkinData(this); }