Textures for Woodworking

A forum to discuss the implementation of a good Materials system in FreeCAD
User avatar
dprojects
Posts: 261
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Textures for Woodworking

Post by dprojects »

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:

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)
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.

Thanks
Darek
github.com/dprojects

Image
User avatar
dprojects
Posts: 261
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Textures for Woodworking

Post by dprojects »

OK, I did it. I am able to store permanently textures in FreeCAD project as URLs under object's description ;-) LOL
This not load after project open but if you run macro all the textures are back again.
Here is the code: https://github.com/dprojects/setTextures

Thanks
Darek
github.com/dprojects

Image
paullee
Veteran
Posts: 4259
Joined: Wed May 04, 2016 3:58 pm

Re: Textures for Woodworking

Post by paullee »

Seem there is some fun here :D
User avatar
dprojects
Posts: 261
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Textures for Woodworking

Post by dprojects »

paullee wrote: Sun Mar 27, 2022 5:17 pm Seem there is some fun here :D
Indeed ;-) I just added more locations, now you can store URL at:
  • object's description (Label2)
  • Texture property
  • Material Card applied to the object (this works!). However I don't know how this would be with layers. Someday I will try to investigate it too.
I have to add it to woodworking workbench as button ;-)

Thanks
Darek
github.com/dprojects

Image
Post Reply