Determine Scale of 3D View?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Determine Scale of 3D View?

Postby wandererfan » Thu Feb 28, 2019 6:37 pm

Is the scale of the 3D view available anywhere? For example, if the standard 10mm Cube's on screen image is 20mm across then the scale would be 2:1. If the scale is not available, what about the parameters to calculate it?

I found "SbViewVolume::getWorldToScreenScale" but I can not understand the resulting values. If our cube is 40mm on the screen, getWorldToScreenScale returns ~20. 20 what to 1 what?

Any advice appreciated.
User avatar
microelly2
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Determine Scale of 3D View?

Postby microelly2 » Fri Mar 01, 2019 8:46 am

I use the camera properties focal lenght, height Angle
see SoCamera manumal
User avatar
regis
Posts: 721
Joined: Sun Jul 12, 2015 8:17 am
Contact:

Re: Determine Scale of 3D View?

Postby regis » Fri Mar 01, 2019 1:09 pm

wandererfan wrote:
Thu Feb 28, 2019 6:37 pm
I found "SbViewVolume::getWorldToScreenScale
Where did you find this?
microelly2 wrote:
Fri Mar 01, 2019 8:46 am
I use the camera properties focal lenght, height Angle
see SoCamera manumal
Please explain more, howw do you use it to have your drawings to a certain scale in 3D view,\
Another question, is it possible to have a 3D view window inside of the main 3D space where all the modeling is done? for example like a view port, if I draw a box, or any flat shape, and tell it to be a view port, can I insert a 3d view inside that shape?
User avatar
DeepSOIC
Posts: 7824
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Determine Scale of 3D View?

Postby DeepSOIC » Fri Mar 01, 2019 1:24 pm

For Lattice Autosize, I use camera properties to figure out the scale. It's not straightforward.
https://github.com/DeepSOIC/Lattice2/bl ... #L102-L125
wandererfan wrote:
Thu Feb 28, 2019 6:37 pm

I found "SbViewVolume::getWorldToScreenScale" but I can not understand the resulting values. If our cube is 40mm on the screen, getWorldToScreenScale returns ~20. 20 what to 1 what?
Interesting, that might simplify Lattice autosize a little bit. 20 is likely "20 pixels per 1 mm". You need to know your screen's pixel density to match to size on your screen, and AFAIK this value is difficult if not impossible to obtain from the OS.
User avatar
microelly2
Posts: 4690
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Determine Scale of 3D View?

Postby microelly2 » Fri Mar 01, 2019 1:38 pm

regis wrote:
Fri Mar 01, 2019 1:09 pm
microelly2 wrote:
Fri Mar 01, 2019 8:46 am
I use the camera properties focal lenght, height Angle
see SoCamera manumal
Please explain more, howw do you use it to have your drawings to a certain scale in 3D view,\
Another question, is it possible to have a 3D view window inside of the main 3D space where all the modeling is done? for example like a view port, if I draw a box, or any flat shape, and tell it to be a view port, can I insert a 3d view inside that shape?
I use this command

camt='#Inventor V2.1 ascii\n\n\nOrthographicCamera {\n viewportMapping ADJUST_CAMERA\n position 0 0 1\n orientation .00 0.00 -1.0 4.7123\n nearDistance -54.94503\n farDistance 515.51514\n aspectRatio 1\n focalDistance 5\n height 500\n\n}\n'

FreeCADGui.activeDocument().activeView().setCamera(camt)

to get the window to 500 mm
if the window is not quadratic the min dimension is 500 mm
bp_967.png
bp_967.png (13.05 KiB) Viewed 898 times
in the picture the cylinder has a radius of 250. when i scale the window the cylinder/circle always connects to borders of the window.
User avatar
regis
Posts: 721
Joined: Sun Jul 12, 2015 8:17 am
Contact:

Re: Determine Scale of 3D View?

Postby regis » Fri Mar 01, 2019 5:12 pm

microelly2 wrote:
Fri Mar 01, 2019 1:38 pm
regis wrote:
Fri Mar 01, 2019 1:09 pm
microelly2 wrote:
Fri Mar 01, 2019 8:46 am
I use the camera properties focal lenght, height Angle
see SoCamera manumal
Please explain more, howw do you use it to have your drawings to a certain scale in 3D view,\
Another question, is it possible to have a 3D view window inside of the main 3D space where all the modeling is done? for example like a view port, if I draw a box, or any flat shape, and tell it to be a view port, can I insert a 3d view inside that shape?
I use this command

camt='#Inventor V2.1 ascii\n\n\nOrthographicCamera {\n viewportMapping ADJUST_CAMERA\n position 0 0 1\n orientation .00 0.00 -1.0 4.7123\n nearDistance -54.94503\n farDistance 515.51514\n aspectRatio 1\n focalDistance 5\n height 500\n\n}\n'

FreeCADGui.activeDocument().activeView().setCamera(camt)

to get the window to 500 mm
if the window is not quadratic the min dimension is 500 mm
bp_967.png
in the picture the cylinder has a radius of 250. when i scale the window the cylinder/circle always connects to borders of the window.
Thanks in what folder will I see this information related to this code commands?
DeepSOIC wrote:
Fri Mar 01, 2019 1:24 pm
For Lattice Autosize, I use camera properties to figure out the scale. It's not straightforward.
https://github.com/DeepSOIC/Lattice2/bl ... #L102-L125
How do you use this?
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Determine Scale of 3D View?

Postby wandererfan » Fri Mar 01, 2019 6:04 pm

regis wrote:
Fri Mar 01, 2019 1:09 pm
Where did you find this?
https://grey.colorado.edu/coin3d/classS ... df1447c780

It's used a few places in Gui, but I don't understand it yet.
User avatar
DeepSOIC
Posts: 7824
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Determine Scale of 3D View?

Postby DeepSOIC » Fri Mar 01, 2019 6:14 pm

regis wrote:
Fri Mar 01, 2019 5:12 pm
For Lattice Autosize, ...
How do you use this?
It is the inverse of what you need. Find out how large one pixel on your screen is. Then Invert the math of my module to achieve what you need. Sorry, I don't have it pre-made, yet.
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Determine Scale of 3D View?

Postby wandererfan » Sat Mar 02, 2019 3:39 pm

DeepSOIC wrote:
Fri Mar 01, 2019 6:14 pm
It is the inverse of what you need. Find out how large one pixel on your screen is. Then Invert the math of my module to achieve what you need.
Awesome hints, DeepSOIC, thanks.

I can now put a correctly scaled 3D window grab onto a TD Page.
Attachments
hypno_sameSize.png
hypno_sameSize.png (30.84 KiB) Viewed 830 times