Exemplo n.º 1
0
        public override void RenderModel(Camera camera, MeshRenderMode mode = MeshRenderMode.Solid)
        {
            RenderHelper.ModelShader.Use();
            RenderHelper.ModelShader.UseTexture.Set(mode != MeshRenderMode.Wireframe && Surface.SurfaceID > 0);

            RenderHelper.RenderWithStencil(IsSelected,
                                           () =>
            {
                RenderPartialMesh(mode, this, SurfaceModel.Material);
            },
                                           () =>
            {
                DrawWireframeModel(RenderHelper.SelectionOutlineColor, 4f);
            }
                                           );

            if (IsSelected && !BoundingBox.IsEmpty)
            {
                var selectionBox = BoundingBox;
                selectionBox.Size += new Vector3(0.1f);
                RenderHelper.DrawBoundingBox(Transform,
                                             selectionBox,
                                             new Vector4(0f, 1f, 1f, 1f), 1.5f);
            }

            if (Surface.SurfaceID > 0)
            {
                RenderHelper.ModelShader.Use();
                RenderHelper.ModelShader.UseTexture.Set(false);
            }
        }
Exemplo n.º 2
0
        public void Render(Camera camera, MeshRenderMode renderMode)
        {
            var visibleMeshes = MeshModels.Where(x => x.Visible)
                                .OrderByDescending(x => x.IsSelected).ToList();

            if (!visibleMeshes.Any())
            {
                return;
            }

            RenderHelper.ModelShader.Use();
            RenderHelper.ModelShader.UseTexture.Set(renderMode != MeshRenderMode.Wireframe && Surface.SurfaceID > 0);

            bool useOutlineStencil = visibleMeshes.Any(x => x.IsSelected);

            if (useOutlineStencil)
            {
                RenderHelper.EnableStencilTest();
            }

            foreach (var model in visibleMeshes)
            {
                if (model.IsSelected && !useOutlineStencil)
                {
                }

                RenderHelper.RenderWithStencil(model.IsSelected,
                                               () =>
                {
                    RenderPartialMesh(renderMode, model, Material);
                },
                                               () =>
                {
                    DrawWireframeModel(model, RenderHelper.SelectionOutlineColor, 4f);
                }
                                               );

                if (useOutlineStencil)
                {
                    RenderHelper.ClearStencil();
                }
            }

            if (useOutlineStencil)
            {
                RenderHelper.DisableStencilTest();
            }

            //Draw selected models bounding boxes
            foreach (var model in visibleMeshes)
            {
                if (model.IsSelected)
                {
                    var selectionBox = model.BoundingBox;
                    selectionBox.Size += new Vector3(0.1f);
                    RenderHelper.DrawBoundingBox(model.Transform, selectionBox,
                                                 new Vector4(0f, 1f, 1f, 1f), 1.5f);
                }
            }
        }
Exemplo n.º 3
0
        private void DrawBoxCollision()
        {
            var wireColor = IsSelected ? RenderHelper.WireframeColorAlt : RenderHelper.WireframeColor;

            RenderHelper.RenderWithStencil(IsSelected,
                                           () =>
            {
                RenderHelper.BeginDrawModel(ModelManager.CubeModel, ScaleTransform * Transform, RenderHelper.CollisionMaterial);
                RenderHelper.ModelShader.IsSelected.Set(IsSelected);

                ModelManager.CubeModel.DrawElements();

                RenderHelper.EndDrawModel(ModelManager.CubeModel);

                RenderHelper.DrawBoundingBox(Transform, BoundingBox, wireColor, 1.5f);
            },
                                           () =>
            {
                RenderHelper.DrawBoundingBox(Transform, BoundingBox, RenderHelper.SelectionOutlineColor, 4f);
            });
        }
Exemplo n.º 4
0
        private void DrawSphereCollision()
        {
            RenderHelper.RenderWithStencil(
                () =>
            {
                RenderHelper.BeginDrawModel(ModelManager.SphereModel, ScaleTransform * Transform, RenderHelper.CollisionMaterial);
                RenderHelper.ModelShader.IsSelected.Set(IsSelected);
                ModelManager.SphereModel.DrawElements();
                RenderHelper.EndDrawModel(ModelManager.SphereModel);
            },
                () =>
            {
                var wireColor = IsSelected ? RenderHelper.SelectionOutlineColor : RenderHelper.WireframeColor;

                RenderHelper.ApplyStencilMask();

                RenderHelper.BeginDrawWireframe(ModelManager.SphereModel.VertexBuffer, ScaleTransform * Transform,
                                                IsSelected ? 4f : 2.5f, wireColor);
                ModelManager.SphereModel.DrawElements();
                RenderHelper.EndDrawWireframe(ModelManager.SphereModel.VertexBuffer);
            });
        }