This commit is contained in:
2020-12-02 16:10:17 +01:00
parent c32ffbbc08
commit badf771c47

View File

@@ -29,6 +29,7 @@ Namespace PreviewN
Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer) Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer)
Private WithEvents RenderTimer As New Timers.Timer(25) With {.AutoReset = True} Private WithEvents RenderTimer As New Timers.Timer(25) With {.AutoReset = True}
Private _EnableCameraControlling As Boolean = False Private _EnableCameraControlling As Boolean = False
Private finishedLoading As Boolean = False
Public Property Scaling As Single = 500.0F Public Property Scaling As Single = 500.0F
Public Property ClearColor As Color = Color.CornflowerBlue Public Property ClearColor As Color = Color.CornflowerBlue
@@ -125,13 +126,12 @@ Namespace PreviewN
End Sub End Sub
Public Sub New(objs As Object3D(), scale As Single) Public Sub New(objs As Object3D(), scale As Single)
Me.SuspendLayout() SuspendLayout()
InitializeComponent() InitializeComponent()
'glControl1 'glControl1
Dim glControl1 As New GLWpfControl Dim glControl1 As New GLWpfControl
glControl1.IsEnabled = False
Dim glControlHost = New ElementHost Dim glControlHost = New ElementHost
glControlHost.BackColor = Color.Black glControlHost.BackColor = Color.Black
glControlHost.Name = "glControl1" glControlHost.Name = "glControl1"
@@ -141,7 +141,6 @@ Namespace PreviewN
glControlHost.MinimumSize = New Size(600, 120) glControlHost.MinimumSize = New Size(600, 120)
glControlHost.TabIndex = 0 glControlHost.TabIndex = 0
glControlHost.TabStop = False glControlHost.TabStop = False
ResumeLayout(False)
Me.glControl1 = glControl1 Me.glControl1 = glControl1
Me.glControlHost = glControlHost Me.glControlHost = glControlHost
@@ -160,14 +159,16 @@ Namespace PreviewN
ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControlHost.Width / glControlHost.Height, 100.0F, 100000.0F) ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControlHost.Width / glControlHost.Height, 100.0F, 100000.0F)
ResumeLayout()
MyCamera.SetCameraMode(CameraMode.FLY, camMtx) MyCamera.SetCameraMode(CameraMode.FLY, camMtx)
MyCamera.UpdateMatrix(camMtx) MyCamera.UpdateMatrix(camMtx)
Me.ResumeLayout()
For Each obj As Object3D In objs For Each obj As Object3D In objs
AddModel(obj) AddModel(obj)
Next Next
finishedLoading = True
End Sub End Sub
Public Sub UpdateOrbitCamera() Public Sub UpdateOrbitCamera()
@@ -177,12 +178,12 @@ Namespace PreviewN
End Sub End Sub
Public Sub UpdateView() Public Sub UpdateView()
If glControl1.IsEnabled Then If glControlHost.Enabled AndAlso finishedLoading Then
Invoke(Sub() InvalidateGL()) Invoke(Sub() InvalidateGL())
End If End If
End Sub End Sub
Public Sub InvalidateGL() Private Sub InvalidateGL()
glControl1.InvalidateVisual() glControl1.InvalidateVisual()
glControlHost.Invalidate() glControlHost.Invalidate()
End Sub End Sub
@@ -198,7 +199,6 @@ Namespace PreviewN
End Sub End Sub
Public Sub HandlesOnShown(sender As Object, e As EventArgs) Handles MyBase.Shown Public Sub HandlesOnShown(sender As Object, e As EventArgs) Handles MyBase.Shown
glControl1.IsEnabled = True
RenderModels() RenderModels()
InvalidateGL() InvalidateGL()
End Sub End Sub
@@ -248,9 +248,8 @@ Namespace PreviewN
Public Sub HandlesOnPaint(renderTime As TimeSpan) Handles glControl1.Render Public Sub HandlesOnPaint(renderTime As TimeSpan) Handles glControl1.Render
GL.ClearColor(ClearColor) GL.ClearColor(ClearColor)
GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit) GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit)
GL.LoadIdentity()
GL.MatrixMode(MatrixMode.Projection) GL.MatrixMode(MatrixMode.Projection)
GL.LoadMatrix(ProjMatrix) GL.LoadMatrix(ProjMatrix)
GL.MatrixMode(MatrixMode.Modelview) GL.MatrixMode(MatrixMode.Modelview)
@@ -262,6 +261,9 @@ Namespace PreviewN
End If End If
Next Next
GL.End()
GL.Finish()
'glControl1.SwapBuffers() 'glControl1.SwapBuffers()
End Sub End Sub