shadows in the freecad viewport

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
wmayer
Site Admin
Posts: 14614
Joined: Thu Feb 19, 2009 10:32 am

Re: shadows in the freecad viewport

Postby wmayer » Tue Jan 09, 2018 10:51 am

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
Posts: 4329
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Postby microelly2 » Tue Jan 09, 2018 8:28 pm

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 974 times
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: shadows in the freecad viewport

Postby yorik » 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?
User avatar
microelly2
Posts: 4329
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Postby microelly2 » Wed Jan 10, 2018 11:56 am

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
Posts: 4329
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Postby microelly2 » Wed Jan 10, 2018 2:09 pm

phpBB [video]
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: shadows in the freecad viewport

Postby yorik » Thu Jan 11, 2018 1:55 pm

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
Posts: 4329
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Postby microelly2 » Thu Jan 11, 2018 3:21 pm

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 23 times
and the testcase
phpBB [video]
paullee
Posts: 1629
Joined: Wed May 04, 2016 3:58 pm

Re: shadows in the freecad viewport

Postby paullee » Sun May 26, 2019 2:00 am

Just revisit this.

Now 0.18 had been released, any chance to implement in 0.19? :)
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: shadows in the freecad viewport

Postby yorik » Thu Jul 18, 2019 8:58 pm

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 424 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
pablogil
Posts: 747
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: shadows in the freecad viewport

Postby pablogil » Fri Jul 19, 2019 8:57 am

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