0
Draw Triangle from "for cycles" iusse
I need to draw from code behind, (not from xaml), a large number of triangle. For calculation I calc half Triangleindices with a for cycle and the other half with another. Here the code : xaml:
<Window x:Name="MainWindowX" x:Class="MainWindow"
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:HelixTest"
xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<HelixToolkit:HelixViewport3D Name="myviewport" ZoomExtentsWhenLoaded="True" Background="Black" ShowCoordinateSystem="True" >
<!-- Remember to add light to the scene -->
<HelixToolkit:SunLight/>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D x:Name="myGeometryModel3D">
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="myMeshGeometry3D">
</MeshGeometry3D>
</GeometryModel3D.Geometry >
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="red" Offset="2" />
<GradientStop Color="Red" Offset="3" />
<GradientStop Color="Blue" Offset="4" />
<GradientStop Color="LimeGreen" Offset="5" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
<HelixToolkit:BillboardTextVisual3D Position="11 0 0" Text="X" Foreground="Yellow"/>
<HelixToolkit:BillboardTextVisual3D Position="0 11 0" Text="Y" Foreground="Yellow" />
<HelixToolkit:BillboardTextVisual3D Position="0 0 11" Text="Z" Foreground="Yellow"/>
</HelixToolkit:HelixViewport3D>
</Grid>
and vb.net code behind
Imports System.Windows.Media.Media3D
Imports HelixToolkit
Class MainWindow
Dim punti = 5
Dim curve = 5
Dim valori As New List(Of Integer)
Dim indices As New List(Of Integer)
Dim triangoli = (punti - 1) * (curve - 1) * 2
Private Sub MainWindowX_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded, MyBase.Loaded
myMeshGeometry3D.Positions.Clear()
myMeshGeometry3D.TriangleIndices.Clear()
valori.Add(0)
valori.Add(1)
valori.Add(2)
valori.Add(3)
valori.Add(3)
valori.Add(0)
valori.Add(1)
valori.Add(2)
valori.Add(3)
valori.Add(3)
valori.Add(0)
valori.Add(1)
valori.Add(2)
valori.Add(3)
valori.Add(3)
valori.Add(0)
valori.Add(1)
valori.Add(2)
valori.Add(3)
valori.Add(3)
valori.Add(0)
valori.Add(1)
valori.Add(2)
valori.Add(3)
valori.Add(3)
'load myMeshGeometry3d.Positions
For I = 0 To curve - 1
'per ogni curva
For b = 0 To punti - 1
myMeshGeometry3D.Positions.Add(New Point3D(b, I, valori(I * punti + b)))
Next
Next
'First half
For d = punti + 1 To triangoli - 2 Step punti
For f = 0 To punti - 2 Step 1
myMeshGeometry3D.TriangleIndices.Add(d + f)
myMeshGeometry3D.TriangleIndices.Add((d - 1) + f)
myMeshGeometry3D.TriangleIndices.Add((d - punti) + f)
Next
Next
'second half
For j = 0 To triangoli Step punti
For i = 0 To punti - 2 Step 1
myMeshGeometry3D.TriangleIndices.Add(j + i)
myMeshGeometry3D.TriangleIndices.Add((j + 1) + i)
myMeshGeometry3D.TriangleIndices.Add((j + punti) + i)
Next
Next
End Sub
End Class
My iusse is that only the triagles that are generate from the first cycle are showed, the second not. I tried to swap the cycle and they are both correct. I also tryed to add 2 button, one for cycle. they work to show half triangle, but only it first I clear the triangleindices.What am I missing? Any advice?
Customer support service by UserEcho
I have read many blogs. This blog is the best I have ever come across. Thanks for creating this blog.
sagame
สมัครสมาชิกเว็บคาสิโนเอสเอเกม
สมัครเว็บคาสิโนบนมือถือเอสเอเกม