111,097
社区成员




<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800">
<Grid Background="DarkGray">
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,100" LookDirection="0,0,-1" FieldOfView="60" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="mesh" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<EmissiveMaterial Brush="Green" />
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var points = GenerateRandomPoints(10000);
AddPointCloudMesh(points);
}
void AddPointCloudMesh(IEnumerable<Point3D> points)
{
var positions = new Point3DCollection();
foreach(var p in points)
{
positions.Add(p);
positions.Add(new Point3D(p.X, p.Y - 0.2, p.Z));
positions.Add(new Point3D(p.X + 0.2, p.Y, p.Z));
}
this.mesh.Positions = positions;
this.mesh.TriangleIndices = new Int32Collection(Enumerable.Range(0, positions.Count));
}
IEnumerable<Point3D> GenerateRandomPoints(int count)
{
Random random = new Random();
for (int i = 0; i < count; i++)
{
yield return new Point3D()
{
X = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2),
Y = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2),
Z = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2),
};
}
}
}
}