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!
Post Reply
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

shadows in the freecad viewport

Post by yorik »

Proof of concept, it works!!! It's even pretty fast!

Apparently you need a good 3D hardware. It works with my nvidia chip, but not when running on the intel...
freecad-shadows.jpg
freecad-shadows.jpg (201.43 KiB) Viewed 13948 times
Attached is the .iv file...
Attachments
shadow-test.iv
(266.83 KiB) Downloaded 506 times
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: shadows in the freecad viewport

Post by quick61 »

Hey Yorik, that looks great. Is it easy to position the light source, or length of shadow or whatever method is used? Like can it have a variable setting? Also, if this actually easy to implement, is it the same for other features like mirror Z, mirror texture, atmosphere, and whatever other goodies there are available?

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
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 »

If you look in the .iv file you'll see how it works: You need a spotlight (IFAICS directionalLights don't work), the cutOffAngle and dropOffRate control how the shadows look like. There is more info on http://coin3d.bitbucket.org/Coin/classS ... Group.html

Implementing this FreeCAD-wide seems not specially difficult (one just needs to "encapsulate" the whole scene inside a SoShadowGroup object and add a ground plane, maybe modify the default lights too), then there could easily be some setting to switch that behaviour on/off.

About the other features, I haven't looked much yet. Fog seems easy too, same system ( http://coin3d.bitbucket.org/Coin/classS ... nment.html ), mirroring I don't remember exactly how Jürgen did it, but I think it involved copying all the scene contents... As for advanced texturing, that's a whole more complex matter, it involves implementing stuff at object level, and will ask for mch more complex controls...
balazs
Posts: 100
Joined: Thu Oct 16, 2014 3:40 pm

Re: shadows in the freecad viewport

Post by balazs »

Hi Yorik,

This looks really great...
yorik wrote:If you look in the .iv file you'll see how it works: You need a spotlight (IFAICS directionalLights don't work), the
Where do you position your spotlight? From an architect point of view a SoDirectionalLight (as the model of the Sun) would be important, too. For it, a practical set of control properties would be
  • a north arrow
  • latitude of the building (or a major city, but that may come in the future)
  • month and day
  • local time
It is sure we can find a library or algorithm calculating sunlight direction from the above data. I do not know one.

What do you think about it?

Best regards: Balázs
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 »

If coin3d doesn't produce shadows from directional lights, there is little we can do unfortunately. Note that blender also doesn't do that... There must be something that prevents it, most probably it is not supported by OpenGL.

But we could still find something that allows to place a light automatically at a correct sun position.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: shadows in the freecad viewport

Post by shoogen »

yorik wrote:But we could still find something that allows to place a light automatically at a correct sun position.
Like 1.5E14 mm from the origin? ;)
balazs
Posts: 100
Joined: Thu Oct 16, 2014 3:40 pm

Re: shadows in the freecad viewport

Post by balazs »

shoogen wrote:Like 1.5E14 mm from the origin? ;)
Yes, something like it. A distance big enough to give a good approximate of the Sun - which itself is also far closer than infinity :)

Yorik, have you tried smoothBorder > 0 in SoShadowGroup?
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: shadows in the freecad viewport

Post by quick61 »

shoogen wrote:
yorik wrote:But we could still find something that allows to place a light automatically at a correct sun position.
Like 1.5E14 mm from the origin? ;)
Hey, that's only about 1.58553512 × 10^-5 light years. Hummm, sounds about right.
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Post by microelly2 »

I have done some experiments with inventor/vrml-lights and the seem to work - but there is to much light by default.
Is there a way to shut off the light in the 3D scene to get a dark room?


EDIT
I have 3 spotlights to the cones, but there is still some ambient light :?
the spotlights still do not work as in the examples of the inventor mentor book
I cannot see the end of the light cones
Attachments
bn_553.png
bn_553.png (66.17 KiB) Viewed 13733 times
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Post by microelly2 »

microelly2 wrote: Thu Mar 05, 2015 9:54 am Is there a way to shut off the light in the 3D scene to get a dark room?
some years later I found where to turn the light on and off ...
bp_671.png
bp_671.png (41.69 KiB) Viewed 11876 times

Code: Select all


from pivy import coin

rGrp=FreeCAD.ParamGet('User parameter:BaseApp/Preferences/View')
atr="HeadlightIntensity"
rGrp.GetInt(atr)

#set headlight on
rGrp.SetInt(atr,100)

# or off
rGrp.SetInt(atr,0)

myCustomNode=Gui.ActiveDocument.ActiveView.getSceneGraph()


l=coin.SoSpotLight()
l.direction.setValue(coin.SbVec3f(-100,-0,-100))
l.color.setValue(coin.SbColor(1,1,0))
l.location.setValue(coin.SbVec3f(200,0,100))
l.cutOffAngle.setValue(0.3)
l.dropOffRate.setValue(0.)
myCustomNode.insertChild(l,0)


l=coin.SoSpotLight()
l.direction.setValue(coin.SbVec3f(-30,50,-100))
l.color.setValue(coin.SbColor(0,1,1))
l.location.setValue(coin.SbVec3f(200,-150,300))
l.cutOffAngle.setValue(.1)
l.dropOffRate.setValue(0.)
myCustomNode.insertChild(l,0)


l=coin.SoSpotLight()
l.direction.setValue(coin.SbVec3f(350,200,-300))
l.color.setValue(coin.SbColor(1,0,1))
l.location.setValue(coin.SbVec3f(-200,-200,300))
l.cutOffAngle.setValue(0.05)
l.dropOffRate.setValue(0.)
myCustomNode.insertChild(l,0)

Warning: if someone tests the script he has to set the HeadlightIntensity back to 100 to get the old behaviour:

rGrp=FreeCAD.ParamGet('User parameter:BaseApp/Preferences/View')
atr="HeadlightIntensity"

#set headlight on
rGrp.SetInt(atr,100)
Post Reply