1

如何删除场景中的这个红框?我使用 SharpGL。如果它是默认框,我不能删除它?需要你们的帮助,伙计们。

程序代码在这里。它应该旋转和缩放 .obj 文件。所有工作正常,但我需要删除这个红框。也许有删除这个redbox的任何功能?

using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using SharpGL.SceneGraph.Effects;
using SharpGL.SceneGraph.Primitives;
using SharpGL.Serialization.Wavefront;

namespace WindowsFormsApp1
{
    public partial class MainForm : Form
    {
        private readonly ArcBallEffect arcBallEffect = new ArcBallEffect();
        public MainForm()
        {
            InitializeComponent();
            InitializeScene();
        }
        private void InitializeScene()
        {
            sceneControl.MouseDown += new MouseEventHandler(sceneControl_MouseDown);
            sceneControl.MouseMove += new MouseEventHandler(sceneControl_MouseMove);
            sceneControl.MouseUp += new MouseEventHandler(sceneControl_MouseUp);

            sceneControl.Scene.SceneContainer.AddChild(new Grid());
            sceneControl.Scene.SceneContainer.AddChild(new Axies());

            // Загрузка объекта 
            var objec = new ObjFileFormat();
            var objScene = objec.LoadData(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data", "Raptor.obj"));

            // Заполнение сцены
            foreach (var asset in objScene.Assets)
                sceneControl.Scene.Assets.Add(asset);

            // Работа с полигонами
            var polygons = objScene.SceneContainer.Traverse<Polygon>().ToList();

            foreach (var polygon in polygons)
            {
                polygon.Name = "Polygon";
                polygon.Transformation.RotateX = 90f;// положение при старте
                //  Границы полигона.
                var boundingVolume = polygon.BoundingVolume;
                var extent = new float[3];
                polygon.BoundingVolume.GetBoundDimensions(out extent[0], out extent[1], out extent[2]);
                var maxExtent = extent.Max();
                // Скалирование.
                var scaleFactor = maxExtent > 10 ? 7.0f / maxExtent : 1;
                polygon.Parent.RemoveChild(polygon);
                polygon.Transformation.ScaleX = scaleFactor;
                polygon.Transformation.ScaleY = scaleFactor;
                polygon.Transformation.ScaleZ = scaleFactor;
                polygon.Freeze(sceneControl.OpenGL);
                sceneControl.Scene.SceneContainer.AddChild(polygon);
                // Эффекты.
                polygon.AddEffect(new OpenGLAttributesEffect());
                polygon.AddEffect(arcBallEffect);
            }
        }
        //Движения Мыши
        private void sceneControl_MouseDown(object sender, MouseEventArgs e)
        {
            arcBallEffect.ArcBall.SetBounds(sceneControl.Width, sceneControl.Height);
            arcBallEffect.ArcBall.MouseDown(e.X, e.Y);
        }

        private void sceneControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                arcBallEffect.ArcBall.MouseMove(e.X, e.Y);
        }

        private void sceneControl_MouseUp(object sender, MouseEventArgs e)
        {
            arcBallEffect.ArcBall.MouseUp(e.X, e.Y);
        }
    }
}
4

1 回答 1

1

只需将Scene'RenderBoundingVolumes属性设置为false

sceneControl.Scene.RenderBoundingVolumes = false;

于 2021-06-11T08:30:25.440 回答