/// <summary>
        /// Creates a BoundingSphere from a given ModelMesh.
        /// </summary>
        /// <param name="mesh">ModelMesh to create BoundingSphere from.</param>
        /// <param name="roomNum">0-based room number.</param>
        /// <param name="modelPos">Position of Model in world space.</param>
        /// <returns></returns>
        public static BoundingSphere CreateBoundingSphere(ModelMesh mesh, string roomNum, Vector3 modelPos)
        {
            BoundingSphere b;
            XmlDocument read = new XmlDocument();
            XmlNode l;
            Matrix world;
            Vector3 pos;
            /*Matrix[] boneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);*/

            read.Load(string.Format("Content/Models/Rooms/XML/{0}.xml", roomNum));
            l = read.SelectSingleNode(string.Format("/Meshes/{0}", mesh.Name));

            pos = new Vector3(float.Parse(l.Attributes["X"].Value),
                float.Parse(l.Attributes["Y"].Value),
                float.Parse(l.Attributes["Z"].Value));

            pos += new Vector3(modelPos.X, 0, modelPos.Z);

            world = Matrix.Translation(pos);

            b = new BoundingSphere(pos, float.Parse(l.Attributes["Radius"].Value));

            /*for (int i = 0; i < model.Meshes.Count; i++)
            {
                meshSphere = TransformBoundingSphere(boneTransforms[i], model.Meshes[i].BoundingSphere);
                boundingSphere = BoundingSphere.Merge(boundingSphere, meshSphere);
            }*/
            return TransformBoundingSphere(world, mesh.BoundingSphere);
        }
Example #2
0
        protected virtual void ReadMesh(ref ModelMesh mesh)
        {
            CurrentMesh = mesh;
            Serialize(ref mesh.name, false, SerializeFlags.Nullable);
            int parentBoneIndex = Reader.ReadInt32();

            if (parentBoneIndex >= 0)
            {
                mesh.ParentBone = Model.Bones[parentBoneIndex];
            }

            // Read the bounding sphere
            Serialize(ref mesh.BoundingSphere);

            ReadVertexBuffers(ref mesh.VertexBuffers);
            ReadIndexBuffers(ref mesh.IndexBuffers);
            ReadMeshParts(ref mesh.MeshParts);

            ReadProperties(ref mesh.Properties);
            CurrentMesh = null;
        }