def getTextureForMaterial(self, material): materialName = material.Name if materialName in self.textureData['materials']: materialConfig = self.textureData['materials'][materialName] imageFile = py2_utils.textureFileString(materialConfig['file']) bumpMapFile = None bumpMap = None if 'bumpMap' in materialConfig: bumpMapFile = py2_utils.textureFileString( materialConfig['bumpMap']) if imageFile not in self.textureCache: tex = coin.SoTexture2() tex.filename = imageFile self.textureCache[imageFile] = tex if bumpMapFile is not None: if bumpMapFile not in self.bumpMapCache: bumpMap = coin.SoBumpMap() bumpMap.filename.setValue(bumpMapFile) self.bumpMapCache[bumpMapFile] = bumpMap bumpMap = self.bumpMapCache[bumpMapFile] texture = self.textureCache[imageFile] return (texture, bumpMap, materialConfig) return (None, None, None)
def coinSetUp(self): #print "coinSetUp" self.TexW = 10 self.TexH = 100 self.sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() #print str( FreeCADGui.ActiveDocument.Document.Label ) #print str( self.sg ) self.stripes = coin.SoTexture2() self.sg.insertChild(self.stripes, 0) self.stripes.filename = "" self.string = '\xff' * 50 + '\x00' * self.StripeWidth self.chars = self.string * self.TexW * self.TexH self.img = coin.SoSFImage() self.img.setValue( coin.SbVec2s(len(self.string) * self.TexW, self.TexH), 1, self.chars) self.stripes.image = self.img # **** here we can transform the texture self.transTexture = coin.SoTexture2Transform() self.sg.insertChild(self.transTexture, 1) #transTexture.translation.setValue(1, 1) self.transTexture.scaleFactor.setValue(self.Scale, self.Scale) self.transTexture.rotation.setValue(1. * self.Rotation / 100) #transTexture.center.setValue(0, .5) self.tc = coin.SoTextureCoordinateEnvironment() self.sg.insertChild(self.tc, 2)
def setupGroundNode(self): groundNode = coin.SoSeparator() self.groundCoordinates = coin.SoCoordinate3() self.groundTexture = coin.SoTexture2() self.groundTexture.filename = py2_utils.textureFileString( self.Object.GroundImage) self.groundTexture.model = coin.SoMultiTextureImageElement.REPLACE groundTextureCoordinates = coin.SoTextureCoordinate2() groundTextureCoordinates.point.set1Value(0, 0, 0) groundTextureCoordinates.point.set1Value(1, 1, 0) groundTextureCoordinates.point.set1Value(2, 1, 1) groundTextureCoordinates.point.set1Value(3, 0, 1) faceset = coin.SoFaceSet() faceset.numVertices.set1Value(0, 4) groundNode.addChild(self.groundCoordinates) groundNode.addChild(groundTextureCoordinates) groundNode.addChild(self.groundTexture) groundNode.addChild(faceset) return groundNode
def setupSkyNode(self): skyNode = coin.SoSeparator() self.skyCoordinates = coin.SoCoordinate3() self.skyTexture = coin.SoTexture2() self.skyTexture.filename = py2_utils.textureFileString( self.Object.SkyImage) self.skyTexture.model = coin.SoMultiTextureImageElement.REPLACE self.skyTextureCoordinates = coin.SoTextureCoordinate2() faceset = coin.SoFaceSet() faceset.numVertices.set1Value(0, 4) faceset.numVertices.set1Value(1, 4) faceset.numVertices.set1Value(2, 4) faceset.numVertices.set1Value(3, 4) faceset.numVertices.set1Value(4, 3) faceset.numVertices.set1Value(5, 4) skyNode.addChild(self.skyCoordinates) skyNode.addChild(self.skyTextureCoordinates) skyNode.addChild(self.skyTexture) skyNode.addChild(faceset) return skyNode
def _reinitTexture(self, obj): if _pixelContainer.get(obj.Name): del _pixelContainer[obj.Name] _pixelContainer[obj.Name] = FPPixelContainer.PixelContainer( obj.ResolutionX, obj.ResolutionY) _pixelContainer[obj.Name].clear(Proto.Color(r=0, g=0, b=0, a=255)) pixelStr = _pixelContainer[obj.Name].toString() resolution = coin.SbVec2s(obj.ResolutionX, obj.ResolutionY) for child in obj.Group: rootNode = child.ViewObject.RootNode # find texture node tex = _findNodeIn(coin.SoTexture2.getClassTypeId(), rootNode) if not tex: #FreeCAD.Console.PrintMessage("inserting new texture\n") tex = coin.SoTexture2() rootNode.insertChild(tex, 1) tex.model = coin.SoTexture2.REPLACE # create the image for the texture image = coin.SoSFImage() #FreeCAD.Console.PrintMessage("Initial Texture begin:\n" + self._getTextureString(obj) + "\nTexture End") image.setValue( resolution, FPPixelContainer.PixelContainer.NUM_COLOR_COMPONENTS, pixelStr) tex.image = image # find complexity node complexity = _findNodeIn(coin.SoComplexity.getClassTypeId(), rootNode) if not complexity: #FreeCAD.Console.PrintMessage("inserting new complexity\n") complexity = coin.SoComplexity() rootNode.insertChild(complexity, 1) complexity.textureQuality = 0.00001
def navi(): '''navigator startup''' mw = QtGui.qApp #mw.setOverrideCursor(QtCore.Qt.PointingHandCursor) ef = EventFilter() ef.navi = myNavigatorWidget(ef) # get a jpg filename fn = os.path.dirname(__file__) + "/pics/transpa.jpg" sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() trans = coin.SoTranslation() trans.translation.setValue([0, 0, 0]) myCustomNode = coin.SoSeparator() cub = coin.SoSphere() cub.radius.setValue(10000000) i = coin.SoRotationXYZ() i.angle.setValue(1.5708) i.axis.setValue(0) myCustomNode.addChild(i) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) #myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode) tex = coin.SoTexture2() tex.filename = fn myCustomNode.insertChild(tex, 0) ef.background = myCustomNode ef.tex = tex FreeCAD.eventfilter = ef mw.installEventFilter(ef) on_key_press(FreeCAD.eventfilter, 'O') view = FreeCADGui.activeDocument().activeView() FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False) mgr = view.getViewer().getSoRenderManager() mgr.setAutoClipping(0) FreeCAD.ActiveDocument.recompute() FreeCADGui.updateGui() return ef
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 Texture(self, value): if self.feature.ViewObject is None: return vo = self.feature.ViewObject rootnode = vo.RootNode if len(rootnode) < 2: return from pivy import coin if isinstance(rootnode[1], coin.SoTexture2): rootnode.removeChild(1) if value is not None and value != "": tex = coin.SoTexture2() tex.filename = value rootnode.insertChild(tex, 1)
def addTextureImage(obj, fn, color=(1.0, 1.0, 1.0), transparency=0): rootnode = obj.ViewObject.RootNode cl = rootnode.getChildren() try: cl[1].filename.getValue() rootnode.removeChild(1) except: pass # print "no image to delete" tex = coin.SoTexture2() tex.filename = str(fn) rootnode.insertChild(tex, 1) obj.ViewObject.Transparency = transparency obj.ViewObject.ShapeColor = color
def attach(self,vobj): self.Object = vobj.Object from pivy import coin tex = coin.SoTexture2() tex.image = Draft.loadTexture(Draft.svgpatterns()['simple'][1], 128) texcoords = coin.SoTextureCoordinatePlane() s = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("patternScale",0.01) texcoords.directionS.setValue(s,0,0) texcoords.directionT.setValue(0,s,0) self.fcoords = coin.SoCoordinate3() self.fset = coin.SoIndexedFaceSet() sep = coin.SoSeparator() sep.addChild(tex) sep.addChild(texcoords) sep.addChild(self.fcoords) sep.addChild(self.fset) vobj.RootNode.addChild(sep) ArchComponent.ViewProviderComponent.attach(self,vobj)
def addImageTexture(obj,fn,scale=(1,1)): '''fuegt dem Viewobjekt von obj eine Image-Texture aus der Imagefile fn bei, Skalierung mit Faktoren Scale ''' rootnode = obj.ViewObject.RootNode t1=time.time() cl=rootnode.getChildren() ''' print ("childeren",cl.getLength()) for c in cl: print(c) ''' try: cl[1].scaleFactor.getValue() rootnode.removeChild(1) except: print("no texture scaler found") try: cl[1].filename.getValue() rootnode.removeChild(1) except: print("no texture image found") tex = coin.SoTexture2() tex.filename = str(fn) #----------------- rootnode.insertChild(tex,1) # texture 5#20mal wiederholen (zoom auf 50%) p=coin.SoTexture2Transform() p.scaleFactor = scale # (5.0,20.0) rootnode.insertChild(p,1) t2=time.time() print ("insert node", t2-t1) FreeCAD.Console.PrintMessage(str(("insert node", t2-t1)) +"\n")
def attach(self, vobj): self.ViewObject = vobj self.Object = vobj.Object self.LithophaneImage = self.Object.Proxy self.Object.setEditorMode("UpdateNotifier", 2) self.imageNode = coin.SoSeparator() self.coords = coin.SoCoordinate3() self.coords.point.set1Value(0, 0, 0, -1) self.coords.point.set1Value(1, 1, 0, -1) self.coords.point.set1Value(2, 1, 1, -1) self.coords.point.set1Value(3, 0, 1, -1) textureCoords = coin.SoTextureCoordinate2() textureCoords.point.set1Value(0, 0, 0) textureCoords.point.set1Value(1, 1, 0) textureCoords.point.set1Value(2, 1, 1) textureCoords.point.set1Value(3, 0, 1) faceset = coin.SoFaceSet() faceset.numVertices.set1Value(0, 4) # This makes it possible to select the object in the 3D View selectionNode = coin.SoType.fromName("SoFCSelection").createInstance() selectionNode.documentName.setValue(FreeCAD.ActiveDocument.Name) selectionNode.objectName.setValue(self.Object.Name) selectionNode.subElementName.setValue("Face") selectionNode.addChild(faceset) self.texture = coin.SoTexture2() self.imageNode.addChild(self.coords) self.imageNode.addChild(textureCoords) self.imageNode.addChild(self.texture) self.imageNode.addChild(selectionNode) vobj.addDisplayMode(self.imageNode, "LithophaneImage")
def setupPanoramaNode(self): panoramaNode = coin.SoSeparator() self.panoramaCoordinates = coin.SoCoordinate3() self.panoramaTextureCoordinates = coin.SoTextureCoordinate2() self.panoramaTexture = coin.SoTexture2() self.panoramaTexture.filename = py2_utils.textureFileString( self.Object.PanoramaImage) self.panoramaTexture.model = coin.SoMultiTextureImageElement.REPLACE faceset = coin.SoFaceSet() faceset.numVertices.set1Value(0, 4) faceset.numVertices.set1Value(1, 4) faceset.numVertices.set1Value(2, 4) panoramaNode.addChild(self.panoramaCoordinates) panoramaNode.addChild(self.panoramaTextureCoordinates) panoramaNode.addChild(self.panoramaTexture) panoramaNode.addChild(faceset) return panoramaNode
def onChanged(self, vobj, prop): """Run when a view property is changed. Override this method to handle the behavior of the view provider depending on changes that occur to its properties such as line color, line width, point color, point size, draw style, shape color, transparency, and others. This method updates the texture and pattern if the properties `TextureImage`, `Pattern`, `DiffuseColor`, and `PatternSize` change. Parameters ---------- vobj : the view provider of the scripted object. This is `obj.ViewObject`. prop : str Name of the property that was modified. """ # treatment of patterns and image textures if prop in ("TextureImage", "Pattern", "DiffuseColor"): if hasattr(self.Object, "Shape"): if self.Object.Shape.Faces: path = None if hasattr(vobj, "TextureImage"): if vobj.TextureImage: path = vobj.TextureImage if not path: if hasattr(vobj, "Pattern"): if str(vobj.Pattern) in list(utils.svg_patterns().keys()): path = utils.svg_patterns()[vobj.Pattern][1] else: path = "None" if path and vobj.RootNode: if vobj.RootNode.getChildren().getLength() > 2: if vobj.RootNode.getChild(2).getChildren().getLength() > 0: if vobj.RootNode.getChild(2).getChild(0).getChildren().getLength() > 2: r = vobj.RootNode.getChild(2).getChild(0).getChild(2) i = QtCore.QFileInfo(path) if self.texture: r.removeChild(self.texture) self.texture = None if self.texcoords: r.removeChild(self.texcoords) self.texcoords = None if i.exists(): size = None if ".SVG" in path.upper(): size = utils.get_param("HatchPatternResolution", 128) if not size: size = 128 im = gui_utils.load_texture(path, size) if im: self.texture = coin.SoTexture2() self.texture.image = im r.insertChild(self.texture, 1) if size: s = 1 if hasattr(vobj, "PatternSize"): if vobj.PatternSize: s = vobj.PatternSize self.texcoords = coin.SoTextureCoordinatePlane() self.texcoords.directionS.setValue(s, 0, 0) self.texcoords.directionT.setValue(0, s, 0) r.insertChild(self.texcoords, 2) elif prop == "PatternSize": if hasattr(self, "texcoords"): if self.texcoords: s = 1 if vobj.PatternSize: s = vobj.PatternSize vS = App.Vector(self.texcoords.directionS.getValue().getValue()) vT = App.Vector(self.texcoords.directionT.getValue().getValue()) vS.Length = s vT.Length = s self.texcoords.directionS.setValue(vS.x, vS.y, vS.z) self.texcoords.directionT.setValue(vT.x, vT.y, vT.z) return
def navi(): '''navigator startup''' mw = QtGui.QApplication #widget.setCursor(QtCore.Qt.SizeAllCursor) #cursor ausblenden #mw.setOverrideCursor(QtCore.Qt.BlankCursor) # FreeCADGui.activateWorkbench("NoneWorkbench") mw.setOverrideCursor(QtCore.Qt.PointingHandCursor) ef = EventFilter() ef.laenge = 0.0 ef.breite = 0.0 ef.campos = FreeCAD.Vector(0, 0, 20000) # ef.output.hide() ef.mouseMode = False ef.firstCall = True ef.mode = "turn" ef.navi = myNavigatorWidget(ef) ef.speed = 100 ef.direction = 0.5 * math.pi ef.roll = 0 #-------------- # get a jpg filename # jpgfilename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open image file','*.jpg') fn = '/home/microelly2/FCB/b175_camera_controller/winter.jpg' fn = os.path.dirname(__file__) + "/../pics/winter.jpg" sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() col = coin.SoBaseColor() #col.rgb=(1,0,0) trans = coin.SoTranslation() trans.translation.setValue([0, 0, 0]) myCustomNode = coin.SoSeparator() #myCustomNode.addChild(col) if 0 or False: cub = coin.SoCylinder() cub.radius.setValue(3000) cub.height.setValue(4000) cub.parts.set("SIDES") s = coin.SoRotationXYZ() s.angle.setValue(1.5708) s.axis.setValue(0) myCustomNode.addChild(s) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) else: cub = coin.SoSphere() cub.radius.setValue(10000000) s = coin.SoRotationXYZ() s.angle.setValue(1.5708) s.axis.setValue(0) myCustomNode.addChild(s) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) if False: l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, 1, 0)) l.color.setValue(coin.SbColor(0, 0, 1)) myCustomNode.addChild(l) l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, -1, 0)) l.color.setValue(coin.SbColor(0, 1, 1)) myCustomNode.addChild(l) l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, 0, 1)) l.color.setValue(coin.SbColor(1, 0, 0)) myCustomNode.addChild(l) l = coin.SoDirectionalLight() l.direction.setValue(coin.SbVec3f(0, 0, -1)) l.color.setValue(coin.SbColor(0.6, 0.6, 1)) myCustomNode.addChild(l) l = coin.SoSpotLight() l.direction.setValue(coin.SbVec3f(1, 0, 1)) l.color.setValue(coin.SbColor(0, 1, 0)) l.location.setValue(coin.SbVec3f(0, 0, 0)) # l.cutOffAngle.setValue(0.01) # l.dropOffRate.setValue(1) myCustomNode.addChild(l) #myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode) tex = coin.SoTexture2() tex.filename = fn myCustomNode.insertChild(tex, 0) #--------------- ef.background = myCustomNode ef.tex = tex FreeCAD.eventfilter = ef mw.installEventFilter(ef) FreeCAD.eventfilter.on_key_press = on_keypress2 FreeCAD.eventfilter.on_move = on_move3 FreeCAD.eventfilter.on_clicks = on_clicks3 FreeCAD.eventfilter.on_windowslist = on_windowslist2 on_keypress2(FreeCAD.eventfilter, 'O') view = FreeCADGui.activeDocument().activeView() FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False) mgr = view.getViewer().getSoRenderManager() mgr.setAutoClipping(0) FreeCAD.ActiveDocument.recompute() FreeCADGui.updateGui() return ef
def navi(): '''navigator startup''' mw = QtGui.QApplication #widget.setCursor(QtCore.Qt.SizeAllCursor) #cursor ausblenden #mw.setOverrideCursor(QtCore.Qt.BlankCursor) # FreeCADGui.activateWorkbench("NoneWorkbench") mw.setOverrideCursor(QtCore.Qt.PointingHandCursor) ef = EventFilter() ef.laenge = 0.0 ef.breite = 0.0 ef.campos = FreeCAD.Vector(0, 0, 20000) # ef.output.hide() ef.mouseMode = False ef.firstCall = True ef.mode = "turn" ef.navi = myNavigatorWidget(ef) ef.speed = 100 ef.direction = 0.5 * math.pi ef.roll = 0 #-------------- # get a jpg filename fn = os.path.dirname(__file__) + "/../pics/winter.jpg" sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph() trans = coin.SoTranslation() trans.translation.setValue([0, 0, 0]) myCustomNode = coin.SoSeparator() cub = coin.SoSphere() cub.radius.setValue(10000000) i = coin.SoRotationXYZ() i.angle.setValue(1.5708) i.axis.setValue(0) myCustomNode.addChild(i) s = coin.SoRotationXYZ() s.angle.setValue(math.pi) s.axis.setValue(1) myCustomNode.addChild(s) #myCustomNode.addChild(trans) myCustomNode.addChild(cub) sg.addChild(myCustomNode) tex = coin.SoTexture2() tex.filename = fn myCustomNode.insertChild(tex, 0) #--------------- ef.background = myCustomNode ef.tex = tex FreeCAD.eventfilter = ef mw.installEventFilter(ef) FreeCAD.eventfilter.on_key_press = on_keypress2 FreeCAD.eventfilter.on_move = on_move3 FreeCAD.eventfilter.on_clicks = on_clicks3 FreeCAD.eventfilter.on_windowslist = on_windowslist2 on_keypress2(FreeCAD.eventfilter, 'O') view = FreeCADGui.activeDocument().activeView() FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False) mgr = view.getViewer().getSoRenderManager() mgr.setAutoClipping(0) FreeCAD.ActiveDocument.recompute() FreeCADGui.updateGui() return ef