如何将程序生成的广告牌添加到 helix 3D

How to add a proceduaraly generated billboard to helix 3D

我有一组程序图像,我想将它们作为广告牌添加到我的 helix 3D 应用程序中。

目前我的应用程序如下所示:

public partial class _3DControl
{
    HelixViewport3D hVp3D;
    public _3DControl()
    {
        InitializeComponent();
        createView();
    }

    public void createView()
    {
        hVp3D = new HelixViewport3D();
        var lights = new SunLight();
        lights.Altitude=40;
        lights.Ambient=0.4;
        this.Content = hVp3D;
        hVp3D.Children.Add(lights);
        this.Show();
    }

    public void  UploadBillboard(BitmapImage im, System.Windows.Media.Media3D.Point3D position,double width,double height)
    { 
        //create material 
        var mat = MaterialHelper.CreateImageMaterial(im, 0);
        var bboard = new BillboardVisual3D();
        bboard.Material = mat;

        //set coordinates 
        bboard.Position = position;
        bboard.Width = width;
        bboard.Height = height;

        //add the billboard 
        hVp3D.Children.Add(bboard);
    }

但是当我调用添加广告牌的函数时:

           HelixLinker.GetHelix().UploadBillboard(((Bitmap)e).bitmapToBitmapImage(), 
new System.Windows.Media.Media3D.Point3D(0, 0, 0), 100, 100);

然后我发现没有添加任何内容,知道我哪里做错了吗?

我也尝试使用 RectangleVisual3D class。

public void UploadRect(BitmapImage im, System.Windows.Media.Media3D.Point3D position, double width, double height)
        {
            var mat = MaterialHelper.CreateImageMaterial(im, 0);
            var bboard = new RectangleVisual3D ();
            bboard.Material = mat;
            bboard.Width = width;

            hVp3D.Children.Add(bboard);
        }

如果以相同的方式执行会产生(有前途的)图像 但是在这种情况下 material 似乎设置不正确。

注意:我希望 BillboardVisual3D 是正确的 class,我正在研究可以让我放置图像的东西 "on the floor" 可以这么说,我想要平面图像没有深度并允许透明度。

为什么将不透明度设置为 0?那你就什么都看不到了。

试试这个:

//create material 
var mat = MaterialHelper.CreateImageMaterial(im);

documentation

编辑:

对不起,我的字符串不好。但这对我有用:

代码:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        CreateBilboard();
    }

    private void CreateBilboard()
    {
        BitmapImage im = new BitmapImage(new System.Uri(@"C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg"));

        var mat = MaterialHelper.CreateImageMaterial(im, 1);
        var bboard = new BillboardVisual3D();
        bboard.Material = mat;

        var position = new System.Windows.Media.Media3D.Point3D(0, 0, 0);
        var width = 100;
        var height = 100;


        //set coordinates 
        bboard.Position = position;
        bboard.Width = width;
        bboard.Height = height;

        //add the billboard 
        viewPort.Children.Add(bboard);
    }
}

XAML:

<Window x:Class="BillboardImageMaterialDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ht="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" 
        Title="BillboardImageMaterialDemo" Height="480" Width="640">
    <Grid>
        <ht:HelixViewport3D x:Name="viewPort" ZoomExtentsWhenLoaded="True">
            <!-- Remember to add some lights -->
            <ht:SunLight/>
        </ht:HelixViewport3D>
    </Grid>
</Window>

结果: