ここで最初の質問 - うまくいけば、フォーマットが正しく行われます。
Visual Studio 2015 の Helix-Toolkit を使用して、WPF で 512 個の LED (8x8x8) を備えた 3D LED キューブを作成しようとしています。基本的に私が今やっていることは次のとおりです。
- XAML コード namend "cube" に ModelVisual3D があります。
- 512 回実行されるループがあります。これは SphereVisual3D を作成し、そのマテリアルを設定します
- LED を ModelVisual3D に追加します
キューブの内側にある LED がいつ点灯するかを確認できるように、LED をほぼ透明にしたいと考えています。それが私がこのマテリアルを使用した理由です:
DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(50,255,255,255)));
sphere.Material = material;
透明性は一種の機能です。例: 透明度は立方体の右側/前面で機能しています (ボタンを押すと、LED が「オン」になります)。しかし、立方体の左側または裏側では機能していません。誰かが私に理由を説明できますか? このシーンの光源が関係していると思います。表面の透明度:
左側:
これは私の MainWindow.xaml です:
<Window
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:local="clr-namespace:WpfApplication1"
xmlns:h="http://helix-toolkit.org/wpf"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="WpfApplication1.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="720.268" Width="894.578"
xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" >
<Grid>
<!-- Using the HelixToolkit -->
<HelixToolkit:HelixViewport3D x:Name="viewport" ZoomExtentsWhenLoaded="True" ShowFrameRate="True" ShowCoordinateSystem="True" Margin="0,0,0,45" ClipToBounds="False" InfiniteSpin="True">
<!-- Using the SunLight. Strange thing is: If I use the DefaultLight my Performance gets really bad -->
<HelixToolkit:SunLight Brightness="1" ShowLights="True">
</HelixToolkit:SunLight>
<!-- This ModelVisual3D Object should contain my LED cube -->
<ModelVisual3D x:Name="cube">
</ModelVisual3D>
</HelixToolkit:HelixViewport3D>
<!-- The button turns on a LED - for transparecy testing purpose -->
<Button Margin="377,650,386,0" Content="Push Me!" Click="Button_Click"/>
</Grid>
そして、これは私のコード ビハインド Mainwindow.xaml.cs です。
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;
}
}
}
もう 1 つの奇妙な点は、"HelixToolkit:DefaultLights" を使用しているときにパフォーマンスが非常に悪いことです。私は0〜2 fpsのようになっています。その理由は何ですか?