private void SetupBoundingBoxes(ModelComponent modelComp)
        {
            boundingBoxes = new List <BoundingBox>();
            Matrix[] transforms = new Matrix[modelComp.model.Bones.Count];
            modelComp.model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in modelComp.model.Meshes)
            {
                Matrix meshTransform = transforms[mesh.ParentBone.Index];
                boundingBoxes.Add(CreateBoundingBox(mesh, meshTransform));
            }
        }
Exemple #2
0
        private BoundingSphere CreateBoundingSphere(ModelComponent modelComp, Vector3 position)
        {
            BoundingSphere sphere = new BoundingSphere(position, 0);

            //build a boundingshpere from the model
            foreach (ModelMesh mesh in modelComp.model.Meshes)
            {
                if (sphere.Radius == 0)
                {
                    sphere = mesh.BoundingSphere;
                }
                else
                {
                    sphere = BoundingSphere.
                             CreateMerged(sphere, mesh.BoundingSphere);
                }
            }
            return(sphere);
        }
 public ModelBoundingBoxComponent(ModelComponent modelComp)
 {
     SetupBoundingBoxes(modelComp);
 }
Exemple #4
0
 public ModelBoundingSphereComponent(ModelComponent modelComp, Vector3 position)
 {
     this.sphere = CreateBoundingSphere(modelComp, position);
 }