[solved] How to show an overlay image with Coin?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

[solved] How to show an overlay image with Coin?

Post by DorinDXN »

Hi everyone,

I'm currently using the below code to overlay text and works flawlessly.

It is possible to show also an image e.g. jpg, bmp ?

thank you!

cheers,
Dorin

Code: Select all

textSep = coin.SoSeparator()
cam = coin.SoOrthographicCamera()
cam.aspectRatio = 1
cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

trans = coin.SoTranslation()
trans.translation = (-0.95, -0.5, 0)

myFont = coin.SoFont()
myFont.name = "Arial"
size = 75
myFont.size.setValue(size)
SoText2 = coin.SoText2()
SoText2.string.setValues(0,3,["A","","BCD"])
SoText2.justification = 1
color = coin.SoBaseColor()
color.rgb = (0, 0, 0)

textSep.addChild(cam)
textSep.addChild(trans)
textSep.addChild(color)
textSep.addChild(myFont)
textSep.addChild(SoText2)

activeDoc = FreeCADGui.ActiveDocument
view = activeDoc.ActiveView
sg = view.getSceneGraph()
viewer = view.getViewer()
render = viewer.getSoRenderManager()
sup = render.addSuperimposition(textSep)
Last edited by DorinDXN on Wed Jul 20, 2022 3:38 pm, edited 1 time in total.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to show an overlay image with Coin?

Post by wmayer »

It is possible to show also an image e.g. jpg, bmp ?
Yes, instead of an SoText2 node use an SoImage node.

Code: Select all

textSep = coin.SoSeparator()
cam = coin.SoOrthographicCamera()
cam.aspectRatio = 1
cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

trans = coin.SoTranslation()
trans.translation = (-0.95, -0.5, 0)

myImage = coin.SoImage()
myImage.filename.setValue("Path_to_bitmap_file")

textSep.addChild(cam)
textSep.addChild(trans)
textSep.addChild(myImage)

activeDoc = FreeCADGui.ActiveDocument
view = activeDoc.ActiveView
sg = view.getSceneGraph()
viewer = view.getViewer()
render = viewer.getSoRenderManager()
sup = render.addSuperimposition(textSep)
IIRC then by default SoImage only supports the bmp format out of the box. In order to support further image formats you need the simage plugin.
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to show an overlay image with Coin?

Post by DorinDXN »

Works flawlessly,

Thanks a million :)

cheers,
Dorin
Post Reply