Exemple #1
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            //null checks are for editor!
            //remove these eventually maybe using a compiler directive for an editorer version of the DLL?
            if (model != null && PhysicsObject != null && model.loaded)
            {
                if (AlphaBlendable)
                {
                    X.GraphicsDevice.RenderState.AlphaBlendEnable      = true;
                    X.GraphicsDevice.RenderState.SourceBlend           = Blend.SourceAlpha;        // source rgb * source alpha
                    X.GraphicsDevice.RenderState.AlphaSourceBlend      = Blend.One;                // don't modify source alpha
                    X.GraphicsDevice.RenderState.DestinationBlend      = Blend.InverseSourceAlpha; // dest rgb * (255 - source alpha)
                    X.GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.InverseSourceAlpha; // dest alpha * (255 - source alpha)
                    X.GraphicsDevice.RenderState.BlendFunction         = BlendFunction.Add;        // add source and dest results
                }
                else
                {
                    X.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                }

                //Set camera params, compute matrices
                //model.SASData.Camera.NearFarClipping.X = Camera.NearPlane;
                //model.SASData.Camera.NearFarClipping.Y = Camera.FarPlane;
                //model.SASData.Camera.Position.X = Camera.Position.X;
                //model.SASData.Camera.Position.Y = Camera.Position.Y;
                //model.SASData.Camera.Position.Z = Camera.Position.Z;
                model.SASData.Projection = Camera.Projection;
                model.SASData.View       = Camera.View;
                model.SASData.World      = PhysicsObject.GetWorldMatrix(model.Model, Vector3.Zero); //modeloffset);
                model.SASData.ComputeViewAndProjection();
                //model.SASData.ComputeModel();

                //X.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

                X.Renderer.DrawModel(ref model, ref Camera);

                //restore render modes (shader files might have changes this!
                X.GraphicsDevice.RenderState.AlphaBlendEnable = false;

#if DEBUG
                //Render debug volumes for frustrum clulling
                XDebugVolumeRenderer.RenderSphere(model.bs, Color.Yellow, ref Camera.View, ref Camera.Projection);

                //Render debug volumes for physics
                X.DebugDrawer.DrawShape(PhysicsObject.GetCollisionWireframe(), Color.White);
#endif
            }//end if (model != null && model.loaded)
        }
Exemple #2
0
        /// <summary>
        /// This method only support drawing static models. If you attempt to draw an animated (skinned) model it won't look right
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="Camera"></param>
        public virtual void DrawModel(ref XModel Model, ref XCamera Camera)
        {
            for (int i = 0; i < Model.Model.Meshes.Count; i++)
            {
                ModelMesh mesh = Model.Model.Meshes[i];

                //calc new boundingsphere with new position from World/Model matrix
                BoundingSphere bs = mesh.BoundingSphere.Transform(Matrix.CreateTranslation(Model.SASData.World.Translation));

                //Is it in view?
                if (Camera.Frustrum.Contains(bs) == ContainmentType.Disjoint)
                {
                    continue;
                }


#if DEBUG
                //render boundingspheres for each mesh!
                XDebugVolumeRenderer.RenderSphere(bs, Color.Yellow, ref Camera.View, ref Camera.Projection);
#endif

                Model.SASData.ComputeModel();

                for (int j = 0; j < mesh.Effects.Count; j++)
                {
                    Effect effect = mesh.Effects[j];
                    // bind SAS shader parameters
                    for (int k = 0; k < effect.Parameters.Count; k++)
                    {
                        if (effect.Parameters[k].ParameterType == EffectParameterType.String)
                        {
                            if (effect.Parameters[k].Name.Contains("AnimationFileName"))
                            {
                                string animfilename = effect.Parameters[k].GetValueString();
                                if (!string.IsNullOrEmpty(animfilename))
                                {
                                    //there is an animated texture here
                                    foreach (EffectAnnotation anno in effect.Parameters[k].Annotations)
                                    {
                                        if (anno.Name.Contains("AnimatedMap"))
                                        {
                                            effect.Parameters[anno.GetValueString()].SetValue(
                                                Model.Giftextures[j].GetTexture());
                                        }
                                    }
                                }
                            }
                        }
                        Model.SASData.SetEffectParameterValue(effect.Parameters[k]);
                    }

                    //if rendering a depthmap
                    if (Camera.RenderType == RenderTypes.Depth)
                    {
                        //override any techniques with DepthMap technique shader
                        if (effect.Techniques["DepthMapStatic"] != null)
                        {
                            effect.CurrentTechnique = effect.Techniques["DepthMapStatic"];
                        }
                        else
                        {//if we get there there is no DepthMap shader so we can't render this into our depth MAP!!
                            break;
                        }
                        continue;
                    }

                    if (effect.Techniques["Static"] != null)
                    {
                        effect.CurrentTechnique = effect.Techniques["Static"];
                    }
                    else
                    {
                        effect.CurrentTechnique = effect.Techniques[0];
                    }
                }
                mesh.Draw(SaveStateMode.SaveState);
            }
        }