Bonjour à tous

Je commence à utiliser OpenTK avec VB.NET 2010

Une fois n'est pas coutume j'ai suivit un tutoriel en vidéo :


OpenTK a l'air très intéressant... mais le site www.OpenTK.com est mort, et avec lui ont disparu le contenu des forums et une partie de la doc

Est-ce que quelqu'un aurait sur son disque dur la doc sur OpenTK et son GlControl ?

J'ai un code qui tourne mais il est très rudimentaire... par exemple a chaque affichage il redéfinit entièrement la scène depuis le debut au lieu de simplement la ré-afficher

Mon besoin est le suivant : j'ai une liste de triangles (correspondant à un objet 3D au format STL). Mes données sont OK (fichiers STL générés vérifiés sans erreurs). J'aimerais simplement permettre à l'utilisateur de visualiser le fichier directement dans mon appli plutôt que de devoir enregistrer le fichier STL et le visualiser avec un autre logiciel. Il sera possible de tourner et translater l'objet à la souris (j'ai déjà codé cette fonction) ; je n'ai pas besoin de choses complexes comme plusieurs éclairages ou des collisions.

Merci

A bientôt

Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
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
173
174
175
176
177
178
179
180
181
Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
 
Public Class Visu3D
    Dim EtatBouton As Integer
    Dim XPrec As Integer, YPrec As Integer
    Dim AX As Double, AY As Double
    Dim AXPrec As Double, AYPrec As Double
    Dim PX As Single, PY As Single, PZ As Single
    Dim PXPrec As Single, PYPrec As Single, PZPrec As Single
    Dim Debut As Boolean
 
    Public Sub New()
        Debut = True
        InitializeComponent()
    End Sub
 
    Private Sub GlControl1_Load(sender As System.Object, e As System.EventArgs) Handles GlControl1.Load
        GL.ClearColor(Color.Black)
    End Sub
 
    Public Sub Montrer()
        EtatBouton = 0
        Debut = True
        Me.ShowDialog()
    End Sub
 
    Private Sub GlControl1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles GlControl1.MouseDown
        Dim eX As Integer, eY As Integer
        eX = e.X
        eY = e.Y
        Select Case e.Button
            Case Windows.Forms.MouseButtons.Left : EtatBouton = 1
            Case Windows.Forms.MouseButtons.Right : EtatBouton = 2
            Case Else : EtatBouton = 0
        End Select
        If EtatBouton <> 0 Then
            XPrec = eX
            YPrec = eY
        End If
        Select Case EtatBouton
            Case 0
            Case 1
                AXPrec = AX
                AYPrec = AY
            Case 2
                PXPrec = PX
                PYPrec = PY
                PZPrec = PZ
        End Select
    End Sub
 
    Private Sub GlControl1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles GlControl1.MouseMove
        Dim DX As Integer, DY As Integer
        Dim eX As Integer, eY As Integer
        eX = e.X
        eY = e.Y
        DX = eX - XPrec
        DY = eY - YPrec
        Select Case EtatBouton
            Case 0 'RIEN
            Case 1 'ROTATION
                AX = AXPrec + DX * 0.3
                AY = AYPrec + DY * (-0.3)
                GlControl1.Invalidate()
            Case 2 'DEPLACEMENT
                'PX = PXPrec + DX
                PY = PYPrec + DY * (-0.5F)
                PZ = PZPrec + DX * (-0.5F)
                GlControl1.Invalidate()
        End Select
    End Sub
 
    Private Sub GlControl1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles GlControl1.MouseUp
        Dim eX As Integer
        Dim eY As Integer
        Select Case EtatBouton
            Case 0
            Case 1
                AXPrec = AX
                AYPrec = AY
            Case 2
                PXPrec = PX
                PYPrec = PY
                PZPrec = PZ
        End Select
 
        EtatBouton = 0
        eX = e.X
        eY = e.Y
    End Sub
 
    Private Sub Visu3D_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
        Dim eX As Integer
        Dim eY As Integer
        eX = e.X
        eY = e.Y
    End Sub
 
    Private Sub GlControl1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
        If Debut Then
            AX = 0
            AY = 0
            PX = 0
            PY = 0
            Call Init3D(AX, AY, PX, PY, PZ)
            Debut = False
        Else
            'ICI C'EST DEBILE : on créé toute la scène à chaque fois
            'alors qu'il faudrait juste la déplacer si AX, AY, PX, PY, PZ changent)
            'et l'afficher
 
            Call Init3D(AX, AY, PX, PY, PZ)
        End If
    End Sub
 
    Private Sub Init3D(AX As Double, AY As Double, PX As Single, PY As Single, PZ As Single)
        'First Clear Buffers
        GL.Clear(ClearBufferMask.ColorBufferBit)
        GL.Clear(ClearBufferMask.DepthBufferBit)
 
        Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.04, 4 / 3, 1, 10000) 'Setup Perspective
        Dim lookat As Matrix4 = Matrix4.LookAt(100, 20, 0, 0, 0, 0, 0, 1, 0) 'Setup camera
        GL.MatrixMode(MatrixMode.Projection) 'Load Perspective
        GL.LoadIdentity()
        GL.LoadMatrix(perspective)
        GL.MatrixMode(MatrixMode.Modelview) 'Load Camera
        GL.LoadIdentity()
        GL.LoadMatrix(lookat)
        GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height) 'Size of window
        GL.Enable(EnableCap.DepthTest) 'Enable correct Z Drawings
        GL.DepthFunc(DepthFunction.Less) 'Enable correct Z Drawings
 
        'Rotating
        'GL.Rotate(NumericUpDown1.Value, 0, 0, 1)
        'GL.Rotate(NumericUpDown2.Value, 0, 1, 0)
        GL.Rotate(AX, 0, 1, 0)
        GL.Rotate(AY, 0, 0, 1)
 
        'Draw pyramid, Y is up, Z is twards you, X is left and right
        'Vertex goes (X,Y,Z)
        GL.Begin(BeginMode.Triangles)
        'Face 1
        GL.Color3(Color.Red)
        GL.Vertex3(50 + PX, 0 + PY, 0 + PZ)
        GL.Color3(Color.Red)
        GL.Vertex3(0 + PX, 25 + PY, 0 + PZ)
        GL.Color3(Color.Red)
        GL.Vertex3(0 + PX, 0 + PY, 50 + PZ)
        'Face 2
        GL.Color3(Color.Green)
        GL.Vertex3(-50 + PX, 0 + PY, 0 + PZ)
        GL.Color3(Color.Green)
        GL.Vertex3(0 + PX, 25 + PY, 0 + PZ)
        GL.Color3(Color.Green)
        GL.Vertex3(0 + PX, 0 + PY, 50 + PZ)
        'Face 3
        GL.Color3(Color.White)
        GL.Vertex3(50 + PX, 0 + PY, 0 + PZ)
        GL.Color3(Color.White)
        GL.Vertex3(0 + PX, 25 + PY, 0 + PZ)
        GL.Color3(Color.White)
        GL.Vertex3(0 + PX, 0 + PY, -50 + PZ)
        'Face 4
        GL.Color3(Color.Blue)
        GL.Vertex3(-50 + PX, 0 + PY, 0 + PZ)
        GL.Color3(Color.Blue)
        GL.Vertex3(0 + PX, 25 + PY, 0 + PZ)
        GL.Color3(Color.Blue)
        GL.Vertex3(0 + PX, 0 + PY, -50 + PZ)
        'Finish the begin mode with "end"
        GL.End()
 
        'Finally...
        GraphicsContext.CurrentContext.VSync = True 'Caps frame rate as to not over run GPU
        GlControl1.SwapBuffers() 'Takes from the 'GL' and puts into control
    End Sub
 
 
End Class

Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
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
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Visu3D
    Inherits System.Windows.Forms.Form
 
    'Form remplace la méthode Dispose pour nettoyer la liste des composants.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
 
    'Requise par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer
 
    'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
    'Elle peut être modifiée à l'aide du Concepteur Windows Form.  
    'Ne la modifiez pas à l'aide de l'éditeur de code.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.GlControl1 = New OpenTK.GLControl()
        Me.SuspendLayout()
        '
        'GlControl1
        '
        Me.GlControl1.BackColor = System.Drawing.Color.Black
        Me.GlControl1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GlControl1.Location = New System.Drawing.Point(0, 0)
        Me.GlControl1.Name = "GlControl1"
        Me.GlControl1.Size = New System.Drawing.Size(627, 519)
        Me.GlControl1.TabIndex = 0
        Me.GlControl1.VSync = False
        '
        'Visu3D
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(627, 519)
        Me.Controls.Add(Me.GlControl1)
        Me.Name = "Visu3D"
        Me.Text = "Visu3D"
        Me.ResumeLayout(False)
 
    End Sub
    Friend WithEvents GlControl1 As OpenTK.GLControl
End Class