我正在WPF(。NET核心)应用程序上使用HelixToolkit。我设置了一个Viewport3Dx,内部有一个立方体,如下所示:
XAML:
<Window x:Class="Test1.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:hx="http://helix-toolkit.org/wpf/SharpDX"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<hx:Viewport3DX x:Name="Viewport3Dx"
Grid.Row="0"
Grid.Column="0"
Background="White"
BackgroundColor="White"
Title="SharpDXView"
ShowCoordinateSystem="False">
<hx:AmbientLight3D Color="#515151" />
<hx:DirectionalLight3D Direction="-0.5, -1, -0.2"
Color="White" />
</hx:Viewport3DX>
</Grid>
后面的代码:
using HelixToolkit.SharpDX.Core;
using HelixToolkit.Wpf.SharpDX;
using System.Windows;
using System.Windows.Media.Media3D;
namespace Test1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Viewport3Dx.Camera = new HelixToolkit.Wpf.SharpDX.PerspectiveCamera();
Viewport3Dx.Camera.Position = new Point3D(5, 0, 0);
Viewport3Dx.Camera.LookAt(new Point3D(0, 0, 0), 0);
Viewport3Dx.EffectsManager = new DefaultEffectsManager();
var mb = new MeshBuilder();
mb.AddCube();
var meshGeometry = new MeshGeometryModel3D
{
Material = PhongMaterials.Green,
Transform = Transform3D.Identity,
Geometry = mb.ToMeshGeometry3D()
};
Viewport3Dx.Items.Add(meshGeometry);
}
}
}
现在我想添加一些文本到立方体的每一边(在中心)。文本应该在立方体的表面。如果可能的话,我想不使用纹理,因为立方体可能会有不同的边长以后。
纹理坐标不受立方体边长的影响,只要你的模型是立方体。