Ejemplo n.º 1
0
        public static void CalcBoundingBox(MeshContent mesh, ModelContent owner)
        {
            Vector3 minBox = new Vector3(Single.MaxValue, Single.MaxValue, Single.MaxValue);
            Vector3 maxBox = new Vector3(-Single.MaxValue, -Single.MaxValue, -Single.MaxValue);

            foreach (Vector3 x in mesh.Positions)
            {
                minBox.X = Math.Min(minBox.X, x.X);
                minBox.Y = Math.Min(minBox.Y, x.Y);
                minBox.Z = Math.Min(minBox.Z, x.Z);

                maxBox.X = Math.Max(maxBox.X, x.X);
                maxBox.Y = Math.Max(maxBox.Y, x.Y);
                maxBox.Z = Math.Max(maxBox.Z, x.Z);
            }

            // find the ModelMeshContent of the same name and store the bbox there
            // a little funky backwoods of the xna process, methinks
            foreach (ModelMeshContent m in owner.Meshes)
            {
                if (m.Name == mesh.Name)
                {
                    UIMeshData data = new UIMeshData();
                    data.bBox.Min = minBox;
                    data.bBox.Max = maxBox;

                    m.Tag = data;
                }
            }
        }
Ejemplo n.º 2
0
        protected void AddBoundingFrame(Model model, ModelBone bone)
        {
            if (bone.Children.Count > 0)
            {
                ModelBone boneChild = bone.Children[0];

                // we really only support one mesh as the box
                ModelMesh mesh = ModelHelper.FindMatchingMeshForBone(model, boneChild);

                // include upto panel transform as
                // we want them relative to the panels parent
                Matrix boxTransform = boneChild.Transform * bone.Transform * boneClass.Transform;

                // for now just use an empty one until we have a content pipeline solution
                // BoundingBox box = ModelHelper.CalculateBoundingBox(mesh);
                BoundingBox box;
                UIMeshData  data = mesh.Tag as UIMeshData;
                Debug.Assert(data != null, "Missing bounding box on mesh " + mesh.Name + ". Set the content processor on your model to UIModelProcessor.");

                if (data != null)
                {
                    box = data.bBox;
                }
                else
                {
                    box = new BoundingBox();
                }

                // apply transform to min and max and create a new aligned box
                Vector3[] points = new Vector3[2];
                points[0] = Vector3.Transform(box.Min, boxTransform);
                points[1] = Vector3.Transform(box.Max, boxTransform);

                this.boundingFrame = BoundingBox.CreateFromPoints(points);
            }
        }