However, I was looking into Arch Texture workbench code and there are many good things that not working, there is some kind of manager but I don't know how to turn it on. I guess this would be much quicker to write something from scratch instead of trying to understand the code.
Yorik created great texture sample here: https://wiki.freecadweb.org/Macro_Texture_Objects
I change it little bit and get ability to apply texture from the internet, external url:
Code: Select all
import FreeCADGui
from PySide import QtGui
from pivy import coin
import urllib.request
textureURL = "https://upload.wikimedia.org/wikipedia/commons/b/b3/Wood_004_plywood.jpg"
extension = ".jpg"
tmpDir = "./"
data = urllib.request.urlopen(textureURL)
for obj in FreeCADGui.Selection.getSelection():
texFilename = tmpDir + obj.Label + extension
out = open(str(texFilename), "wb")
out.write(data.read())
out.close()
rootnode = obj.ViewObject.RootNode
texture = coin.SoTexture2()
texture.filename = texFilename
rootnode.insertChild(texture, 1)
Now I have to find out what will be the best place to store temporary files (textures) because I have no idea how to load texture on-the-fly without reading it from disk. I was looking into Coin.SoTexture2 library but I didn't see exact object field with raw image data to assign. There is only filename or image and I have no idea what the image should look like.