Skip to content

Instantly share code, notes, and snippets.

@yorikvanhavre
Created July 8, 2013 22:41
Show Gist options
  • Save yorikvanhavre/5953106 to your computer and use it in GitHub Desktop.
Save yorikvanhavre/5953106 to your computer and use it in GitHub Desktop.
How to scale a texture with pivy. Last method (using a SoTextureCoordinatePlane) allows to give a scale independently of the size of the object
Python 2.7.5+ (default, Jun 2 2013, 13:28:26)
[GCC 4.7.3] on linux2
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> App.setActiveDocument("Unnamed")
>>> App.ActiveDocument=App.getDocument("Unnamed")
>>> Gui.ActiveDocument=Gui.getDocument("Unnamed")
>>> import Draft
>>> pl = FreeCAD.Placement()
>>> pl.Rotation.Q = (0.0,-0.0,-0.0,1.0)
>>> pl.Base = FreeCAD.Vector(-1.33731794357,0.644989609718,0.0)
>>> Draft.makeRectangle(length=2.98825466633,height=-1.70419287682,placement=pl,face=False,support=None)
>>> import Draft
>>> i=Draft.loadTexture(":/patterns/simple.svg",256)
>>> from pivy import coin
>>> t=coin.SoTexture2()
>>> t.image=i
>>> o=App.ActiveDocument.ActiveObject
>>> r=o.ViewObject.RootNode
>>> r.insertChild(t,0)
>>> p=coin.SoTexture2Transform()
>>> p.scale
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/yorik/Apps/FreeCAD/bin/pivy/coin.py", line 3706, in __getattr__
raise e
AttributeError: 'SoTexture2Transform' object has no attribute 'scale'
>>> p.x
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/yorik/Apps/FreeCAD/bin/pivy/coin.py", line 3706, in __getattr__
raise e
AttributeError: 'SoTexture2Transform' object has no attribute 'x'
>>> p
<pivy.coin.SoTexture2Transform; proxy of <Swig Object of type 'SoTexture2Transform *' at 0x4ae2bc0> >
>>> p.scaleFactor
<pivy.coin.SoSFVec2f; proxy of <Swig Object of type 'SoSFVec2f *' at 0x4ae2c50> >
>>> p.scaleFactor.setValue(2)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/yorik/Apps/FreeCAD/bin/pivy/coin.py", line 17692, in setValue
return _coin.SoSFVec2f_setValue(*args)
NotImplementedError: Wrong number of arguments for overloaded function 'SoSFVec2f_setValue'.
Possible C/C++ prototypes are:
setValue(SoSFVec2f *,SbVec2f const &)
setValue(SoSFVec2f *,float,float)
setValue(SoSFVec2f *,float const [2])
setValue(SoSFVec2f *,SoSFVec2f const *)
>>> p.scaleFactor.setValue(2.0)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/yorik/Apps/FreeCAD/bin/pivy/coin.py", line 17692, in setValue
return _coin.SoSFVec2f_setValue(*args)
NotImplementedError: Wrong number of arguments for overloaded function 'SoSFVec2f_setValue'.
Possible C/C++ prototypes are:
setValue(SoSFVec2f *,SbVec2f const &)
setValue(SoSFVec2f *,float,float)
setValue(SoSFVec2f *,float const [2])
setValue(SoSFVec2f *,SoSFVec2f const *)
>>> p.scaleFactor.setValue([2,2])
>>> r.insertChild(p,1)
>>> p.scaleFactor.setValue([2,3])
>>> p.scaleFactor.setValue([4,3])
>>> Gui.activeDocument().activeView().viewTop()
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 3.00
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Height = -1.70
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 4.00
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Height = 3.00
>>> r.removeChild(p)
>>> p = coin.SoTextureCoordinatePlane()
>>> p.directionS
<pivy.coin.SoSFVec3f; proxy of <Swig Object of type 'SoSFVec3f *' at 0x4fd2220> >
>>> p.directionS.setValue(1,0,0)
>>> p.directionT.setValue(0,1,0)
>>> r.insertChild(p,1)
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 5.00
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 1.00
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 10.00
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 1.00
>>> FreeCAD.getDocument("Unnamed").getObject("Rectangle").Length = 10.00
>>> p.directionS.setValue(2,0,0)
>>> p.directionT.setValue(0,2,0)
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment