Textures for Woodworking

A forum to discuss the implementation of a good Materials system in FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
dprojects
Posts: 720
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

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
dprojects
Posts: 720
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

workbench for woodworking is available at: github.com/dprojects/Woodworking
paullee
Veteran
Posts: 5092
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: 720
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

workbench for woodworking is available at: github.com/dprojects/Woodworking
FreeCadMax
Posts: 3
Joined: Tue Mar 08, 2022 12:09 pm

Re: Textures for Woodworking

Post by FreeCadMax »

That's awesome!

One question though: How do you do this with a link to a file on your computer. For me it never worked.

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

Re: Textures for Woodworking

Post by dprojects »

FreeCadMax wrote: Tue May 31, 2022 9:23 am How do you do this with a link to a file on your computer. For me it never worked.
Hi, this setTextures tool is not intended to set texture from local disk. The FreeCAD Std_TextureMapping command does this. The setTextures tool solves problem with texture sharing without huge file.

However, if you run http server locally and give http URL to your local file publicly shared (or with permissions to FreeCAD) this may work. I didn't test it but it is no matter if the URL is to local server or external in fact, so this should work.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
FreeCadMax
Posts: 3
Joined: Tue Mar 08, 2022 12:09 pm

Re: Textures for Woodworking

Post by FreeCadMax »

Hi! Yeah I get that, but with the texture mapping you can't permanently add it to the model (or at least I haven't found out how to do it).

With referencing links on the internet there is just the thing, that those pictures don't always exist forever or the link gets broken somehow. I have a folder with the typical wood textures I use in sketchup and I just wanted to add those "grain-appropriately" (I guess thats not a word ;) ) to a workpiece so I get a somewhat good representation.

I would even be okay to color them in face by face (as you can do it in Sketchup), but I haven't figured out how to do that in Freecad as of yet.

Texture mapping doesn't do that and you can't mix wood species (I know it's an acquired taste, but still I want to do it :lol:), especially if you work with several sheet goods.
User avatar
dprojects
Posts: 720
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Textures for Woodworking

Post by dprojects »

FreeCadMax wrote: Wed Jun 01, 2022 9:32 am Hi! Yeah I get that, but with the texture mapping you can't permanently add it to the model (or at least I haven't found out how to do it).
No the FreeCAD Std_TextureMapping command not allow to store texture. Also it allow only for load texture for all objects (same texture) from local disk. However, I found it useful for quick texture preview. I think this command is useful, even so limited.

FreeCadMax wrote: Wed Jun 01, 2022 9:32 am With referencing links on the internet there is just the thing, that those pictures don't always exist forever or the link gets broken somehow.
Well, yes ;-) You must choose a server where the worms have no power. ;-) LOL

FreeCadMax wrote: Wed Jun 01, 2022 9:32 am I would even be okay to color them in face by face (as you can do it in Sketchup), but I haven't figured out how to do that in Freecad as of yet.
You can use colorManager:

Image


FreeCadMax wrote: Wed Jun 01, 2022 9:32 am Texture mapping doesn't do that and you can't mix wood species
but you can do it with setTextures:

Image

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
Post Reply