示例#1
0
        public void Draw3D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            if (_document.TextureCollection.LightmapTextureOutdated)
            {
                _document.TextureCollection.UpdateLightmapTexture();
                List <Face> faces = new List <Face>();
                foreach (Solid solid in _document.Map.WorldSpawn.Find(x => x is Solid).OfType <Solid>())
                {
                    foreach (Face tface in solid.Faces)
                    {
                        faces.Add(tface);
                    }
                }
                UpdatePartial(faces);
            }

            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 || type == Viewport3D.ViewType.Lightmapped,
                Textured        = type == Viewport3D.ViewType.Textured || type == Viewport3D.ViewType.Lightmapped,
                Wireframe       = type == Viewport3D.ViewType.Wireframe,
                LightmapEnabled = type == Viewport3D.ViewType.Lightmapped
            };

            var cam      = ((Viewport3D)context).Camera;
            var location = new Coordinate((decimal)cam.Location.X, (decimal)cam.Location.Y, (decimal)cam.Location.Z);
            var lookAt   = new Coordinate((decimal)cam.LookAt.X, (decimal)cam.LookAt.Y, (decimal)cam.LookAt.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.5f, 0.5f, 1);

                // Render textured polygons
                _array.RenderTextured(context.Context, _document.TextureCollection.LightmapTexture);

                // Render textured models
                if (!CBRE.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 scale = tuple.Item1.EntityData.GetPropertyCoordinate("scale", Coordinate.One);
                        scale = new Coordinate(scale.X, scale.Z, scale.Y);
                        var    angles = tuple.Item1.EntityData.GetPropertyCoordinate("angles", Coordinate.Zero);
                        Matrix pitch  = Matrix.Rotation(Quaternion.EulerAngles(DMath.DegreesToRadians(angles.X), 0, 0));
                        Matrix yaw    = Matrix.Rotation(Quaternion.EulerAngles(0, 0, -DMath.DegreesToRadians(angles.Y)));
                        Matrix roll   = Matrix.Rotation(Quaternion.EulerAngles(0, DMath.DegreesToRadians(angles.Z), 0));
                        if (tuple.Item1.IsSelected)
                        {
                            origin *= _selectionTransformMat;
                            // TODO: rotation/angles
                        }
                        var tform = (yaw * roll * pitch * Matrix.Scale(scale)).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, 1, 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, lookAt);
                _mapObject3DShader.Unbind();
            }
        }
示例#2
0
        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.5f, 0.5f, 1);

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

                // Render textured models
                if (!Sledge.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, 1, 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();
            }
        }