Re: Textures for Woodworking
Posted: Sun Mar 27, 2022 12:46 pm
I am not capable to write anything smart, the documentation is job not for me, maybe I have to wait for better days to write something with sense.
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:
I guess, I can improve this code and make some kind of tool with GUI and ability to store permanently textures URLs. I have some ideas and I think this will be possible. I have no idea how to rotate texture on face and many other things but this will be to improve later.
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.
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.