【问题标题】:How to create an extruded geometry using Helix toolkit MeshBuilder in WPF?如何在 WPF 中使用 Helix 工具包 MeshBuilder 创建拉伸几何体?
【发布时间】:2020-01-08 17:23:11
【问题描述】:

我尝试通过点列表制作自定义形状,以便您可以在 WPF 中查看它并使用HelixToolKit。首先,我尝试制作一个简单的立方体,请参见下面的代码。但是 WPF 表单中没有显示任何内容。代码有什么问题?

MeshBuilder builder = new MeshBuilder();
// points
IList<Point> points = new List<Point>();
points.Add(new Point(0, 0));
points.Add(new Point(0, 100));
points.Add(new Point(100, 100));
points.Add(new Point(100, 0));

Vector3D extrusionVector = new Vector3D(0, 0, 1);
Point3D p0 = new Point3D(0, 0, 0);
Point3D p1 = new Point3D(0, 0, 1);

builder.AddExtrudedGeometry(points, extrusionVector, p0, p1);

GeometryModel3D geomModel = new GeometryModel3D { Geometry = builder.ToMesh(), Material = Materials.Red, BackMaterial = Materials.Gray };
ModelVisual3D cube = new ModelVisual3D();
cube.Content = geomModel;
viewPort3d.Children.Add(cube);
<Window x:Class="HelixWpfAppOne.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:helix="http://helix-toolkit.org/wpf"
    xmlns:local="clr-namespace:HelixWpfAppOne"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Grid>
    <helix:HelixViewport3D x:Name="viewPort3d" ZoomExtentsWhenLoaded="true" Grid.RowSpan="2" >
        <!-- Remember to add light to the scene -->
        <helix:DefaultLights/>
        <helix:GridLinesVisual3D Width="200" Length="200" Thickness="0.1" MinorDistance="5" MajorDistance="10" Fill="#FFB2B2B2"/>
    </helix:HelixViewport3D>

</Grid>

【问题讨论】:

  • 能否将 XAML 包含在 HelixViewPort 中?
  • 我添加了 XAML。添加茶壶时,视口正在发挥作用。

标签: c# wpf helix-3d-toolkit


【解决方案1】:

请检查 AddExtrudedGeometry 的定义,我更改了参数然后它可以显示 3d 模型。当我更改参数时,我发现有些东西是连线的。如果你想建立一个挤压模型,请参阅 ExtrudedVisual3D()。效果很好。

        var render = new ExtrudedVisual3D();
        render.Section = contour;
        render.Path.Add(new Point3D(0, 0, 0));
        render.Path.Add(new Point3D(0, 0, bimWall.Thickness));
        render.SectionXAxis = axis;
        render.Fill = Brushes.WhiteSmoke;
        render.IsPathClosed = true;
        render.IsSectionClosed = true;                                     
        var wallModel = new ModelVisual3D();   
        wallModel.Children.Add(render);

【讨论】:

  • 我们想在这里查看代码 :) 你能提供什么对你有用吗?此外,您可能会从阅读本指南“如何写出好的答案”中受益:stackoverflow.com/help/how-to-answer
  • @John,感谢您提供的代码行。我得到了 Extruded Visual,但该部分始终是打开的。如何将挤出的对象关闭为实体而不是由挤出的剖面线构建的侧面?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-13
  • 2013-07-23
  • 2010-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多