1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| 'Code d'affichage OPENGL :
GlControl3D.MakeCurrent()
'Nettoyage -----------------------------------------------------------------
GL.Clear(ClearBufferMask.ColorBufferBit)
GL.Clear(ClearBufferMask.DepthBufferBit)
'Taille de la fenêtre ------------------------------------------------------
GL.Viewport(0, 0, GlControl3D.Width, GlControl3D.Height)
'** Degradé en fond d'écran ------------------------------------------------
GL.ShadeModel(ShadingModel.Smooth)
GL.MatrixMode(MatrixMode.Projection)
GL.LoadIdentity()
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
GL.Disable(EnableCap.DepthTest)
GL.Disable(EnableCap.Lighting)
GL.Begin(BeginMode.Quads)
GL.Color3(CoulDegGB3D)
GL.Vertex2(-1.0, -1.0)
GL.Color3(CoulDegDB3D)
GL.Vertex2(1.0, -1.0)
GL.Color3(CoulDegDH3D)
GL.Vertex2(1.0, 1.0)
GL.Color3(CoulDegGH3D)
GL.Vertex2(-1.0, 1.0)
GL.End()
'---
GL.ShadeModel(ShadingModel.Flat)
GL.MatrixMode(MatrixMode.Projection) 'Load Perspective
GL.LoadMatrix(Perspective3D) 'Setup Perspective
GL.MatrixMode(MatrixMode.Modelview) 'Load Camera
GL.Enable(EnableCap.DepthTest)
GL.Enable(EnableCap.Lighting)
'** -----------------------------------------------------------------------
'Préparation ---------------------------------------------------------------
GL.LoadMatrix(Lookat3D)
'Choix de la position de la pièce (permet navigation à la souris) ------------------------------------------
GL.Translate(PX3D, PY3D, PZ3D)
GL.Rotate(AZ3D, 0, 0, 1)
GL.Rotate(AX3D, 0, 1, 0)
GL.Rotate(AY3D, 1, 0, 0)
'Lumière *******************************************************************
GL.Light(LightName.Light0, LightParameter.Position, New Single() {LumX3D, LumY3D, 0})
GL.Light(LightName.Light1, LightParameter.Position, New Single() {-LumX3D, -LumY3D, -0.5!})
GL.Light(LightName.Light2, LightParameter.Position, New Single() {0!, 0!, 1.0!})
'Dessin de la pièce --------------------------------------------------------
'Affichage STL "libre" (pour imprimante 3D) $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
If AfficherFlippedTriangles Then '24/12/2018
GL.Enable(EnableCap.CullFace)
GL.CullFace(CullFaceMode.Front)
GL.Color3(Color.Red)
Call Peindre_Visu3D_STL()
GL.CullFace(CullFaceMode.Back)
GL.Color3(Color.Green)
Call Peindre_Visu3D_STL()
Else
GL.Disable(EnableCap.CullFace)
Call Peindre_Visu3D_STL(True)
End If
If AfficherWireFrame Then
GL.Disable(EnableCap.Lighting)
GL.Disable(EnableCap.CullFace)
GL.Color3(Color.Black)
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line)
Call Peindre_Visu3D_STL()
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill)
End If
GlControl3D.MakeCurrent()
GlControl3D.SwapBuffers()
Private Sub Peindre_Visu3D_STL(Optional Colored As Boolean = False)
Dim i As Integer, j As Integer, k As Integer, n As Integer
GL.Begin(BeginMode.Triangles)
If Colored Then
For j = 0 To STL_ListeT.Count - 1
STL_ListeT_Current = STL_ListeT.Item(j)
STL_ListeColor3_Current = STL_ListeColor3.Item(j)
n = STL_ListeT_Current.Count \ 12
For i = 0 To n - 1
GL.Color3(STL_ListeColor3_Current.Item(i))
k = 12 * i
GL.Normal3(STL_ListeT_Current.Item(k), STL_ListeT_Current.Item(k + 1), STL_ListeT_Current.Item(k + 2))
GL.Vertex3(STL_ListeT_Current.Item(k + 3) + dtx3D, STL_ListeT_Current(k + 4) + dty3D, STL_ListeT_Current.Item(k + 5) + dtz3D)
GL.Vertex3(STL_ListeT_Current.Item(k + 6) + dtx3D, STL_ListeT_Current.Item(k + 7) + dty3D, STL_ListeT_Current.Item(k + 8) + dtz3D)
GL.Vertex3(STL_ListeT_Current.Item(k + 9) + dtx3D, STL_ListeT_Current.Item(k + 10) + dty3D, STL_ListeT_Current.Item(k + 11) + dtz3D)
Next
Next
Else
For j = 0 To STL_ListeT.Count - 1
STL_ListeT_Current = STL_ListeT.Item(j)
n = STL_ListeT_Current.Count \ 12
For i = 0 To n - 1
k = 12 * i
GL.Normal3(STL_ListeT_Current.Item(k), STL_ListeT_Current.Item(k + 1), STL_ListeT_Current.Item(k + 2))
GL.Vertex3(STL_ListeT_Current.Item(k + 3) + dtx3D, STL_ListeT_Current(k + 4) + dty3D, STL_ListeT_Current.Item(k + 5) + dtz3D)
GL.Vertex3(STL_ListeT_Current.Item(k + 6) + dtx3D, STL_ListeT_Current.Item(k + 7) + dty3D, STL_ListeT_Current.Item(k + 8) + dtz3D)
GL.Vertex3(STL_ListeT_Current.Item(k + 9) + dtx3D, STL_ListeT_Current.Item(k + 10) + dty3D, STL_ListeT_Current.Item(k + 11) + dtz3D)
Next
Next
End If
For i = 0 To GL_Liste_LotTri2D.Count - 1
GL_Liste_LotTri2D.Item(i).GL_Paint(Colored)
Next
For i = 0 To GL_Liste_LotTri3D.Count - 1
GL_Liste_LotTri3D.Item(i).GL_Paint(Colored)
Next
GL.End()
For i = 0 To GL_Liste_TriFan3D.Count - 1
GL_Liste_TriFan3D.Item(i).GL_Paint(Colored)
Next
For i = 0 To GL_Liste_TriFan2D.Count - 1
GL_Liste_TriFan2D.Item(i).GL_Paint(Colored)
Next
For i = 0 To GL_Liste_TriStrip3D.Count - 1
GL_Liste_TriStrip3D.Item(i).GL_Paint(Colored)
Next
'For i = 0 To GL_Liste_ColTriStrip3D.Count - 1
' GL_Liste_ColTriStrip3D.Item(i).GL_Paint(Colored)
'Next
For i = 0 To GL_Liste_TriStrip25D.Count - 1
GL_Liste_TriStrip25D.Item(i).GL_Paint(Colored)
Next
For i = 0 To GL_Liste_TriStrip2D.Count - 1
GL_Liste_TriStrip2D.Item(i).GL_Paint(Colored)
Next
End Sub
'Code de GL_Liste_LotTri2D.Item(i).GL_Paint(Colored) :
Public Sub GL_Paint(Optional Colored As Boolean = False)
Dim i As Integer, k As Integer, n As Integer
n = ListeXY.Count \ 6
If n < 1 Then Exit Sub
If Colored Then GL.Color3(Couleur)
Dim DoRotate As Boolean = RX <> 0 OrElse RY <> 0
If DoRotate Then
GL.End()
GL.PushMatrix()
GL.Translate(CX, CY, CZ)
GL.Rotate(RX, 1, 0, 0)
GL.Rotate(RY, 0, 1, 0)
GL.Translate(-CX, -CY, -CZ)
GL.Begin(BeginMode.Triangles)
End If
'GL.Begin(BeginMode.Triangles)
GL.Normal3(0.0!, 0.0!, NZ)
For i = 0 To n - 1
k = 6 * i
GL.Vertex3(ListeXY.Item(k + 0) + dtx3D, ListeXY.Item(k + 1) + dty3D, Z + dtz3D)
GL.Vertex3(ListeXY.Item(k + 2) + dtx3D, ListeXY.Item(k + 3) + dty3D, Z + dtz3D)
GL.Vertex3(ListeXY.Item(k + 4) + dtx3D, ListeXY.Item(k + 5) + dty3D, Z + dtz3D)
Next
'GL.End()
If DoRotate Then
GL.End()
GL.PopMatrix()
GL.Begin(BeginMode.Triangles)
End If
End Sub |
Partager