Пример #1
0
    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 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")