Announcement

Collapse
No announcement yet.

Easy way to set the focus - useful script !!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Easy way to set the focus - useful script !!!

    Hi,

    last I have got this great script at the Rhino forum. I would say, a must.
    The script help to set the focus of rendering with DOF effect to nay point in the perspective viewport without to change the view.

    -Micha

    PS: Joe or Corey, could be great, if this script could be added to the V-Ray menu - "set focus point" could be a good command name.

    Copy the code to a button and ready.
    Code:
    -_RunScript (
    ' Tested with Rhino3 SR4 only.
    
    ' Move a perspective projection view's target plane to pass through a given point.
    
    ' Affected view is that which is active when the script is launched.
    
    ' User is prompted to pick a point, in any view, through which  the initial view's 
    
    ' target plane is to pass.
    
    Option Explicit
    
    MoveTargetPlane
    
    Sub MoveTargetPlane()
    
    	Dim viewName
    
    	Dim cameraPoint
    
    	Dim viewCPlane
    
    	Dim targetCPlane
    
    	Dim userPoint, userPointCP
    
    	Dim targetPoint, targetPointCP
    
    	Dim newTargetPoint, newTargetPointCP
    
    	Dim deltaZCP
    
    	viewName = Rhino.CurrentView
    
    	If Not Rhino.IsViewPerspective(viewName) Then
    
    		Rhino.Print "MoveTargetPlane works in perspective projection views only."
    
    		Exit Sub
    
    	End If
    
    	cameraPoint = Rhino.ViewCamera(viewName)
    
    	viewCPlane = Rhino.ViewCPlane(viewName)
    
    	Rhino.EnableRedraw False
    
    	Rhino.Command "_CPlane _View"
    
    	targetCPlane = Rhino.ViewCPlane(viewName)
    
    	Rhino.ViewCPlane viewName, viewCPlane
    
    	Rhino.EnableRedraw True
    
    	userPoint = Rhino.GetPoint("Pick point in desired target plane")
    
    	If IsNull(userPoint) Then
    
    		Rhino.Print "No point was picked."
    
    		Exit Sub
    
    	End If
    
    	userPointCP = Rhino.XformWorldToCPlane(userPoint, targetCPlane)
    
    	targetPoint = Rhino.ViewTarget(viewName)
    
    	targetPointCP = Rhino.XformWorldToCPlane(targetPoint, targetCPlane)
    
    	newTargetPointCP = targetPointCP
    
    	newTargetPointCP(2) = userPointCP(2)
    
    	newTargetPoint = Rhino.XformCPlaneToWorld(newTargetPointCP, targetCPlane)
    
    	Rhino.ViewCameraTarget viewName, cameraPoint, newTargetPoint
    
    	deltaZCP = newTargetPointCP(2) - targetPointCP(2)
    
    	Rhino.Print "Target plane moved by " & CStr(Abs(deltaZCP)) & " units."
    
    End Sub
    )
    www.simulacrum.de - visualization for designer and architects

  • #2
    Easy way to set the focus - useful script !!!

    GREAT STUFF!!!

    Comment


    • #3
      Easy way to set the focus - useful script !!!

      ... and here a new script from the unknown script writer. Here my request at the rhino forum:

      Hallo,

      some weeks befor I have got this great script that allow to set the focus
      (camera target) so, that the view direction stay the same. A must for rendering
      with DOF and fine adjust the focus. )

      http://news2.mcneel.com/scripts/dnew...m=236453&utag=

      Now I search for a script that place a plane in the perspective viewport
      at the camera target point. So, I could see the which parts of a scene are
      in the focus. A nice luxery feature could be, that the material of the plane
      is set to transparency 30. So, in rendered viewport mode, the plane show
      the part befor and behind this focus plane.

      Example: I'm working on a jewelry ring rendering. I set the focus at the
      gem stones but I don't know which parts are in the focus plane.

      I hope somebody of the script writers like the idea and can help. ;o)

      Regards
      Micha
      Here the script ready to copy to a button. I have copy the both scripts to the default "right view" button of Rhino (red car).

      -Micha

      Code:
      -_RunScript (
      ' Tested with Rhino3 SR4 only.
      
      ' Draws a 30% transparent plane on a perspective projection view's target plane.
      
      ' Affected view is that which is active when the script is launched.
      
      ' The drawn plane fills the view. Selection state of objects is unaffected.
      
      
      
      Option Explicit
      
      
      
      DrawTargetPlane 30
      
      
      
      Sub DrawTargetPlane(transparency)
      
      	Dim viewName
      
      	Dim initialViewCPlane
      
      	Dim targetCPlane
      
      	Dim viewPixelSize
      
      	Dim camera
      
      	Dim cameraCP
      
      	Dim nearClipPlaneTopLeft, nearClipPlaneBottomRight
      
      	Dim nearClipPlaneTopLeftCP, nearClipPlaneBottomRightCP
      
      	Dim nearToTargetFactor
      
      	Dim targetTopLeftCP, targetBottomRightCP
      
      	viewName = Rhino.CurrentView
      
      	If Not Rhino.IsViewPerspective(viewName) Then
      
      		Rhino.Print "DrawTargetPlane works in perspective projection views only."
      
      		Exit Sub
      
      	End If
      
      	initialViewCPlane = Rhino.ViewCPlane(viewName)
      
      	Rhino.EnableRedraw False
      
      	Rhino.Command "_CPlane _View"
      
      	camera = Rhino.ViewCamera(viewName)
      
      	targetCPlane = Rhino.ViewCPlane(viewName)
      
      	viewPixelSize = Rhino.ViewSize(viewName)
      
      	nearClipPlaneTopLeft = Rhino.XformScreenToWorld(Array(0,0))
      
      	nearClipPlaneBottomRight = Rhino.XformScreenToWorld(viewPixelSize)
      
      	nearClipPlaneTopLeftCP = Rhino.XformWorldToCPlane(nearClipPlaneTopLeft, targetCPlane)
      
      	nearClipPlaneBottomRightCP = Rhino.XformWorldToCPlane(nearClipPlaneBottomRight, targetCPlane)
      
      	cameraCP = Rhino.XformWorldToCPlane(camera, targetCPlane)
      
      	nearToTargetFactor = cameraCP(2) / (cameraCP(2) - nearClipPlaneTopLeftCP(2))
      
      	targetTopLeftCP = VectorScale(nearClipPlaneTopLeftCP, nearToTargetFactor)
      
      	targetTopLeftCP(2) = 0
      
      	targetBottomRightCP = VectorScale(nearClipPlaneBottomRightCP, nearToTargetFactor)
      
      	targetBottomRightCP(2) = 0
      
      	AddTransparentPlane targetTopLeftCP, targetBottomRightCP, transparency
      
      	Rhino.ViewCPlane viewName, initialViewCPlane
      
      	Rhino.EnableRedraw True
      
      End Sub
      
      
      
      Sub AddTransparentPlane(topLeft, bottomRight, transparency)
      
      	Dim initialSelectedObjects
      
      	initialSelectedObjects = Rhino.SelectedObjects(True)
      
      	Rhino.UnselectAllObjects
      
      	Rhino.Command "_Plane " & Rhino.Pt2Str(topLeft, 12, True) & Rhino.Pt2Str(bottomRight, 12)
      
      	If Rhino.LastCommandResult <> 0 Then
      
      		Rhino.Print "Error adding plane."
      
      	Else
      
      		Rhino.FirstObject True
      
      		Rhino.Command "_-Properties _Material _Object _Enter _Transparency " & transparency & " _Enter _Enter"
      
      		Rhino.UnselectAllObjects
      
      	End If
      
      	If IsArray&#40;initialSelectedObjects&#41; Then
      
      		Rhino.SelectObjects initialSelectedObjects
      
      	End If
      
      End Sub
      
      
      
      Function VectorAdd&#40;v1, v2&#41;
      
        VectorAdd = Null
      
        If Not IsArray&#40;v1&#41; Or &#40;UBound&#40;v1&#41; <> 2&#41; Then Exit Function
      
        If Not IsArray&#40;v2&#41; Or &#40;UBound&#40;v2&#41; <> 2&#41; Then Exit Function
      
        VectorAdd = Array&#40;v1&#40;0&#41; + v2&#40;0&#41;, v1&#40;1&#41; + v2&#40;1&#41;, v1&#40;2&#41; + v2&#40;2&#41;&#41;
      
      End Function
      
      
      
      Function VectorScale&#40;v, d&#41;
      
        VectorScale = Null
      
        If Not IsArray&#40;v&#41; Or &#40;UBound&#40;v&#41; <> 2&#41; Then Exit Function
      
        If Not IsNumeric&#40;d&#41; Then Exit Function
      
        VectorScale = Array&#40;v&#40;0&#41; * d, v&#40;1&#41; * d, v&#40;2&#41; * d&#41;
      
      End Function
      &#41;
      www.simulacrum.de - visualization for designer and architects

      Comment


      • #4
        Easy way to set the focus - useful script !!!


        I have to test it.

        Comment


        • #5
          Easy way to set the focus - useful script !!!

          Originally posted by McNeel Rhino forum
          "Micha" <M@m.m> wrote:
          >
          >One wish more for the previous "move trarget plane" script. If the camera
          >is turned by Alt+Shift+RMB and I use the script, than the view jump so that
          >the camera is not turned. Maybe it is possible to keep the camera rotation.
          >
          >Ciao Micha
          >

          Hi Micha,
          MoveTargetPlane fixed. Also, MoveTargetPlane and DrawTargetPlane are in the
          attached zip because they have both been changed to not litter the command
          history.
          And here the new scripts ready to copy to a Rhino button:

          Move target plane
          Code:
          -_RunScript &#40;
          ' Tested with Rhino3 SR4 only.
          ' Moves a perspective projection view's target plane to pass through a given point.
          ' Affected view is that which is active when the script is launched.
          ' User is prompted to pick a point, in any view, through which the initial view's 
          ' target plane is to pass.
          ' Last modified - 2006 September 30
          
          Option Explicit
          
          MoveTargetPlane
          
          Sub MoveTargetPlane&#40;&#41;
          	Dim viewName
          	Dim targetCPlane
          	Dim userPoint, userPointCP
          	Dim newTargetPoint, newTargetPointCP
          	Dim cameraPoint
          	Dim cameraUp
          	viewName = Rhino.CurrentView
          	If Not Rhino.IsViewPerspective&#40;viewName&#41; Then
          		Rhino.Print "MoveTargetPlane works in perspective projection views only."
          		Exit Sub
          	End If
          	userPoint = Rhino.GetPoint&#40;"Pick point in desired target plane"&#41;
          	Rhino.CurrentView viewName
          	If IsNull&#40;userPoint&#41; Then
          		Rhino.Print "No point was picked."
          		Exit Sub
          	End If
          	Rhino.EnableRedraw False
          	targetCPlane = GetViewTargetCPlane&#40;viewName&#41;
          	userPointCP = Rhino.XformWorldToCPlane&#40;userPoint, targetCPlane&#41;
          	newTargetPointCP = Array&#40;0,0,userPointCP&#40;2&#41;&#41;
          	newTargetPoint = Rhino.XformCPlaneToWorld&#40;newTargetPointCP, targetCPlane&#41;
          	cameraPoint = Rhino.ViewCamera&#40;viewName&#41;
          	cameraUp = Rhino.ViewCameraUp&#40;viewName&#41;
          	Rhino.ViewCameraTarget viewName, cameraPoint, newTargetPoint
          	Rhino.ViewCameraUp viewName, cameraUp
          	Rhino.Print "Target plane moved by " & CStr&#40;Abs&#40;newTargetPointCP&#40;2&#41;&#41;&#41; & " units."
          	Rhino.EnableRedraw True
          End Sub
          
          Function GetViewTargetCPlane&#40;viewName&#41;
          	GetViewTargetCPlane = Null
          	If Not Rhino.IsView&#40;viewName&#41; Then Exit Function
          	Dim initialActiveView
          	Dim initialViewCPlane
          	Dim targetCPlane
          	initialActiveView = Rhino.CurrentView&#40;viewName&#41;
          	initialViewCPlane = Rhino.ViewCPlane&#40;viewName&#41;
          	Rhino.Command "_CPlane _View", False
          	targetCPlane = Rhino.ViewCPlane&#40;viewName&#41;
          	Rhino.ViewCPlane viewName, initialViewCPlane
          	Rhino.CurrentView initialActiveView
          	GetViewTargetCPlane = targetCPlane
          End Function
          &#41;
          Show target plane
          Code:
          -_RunScript &#40;
          ' Tested with Rhino3 SR4 only.
          ' Draws a 30% transparent plane on a perspective projection view's target plane.
          ' Affected view is that which is active when the script is launched.
          ' The drawn plane fills the view. Selection state of objects is unaffected.
          ' Last modified - 2006 September 30
          
          Option Explicit
          
          DrawTargetPlane 30
          
          Sub DrawTargetPlane&#40;transparency&#41;
          	Dim viewName
          	Dim initialViewCPlane
          	Dim targetCPlane
          	Dim nearClipPlaneTopLeft, nearClipPlaneTopLeftCP
          	Dim cameraCP
          	Dim nearToTargetFactor
          	Dim targetTopLeftCP, targetBottomRightCP
          	viewName = Rhino.CurrentView
          	If Not Rhino.IsViewPerspective&#40;viewName&#41; Then
          		Rhino.Print "DrawTargetPlane works in perspective projection views only."
          		Exit Sub
          	End If
          	initialViewCPlane = Rhino.ViewCPlane&#40;viewName&#41;
          	Rhino.EnableRedraw False
          	Rhino.Command "_CPlane _View", False
          	targetCPlane = Rhino.ViewCPlane&#40;viewName&#41;
          	nearClipPlaneTopLeft = Rhino.XformScreenToWorld&#40;Array&#40;0,0&#41;&#41;
          	nearClipPlaneTopLeftCP = Rhino.XformWorldToCPlane&#40;nearClipPlaneTopLeft, targetCPlane&#41;
          	cameraCP = Rhino.XformWorldToCPlane&#40;Rhino.ViewCamera&#40;viewName&#41;, targetCPlane&#41;
          	nearToTargetFactor = cameraCP&#40;2&#41; / &#40;cameraCP&#40;2&#41; - nearClipPlaneTopLeftCP&#40;2&#41;&#41;
          	targetTopLeftCP = VectorScale&#40;nearClipPlaneTopLeftCP, nearToTargetFactor&#41;
          	targetTopLeftCP&#40;2&#41; = 0
          	targetBottomRightCP = VectorNegate&#40;targetTopLeftCP&#41;
          	AddTransparentPlane targetTopLeftCP, targetBottomRightCP, transparency
          	Rhino.ViewCPlane viewName, initialViewCPlane
          	Rhino.EnableRedraw True
          End Sub
          
          Sub AddTransparentPlane&#40;topLeft, bottomRight, transparency&#41;
          	Dim initialSelectedObjects
          	initialSelectedObjects = Rhino.SelectedObjects&#40;True&#41;
          	Rhino.UnselectAllObjects
          	Rhino.Command &#40;"_Plane " & Rhino.Pt2Str&#40;topLeft, 12, True&#41; & Rhino.Pt2Str&#40;bottomRight, 12&#41;&#41;, False
          	If Rhino.LastCommandResult <> 0 Then
          		Rhino.Print "Error adding plane."
          	Else
          		Rhino.FirstObject True
          		Rhino.Command &#40;"_-Properties _Material _Object _Enter _Transparency " & transparency & " _Enter _Enter"&#41;, False
          		Rhino.UnselectAllObjects
          	End If
          	If IsArray&#40;initialSelectedObjects&#41; Then
          		Rhino.SelectObjects initialSelectedObjects
          	End If
          End Sub
          
          Function VectorNegate&#40;v&#41;
            VectorNegate = Null
            If Not IsArray&#40;v&#41; Or &#40;UBound&#40;v&#41; <> 2&#41; Then Exit Function
            VectorNegate = Array&#40;-v&#40;0&#41;, -v&#40;1&#41;, -v&#40;2&#41;&#41;
          End Function
          
          Function VectorScale&#40;v, d&#41;
            VectorScale = Null
            If Not IsArray&#40;v&#41; Or &#40;UBound&#40;v&#41; <> 2&#41; Then Exit Function
            If Not IsNumeric&#40;d&#41; Then Exit Function
            VectorScale = Array&#40;v&#40;0&#41; * d, v&#40;1&#41; * d, v&#40;2&#41; * d&#41;
          End Function
          &#41;
          www.simulacrum.de - visualization for designer and architects

          Comment


          • #6
            Easy way to set the focus - useful script !!!

            great micha, I will try it.
            but why don't you download the latest SR of Rhino ? SR5b ?
            jp

            Originally posted by Micha

            Code:
            -_RunScript &#40;
            ' Tested with Rhino3 SR4 only.
            Freelance Industrial Designer - Rhino3d v4 - Vray for Rhino

            Comment


            • #7
              Easy way to set the focus - useful script !!!

              The script is not from me, I have wished it at the rhino forum and an anonymous script writer has post it. The script are a must for renderings with DOF!!!
              www.simulacrum.de - visualization for designer and architects

              Comment


              • #8
                Easy way to set the focus - useful script !!!

                oh...ok

                complement of information, interesting tool Dept of Field Calculator:
                http://www.cambridgeincolour.com/tut...calculator.htm
                Freelance Industrial Designer - Rhino3d v4 - Vray for Rhino

                Comment


                • #9
                  Easy way to set the focus - useful script !!!

                  Thanks for the link.

                  Joe and Corey, could the scripts add as command to the Vray menu? Could be nice if every user could use this tools per standard installation.

                  I have ask the programmer and he allow to use the scripts for Vray for Rhino.

                  http://news2.mcneel.com/scripts/dnew...m=239730&utag=
                  www.simulacrum.de - visualization for designer and architects

                  Comment


                  • #10
                    Easy way to set the focus - useful script !!!

                    I agree. I use both sripts and I love it.

                    Comment

                    Working...
                    X