Home › Forum › SOFA › Using SOFA › [SOLVED] How to change the texture of OglModel at runtime?
Tagged: 64_bits, change texture, runtime, SOFA_1712, Windows_10
- This topic has 5 replies, 2 voices, and was last updated 5 years, 11 months ago by Hugo.
-
AuthorPosts
-
8 January 2019 at 08:46 #12734WongBlocked
Hello everyone,
I want to change the texture of OglModel using PNG at runtime but I do not know how to do it.
Could anyone give me some help?
Wong
9 January 2019 at 14:27 #12743HugoKeymasterDear @outtt
I don’t think the OglModel can handle changes in its input texture.
Would you like to script this change of texture in Python, or code it in cpp ?Hugo
10 January 2019 at 05:35 #1274810 January 2019 at 18:13 #12755HugoKeymasterHey @outtt
I am fine with helping you, but you should learn coding in Python since it is extremely useful in SOFA. Here is what I would write to test if it works (do not forget to use the PythonScriptController in your xml scene).
XML (inspired from the example examples/Components/visualmodel/OglModel.scn)<?xml version="1.0"?> <Node name="root" dt="0.01"> <RequiredPlugin name="SofaPython" pluginName="SofaPython" /> <PythonScriptController filename="model.py" classname="ChangeTexture" listening="true"/> <OglModel name="VisualModel" fileMesh="mesh/raptor_8kp.obj" texturename="/data/Softwares/sofa/src/master/share/textures/bubble_skin.bmp" translation="30 0 0" useNormals="0"/> <MeshObjLoader name="loader" filename="mesh/raptor_8kp.obj" translation="0 0 0"/> <OglModel name="VisualModel2" src="@loader" color="red"/> </Node>
Python:
import sys import Sofa class ChangeTexture(Sofa.PythonScriptController): def initGraph(self,node): print 'initGraph called (python side)' self.VM=node.getObject('VisualModel') return 0 def onKeyPressed(self,k): if k=="M" : self.VM.findData('texturename').value='/data/Softwares/sofa/src/master/share/textures/brushed_metal.bmp' self.VM.init() self.VM.initVisual() return 0
Dear @outtt, do you know whether GDUT would be ready to support the open-source project SOFA? Many ways are available to support the open-source initiative : donations, memberships, projects.
And many non-profit ways also exist like feature contributions, communication about your plugins (conferences, youtube, linkedin, twitter) and setup collaborations with the community!Best,
Hugo
11 January 2019 at 11:09 #12764WongBlockedHello @hugo,
Thank you for your reply hugo. I once tried to use the similar code but it did not work because I omitted the initVisual() function!
By the way, GDUT is my College that I once attended, but now I have graduated.
However, I am interested about the memberships. So can and how can I join in?
But I still need more help because Sofa is still difficult for me, you know. So can I communicate with other developers if I join in?
Wong
11 January 2019 at 11:36 #12767HugoKeymasterDear Wong,
I will tell you more in details about the memberships in a private email. But most information is available online.
Regarding developer room, note that we recently setup a Gitter room. This room is dedicated to developers, for development questions. So if you have such developer questions, do not hesitate to join. For user question, the forum is the right place to be.
Note that scripting in Python is not really considered as SOFA development.Best regards,
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.