Exemple #1
0
        /****************************************************************************/
        /****************************************************************************/
        /*                      End Remove                                          */
        /****************************************************************************/
        /****************************************************************************/
        public void DrawBsp(Camera camera)
        {
            // invoke "makeOrthonormalCross" if derived from "Movable"
            // otherwise, use "makeOrthonormal"
            this.makeOrthonormal ();

            // a Model has multiple meshes, each with a parent ModelBone
            //   containing a transform for that mesh
            m_model.CopyAbsoluteBoneTransformsTo (m_transforms);

            // Grab the Bsp tree from the model's tag
            ITree tree = (ITree)m_model.Tag;

            // Get the camera's BoundingFrustum
            BoundingFrustum frustum = camera.computeBoundingFrustum ();

            // Compute the current visibility and get the list of visible ModelMeshes
            tree.ComputeVisibility (camera.Position);
            List<String> visibleModelMeshes = tree.VisibleMeshNames (frustum);

            // Run through the list of visible model meshes and draw them
            for (int currentModelMesh = 0; currentModelMesh < visibleModelMeshes.Count; ++currentModelMesh)
            {
                // Grab the current mesh
                ModelMesh mesh = m_model.Meshes[visibleModelMeshes[currentModelMesh]];

                // Save the current AlphaBlendEnable value
                bool oldBlend = mesh.Effects[0].GraphicsDevice.RenderState.AlphaBlendEnable;

                // Set the AlphaBlendEnable to the value stored in the shader
                mesh.Effects[0].GraphicsDevice.RenderState.AlphaBlendEnable = mesh.Effects[0].Parameters["translucent"].GetValueBoolean ();

                foreach (Effect effect in mesh.Effects)
                {
                    effect.Parameters["World"].SetValue (m_transforms[mesh.ParentBone.Index] * this.Transform);
                    effect.Parameters["View"].SetValue (camera.View);
                    effect.Parameters["Projection"].SetValue (camera.Projection);
                }
                mesh.Draw ();

                // Restore AlphaBlendEnable to what is was before DrawBsp was called
                mesh.Effects[0].GraphicsDevice.RenderState.AlphaBlendEnable = oldBlend;
            }
        }
Exemple #2
0
        public void DrawObserver(Camera observer, Camera actor)
        {
            // invoke "makeOrthonormalCross" if derived from "Movable"
            // otherwise, use "makeOrthonormal"
            this.makeOrthonormal ();

            // a Model has multiple meshes, each with a parent ModelBone
            //   containing a transform for that mesh
            m_model.CopyAbsoluteBoneTransformsTo (m_transforms);

            BoundingFrustum frustum = actor.computeBoundingFrustum ();
            foreach (ModelMesh mesh in m_model.Meshes)
            {
                // frustum cull meshes that aren't intersecting or contained within the view volume
                BoundingSphere sphere = mesh.BoundingSphere;
                sphere.Center = Vector3.Transform (sphere.Center, this.getRotation ());
                ContainmentType type = frustum.Contains (sphere);
                if (type == ContainmentType.Disjoint)
                    continue;

                EffectParameter translucent = mesh.Effects[0].Parameters.GetParameterBySemantic ("MuxEngineTranslucent");
                bool oldBlend = mesh.Effects[0].GraphicsDevice.RenderState.AlphaBlendEnable;
                if (translucent != null)
                {
                    mesh.Effects[0].GraphicsDevice.RenderState.AlphaBlendEnable = translucent.GetValueBoolean ();
                }
                foreach (Effect effect in mesh.Effects)
                {
                    EffectParameter world = effect.Parameters["World"];

                    if (world != null)
                    {
                        world.SetValue (m_transforms[mesh.ParentBone.Index] * this.Transform);
                        effect.Parameters["View"].SetValue (observer.View);
                        effect.Parameters["Projection"].SetValue (observer.Projection);
                    }
                }
                mesh.Draw ();

                mesh.Effects[0].GraphicsDevice.RenderState.AlphaBlendEnable = oldBlend;
            }
        }