protected override void OnLoad() { //var unptr = Assimp.Unmanaged.AssimpLibrary.Instance.ImportFile(JointPath, Assimp.PostProcessSteps.None, Assimp.Unmanaged.AssimpLibrary.Instance.CreatePropertyStore()); //var manptr = Assimp.Scene.FromUnmanagedScene(unptr); //var ptr = Assimp.Unmanaged.AssimpLibrary.Instance.ApplyPostProcessing(unptr, Assimp.PostProcessSteps.Triangulate); //manptr = Assimp.Scene.FromUnmanagedScene(ptr); _dummyColliders = new Collider[100]; _dummyTasks = new Thread[100]; //for (int i = 0; i < 2; i++) //{ // int index = i; // _dummyColliders[index] = PhysicsHandler.CreateKinematicCollider(new BoxShape(0.5f)); // _dummyTasks[index] = new Thread(() => // { // while (true) // { // var mat = Matrix.Identity; // _dummyColliders[index].Body.WorldTransform = mat; // _dummyColliders[index].Body.MotionState.SetWorldTransform(ref mat); // } // }); // _dummyTasks[index].Start(); //} ManipulatorHandler.LoadDefaultModels(); ShaderHandler.InitializeShaders(); // attach ImGUI to this window _imGui = new MainWindowImGui(this); // TODO: make static? // Camera is 6 units back and has the proper aspect ratio _camera = new Camera((float)(0.75 * Size.X / Size.Y), new Vector3(-5, 3, 5), -15, -45); InputHandler.TranslationalWidget = new TranslationalWidget(Vector3.Zero, new (Vector3, Vector4)[3]
private void RenderManipulatorsWindow() { // manipulators window if (ImGui.Begin("Manipulators", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.HorizontalScrollbar)) { ImGui.SetWindowPos(new System.Numerics.Vector2(0, 19)); ImGui.SetWindowSize(new System.Numerics.Vector2((int)(0.25 * Window.Size.X - 2), (int)(0.5 * (Window.Size.Y - 19)))); if (ImGui.Button("Create")) { ImGui.OpenPopup("ManipulatorCreate"); } ImGui.SameLine(); if (ImGui.Button("Remove")) { if (InputHandler.CurrentSelectedObject is Manipulator manipulator) { ManipulatorHandler.Remove(manipulator); } } if (ImGui.BeginPopup("ManipulatorCreate")) { int linksNumber = ManipulatorHandler.DefaultLinksNumber; ImGui.InputInt("Links number", ref linksNumber); float linksLength = ManipulatorHandler.DefaultLinksLength; ImGui.InputFloat("Links length", ref linksLength); if (linksNumber < 2 || linksLength <= 0) { // TODO: handle unallowed cases } else { // memoize parameters ManipulatorHandler.DefaultLinksNumber = linksNumber; ManipulatorHandler.DefaultLinksLength = linksLength; if (ImGui.Button("Create")) { MainWindow.CreateDefaultManipulator(); ImGui.CloseCurrentPopup(); } } ImGui.EndPopup(); } ImGui.Separator(); ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, 5); if (ImGui.BeginChild("ManipulatorList", ImGui.GetContentRegionAvail(), true)) { if (ManipulatorHandler.Count != 0) { for (int i = 0; i < ManipulatorHandler.Count; i++) { var manipulator = ManipulatorHandler.Manipulators[i]; bool manipulatorTreeNodeOpen = ImGui.TreeNodeEx($"Manipulator {i}", _baseTreeNodeFlags | GetTreeNodeSelectionFlag(manipulator)); if (ImGui.IsItemDeactivated() && !ImGui.IsItemToggledOpen()) { UpdateSelection(manipulator); } if (manipulatorTreeNodeOpen) // TODO: refactor, perhaps move all updates to UpdateFrame { for (int j = 0; j < manipulator.Links.Length; j++) { var joint = manipulator.Joints[j]; ImGui.TreeNodeEx($"Joint {j}", _baseTreeLeafFlags | GetTreeNodeSelectionFlag(joint)); if (ImGui.IsItemDeactivated()) { UpdateSelection(joint); } var link = manipulator.Links[j]; ImGui.TreeNodeEx($"Link {j}", _baseTreeLeafFlags | GetTreeNodeSelectionFlag(link)); if (ImGui.IsItemDeactivated()) { UpdateSelection(link); } } var gripper = manipulator.Joints[manipulator.Joints.Length - 1]; ImGui.TreeNodeEx($"Gripper", _baseTreeLeafFlags | GetTreeNodeSelectionFlag(gripper)); if (ImGui.IsItemDeactivated()) { UpdateSelection(gripper); } ImGui.TreePop(); } } } else { ImGui.Text("Empty."); } ImGui.EndChild(); } ImGui.End(); } }