From 942e0d65f3c58137112c86afe825a4b53751ac98 Mon Sep 17 00:00:00 2001 From: Pascal Schedel Date: Tue, 2 Jul 2019 06:31:34 +0200 Subject: [PATCH 1/4] 190702 c1 --- .../Preview/ModelPreview.vb | 115 ++++++++++++------ .../Rendering/Renderer.vb | 5 +- 2 files changed, 80 insertions(+), 40 deletions(-) diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb index 85b4b8b..2990e15 100644 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb @@ -6,6 +6,9 @@ Imports OpenTK Imports OpenTK.Graphics.OpenGL Imports Pilz.S3DFileParser Imports Point = System.Drawing.Point +Imports KeyboardState = OpenTK.Input.KeyboardState +Imports Keyboard = OpenTK.Input.Keyboard +Imports Key = OpenTK.Input.Key Namespace PreviewN @@ -20,7 +23,7 @@ Namespace PreviewN Private camMtx As Matrix4 = Matrix4.Identity Private savedCamPos As New Vector3 Private _isMouseDown As Boolean = False - Private myPressedKeys As New List(Of Keys) + 'Private myPressedKeys As New List(Of Keys) Private isDeactivated As Boolean = False Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer) @@ -29,11 +32,11 @@ Namespace PreviewN Public Property Scaling As Single = 500.0F Public Property ClearColor As Color = Color.CornflowerBlue - Public ReadOnly Property PressedKeys As IReadOnlyList(Of Keys) - Get - Return myPressedKeys - End Get - End Property + 'Public ReadOnly Property PressedKeys As IReadOnlyList(Of Keys) + ' Get + ' Return myPressedKeys + ' End Get + 'End Property Public ReadOnly Property Camera As Camera Get @@ -55,13 +58,17 @@ Namespace PreviewN Private ReadOnly Property IsStrgPressed As Boolean Get - Return myPressedKeys.Contains(Keys.ControlKey) + 'Return myPressedKeys.Contains(Keys.ControlKey) + Dim state As KeyboardState = Keyboard.GetState() + Return state(Key.ControlLeft) OrElse state(Key.ControlRight) End Get End Property Private ReadOnly Property IsShiftPressed As Boolean Get - Return myPressedKeys.Contains(Keys.ShiftKey) + 'Return myPressedKeys.Contains(Keys.ShiftKey) + Dim state As KeyboardState = Keyboard.GetState() + Return state(Key.ShiftLeft) OrElse state(Key.ShiftRight) End Get End Property @@ -286,44 +293,74 @@ UVs:{0}{0}{5}", End If End Sub - Public Sub HandlesOnKeyDown(sender As Object, e As KeyEventArgs) Handles glControl1.KeyDown - If Not myPressedKeys.Contains(e.KeyCode) Then myPressedKeys.Add(e.KeyCode) - End Sub + 'Public Sub HandlesOnKeyDown(sender As Object, e As KeyEventArgs) Handles glControl1.KeyDown + ' If Not myPressedKeys.Contains(e.KeyCode) Then myPressedKeys.Add(e.KeyCode) + 'End Sub - Public Sub HandlesOnKeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp - If myPressedKeys.Contains(e.KeyCode) Then myPressedKeys.Remove(e.KeyCode) - End Sub + 'Public Sub HandlesOnKeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp + ' If myPressedKeys.Contains(e.KeyCode) Then myPressedKeys.Remove(e.KeyCode) + 'End Sub Public Sub MoveCameraViaWASDQE() Dim moveSpeed As Integer = Convert.ToInt32(Math.Round((If(IsShiftPressed, 60, 30)) * (MyCamera.CamSpeedMultiplier), 0)) Dim allowCamMove As Boolean = Not (IsMouseDown AndAlso IsShiftPressed) - For Each k As Keys In myPressedKeys - If allowCamMove Then - Select Case k - Case Keys.W - 'camera.Move(moveSpeed, moveSpeed, camMtx) - MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, camMtx) - savedCamPos = MyCamera.Position - Case Keys.S - 'camera.Move(-moveSpeed, -moveSpeed, camMtx) - MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, camMtx) - savedCamPos = MyCamera.Position - Case Keys.A - 'camera.Move(-moveSpeed, 0, camMtx) - MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, camMtx) - Case Keys.D - 'camera.Move(moveSpeed, 0, camMtx) - MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, camMtx) - Case Keys.E - 'camera.Move(0, -moveSpeed, camMtx) - MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, camMtx) - Case Keys.Q - 'camera.Move(0, moveSpeed, camMtx) - MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, camMtx) - End Select + 'For Each k As Keys In myPressedKeys + ' If allowCamMove Then + ' Select Case k + ' Case Keys.W + ' 'camera.Move(moveSpeed, moveSpeed, camMtx) + ' MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, camMtx) + ' savedCamPos = MyCamera.Position + ' Case Keys.S + ' 'camera.Move(-moveSpeed, -moveSpeed, camMtx) + ' MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, camMtx) + ' savedCamPos = MyCamera.Position + ' Case Keys.A + ' 'camera.Move(-moveSpeed, 0, camMtx) + ' MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, camMtx) + ' Case Keys.D + ' 'camera.Move(moveSpeed, 0, camMtx) + ' MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, camMtx) + ' Case Keys.E + ' 'camera.Move(0, -moveSpeed, camMtx) + ' MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, camMtx) + ' Case Keys.Q + ' 'camera.Move(0, moveSpeed, camMtx) + ' MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, camMtx) + ' End Select + ' End If + 'Next + If allowCamMove Then + Dim state As KeyboardState = Keyboard.GetState + + If state(Key.W) Then + 'camera.Move(moveSpeed, moveSpeed, camMtx) + MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, camMtx) + savedCamPos = MyCamera.Position End If - Next + If state(Key.S) Then + 'camera.Move(-moveSpeed, -moveSpeed, camMtx) + MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, camMtx) + savedCamPos = MyCamera.Position + End If + If state(Key.A) Then + 'camera.Move(-moveSpeed, 0, camMtx) + MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, camMtx) + End If + If state(Key.D) Then + 'camera.Move(moveSpeed, 0, camMtx) + MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, camMtx) + End If + If state(Key.E) Then + 'camera.Move(0, -moveSpeed, camMtx) + MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, camMtx) + End If + If state(Key.Q) Then + 'camera.Move(0, moveSpeed, camMtx) + MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, camMtx) + End If + End If End Sub Private Sub Camera_NeedSelectedObject(e As Camera.NeedSelectedObjectEventArgs) Handles MyCamera.NeedSelectedObject diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb index 86eb404..64ccb41 100644 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb @@ -155,7 +155,7 @@ Namespace RenderingN indices.Add(curvi) curvi += 1 - If verts IsNot Nothing Then + If p.Vertex IsNot Nothing Then verts.Add(New Vector3(p.Vertex.X, p.Vertex.Y, p.Vertex.Z)) Else verts.Add(New Vector3(0, 0, 0)) @@ -260,9 +260,11 @@ Namespace RenderingN Public Sub DrawModel(mode As RenderMode) DrawModel(mode, Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling)) End Sub + Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion) DrawModel(mode, pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling)) End Sub + Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion, scale As Vector3) If mode = RenderMode.None Then Return If Not _HasRendered Then Return @@ -277,6 +279,7 @@ Namespace RenderingN GL.EnableClientState(ArrayCap.TextureCoordArray) For Each mesh As Mesh In obj3d.Meshes + If VertexColorBuffers.ContainsKey(mesh) Then GL.EnableClientState(ArrayCap.ColorArray) ElseIf NormalBuffers.ContainsKey(mesh) Then From bf92420624c1bec51086700e08074e88e462acf6 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Wed, 10 Jul 2019 10:34:31 +0000 Subject: [PATCH 2/4] Add README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..44a953d --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# SM64 ROM Manager +A brand new all-in-one SM64 Hacking tool that allows you to import and modify custom levels, edit texts, music and many more! + +## Download & Compile +Let me explain how to get tbe able to compile the source code. + 1. Download the source code + 2. Download the latest version of SM64 ROM Manager. + 3. Copy the "Data" folder from the latest version to the repo folder in "SM64 ROM Manager\SM64 ROM Manager\bin\Debug" to be able to debug this tool. + 4. Go inside the "Shared Libs" folder in the repo folder: "SM64 ROM Manager\Shared Libs" + 5. Double-Click the registry file "DotNetBar_License.reg" to instert it to your registry. + This will install a working license for DotNetBar for SM64 ROM Manager development. + 6. Open the project solution. + 7. Restore the NuGet packages for the whole package. + There is an option for that in Visual Studio by right-click on the project solution and click to "Restore NuGet packages". + 9. Done! + +Now you should be able to compile the source code without problems for private use. + +## Requiements + - Visual Studio 2017 + - .Net Framework 4.5 + - Internet connection (for restoring NuGet packages) From 1d9e47622ad40158d956073250b725b34badca45 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Wed, 10 Jul 2019 10:35:35 +0000 Subject: [PATCH 3/4] Revert "Add README.md" This reverts commit bf92420624c1bec51086700e08074e88e462acf6 --- README.md | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 44a953d..0000000 --- a/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# SM64 ROM Manager -A brand new all-in-one SM64 Hacking tool that allows you to import and modify custom levels, edit texts, music and many more! - -## Download & Compile -Let me explain how to get tbe able to compile the source code. - 1. Download the source code - 2. Download the latest version of SM64 ROM Manager. - 3. Copy the "Data" folder from the latest version to the repo folder in "SM64 ROM Manager\SM64 ROM Manager\bin\Debug" to be able to debug this tool. - 4. Go inside the "Shared Libs" folder in the repo folder: "SM64 ROM Manager\Shared Libs" - 5. Double-Click the registry file "DotNetBar_License.reg" to instert it to your registry. - This will install a working license for DotNetBar for SM64 ROM Manager development. - 6. Open the project solution. - 7. Restore the NuGet packages for the whole package. - There is an option for that in Visual Studio by right-click on the project solution and click to "Restore NuGet packages". - 9. Done! - -Now you should be able to compile the source code without problems for private use. - -## Requiements - - Visual Studio 2017 - - .Net Framework 4.5 - - Internet connection (for restoring NuGet packages) From 766a96bb002e564f021c5081b8c7a2e595648981 Mon Sep 17 00:00:00 2001 From: Denis Kopyrin Date: Sun, 11 Aug 2019 16:37:25 +0000 Subject: [PATCH 4/4] Simple3DFileParser - Assimp takes Transform matrix into account for building Object3D --- .../FileParser/AssimpLoader.vb | 316 +++++++++++------- 1 file changed, 188 insertions(+), 128 deletions(-) diff --git a/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb b/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb index f5df5f5..9dd5fbe 100644 --- a/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb +++ b/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb @@ -3,6 +3,40 @@ Imports Assimp Imports Assimp.Unmanaged Namespace AssimpModule + Structure ConversionContext + Public Sub New(daeMdlP As Scene, upAxis As UpAxis) + daeMdl = daeMdlP + upAxis = upAxis + newMesh = New Mesh + newObj = New Object3D + + newObj.Meshes.Add(newMesh) + + channelIndicies = New Dictionary(Of Material, Integer) + End Sub + + Dim daeMdl As Scene + Dim UpAxis As UpAxis + Dim newMesh As Mesh + Dim newObj As Object3D + Dim channelIndicies As Dictionary(Of Material, Integer) + End Structure + + Structure ParsingContext + Public Sub New(ctx As ConversionContext) + cc = ctx + dicVertices = New Dictionary(Of Vector3D, Vertex) + dicNormals = New Dictionary(Of Vector3D, Normal) + dicUVs = New Dictionary(Of Vector3D, UV) + dicVertexColors = New Dictionary(Of Color4D, VertexColor) + End Sub + + ReadOnly cc As ConversionContext + Dim dicVertices As Dictionary(Of Vector3D, Vertex) + Dim dicNormals As Dictionary(Of Vector3D, Normal) + Dim dicUVs As Dictionary(Of Vector3D, UV) + Dim dicVertexColors As Dictionary(Of Color4D, VertexColor) + End Structure Public Class AssimpLoader @@ -15,14 +49,163 @@ Namespace AssimpModule End If End Sub + Private Shared Sub ComputeNewObj(cc As ConversionContext) + Dim identity As Matrix4x4 = Matrix4x4.Identity + ComputeNode(cc.daeMdl.RootNode, identity, New ParsingContext(cc)) + End Sub + + Private Shared Sub ComputeNode(node As Node, trafo As Matrix4x4, ByRef pc As ParsingContext) + Dim newObj = pc.cc.newObj + Dim newMesh = pc.cc.newMesh + Dim daeMdl = pc.cc.daeMdl + Dim channelIndicies = pc.cc.channelIndicies + Dim UpAxis = pc.cc.UpAxis + Dim dicVertices = pc.dicVertices + Dim dicNormals = pc.dicNormals + Dim dicUVs = pc.dicUVs + Dim dicVertexColors = pc.dicVertexColors + + trafo = trafo * node.Transform + + If node.HasMeshes Then + For Each meshIndex In node.MeshIndices + Dim m As Assimp.Mesh = daeMdl.Meshes(meshIndex) + + Dim curMat As Material + If m.MaterialIndex > -1 AndAlso newObj.Materials.Count > m.MaterialIndex Then + curMat = newObj.Materials.ElementAt(m.MaterialIndex).Value + Else + curMat = Nothing + End If + + For Each untransformedN As Vector3D In m.Normals + Dim n = trafo * untransformedN + If Not dicNormals.ContainsKey(n) Then + Dim newNormal As New Normal + + Select Case UpAxis + Case UpAxis.Y + newNormal.X = n.X + newNormal.Y = n.Y + newNormal.Z = n.Z + Case UpAxis.Z + newNormal.X = n.Y + newNormal.Y = n.Z + newNormal.Z = n.X + End Select + + newMesh.Normals.Add(newNormal) + dicNormals.Add(n, newNormal) + End If + Next + + For Each untranformedV As Vector3D In m.Vertices + Dim v = trafo * untranformedV + If Not dicVertices.ContainsKey(v) Then + Dim newVert As New Vertex + + Select Case UpAxis + Case UpAxis.Y + newVert.X = v.X + newVert.Y = v.Y + newVert.Z = v.Z + Case UpAxis.Z + newVert.X = v.Y + newVert.Y = v.Z + newVert.Z = v.X + End Select + + newMesh.Vertices.Add(newVert) + dicVertices.Add(v, newVert) + End If + Next + + For Each uvList As List(Of Vector3D) In m.TextureCoordinateChannels + For Each uv As Vector3D In uvList + If Not dicUVs.ContainsKey(uv) Then + Dim newUV As New UV + + newUV.U = uv.X + newUV.V = uv.Y + + newMesh.UVs.Add(newUV) + dicUVs.Add(uv, newUV) + End If + Next + Next + + For Each vcList As List(Of Color4D) In m.VertexColorChannels + For Each vc As Color4D In vcList + If Not dicVertexColors.ContainsKey(vc) Then + Dim newVC As New VertexColor + + newVC.R = vc.R + newVC.G = vc.G + newVC.B = vc.B + newVC.A = vc.A + + newMesh.VertexColors.Add(newVC) + dicVertexColors.Add(vc, newVC) + End If + Next + Next + + For Each f As Assimp.Face In m.Faces + If f.HasIndices Then + Dim newFace As New Face With {.Material = curMat} + + For Each index As Integer In f.Indices + If index > -1 Then + Dim newPoint As New Point + + If m.HasVertices Then + Dim v = trafo * m.Vertices(index) + newPoint.Vertex = dicVertices(v) + End If + + If m.HasNormals Then + Dim n = trafo * m.Normals(index) + newPoint.Normal = dicNormals(n) + End If + + If curMat IsNot Nothing AndAlso channelIndicies.ContainsKey(curMat) Then + Dim tkey As Integer = channelIndicies(curMat) + + If m.HasTextureCoords(tkey) Then + newPoint.UV = dicUVs(m.TextureCoordinateChannels(tkey)(index)) + End If + + If m.HasVertexColors(tkey) Then + newPoint.VertexColor = dicVertexColors(m.VertexColorChannels(tkey)(index)) + End If + End If + + newFace.Points.Add(newPoint) + End If + Next + + If newFace.Points.Count = 3 Then + newMesh.Faces.Add(newFace) + End If + End If + Next + Next + End If + + For Each n In node.Children + ComputeNode(n, trafo, pc) + Next + End Sub + Public Shared Function FromFile(fileName As String, LoadMaterials As Boolean, UpAxis As UpAxis) As Object3D Dim LoadedImages As New Dictionary(Of String, Image) - Dim newObj As New Object3D - Dim daeMdl As Scene = Nothing Dim ac As New AssimpContext - Dim channelIndicies As New Dictionary(Of Material, Integer) - daeMdl = ac.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality Or PostProcessSteps.Triangulate) + Dim cc As New ConversionContext(ac.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality Or PostProcessSteps.Triangulate), UpAxis) + + Dim newObj = cc.newObj + Dim daeMdl = cc.daeMdl + Dim channelIndicies = cc.channelIndicies For Each et As EmbeddedTexture In daeMdl.Textures If et.HasCompressedData Then @@ -94,130 +277,7 @@ Namespace AssimpModule newObj.Materials.Add(mat.Name, newMat) Next - Dim newMesh As New Mesh - newObj.Meshes.Add(newMesh) - - Dim dicVertices As New Dictionary(Of Vector3D, Vertex) - Dim dicNormals As New Dictionary(Of Vector3D, Normal) - Dim dicUVs As New Dictionary(Of Vector3D, UV) - Dim dicVertexColors As New Dictionary(Of Color4D, VertexColor) - - For Each m As Assimp.Mesh In daeMdl.Meshes - Dim curMat As Material - If m.MaterialIndex > -1 AndAlso newObj.Materials.Count > m.MaterialIndex Then - curMat = newObj.Materials.ElementAt(m.MaterialIndex).Value - Else - curMat = Nothing - End If - - For Each n As Vector3D In m.Normals - If Not dicNormals.ContainsKey(n) Then - Dim newNormal As New Normal - - Select Case UpAxis - Case UpAxis.Y - newNormal.X = n.X - newNormal.Y = n.Y - newNormal.Z = n.Z - Case UpAxis.Z - newNormal.X = n.Y - newNormal.Y = n.Z - newNormal.Z = n.X - End Select - - newMesh.Normals.Add(newNormal) - dicNormals.Add(n, newNormal) - End If - Next - - For Each v As Vector3D In m.Vertices - If Not dicVertices.ContainsKey(v) Then - Dim newVert As New Vertex - - Select Case UpAxis - Case UpAxis.Y - newVert.X = v.X - newVert.Y = v.Y - newVert.Z = v.Z - Case UpAxis.Z - newVert.X = v.Y - newVert.Y = v.Z - newVert.Z = v.X - End Select - - newMesh.Vertices.Add(newVert) - dicVertices.Add(v, newVert) - End If - Next - - For Each uvList As List(Of Vector3D) In m.TextureCoordinateChannels - For Each uv As Vector3D In uvList - If Not dicUVs.ContainsKey(uv) Then - Dim newUV As New UV - - newUV.U = uv.X - newUV.V = uv.Y - - newMesh.UVs.Add(newUV) - dicUVs.Add(uv, newUV) - End If - Next - Next - - For Each vcList As List(Of Color4D) In m.VertexColorChannels - For Each vc As Color4D In vcList - If Not dicVertexColors.ContainsKey(vc) Then - Dim newVC As New VertexColor - - newVC.R = vc.R - newVC.G = vc.G - newVC.B = vc.B - newVC.A = vc.A - - newMesh.VertexColors.Add(newVC) - dicVertexColors.Add(vc, newVC) - End If - Next - Next - - For Each f As Assimp.Face In m.Faces - If f.HasIndices Then - Dim newFace As New Face With {.Material = curMat} - - For Each index As Integer In f.Indices - If index > -1 Then - Dim newPoint As New Point - - If m.HasVertices Then - newPoint.Vertex = dicVertices(m.Vertices(index)) - End If - - If m.HasNormals Then - newPoint.Normal = dicNormals(m.Normals(index)) - End If - - If curMat IsNot Nothing AndAlso channelIndicies.ContainsKey(curMat) Then - Dim tkey As Integer = channelIndicies(curMat) - - If m.HasTextureCoords(tkey) Then - newPoint.UV = dicUVs(m.TextureCoordinateChannels(tkey)(index)) - End If - - If m.HasVertexColors(tkey) Then - newPoint.VertexColor = dicVertexColors(m.VertexColorChannels(tkey)(index)) - End If - End If - - newFace.Points.Add(newPoint) - End If - Next - - If newFace.Points.Count = 3 Then - newMesh.Faces.Add(newFace) - End If - End If - Next - Next + ComputeNewObj(cc) Return newObj End Function