public static void AddCollision(this DynamicPrimitive dynamicPrimitive, Microsoft.Xna.Framework.Graphics.Model model, Matrix?world, Color color) { if (bones == null || bones.Length < model.Bones.Count) { bones = new Matrix[model.Bones.Count]; } model.CopyAbsoluteBoneTransformsTo(bones); Matrix transform = world.HasValue ? world.Value : Matrix.Identity; ModelTag tag = model.Tag as ModelTag; // Add collision tree if (tag != null && tag.Collision != null) { transform = bones[model.Meshes[0].ParentBone.Index] * transform; Octree <bool> tree = tag.Collision.CollisionTree; tree.Traverse(node => { if (!node.hasChildren && node.value) { dynamicPrimitive.AddSolidBox(node.bounds, transform, color); } return(TraverseOptions.Continue); }); } // Add collision sphere else { for (int i = 0; i < model.Meshes.Count; ++i) { var mesh = model.Meshes[i]; dynamicPrimitive.AddSolidSphere(mesh.BoundingSphere, 18, bones[mesh.ParentBone.Index] * transform, color); } } }