diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 86f29db..9276659 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -507,40 +507,31 @@ public class RecastDemo cameraPos[1] += (float)((_moveUp - _moveDown) * keySpeed * dt); - // long time = Stopwatch.GetTimestamp(); - // //float dt = (time - prevFrameTime) / TimeSpan.TicksPerMillisecond; - // prevFrameTime = time; - // - // // Update sample simulation. - // float SIM_RATE = 20; - // float DELTA_TIME = 1.0f / SIM_RATE; - // timeAcc = clamp((float)(timeAcc + dt), -1.0f, 1.0f); - // int simIter = 0; - // while (timeAcc > DELTA_TIME) - // { - // timeAcc -= DELTA_TIME; - // if (simIter < 5 && sample != null) - // { - // toolsUI.handleUpdate((float)dt); - // } - // - // simIter++; - // } + long time = Stopwatch.GetTimestamp(); + // float dt = (time - prevFrameTime) / TimeSpan.TicksPerMillisecond; + prevFrameTime = time; + + // Update sample simulation. + float SIM_RATE = 20; + float DELTA_TIME = 1.0f / SIM_RATE; + timeAcc = clamp((float)(timeAcc + dt), -1.0f, 1.0f); + int simIter = 0; + while (timeAcc > DELTA_TIME) + { + timeAcc -= DELTA_TIME; + if (simIter < 5 && sample != null) + { + toolsUI.handleUpdate((float)dt); + } + + simIter++; + } - // if (settingsUI.isMeshInputTrigerred()) - // { - // aFilterPatterns.put(stack.UTF8("*.obj")); - // aFilterPatterns.flip(); - // string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Mesh File", "", aFilterPatterns, - // "Mesh File (*.obj)", false); - // if (filename != null) { - // try (InputStream stream = new FileInputStream(filename)) { - // sample.update(loadInputMesh(stream), null, null); - // } catch (IOException e) { - // Console.WriteLine(e).printStackTrace(); - // } - // } - // } + if (settingsUI.isMeshInputTrigerred()) + { + var bytes = Loader.ToBytes(settingsUI.GetMeshInputFilePath()); + sample.update(loadInputMesh(bytes), null, null); + } // else if (settingsUI.isNavMeshInputTrigerred()) // { // try (MemoryStack stack = stackPush()) { diff --git a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs index b6e570f..6a7694b 100644 --- a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs @@ -68,6 +68,8 @@ public class RcSettingsView : IRcView private int drawModeIdx = DrawMode.DRAWMODE_NAVMESH.Idx; private DrawMode drawMode = DrawMode.DRAWMODE_NAVMESH; + + private string meshInputFilePath; private bool meshInputTrigerred; private bool navMeshInputTrigerred; @@ -90,14 +92,19 @@ public class RcSettingsView : IRcView bool loadSourceGeomPopup = true; if (ImGui.BeginPopupModal(strLoadSourceGeom, ref loadSourceGeomPopup, ImGuiWindowFlags.NoTitleBar)) { - var picker = ImFilePicker.GetFilePicker(strLoadSourceGeom, Path.Combine(Environment.CurrentDirectory)); + var picker = ImFilePicker.GetFilePicker(strLoadSourceGeom, Path.Combine(Environment.CurrentDirectory), ".obj"); if (picker.Draw()) { - Console.WriteLine(picker.SelectedFile); + meshInputTrigerred = true; + meshInputFilePath = picker.SelectedFile; ImFilePicker.RemoveFilePicker(strLoadSourceGeom); } ImGui.EndPopup(); } + else + { + meshInputTrigerred = false; + } ImGui.Text($"Verts: {voxels[0]} Tris: {voxels[1]}"); ImGui.NewLine(); @@ -349,6 +356,11 @@ public class RcSettingsView : IRcView return meshInputTrigerred; } + public string GetMeshInputFilePath() + { + return meshInputFilePath; + } + public bool isNavMeshInputTrigerred() { return navMeshInputTrigerred;