Hi,
I'm working on a script that downloads an aerial photo of a site and I want to place it in the scene on scale.
I have the photo downloader, the geometry is there, but I am poking in the dark when it comes to mapping an image onto geometry.
Is there a minimal viable example around ? A simple macro that I can look at ?
I know about the arch tectures wb, but I was kinda hoping I would have to tweeze out a workbench for a simple script.
thanks.
PS, The texturing on draft.rectangle is broken for me on 0.18. It textures the plane, but it is garbled.
Basic steps to assign a texture to a face ?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 26
- Joined: Fri Aug 30, 2019 9:47 am
Re: Basic steps to assign a texture to a face ?
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
-
- Posts: 26
- Joined: Fri Aug 30, 2019 9:47 am
Re: Basic steps to assign a texture to a face ?
Yes, yes, thank you.
Here is the snippet:
(it relies on owslib, you'll have to adfd that to your python env)
Here is the snippet:
(it relies on owslib, you'll have to adfd that to your python env)
Code: Select all
from owslib.wms import WebMapService
import Part
from pivy import coin
doc=FreeCAD.ActiveDocument
vec = FreeCAD.Base.Vector
def get_luchtfoto(LOC_RD, size):
url="https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms?"
wms=WebMapService(url)
img = wms.getmap(layers=['Actueel_ortho25'],
srs='EPSG:28992',
bbox=(LOC_RD[0]-size, LOC_RD[1]-size, LOC_RD[0]+size, LOC_RD[1]+size),
size=(2048,2048),
format='image/jpeg',
transparent=True
)
filename = 'luchtfoto-'+str(LOC_RD[0])+'_'+str(LOC_RD[1])+'.jpg'
out = open(filename, 'wb')
out.write(img.read())
out.close()
p0 = vec(-size*1000,-size*1000,0)
p1 = vec(size*1000,-size*1000,0)
p2 = vec(size*1000,size*1000,0)
p3 = vec(-size*1000,size*1000,0)
rec = [p2,p1,p0,p3,p2]
shape = Part.makePolygon(rec)
shp=Part.makeFilledFace(shape.Edges)
p = doc.addObject("Part::Feature", "rec")
p.Shape=shp
rootnode = p.ViewObject.RootNode
tex = coin.SoTexture2()
tex.filename = filename
rootnode.insertChild(tex,1)
p.Placement.Rotation= FreeCAD.Base.Rotation(vec(0,0,1),270)
location=(160769, 384904)
get_luchtfoto(location, 200)
-
- Posts: 26
- Joined: Fri Aug 30, 2019 9:47 am
Re: Basic steps to assign a texture to a face ?
In the netherlands you have a bunch of interesting webmapservices and webfeature services, pretty sure other countries have the same.
If you want to take a stab at it, find your country's EPSG and check pyproj.Transformer to transform latlong coords from google maps.
Another question: can I embed a texture in the FCstd ?
cheers,
sander
If you want to take a stab at it, find your country's EPSG and check pyproj.Transformer to transform latlong coords from google maps.
Another question: can I embed a texture in the FCstd ?
cheers,
sander
-
- Posts: 26
- Joined: Fri Aug 30, 2019 9:47 am
Re: Basic steps to assign a texture to a face ?
NB:
the placement is not correct in the above snippet, it needs to be:
the placement is not correct in the above snippet, it needs to be:
Code: Select all
p.Placement.Rotation= FreeCAD.Base.Rotation(vec(1,1,0),180