8 January 2019 at 8 h 46 min #12734
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?
Wong9 January 2019 at 14 h 27 min #12743
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 ?
Hugo10 January 2019 at 5 h 35 min #1274810 January 2019 at 18 h 13 min #12755
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>
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!
Hugo11 January 2019 at 11 h 09 min #12764
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?
Wong11 January 2019 at 11 h 36 min #12767
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.
You must be logged in to reply to this topic.