gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:32:26 30 4
gpt4 key购买 nike

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

如果以相同的方式执行会产生(有前途的)图像 enter image description here然而在这种情况下, Material 似乎没有正确设置。

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

最佳答案

为什么将不透明度设置为 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>

结果:

Bildboard with the lighthouse

关于c# - 如何将程序生成的广告牌添加到 helix 3D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37297990/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com