C# 球体的透明度在我的立方体的所有侧面都不起作用-Helixtoolkit
这里的第一个问题-希望我的格式设置正确。C# 球体的透明度在我的立方体的所有侧面都不起作用-Helixtoolkit,c#,wpf,xaml,3d,helix-3d-toolkit,C#,Wpf,Xaml,3d,Helix 3d Toolkit,这里的第一个问题-希望我的格式设置正确。 因此,我正试图使用Visual Studio 2015中的Helix工具箱,在WPF中创建一个包含512个LED(8x8x8)的3D LED立方体。我对WPF中的所有3D内容都是新手,所以我可能会有一些误解。基本上我现在正在做的是: 在我的XAML代码名“cube”中有一个ModelVisual3D 我有一个循环,运行512次-它创建一个SphereVisual3D并设置其材质 我将LED添加到我的ModelVisual3D中 我希望我的LED几乎是
因此,我正试图使用Visual Studio 2015中的Helix工具箱,在WPF中创建一个包含512个LED(8x8x8)的3D LED立方体。我对WPF中的所有3D内容都是新手,所以我可能会有一些误解。基本上我现在正在做的是:
- 在我的XAML代码名“cube”中有一个ModelVisual3D
- 我有一个循环,运行512次-它创建一个SphereVisual3D并设置其材质
- 我将LED添加到我的ModelVisual3D中
DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(50,255,255,255)));
sphere.Material = material;
透明度是一种工作方式。示例:透明度作用于立方体的右/前侧(按下按钮“打开”led)。但它在立方体的左侧或后侧不起作用。有人能解释一下为什么吗?我觉得跟这个场景的光源有关。
正面的透明度:
左侧:
这是我的MainWindow.xaml:
这是我在Mainwindow.xaml.cs背后的代码:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用HelixToolkit.Wpf;
使用System.Windows.Media.Media3D;
命名空间WpfApplication1
{
///
///创建LED
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
//创建512个LED
对于(int x=0;x<7;x++)
{
对于(int y=7;y>0;y--)
{
对于(intz=0;z<7;z++)
{
addSphere(x,z,y);
}
}
}
}
公共无效添加球体(双x、双z、双y)
{
SphereVisual3D sphere=new SphereVisual3D();//创建新的“LED”
球面半径=0.25;
圆心=新的点3d(x,y,z);
漫反射材质=新的漫反射材质(新的SolidColorBrush(Color.FromArgb(5025255255));
球体。材料=材料;
sphere.BackMaterial=材质;
//sphere.Fill=新的SolidColorBrush(Colors.DarkBlue);
cube.Children.Add(sphere);
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
//将一个LED变为红色以测试透明度
SphereVisual3D model=cube.Children[60]作为SphereVisual3D;
漫反射材质=新漫反射材质(新SolidColorBrush(Color.FromArgb(255,255,0,0));
模型。材料=材料;
}
}
}
另一件奇怪的事情是当我使用“HelixToolkit:DefaultLights”时,性能非常差。我的速度大约为0-2 fps。原因是什么?尝试添加排序Visual3D
<h:HelixViewport3D ShowFrameRate="True" ShowTriangleCountInfo="True" ShowViewCube="True" >
<h:SunLight/>
<h:SortingVisual3D x:Name="view3d" Method="BoundingBoxCorners" SortingFrequency="30" CheckForOpaqueVisuals="True">
<h:GridLinesVisual3D x:Name="grid" Width="500" Length="500" MajorDistance="50" MinorDistance="10"/>
Add yours spheres here!
</h:SortingVisual3D>
</h:HelixViewport3D>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HelixToolkit.Wpf;
using System.Windows.Media.Media3D;
namespace WpfApplication1
{
/// <summary>
/// Creating LEDs
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//Create 512 LEDs
for (int x = 0; x < 7; x++)
{
for (int y = 7; y > 0; y--)
{
for(int z = 0; z < 7; z++)
{
addSphere(x, z, y);
}
}
}
}
public void addSphere(double x, double z, double y)
{
SphereVisual3D sphere = new SphereVisual3D(); //Creating new 'LED'
sphere.Radius = 0.25;
sphere.Center = new Point3D(x, y, z);
DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(50,255,255,255)));
sphere.Material = material;
sphere.BackMaterial = material;
//sphere.Fill = new SolidColorBrush(Colors.DarkBlue);
cube.Children.Add(sphere);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//Turns one LED red to test transparancy
SphereVisual3D model = cube.Children[60] as SphereVisual3D;
DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)));
model.Material = material;
}
}
}
<h:HelixViewport3D ShowFrameRate="True" ShowTriangleCountInfo="True" ShowViewCube="True" >
<h:SunLight/>
<h:SortingVisual3D x:Name="view3d" Method="BoundingBoxCorners" SortingFrequency="30" CheckForOpaqueVisuals="True">
<h:GridLinesVisual3D x:Name="grid" Width="500" Length="500" MajorDistance="50" MinorDistance="10"/>
Add yours spheres here!
</h:SortingVisual3D>
</h:HelixViewport3D>
sphere.ThetaDiv = 10;
sphere.PhiDiv = 10;