File size: 1,914 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # SPDX-License-Identifier: LGPL-2.1-or-later
# (c) 2012 Werner Mayer LGPL
import FreeCAD, FreeCADGui
from pivy import coin
class Texture:
def __init__(self, obj, source):
"Add some custom properties to our box feature"
obj.addProperty("App::PropertyLink","Source","Texture", "Link to the shape", locked=True).Source = source
obj.Proxy = self
def onChanged(self, fp, prop):
return
def execute(self, fp):
return
class ViewProviderTexture:
def __init__(self, obj):
obj.addProperty("App::PropertyPath","File","Texture", "File name to the texture resource", locked=True)
self.obj = obj
obj.Proxy = self
def onChanged(self, obj, prop):
if prop == "File":
self.tex.filename = str(obj.File)
return
def updateData(self, fp, prop):
return
def getDisplayModes(self,obj):
''' Return a list of display modes. '''
modes=["Texture"]
return modes
def attach(self, obj):
self.grp = coin.SoGroup()
self.tex = coin.SoTexture2()
#self.env = coin.SoTextureCoordinateEnvironment()
self.grp.addChild(self.tex)
#self.grp.addChild(self.env)
root = obj.Object.Source.ViewObject.RootNode
self.grp.addChild(root)
obj.addDisplayMode(self.grp,"Texture")
# move the original node
doc = obj.Object.Document
doc = FreeCADGui.getDocument(doc.Name)
graph = doc.ActiveView.getSceneGraph()
graph.removeChild(root)
def claimChildren(self):
return [self.obj.Object.Source]
def __getstate__(self):
return None
def __setstate__(self,state):
return None
def makeTexture():
FreeCAD.newDocument()
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
tex=FreeCAD.ActiveDocument.addObject("App::FeaturePython","Texture")
Texture(tex, box)
box.ViewObject.Selectable = False
ViewProviderTexture(tex.ViewObject)
box.touch()
FreeCAD.ActiveDocument.recompute()
|