Пример #1
0
        internal static void Execute(Player p, DrawOp op, Brush brush, Vec3S32[] marks)
        {
            UndoDrawOpEntry entry = new UndoDrawOpEntry();

            entry.Init(op.Name, op.Level.name);

            if (brush != null)
            {
                brush.Configure(op, p);
            }
            Level           lvl       = op.Level;
            DrawOpOutputter outputter = new DrawOpOutputter(op);

            if (op.AffectedByTransform)
            {
                p.Transform.Perform(marks, p, lvl, op, brush, outputter.Output);
            }
            else
            {
                op.Perform(marks, brush, outputter.Output);
            }
            bool needsReload = op.TotalModified >= outputter.reloadThreshold;

            if (op.Undoable)
            {
                entry.Finish(p);
            }
            if (needsReload)
            {
                DoReload(p, op.Level);
            }
            op.TotalModified = 0; // reset total modified (as drawop instances are reused in static mode)
        }
Пример #2
0
        /// <summary>
        /// Renders the mesh with either brush or pen. Both are permitted as well.
        /// If none are provided, an exception is thrown.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="world"></param>
        /// <param name="view"></param>
        /// <param name="projection"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        public virtual void DrawMesh(Mesh mesh, Matrix world, Matrix view, Matrix projection, Brush brush = null, Pen pen = null)
        {
            if (!_attached)
            {
                throw new NotSupportedException("RenderContext is not yet attached");
            }

            if (brush == null && pen == null)
            {
                throw new NotSupportedException("You must set either brush, pen or both. Setting none would result in nothing getting drawn.");
            }
            mesh.Attach();

            _effect.World      = world;
            _effect.View       = view;
            _effect.Projection = projection;

            if (brush != null)
            {
                GraphicsDevice.RasterizerState = _fillState;
                if (!brush.IsPrepared)
                {
                    brush.Prepare(this);
                }
                brush.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    mesh.Draw();
                }
            }
            if (pen != null)
            {
                GraphicsDevice.RasterizerState = _wireFrameState;
                if (!pen.IsPrepared)
                {
                    pen.Prepare(this);
                }
                pen.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    mesh.Draw();
                }
            }
            mesh.Detach();
            GraphicsDevice.RasterizerState = _fillState;
        }
Пример #3
0
        /// <summary>
        /// Renders the mesh with either brush or pen. Both are permitted as well.
        /// If none are provided, an exception is thrown.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="world"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        public void DrawMesh(Mesh mesh, Matrix world, Brush brush = null, Pen pen = null)
        {
            if (brush == null && pen == null)
            {
                throw new NotSupportedException("You must set either brush, pen or both. Setting none would result in nothing getting drawn.");
            }
            mesh.Attach();

            SetupCamera(world);
            if (brush != null)
            {
                RenderContext.GraphicsDevice.RasterizerState = _fillState;
                if (!brush.IsPrepared)
                {
                    brush.Prepare(RenderContext);
                }
                brush.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    mesh.Draw();
                }
            }
            if (pen != null)
            {
                RenderContext.GraphicsDevice.RasterizerState = _wireFrameState;
                if (!pen.IsPrepared)
                {
                    pen.Prepare(RenderContext);
                }
                pen.Configure(_effect);

                foreach (var pass in _effect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    mesh.Draw();
                }
            }

            mesh.Detach();

            RenderContext.GraphicsDevice.RasterizerState = _fillState;
        }