コード例 #1
0
ファイル: ModernRenderer.cs プロジェクト: NCC-Lykos/Chisel
        public ModernRenderer(Document document)
        {
            _document = document;

            _array       = new MapObjectArray(GetAllVisible(document.Map.WorldSpawn));
            _decalArray  = new DecalArray(GetDecals(document.Map.WorldSpawn));
            _modelArrays = new Dictionary <Model, ModelArray>();
            _models      = new List <Tuple <Entity, Model> >();

            // Can't use a single grid array as it varies depending on the zoom level (pixel hiding factor)
            GridArrays = ViewportManager.Viewports.OfType <Viewport2D>().ToDictionary(x => x, x => new GridArray());
            UpdateGrid(document.Map.GridSpacing, document.Map.Show2DGrid, document.Map.Show3DGrid, false);

            _selectionTransformMat = Matrix.Identity;
            _selectionTransform    = Matrix4.Identity;
            _mapObject2DShader     = new MapObject2DShader();
            _mapObject3DShader     = new MapObject3DShader();
        }
コード例 #2
0
        public DisplayListRenderer(Document document)
        {
            Document = document;
            _update  = true;
            _selectionTransformMat = Matrix.Identity;
            _selectionTransform    = Matrix4.Identity;
            _transparentFaces      = new List <Face>();
            _models     = new List <Tuple <Entity, Model> >();
            _modelLists = new Dictionary <Model, int>();

            var idx = GL.GenLists(7);

            _listUntransformed2D         = idx + 0;
            _listTransformed2D           = idx + 1;
            _listUntransformed3D         = idx + 2;
            _listUntransformed3DTextured = idx + 3;
            _listUntransformed3DFlat     = idx + 4;
            _listTransformed3DTextured   = idx + 5;
            _listTransformed3DFlat       = idx + 6;
        }
コード例 #3
0
 public void SetSelectionTransform(Matrix4 selTransform)
 {
     _selectionTransform    = selTransform;
     _selectionTransformMat = Matrix.FromOpenTKMatrix4(selTransform);
 }
コード例 #4
0
        public void Draw3D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            var type     = ((Viewport3D)context).Type;
            var cam      = ((Viewport3D)context).Camera.Location;
            var location = new Coordinate((decimal)cam.X, (decimal)cam.Y, (decimal)cam.Z);

            UpdateCache();

            Matrix4 current;

            GL.GetFloat(GetPName.ModelviewMatrix, out current);
            GL.MatrixMode(MatrixMode.Modelview);

            bool shaded    = type == Viewport3D.ViewType.Shaded || type == Viewport3D.ViewType.Textured,
                 textured  = type == Viewport3D.ViewType.Textured,
                 wireframe = type == Viewport3D.ViewType.Wireframe;

            if (shaded)
            {
                MapObjectRenderer.EnableLighting();
            }
            if (!textured)
            {
                GL.Disable(EnableCap.Texture2D);
            }
            else
            {
                GL.Enable(EnableCap.Texture2D);
            }

            if (!wireframe)
            {
                GL.CallList(textured ? _listUntransformed3DTextured : _listUntransformed3DFlat);

                if (!Document.Selection.InFaceSelection || !Document.Map.HideFaceMask)
                {
                    GL.CallList(_listUntransformed3D);
                }

                // Render models
                if (!View.DisableModelRendering)
                {
                    foreach (var tuple in _models)
                    {
                        var arr    = _modelLists[tuple.Item2];
                        var origin = tuple.Item1.Origin;
                        if (tuple.Item1.HideDistance() <= (location - origin).VectorMagnitude())
                        {
                            MapObjectRenderer.DrawFilled(tuple.Item1.GetBoxFaces(), Color.Empty, textured);
                        }
                        else
                        {
                            var angles = tuple.Item1.EntityData.GetPropertyCoordinate("angles", Coordinate.Zero);
                            angles = new Coordinate(DMath.DegreesToRadians(angles.Z), DMath.DegreesToRadians(angles.X), DMath.DegreesToRadians(angles.Y));
                            if (tuple.Item1.IsSelected)
                            {
                                origin *= _selectionTransformMat;
                            }
                            var tform = Matrix.Rotation(Quaternion.EulerAngles(angles)).Translate(origin).ToOpenTKMatrix4();
                            GL.MultMatrix(ref tform);

                            GL.CallList(arr);
                            GL.LoadMatrix(ref current);
                        }
                    }
                }
            }
            else
            {
                GL.CallList(_listUntransformed2D);
            }

            GL.MultMatrix(ref _selectionTransform);
            if (!wireframe)
            {
                GL.CallList(textured ? _listTransformed3DTextured : _listTransformed3DFlat);
            }
            else
            {
                GL.CallList(_listTransformed2D);
            }
            GL.LoadMatrix(ref current);

            if (!wireframe)
            {
                foreach (var face in _transparentFaces.OrderByDescending(x => (location - x.BoundingBox.Center).LengthSquared()))
                {
                    var sel = (!Document.Map.HideFaceMask || !Document.Selection.InFaceSelection) && (face.IsSelected || (face.Parent != null && face.Parent.IsSelected));
                    if (sel)
                    {
                        GL.MultMatrix(ref _selectionTransform);
                    }
                    MapObjectRenderer.DrawFilled(new[] { face }, sel ? Color.FromArgb(255, 255, 128, 128) : Color.Empty, true);
                    GL.LoadMatrix(ref current);
                }
            }
            else
            {
                if (Document.Map.HideFaceMask && Document.Selection.InFaceSelection)
                {
                    MapObjectRenderer.DrawWireframe(_transparentFaces, false, true);
                }
                else
                {
                    MapObjectRenderer.DrawWireframe(_transparentFaces.Where(x => !x.IsSelected && (x.Parent == null || !x.Parent.IsSelected)), false, true);
                    GL.Color4(Color.Red);
                    MapObjectRenderer.DrawWireframe(_transparentFaces.Where(x => x.IsSelected || (x.Parent != null && x.Parent.IsSelected)), true, true);
                }
            }

            MapObjectRenderer.DisableLighting();
        }
コード例 #5
0
ファイル: ModernRenderer.cs プロジェクト: NCC-Lykos/Chisel
        public void Draw3D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            var type = ((Viewport3D)context).Type;
            var opts = new Viewport3DRenderOptions
            {
                Viewport    = viewport,
                Camera      = camera,
                ModelView   = modelView,
                ShowGrid    = Document.Map.Show3DGrid,
                GridSpacing = Document.Map.GridSpacing,
                Shaded      = type == Viewport3D.ViewType.Shaded || type == Viewport3D.ViewType.Textured,
                Textured    = type == Viewport3D.ViewType.Textured,
                Wireframe   = type == Viewport3D.ViewType.Wireframe
            };

            var cam      = ((Viewport3D)context).Camera.Location;
            var location = new Coordinate((decimal)cam.X, (decimal)cam.Y, (decimal)cam.Z);

            if (!opts.Wireframe)
            {
                _mapObject3DShader.Bind(opts);
                _mapObject3DShader.SelectionTransform        = _selectionTransform;
                _mapObject3DShader.SelectionColourMultiplier = Document.Map.HideFaceMask &&
                                                               Document.Selection.InFaceSelection
                                                                   ? new Vector4(1, 1, 1, 1)
                                                                   : new Vector4(1, 0.85f, 0.85f, 1);

                // Render textured polygons
                _array.RenderTextured(context.Context);

                // Render textured models
                if (!Chisel.Settings.View.DisableModelRendering)
                {
                    foreach (var tuple in _models)
                    {
                        var arr    = _modelArrays[tuple.Item2];
                        var origin = tuple.Item1.Origin;
                        if (tuple.Item1.HideDistance() <= (location - origin).VectorMagnitude())
                        {
                            continue;
                        }

                        var angles = tuple.Item1.EntityData.GetPropertyCoordinate("angles", Coordinate.Zero);
                        angles = new Coordinate(-DMath.DegreesToRadians(angles.Z), DMath.DegreesToRadians(angles.X),
                                                -DMath.DegreesToRadians(angles.Y));
                        if (tuple.Item1.IsSelected)
                        {
                            origin *= _selectionTransformMat;
                            // TODO: rotation/angles
                        }
                        var tform = Matrix.Rotation(Quaternion.EulerAngles(angles)).Translate(origin);
                        _mapObject3DShader.Transformation = tform.ToGLSLMatrix4();
                        arr.RenderTextured(context.Context);
                    }
                    _mapObject3DShader.Transformation = Matrix4.Identity;
                }

                // Render untextured polygons
                _mapObject3DShader.IsTextured = false;
                _array.RenderUntextured(context.Context, location);

                // todo Render sprites

                _mapObject3DShader.Unbind();
            }

            // Render wireframe
            _mapObject2DShader.Bind(opts);
            _mapObject2DShader.SelectedColour = new Vector4(1, 0, 0, 1);

            if (opts.Wireframe)
            {
                _mapObject2DShader.SelectedOnly       = false;
                _mapObject2DShader.SelectionTransform = _selectionTransform;
                _array.RenderWireframe(context.Context);
                _decalArray.RenderWireframe(context.Context);
            }

            if (!Document.Selection.InFaceSelection || !Document.Map.HideFaceMask)
            {
                _mapObject2DShader.SelectedOnly       = true;
                _mapObject2DShader.SelectionTransform = Matrix4.Identity;
                _array.RenderWireframe(context.Context);
                _decalArray.RenderWireframe(context.Context);
            }

            _mapObject2DShader.Unbind();

            if (!opts.Wireframe)
            {
                // Render transparent
                _mapObject3DShader.Bind(opts);
                _decalArray.RenderTransparent(context.Context, location);
                _array.RenderTransparent(context.Context, x => _mapObject3DShader.IsTextured = x && opts.Textured, location);
                _mapObject3DShader.Unbind();
            }
        }