1

在此处输入图像描述从我的模型中执行 ClippingPlane1 的 Edit() 函数时,我正在努力显示网格平面。它只显示移动的参考坐标、封盖、对象等……除了平面。调试时,似乎实际上已经计算出了 clippingPlaneMesh(内部结构),但 Visible = false。我尝试了 ProcessClippingPlanesVisibility(gcnew cli::array<ClippingPlane^>(1) { Model1->ClippingPlane1 }, true) 函数但没有成功。我还确保 ShowPlane 是真的。

你知道如何显示裁剪平面的平面网格吗?

谢谢

阿卜杜拉耶

4

1 回答 1

1

在此处输入图像描述

我创建了一个剪裁平面的最小可复制模型。来自DevDept 的体积渲染示例。我注意到的两件事是,您需要确保在调用 Edit(null) 之后重绘视口(viewport.Invalidate(); )。同样在示例中,Plane.Origin.Z 被弄乱了。除非clippingPlane1的整个平面被改变,否则这不会被重新渲染:

viewportLayout1.ClippingPlane1.Plane = new Plane(new Point3D(7, 7, 7), new Vector3D(0, 0, 1));

ClippingPlane1 的代码:

private void addClippingPlane()
{
    // Remove Clipping Plane if Active
    if (viewportLayout1.ClippingPlane1.Active) { viewportLayout1.ClippingPlane1.Cancel(); }

    //sets the Z coordinate of the origin of the clippingPlane      
    viewportLayout1.ClippingPlane1.Plane = new Plane(new Point3D(7, 7, 7), new Vector3D(0, 0, 1));
            
    // enables a clippingPlane                           
    viewportLayout1.ClippingPlane1.Edit(null);          
            
    // refresh the viewport
    viewportLayout1.Invalidate();
}

另一种剪裁网格的方法是CutBy。此方法允许通过平面单独切割网格。不幸的是,平面是几何子副和实体子,因此它不能作为平面添加到视口中。为了缓解这种情况,可以使用Quad实体绘制它,并为绘制的边指定长度。

剪切示例:

private void addCutByPlane()
{
    // Remove Clipping Plane if Active
    if (viewportLayout1.ClippingPlane1.Active) { viewportLayout1.ClippingPlane1.Cancel(); }

    //  Create Meshes
    Plane cutPlane1 = new Plane(new Point3D(7, 7, 7), new Vector3D(0, 0, 1));
    Mesh square = Mesh.CreateBox(15, 15, 15);

    // Cut Mesh by Plane
    square.CutBy(cutPlane1);

    // Length of Drawn part of plane
    double drawPlaneLength = 16;
    double hL = drawPlaneLength / 2;

            
    // Draw Plane region as a Quad Entity
    Point3D pO = cutPlane1.Origin;
    Point3D q1 = (pO + (cutPlane1.AxisX + cutPlane1.AxisY) * hL);
    Point3D q2 = (pO - (cutPlane1.AxisX - cutPlane1.AxisY) * hL);
    Point3D q3 = (pO - (cutPlane1.AxisX + cutPlane1.AxisY) * hL);
    Point3D q4 = (pO + (cutPlane1.AxisX - cutPlane1.AxisY) * hL);           

    Quad drawCutPlane1 = new Quad(q1, q2, q3, q4);
            
    viewportLayout1.Entities.Clear();
    viewportLayout1.Entities.Add(drawCutPlane1, Color.Red);
    viewportLayout1.Entities.Add(square, Color.Blue);

    viewportLayout1.Invalidate();
}

完整示例:

using System;
using System.Drawing;
using System.Windows.Forms;
using devDept.Eyeshot.Entities;
using devDept.Geometry;

namespace EyeshotTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            makeSquare();
        }

        private void makeSquare()
        {
            Mesh square = Mesh.CreateBox(15, 15, 15);
            viewportLayout1.Entities.Add(square, Color.Green);
            viewportLayout1.Invalidate();           
        }

        private void addClippingPlane()
        {
            // Remove Clipping Plane if Active
            if (viewportLayout1.ClippingPlane1.Active) { viewportLayout1.ClippingPlane1.Cancel(); }

            //sets the Z coordinate of the origin of the clippingPlane      
            viewportLayout1.ClippingPlane1.Plane = new Plane(new Point3D(7, 7, 7), new Vector3D(0, 0, 1));
            
            // enables a clippingPlane                           
            viewportLayout1.ClippingPlane1.Edit(null);          
            
            // refresh the viewport
            //viewportLayout1.Entities.Regen(); 
            // ^ unneeded, but when in doubt always Regen & Invalidate
            // Then remove them where ever possible for speed improvments
            viewportLayout1.Invalidate();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            addClippingPlane();
        }

        private void addCutByPlane()
        {
            // Remove Clipping Plane if Active
            if (viewportLayout1.ClippingPlane1.Active) { viewportLayout1.ClippingPlane1.Cancel(); }

            //  Create Meshes
            Plane cutPlane1 = new Plane(new Point3D(7, 7, 7), new Vector3D(0, 0, 1));
            Mesh square = Mesh.CreateBox(15, 15, 15);

            // Cut Mesh by Plane
            square.CutBy(cutPlane1);

            // Length of Drawn part of plane
            double drawPlaneLength = 16;
            double hL = drawPlaneLength / 2;

            
            // Draw Plane region as a Quad Entity
            Point3D pO = cutPlane1.Origin;
            Point3D q1 = (pO + (cutPlane1.AxisX + cutPlane1.AxisY) * hL);
            Point3D q2 = (pO - (cutPlane1.AxisX - cutPlane1.AxisY) * hL);
            Point3D q3 = (pO - (cutPlane1.AxisX + cutPlane1.AxisY) * hL);
            Point3D q4 = (pO + (cutPlane1.AxisX - cutPlane1.AxisY) * hL);           

            Quad drawCutPlane1 = new Quad(q1, q2, q3, q4);
            
            viewportLayout1.Entities.Clear();
            viewportLayout1.Entities.Add(drawCutPlane1, Color.Red);
            viewportLayout1.Entities.Add(square, Color.Blue);

            viewportLayout1.Invalidate();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            addCutByPlane();
        }
    }
}

于 2020-12-28T22:47:34.610 回答