Forum Replies Created
-
AuthorPosts
-
27 October 2021 at 19:27 in reply to: Visual not updating when using with a GLFW window (ImGUI) #20702BrunoB81HKBlocked
Hi @Froy
I’ve tried what you proposed to me and here is the follow-up.
My plugin class now inherit VisualModel. I put my
initTrexUI()
ininitVisual()
and mydrawTrexUI()
indrawVisual()
and I came up with some issues.Just as a reminder:
* If I call
drawTrexUI()
in my component’sdraw()
method, my scene visuals models are rendered, but every other model aren’t. If I want to display the force field or the collision model, they won’t render. The scene still works as intended tho.* If I call
drawTrexUI()
on the AnimationEndEvent or the AnimationBeginEvent, everything is rendered, but the visual models doesn’t move. It’s like they are frozen at their first frame. Apart from that, the scene works as intended.* Also, I should add that on either of those solutions, the background needed to be set from runSofa to have a custom one. Those set from the .scn files were not rendering (the paths was in the
Viewer/Image
tab on runSofa, but I needed to select it and press enter to make it change).With that in mind, with the changes done, I get my custom window to work flawlessly, but the main runSofa windows won’t show any models. Something that is also strange is that it displays the right background this time around. I tried to put the
drawTrexUI()
method insideupdateVisual()
, but I get the following error at runtime:ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile vertex shader! 0:2(1): error: <code>in' qualifier in declaration of</code>Position' only valid for function parameters in GLSL 1.10 0:3(1): error: <code>in' qualifier in declaration of</code>UV' only valid for function parameters in GLSL 1.10 0:4(1): error: <code>in' qualifier in declaration of</code>Color' only valid for function parameters in GLSL 1.10 0:5(1): error: <code>out' qualifier in declaration of</code>Frag_UV' only valid for function parameters in GLSL 1.10 0:6(1): error: <code>out' qualifier in declaration of</code>Frag_Color' only valid for function parameters in GLSL 1.10 ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile fragment shader! 0:2(1): error: <code>in' qualifier in declaration of</code>Frag_UV' only valid for function parameters in GLSL 1.10 0:3(1): error: <code>in' qualifier in declaration of</code>Frag_Color' only valid for function parameters in GLSL 1.10 0:4(1): error: <code>out' qualifier in declaration of</code>Out_Color' only valid for function parameters in GLSL 1.10 0:7(27): error: no function with name 'texture' 0:7(14): error: operands to arithmetic operators must be numeric ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link shader program! (with GLSL '') error: linking with uncompiled/unspecialized shadererror: linking with uncompiled/unspecialized shader
Do you have any ideas what is causing all this? What should I try next?
Thanks a lot for your help!
Bruno
1 October 2021 at 18:02 in reply to: Visual not updating when using with a GLFW window (ImGUI) #20481BrunoB81HKBlockedHi @Froy
– Using
runSofa -l SofaGLFW
is working so that’s a good thing.– In the next weeks, I’ll try what you’re proposing.
Thanks a lot for your input!
Bruno
BrunoB81HKBlockedHi @hugo,
This topics was incorrectly flagged as solved. Do you have any idea on what I should do to solve this?
Thanks a lot,
Bruno
BrunoB81HKBlockedI’ve now switched to Sofa v21.06 and I’m trying to use SofaGLFW. I’ve been able to build it and run
runSofaGLFW
. When I’m trying to run my scenes withrunSofaGLFW -f /my/scene.scn
, I get a black window along with my custom window using ImGUI which work as intended.I changed my code so that the initialization and termination of GLFW is handled by
runSofaGLFW
.Called in my plugin’s
init()
method ;void SofaTrexConnector::initTrexUI() { /*glfwSetErrorCallback(glfw_error_callback); glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);*/ // Create window with graphics context this->m_trexWindow = glfwCreateWindow(SOFATREX_CONFIG_WINDOW_INIT_SIZE, "TrexGui Controls", NULL, NULL); glfwMakeContextCurrent(this->m_trexWindow); glfwSwapInterval(0); // remove the fps cap // Initialize OpenGL loader /*bool err = glewInit() != GLEW_OK; if (err) { msg_error("glew") << stderr << "Failed to initialize OpenGL loader!\n"; }*/ // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImPlot::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; // Setup Dear ImGui style ImGui::StyleColorsDark(); // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOpenGL(this->m_trexWindow, true); ImGui_ImplOpenGL3_Init("#version 130"); // Set the window flags this->m_trexWindowFlags |= ImGuiWindowFlags_NoScrollbar; this->m_trexWindowFlags |= ImGuiWindowFlags_NoCollapse; this->m_trexWindowFlags |= ImGuiWindowFlags_NoBackground; this->m_trexWindowFlags |= ImGuiWindowFlags_NoMove; this->m_trexWindowFlags |= ImGuiWindowFlags_NoResize;
Called in my plugin’s
draw()
method or inhandleEvent
with anAnimationEndEvent
or anAnimationBeginEvent
:void SofaTrexConnector::drawTrexUI() { glfwMakeContextCurrent(this->m_trexWindow); glfwPollEvents(); // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); ImGui::SetNextWindowPos({SOFATREX_CONFIG_CONTROL_WINDOWS_POSITION}, ImGuiCond_Once); ImGui::SetNextWindowSize({SOFATREX_CONFIG_CONTROL_WINDOWS_SIZE}, ImGuiCond_Once); ImGui::Begin("Trex controls", NULL, this->m_trexWindowFlags); ... // Widgets definitions ImGui::End(); // Trex controls // Rendering ImGui::Render(); int display_w, display_h; glfwGetFramebufferSize(this->m_trexWindow, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(this->m_trexWindow); }
Called in my plugin’s destructor :
void SofaTrexConnector::clearTrexUI() { // ImGUI cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImPlot::DestroyContext(); ImGui::DestroyContext(); glfwDestroyWindow(this->m_trexWindow); //glfwTerminate(); }
I don’t really know what to try next. What should I do?
Thanks a lot and have a nice day!
P.S. I don’t know if it’s related, but it seems like I can’t use
runSofa -g glfw
. I get :[ERROR] [GUIManager] GUI 'glfw' creation failed.
.P.P.S Also, I don’t know if it’s related, but when using
runSofaGLFW
, I get every message twice in the console :/home/busb2601/sofa/build/v21.06/bin/runSofaGLFW -a -f /home/busb2601/sofa/ext_plugin_repo/SofaTrex/scenes/Empty/PokeRefEmpty.scn [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaTrex.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaTrex.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaGraphComponent.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaGraphComponent.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaOpenglVisual.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaOpenglVisual.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaHaptics.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaHaptics.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaBoundaryCondition.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaBoundaryCondition.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaConstraint.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaConstraint.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaImplicitOdeSolver.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaImplicitOdeSolver.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaLoader.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaLoader.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaMeshCollision.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaMeshCollision.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaRigid.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaRigid.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaSimpleFem.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaSimpleFem.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaGeneralDeformable.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaGeneralDeformable.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaUserInteraction.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaUserInteraction.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaDeformable.so [INFO] [PluginManager] Loaded plugin: /home/busb2601/sofa/build/v21.06/lib/libSofaDeformable.so [WARNING] [InteractiveCamera(baseCamera)] Too many missing parameters ; taking default ... [WARNING] [InteractiveCamera(baseCamera)] Too many missing parameters ; taking default ... [INFO] [SofaTrexConnector(TrexDriver)] Cleaning Trex mess... [INFO] [SofaTrexConnector(TrexDriver)] Cleaning Trex mess... Process finished with exit code 0
BrunoB81HKBlockedHi @hugo,
Sorry for the late answer. It seems your fix is working. I changed the following line
<UncoupledConstraintCorrection/>
to
<UncoupledConstraintCorrection compliance="0.5 0.5 0.0 0.0 0.5 0.0 0.5"/>
I will take the time to play with the values more to determine which is the best for me.
Thanks a lot for your help!
Bruno
BrunoB81HKBlockedBrunoB81HKBlockedHi @hugo
When I replace it, I get other component that aren’t found.
I guess I’ll wait until the next stable release of SOFA (21.06).
Thank you and see you then!
BrunoB81HKBlockedHi @hugo
When setting those to 0, the instrument will go thru the liver much faster. Normally, the force peak at 0.6N, but it now peak at ~0.16N
Just to be clear, the behavior change when I change the stiffness, the collision instrument is faster to follow the reference if I use a greater stiffness. It is just the computed force that stays the same. I feel like, if the spring between the reference and the collision instrument is bigger, the computed force should be greater for a given displacement. Am I wrong?
Thanks a lot for your help!
Bruno
BrunoB81HKBlockedHi @hugo
Thanks for your answer. I’ve seen SOFA_GLFW but I haven’t been able to make it work. I’m not using the master branch so I guess it would been hard to make it work on my setup. I look very interesting and I think it could help me solve my problem.
When I try to configure with CMake, I get the following error :
Could not find a package configuration file provided by "Sofa.Config" with any of the following names: Sofa.ConfigConfig.cmake sofa.config-config.cmake
I added this with the external plugin repo.
Thanks a lot and have a nice day!
Bruno
BrunoB81HKBlockedHi @hugo
Just tried the method based on the Geomagic Driver and it works like a charm. This is everything I want.
Thanks a lot for your help and have a nice day!
Bruno
BrunoB81HKBlockedHi @hugo
I finally had the time to thinker with a TransformEngine. It looks like its what I want, although I am not ale to use it from c++.
I now retrieve the pointer (
m_instrument
) to the TransformEngine instead of the MechanicalObject. I thought that I could usem_instrument->translation.setValue()
to set the desired position, butm_instrument->translation
is a protected member. I wanted to see if it was the only thing stopping me from using this method, so I setm_instrument->translation
as a public member in TransformEngine.h. This method did work as I wanted it to.Since I changed a part of the source code and I didn’t like it, I reverted the changes and tried to create my own
TrexTransformEngine
which is inherited fromTransformEngine
.After a lot of tinkering, I came up with a solution. Here is my code :
#pragma once #include <SofaGeneralEngine/TransformEngine.h> #include <sofa/core/ObjectFactory.h> namespace sofa::component::engine { template <class DataTypes> class TrexTransformEngine : public TransformEngine<DataTypes> { public: SOFA_CLASS(SOFA_TEMPLATE(TrexTransformEngine, DataTypes), SOFA_TEMPLATE(TransformEngine, DataTypes)); protected: TrexTransformEngine() : TransformEngine<DataTypes>{ } {}; ~TrexTransformEngine() override {} public: void setTranslation(defaulttype::Vector3 trans) { this->translation.setValue(trans); } void setQuaternion(defaulttype::Quaternion quat) { this->quaternion.setValue(quat); } }; int TrexTransformEngineClass = core::RegisterObject("Transform engine to help move the instrument.") .add< TrexTransformEngine<defaulttype::Rigid3Types> >(true) // default template .add< TrexTransformEngine<defaulttype::Vec1Types> >() .add< TrexTransformEngine<defaulttype::Vec2Types> >() .add< TrexTransformEngine<defaulttype::Vec3Types> >() .add< TrexTransformEngine<defaulttype::Rigid2Types> >() ; template class TrexTransformEngine<defaulttype::Vec1Types>; template class TrexTransformEngine<defaulttype::Vec2Types>; template class TrexTransformEngine<defaulttype::Vec3Types>; template class TrexTransformEngine<defaulttype::Rigid2Types>; template class TrexTransformEngine<defaulttype::Rigid3Types>; } //namespace sofa::component::engine
Is this a good way to do such a thing?
Thanks a lot for your help and have a nice day!
Bruno
BrunoB81HKBlockedHi @hugo
Things are moving pretty fast here. This task is still in my backlog. I should be able to try it soon.
Have a nice day!
Bruno
BrunoB81HKBlockedHi @hugo
Thanks a lot for the answer!
I will try it later this week and I’ll keep you posted.
Have a nice day!
Bruno
BrunoB81HKBlockedBrunoB81HKBlockedHi @olivier-goury,
I’m building a scene in python and I try to compute the forces like you wrote there. I’m having trouble finding lambda. Can you Go further in your explanation of how to get the lambda?
Also, there is a Data in the GenericConstraintSolver that is named constraintForces and they doesn’t seems to be the constaints forces. What are they?
Thanks a lot for your help!
Bruno
BrunoB81HKBlockedI’m using the master version.
The install procedure is special for this one. It require us to
git submodule add
the plugin and its dependencies inapplications\plugins
:`shell
git submodule add https://github.com/SofaDefrost/STLIB.git applications/plugins/STLIB
git submodule add https://github.com/faichele/SoftRobots.git applications/plugins/SoftRobots
git submodule add https://github.com/faichele/SofaROSConnector.git applications/plugins/SofaROSConnector
`
What I have done is that I used EXTERNAL_DIR for STLIB and SoftRobots, but I used
git submodule add
for SofaROSConnector since the cmake files kind of require it to be in this directory.I hope it helps you,
Bruno
BrunoB81HKBlockedHi @hugo,
I haven’t solved this issue yet. I think the error might be related to the fact that SafoROSConnector is written to work with an earlier version of boost. I think signals has been replaced with signals2.
Is there anything I should do with FindBoostCMake?
Thanks for your help!
Bruno
BrunoB81HKBlockedI’m using the one from https://github.com/faichele/SoftRobots which is the one required to work with the SofaROSConnector plugin.
I realise tat this one is a fork that is behind the other one.
Thanks,
Bruno
BrunoB81HKBlockedIt’s fine for me!
Thanks a lot!
BrunoB81HKBlockedSorry for the late response, I’m using the master branch.
BrunoB81HKBlockedI had the same problem and I solved it with @hugo. To solve it, go in
fixed_array.h
by double-clicking on the error, and add#include <iostream>
.The top of your file should look like this :
#ifndef SOFA_HELPER_FIXED_ARRAY_H #define SOFA_HELPER_FIXED_ARRAY_H #include <sofa/helper/system/config.h> #include <sofa/helper/helper.h> #include <cstddef> #include <stdexcept> #include <iterator> #include <algorithm> #include <cmath> #include <cassert> #include <iostream>
Let me know if it solved your problem.
BrunoB81HKBlockedIt worked! I changed
sofa_copy_libraries_from_targets(Qt5::Network)
withsofa_install_libraries(TARGETS Qt5::Network)
BrunoB81HKBlockedI’m using SOFA 19.12 with the last version of SoftRobots (I can’t find the version). I’m building it with SOFA_EXTERNAL_DIRECTORIES.
BrunoB81HKBlockedHi,
I have the exact same problem as John. How can I resolve this issue?
Thanks a lot,
Bruno
-
AuthorPosts