4

我有一组程序图像,我想将它们作为广告牌添加到我的 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 类。

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);
        }

如果以相同的方式执行会产生(有希望的)图像在此处输入图像描述,但是在这种情况下,材料似乎没有正确设置。

注意:我希望 BillboardVisual3D 是正确的类,我正在做一些可以让我将图像“放在地板上”的东西,可以这么说,我想要没有深度的平面图像并允许透明度。

4

1 回答 1

3

为什么将不透明度设置为 0?然后你什么都看不到。

尝试这个:

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

请参阅文档

编辑:

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

代码:

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>

结果:

有灯塔的广告牌

于 2016-06-02T15:27:54.250 回答