Distace from Camera to object in drawing.

Distace from Camera to object in drawing.

Postby Al Hart » Wed Feb 03, 2010 12:12 am

I would like to be able to move the mouse around on a drawing and view the distance from the camera to the object near the mouse.

I know I could write a tool to do this, but there is probably one out there already. Can someone point me in the right direction?
1
Al Hart
IRender nXt from Render Plus
User avatar
Al Hart 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby Gaieus » Wed Feb 03, 2010 1:47 am

Hi Al,

Here is one - by Rick - and it's free!
http://www.smustard.com/script/CameraDistance
0
User avatar
Gaieus 
 

Re: Distace from Camera to object in drawing.

Postby Jim » Wed Feb 03, 2010 1:51 am

Maybe Fullmer (or you) can add this to his Onscreen plugin:

viewtopic.php?f=323&t=16837
0
Hi

Jim 
Global Moderator
 

Re: Distace from Camera to object in drawing.

Postby Al Hart » Wed Feb 03, 2010 3:19 am

Gaieus wrote:Hi Al,

Here is one - by Rick - and it's free!
http://www.smustard.com/script/CameraDistance


Thanks, I'll give it a look. :ugeek:
0
Al Hart
IRender nXt from Render Plus
User avatar
Al Hart 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby Chris Fullmer » Wed Feb 03, 2010 6:07 am

Jim wrote:Maybe Fullmer (or you) can add this to his Onscreen plugin:

viewtopic.php?f=323&t=16837


Oh Jim, that is an old plugin. I should look at it again. i can't believe it works at all!

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: Distace from Camera to object in drawing.

Postby Jim » Wed Feb 03, 2010 6:16 am

Oh sorry - I know how you feel!
0
Hi

Jim 
Global Moderator
 

Re: Distace from Camera to object in drawing.

Postby Al Hart » Wed Feb 03, 2010 6:30 am

Gaieus wrote:Hi Al,

Here is one - by Rick - and it's free!
http://www.smustard.com/script/CameraDistance


This one returns to distance from the camera t the eye.

I would like to have a tool which lets you determine the distance from the camera to arbitrary objects in the drawing. I want to use it to set Focal Lengths for Depth of Field calculations.

This is not a good example, because the eye may be in the same place as the center of focus, but if the eye were raised up a bit, then it would probably be way behind the desired focal point.

0
Al Hart
IRender nXt from Render Plus
User avatar
Al Hart 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby thomthom » Wed Feb 03, 2010 8:23 am

Ah - yes. That would be a good tool. And for my use, since I'd use V-Ray I'd want it to display the distance in inches as well as model units.

Not sure if there's a tool like that out there though.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby TIG » Wed Feb 03, 2010 1:23 pm

Assuming that you have something selected then
Code: Select all
model=Sketchup.active_model
eye=model.active_view.camera.eye
ss=model.selection[0]
distance=eye.distance(ss.bounds.center)
returns the distance from the camera's 'eye' to the 'center' of the selection's bounding-box...
You can of course improve this - another way to get the distance to the 'face' of a selection would be to get the vector between the 'eye' and the 'center' and then do a 'raytest' to find the first point hit and get that distance...
Code: Select all
model=Sketchup.active_model
eye=model.active_view.camera.eye
ss=model.selection[0]
distance=(model.raytest[eye, eye.vector_to(ss.bounds.center)])[0].distance(eye)
This then returns the 'distance'...
You can improve it further by testing if the second item in the returned raytest array contains the selected object and if not redo the raytest from the first item [point] in its array along the same vector...
Code: Select all
model=Sketchup.active_model
eye=model.active_view.camera.eye
ss=model.selection[0]
vector=eye.vector_to(ss.bounds.center)
rayt=model.raytest[eye,vector]
pt=rayt[0]
while not rayt[1].include?(ss)
  rayt=model.raytest[pt,vector]
  pt=rayt[0]
end#while
pt=rayt[0]
distance=eye.distance(pt)
Hope this helps... :?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Distace from Camera to object in drawing.

Postby Al Hart » Wed Feb 03, 2010 5:39 pm

I took the utilitiestools.rb script in SketchUp, which displays an X,Y location as you move the mouse and changed it to display the distance from the camera instead.

get_focal_length.jpg


The heart of the change is this routine to display the camera distance:

Code: Select all
   # get camera distance from the eye to a point at (x,y,0)
   def get_distance(target)
      model = Sketchup.active_model
      eye = model.active_view.camera.eye
      distance = eye.distance(target)
      # display in drawing units and inches
      slength = Sketchup.format_length(distance) + sprintf(" (%g\")", distance)
      return slength
   end#def


Try the attached script: get_camera_distance.rb

[Edit: I uploaded a new version of get_camera_distance.rb]
0
Al Hart
IRender nXt from Render Plus
User avatar
Al Hart 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby TIG » Wed Feb 03, 2010 6:01 pm

But that measures the eye to target distance...
You want the eye to object distance ?
The object might be between the target and the eye positions !
See my example on how to use the eye>>>target vector and raytest from the eye along that vector for objects in between... perhaps using a selected object as the source [it needs work as it was only a first draft... but selecting a group/instance between the eye and target will give the distance to it ?]
:?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Distace from Camera to object in drawing.

Postby Al Hart » Wed Feb 03, 2010 6:02 pm

There was a bug in get_camera_distance.rb.

I uploaded a new version.

(One person had downloaded it already - sorry - please get a new version)
0
Al Hart
IRender nXt from Render Plus
User avatar
Al Hart 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby Al Hart » Wed Feb 03, 2010 6:26 pm

TIG wrote:But that measures the eye to target distance...
You want the eye to object distance ?
The object might be between the target and the eye positions !
See my example on how to use the eye>>>target vector and raytest from the eye along that vector for objects in between... perhaps using a selected object as the source [it needs work as it was only a first draft... but selecting a group/instance between the eye and target will give the distance to it ?]
:?




I call get_distance(target) with the point from OnMouseMove() after calling pick(x,y) - not the target of the camera view.

I think it is working properly.

Here is a rendering after selecting the end of the cylinder as the target point and setting the Depth of Field to be very blurry (3.0).

focal_length.jpg
0
Al Hart
IRender nXt from Render Plus
User avatar
Al Hart 
PluginStore Author
PluginStore Author
 

Re: Distace from Camera to object in drawing.

Postby TIG » Wed Feb 03, 2010 8:57 pm

I apologize... :oops:
I hadn't read your script fully - your target isn't camera.target - you have a good idea - it works fine... 8-)
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Distace from Camera to object in drawing.

Postby Bertier » Fri Jul 15, 2011 9:23 am

hello

could that plugin be used to create motion blur in an animation ?

thank you.
0

Bertier 
 

Re: Distace from Camera to object in drawing.

Postby mpowell1234567890 » Tue Aug 09, 2011 9:21 pm

Cool, thanks. Love it when I can know how far away something is in a model. :D

Al Hart wrote:I took the utilitiestools.rb script in SketchUp, which displays an X,Y location as you move the mouse and changed it to display the distance from the camera instead.

get_focal_length.jpg


The heart of the change is this routine to display the camera distance:

Code: Select all
   # get camera distance from the eye to a point at (x,y,0)
   def get_distance(target)
      model = Sketchup.active_model
      eye = model.active_view.camera.eye
      distance = eye.distance(target)
      # display in drawing units and inches
      slength = Sketchup.format_length(distance) + sprintf(" (%g\")", distance)
      return slength
   end#def


Try the attached script: get_camera_distance.rb

[Edit: I uploaded a new version of get_camera_distance.rb]
0

mpowell1234567890 
 

Re: Distace from Camera to object in drawing.

Postby pibuz » Sun Feb 12, 2012 4:10 pm

That is a lovely script, but it seems I'm not able to load it..
How can I do that?

Thanks a lot Al!

**EDIT: ok, I moved the original utilities rb to another folder and renamed your script "utilitiestools.rb", and it works: now I can get camera distance 8-)
Is there a less homemade or brute method? :lol: Thanks again?
0

pibuz 
 

Re: Distace from Camera to object in drawing.

Postby Dan Rathbun » Sun Feb 12, 2012 6:15 pm

Renaming files is dangerous.

Make a subfolder of Plugins dir, named: !_autoload

"Plugins/!_autoload"

Then get my !autoload script here, and put it in Plugins folder.

After.. you can put little scripts that you wish to autoload in the "Plugins/!_autoload" folder.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Distace from Camera to object in drawing.

    Postby angeli7on » Fri Jan 04, 2013 11:37 am

    Hi, I got confused about this.
    I try using get_camera_distance but the result aren't DOF
    am I missing something ?

    here I attach my screen shot
    if too small I also upload here:
    http://imageshack.us/f/254/bingungdof2.jpg

    please advice, thanks alot.
    0

    angeli7on 
     

    Re: Distace from Camera to object in drawing.

    Postby TIG » Fri Jan 04, 2013 12:07 pm

    But the distance given by the tool is 703" - not '10' units in the Camera DOF dialog ?
    Try using the real equivalent distance [in the correct units for that dialog] to see what happens.
    The distance returned by the tool is the distance from the camera 'eye' up to the picked point - in your screenshot it's given in 'inches'...
    0
    TIG
    User avatar
    TIG 
    Global Moderator
     

    Re: Distace from Camera to object in drawing.

    Postby Chris Fullmer » Fri Jan 04, 2013 7:10 pm

    Yeah, so what are the expected units of that rendering dialog box? Feet? Meters? cm?

    703 inches =

    58.58 feet
    17.8562 meters
    1785.62 cm

    My best guess is that it is expecting feet or meters based on the DOF shown in the 2 screenshots. 10 is too close, but 703 is clearly waaaaaaay to far. So its gotta be something in the middle, which would probably be feet or meters.
    0
    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written
    User avatar
    Chris Fullmer 
    SketchUp Team
    SketchUp Team
     

    Re: Distace from Camera to object in drawing.

    Postby angeli7on » Sat Jan 05, 2013 3:32 am

    Hi TIG and Chris Fullmer, thanks for your reply.
    I think I already put the unit into inch. and I already put 703 (not just 10) in Overide_focal_dist, but the result are all sharp.
    I got 703 from get_camera_distance plugin, on the red ball.
    here I attach another screenshot with color and setting, I'm going to make the red ball to be sharp and the other ball become blurry.
    Do you have simple samples of your blurred .skp ?
    and here also my .skp file in google drive:
    https://docs.google.com/open?id=0BxjFhe ... VFKdFNWRHM
    many thanks for your help guys.
    0

    angeli7on 
     

    Re: Distace from Camera to object in drawing.

    Postby Chris Fullmer » Sat Jan 05, 2013 4:26 am

    It's unclear if you tried what we suggested. I told you to try 58.8 in case V-Ray is expecting the input to be in feet, or put 17.8562 in case it is expecting meters. Do those two numbers then report back.
    0
    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written
    User avatar
    Chris Fullmer 
    SketchUp Team
    SketchUp Team
     

    Re: Distace from Camera to object in drawing.

    Postby Chris Fullmer » Sat Jan 05, 2013 4:30 am

    To elaborate again, the SketchUp pop-up is saying 703". But it appears that the V-Ray window is expecting the input to be in something other than inches, otherwise it would have worked. So other common units would be feet or meters. Since we know that object is 703" from the camera, we'll convert that to feet. It is 58.8 feet. Or maybe V-Ray is expecting meters, so convert 703" to meters and you get 17.8562 meters. That is why I'm saying try those two numbers, I'm hoping one will work. Then you will know from that point on, which unit V-Ray is expecting.
    0
    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written
    User avatar
    Chris Fullmer 
    SketchUp Team
    SketchUp Team
     

    Re: Distace from Camera to object in drawing.

    Postby thomthom » Sat Jan 05, 2013 12:25 pm

    Have you tried adjusting the F-Stop?
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: Distace from Camera to object in drawing.

    Postby Chris Fullmer » Sat Jan 05, 2013 5:58 pm

    Looks like he's got his f-stop set at 2.8. That should give a good DOF blur. And indeed in his first post, the image where he has f-stop at 2.8 and focal distance at 703, there is no visible blur, but when he changed the focal distance to 10, the entire image was blurry, indicating that the DOF is working, he just needs to set the correct distance.
    0
    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written
    User avatar
    Chris Fullmer 
    SketchUp Team
    SketchUp Team
     

    Re: Distace from Camera to object in drawing.

    Postby Chris Fullmer » Sat Jan 05, 2013 6:04 pm

    I'm already changing my mind. I can see that lowering the f-stop even more might be needed Thom, good call. That should definitely be tried as well.

    The further the object is, the harder it is to get a shallow DOF (blur). Lowering the aperture will help create even more blur. But its possible the object could be so far away that there will never be any apparent blur. You could resort to using tilt frame to force a blur. But I'm thinking at that distance, you should be able to get some blur.
    0
    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written
    User avatar
    Chris Fullmer 
    SketchUp Team
    SketchUp Team
     

    Re: Distace from Camera to object in drawing.

    Postby thomthom » Sun Jan 06, 2013 1:07 pm

    He used a tool to measure the distance, so it should be correct.
    It is possible that the F-Stop in VfS isn't working 100% like a real camera does.
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: Distace from Camera to object in drawing.

    Postby Chris Fullmer » Sun Jan 06, 2013 5:45 pm

    Well, in thinking about it, he's trying to blur something that is 58 feet or 17+ meters away. I'll get out my camera later today and open it to 2.8 and shoot something at about that distance, see if it produces any blur. At that distance, there is a chance there should be no blur.
    0
    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written
    User avatar
    Chris Fullmer 
    SketchUp Team
    SketchUp Team
     

    Re: Distace from Camera to object in drawing.

    Postby TIG » Sun Jan 06, 2013 7:45 pm

    As I understand it... the bigger the f-stop number the greater the depth of field about the focal-depth.
    So a large number uses a 'pinhole' which has almost everything focused about that point, but a small number uses a 'wide-eyed' aperture which focuses on the point, with things nearer or farther away being shown blurred...
    In real cameras the smaller the aperture size [i.e. the bigger the number] the less light gets into the 'film' and so this affects the shutter-speed in turn - so then there are three variables to juggle. But in rendering the focal-depth and f-stop interact to control the sharpness of objects that are nearer/farther away... and the 'speed' is therefore somewhat arbitrary...
    :?
    0
    TIG
    User avatar
    TIG 
    Global Moderator
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     

    Next


     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: No registered users and 4 guests

    Visit our sponsors: