shadows in the freecad viewport

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: shadows in the freecad viewport

Post by wmayer »

looo wrote: Mon Jan 08, 2018 11:02 pm
SoShadowStyle
is that available in coin? maybe we can add some bindings with pivy.
FYI, with pivy you can create an instance of any SoBase-derived class as soon as it's registered to the type system. So, when pivy doesn't offer a direct way to create an instance you always can go this way:

Code: Select all

from pivy import coin
coin.SoShadowStyle() # => AttributeError: 'module' object has no attribute 'SoShadowStyle'

sotype=coin.SoType.fromName("SoShadowStyle")
sotype.isBad() # => 0, i.e. is OK
inst=sotype.createInstance()
inst.getTypeId().getName() # => ShadowStyle
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Post by microelly2 »

wmayer wrote: Tue Jan 09, 2018 10:51 am FYI, with pivy you can create an instance of any SoBase-derived class as soon as it's registered to the type system
Wow, it works.
So we will have scripted shadows :D
bp_672.png
bp_672.png (28.34 KiB) Viewed 3124 times
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: shadows in the freecad viewport

Post by yorik »

I would really like to have that as a builtin viewing mode in FreeCAD at some point... We might try to implement that after 0.17, no?
The way I see it:

- The whole scenegraph must be embedded inside a SoShadowGroup node
- A SoSpotLight must be added in order to produce shadows. The difficulty is to correctly position that light IRW the objects in the scene.
- There must be some control over that spotlight + the default light in FreeCAD (a UI to specify light position/color/intensity?)

Maybe, simply, the spotlight should be a document object, that the user can position/configure manually...

Maybe also:

- A UI to control shadow quality (maybe just a simple pref setting)
- Shadows can be switched on/off inside the SoShadowGroup. So maybe add a property to each document object?
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Post by microelly2 »

yorik wrote: Wed Jan 10, 2018 11:25 am I would really like to have that as a builtin viewing mode in FreeCAD at some point... We might try to implement that after 0.17, no?
The way I see it:

- The whole scenegraph must be embedded inside a SoShadowGroup node
- A SoSpotLight must be added in order to produce shadows. The difficulty is to correctly position that light IRW the objects in the scene.
- There must be some control over that spotlight + the default light in FreeCAD (a UI to specify light position/color/intensity?)

Maybe, simply, the spotlight should be a document object, that the user can position/configure manually...

Maybe also:

- A UI to control shadow quality (maybe just a simple pref setting)
- Shadows can be switched on/off inside the SoShadowGroup. So maybe add a property to each document object?
I start to put these nodes into my darkroom view.
My idea is to have the soNodes as parametric objects in the document and compose them in a darkroom view.
on this way other nodes like vrml helper illustrations as trees and people sholuld be possible too.
Now when the use of lights and shadows is known a new game can start.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Post by microelly2 »

phpBB [video]
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: shadows in the freecad viewport

Post by yorik »

Cool!!
microelly2 wrote: Wed Jan 10, 2018 11:56 am Now when the use of lights and shadows is known a new game can start.
Yes that is basically the biggest part of the work I think... All the system+UI that is needed to manage lights
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Post by microelly2 »

Today I tested whether it is possible to add pure inventor file with animation inside can be added.
And it works too.
The animation runs in FreeCAD without extra code
and it runs in the darkroom with shadows.
So we can add extra objects for illustration purposes.
the data file
shuttle_sphere.iv
(945 Bytes) Downloaded 92 times
and the testcase
phpBB [video]
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: shadows in the freecad viewport

Post by paullee »

Just revisit this.

Now 0.18 had been released, any chance to implement in 0.19? :)
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: shadows in the freecad viewport

Post by yorik »

Quick script to produce a shadowed view of an opened FreeCAD model, like this:
Screenshot from 2019-07-18 17-52-00.png
Screenshot from 2019-07-18 17-52-00.png (226.55 KiB) Viewed 2574 times

Code: Select all

import OfflineRenderingUtils
objs = [o for o in FreeCAD.ActiveDocument.Objects if o.ViewObject.Visibility == True] # gather visible objects
cam = FreeCADGui.ActiveDocument.ActiveView.getCamera() # gather the camera position
s = OfflineRenderingUtils.buildScene(objs) # build the coin scene
rn = OfflineRenderingUtils.embedLight(s,(1,1,-1)) # embed the wholescene in a ShadowGroup, add directional light
light = rn.getChild(0) # get a ref to the directional light for later
v = FreeCADGui.createViewer() # create an empty 3D view in FreeCAD
v.setCamera(cam) # set the camera
vv = v.getViewer().setSceneGraph(rn) # set our scene as its scenegraph
light.direction = (-1,-1,-1) # change light direction
User avatar
pablogil
Posts: 881
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: shadows in the freecad viewport

Post by pablogil »

Really cool,

Are them real time shadows?
Could you explain how to proceed in order to try it out? if I put the code in the Python console it doesn't work (it launches some errors)

Thanks!
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
Post Reply