コード例 #1
0
ファイル: BrushTool.cs プロジェクト: juanjp600/cbre
 protected override void Render3D(Viewport3D viewport)
 {
     base.Render3D(viewport);
     if (ShouldDraw3DBox() && _preview != null)
     {
         GL.Disable(EnableCap.CullFace);
         TextureHelper.Unbind();
         if (viewport.Type != Viewport3D.ViewType.Flat)
         {
             MapObjectRenderer.EnableLighting();
         }
         MapObjectRenderer.DrawFilled(_preview, GetRenderColour(), false);
         MapObjectRenderer.DisableLighting();
         GL.Color4(Color.GreenYellow);
         MapObjectRenderer.DrawWireframe(_preview, true, false);
     }
 }
コード例 #2
0
        protected override void Render3D(Viewport3D vp)
        {
            base.Render3D(vp);

            if (_currentTool != null)
            {
                _currentTool.Render3D(vp);
            }

            TextureHelper.Unbind();

            if (_currentTool == null || _currentTool.DrawVertices())
            {
                // Get us into 2D rendering
                Matrix.Set(MatrixMode.Projection);
                Matrix.Identity();
                Graphics.Helpers.Viewport.Orthographic(0, 0, vp.Width, vp.Height);
                Matrix.Set(MatrixMode.Modelview);
                Matrix.Identity();

                var half = new Coordinate(vp.Width, vp.Height, 0) / 2;
                // Render out the point handles
                GL.Begin(PrimitiveType.Quads);
                foreach (var point in Points)
                {
                    if (point.IsMidPoint && _showPoints == ShowPoints.Vertices)
                    {
                        continue;
                    }
                    if (!point.IsMidPoint && _showPoints == ShowPoints.Midpoints)
                    {
                        continue;
                    }

                    var c = vp.WorldToScreen(point.Coordinate);
                    if (c == null || c.Z > 1)
                    {
                        continue;
                    }
                    c -= half;

                    GL.Color3(Color.Black);
                    GL.Vertex2(c.DX - 4, c.DY - 4);
                    GL.Vertex2(c.DX - 4, c.DY + 4);
                    GL.Vertex2(c.DX + 4, c.DY + 4);
                    GL.Vertex2(c.DX + 4, c.DY - 4);

                    GL.Color3(point.GetColour());
                    GL.Vertex2(c.DX - 3, c.DY - 3);
                    GL.Vertex2(c.DX - 3, c.DY + 3);
                    GL.Vertex2(c.DX + 3, c.DY + 3);
                    GL.Vertex2(c.DX + 3, c.DY - 3);
                }
                GL.End();

                // Get back into 3D rendering
                Matrix.Set(MatrixMode.Projection);
                Matrix.Identity();
                Graphics.Helpers.Viewport.Perspective(0, 0, vp.Width, vp.Height, View.CameraFOV);
                Matrix.Set(MatrixMode.Modelview);
                Matrix.Identity();
                vp.Camera.Position();
            }

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

            // Render out the solid previews
            GL.Color3(Color.White);
            var faces = _copies.Keys.SelectMany(x => x.Faces).ToList();

            if (!wireframe)
            {
                if (shaded)
                {
                    MapObjectRenderer.EnableLighting();
                }
                GL.Enable(EnableCap.Texture2D);
                MapObjectRenderer.DrawFilled(faces.Where(x => !x.IsSelected), Color.FromArgb(255, 64, 192, 64), textured);
                MapObjectRenderer.DrawFilled(faces.Where(x => x.IsSelected), Color.FromArgb(255, 255, 128, 128), textured);
                GL.Disable(EnableCap.Texture2D);
                MapObjectRenderer.DisableLighting();

                GL.Color3(Color.Pink);
                MapObjectRenderer.DrawWireframe(faces, true, false);
            }
            else
            {
                GL.Color4(Color.FromArgb(255, 64, 192, 64));
                MapObjectRenderer.DrawWireframe(faces.Where(x => !x.IsSelected), true, false);
                GL.Color4(Color.FromArgb(255, 255, 128, 128));
                MapObjectRenderer.DrawWireframe(faces.Where(x => x.IsSelected), true, false);
            }
        }
コード例 #3
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);
                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();
        }