Forgot password?

Create an account!

Forum

« back

RhinoScript – Creating cameras dynamically

Messages

Please log in to write a message.

  • 8. Hanno (Jul 28, 2009 14.12):

    Thats an interesting effect. But your side note (that it only applies to parallel perspectives) already solves it:

    In parallel perspective it does not matter how far away your camera is from the target. The only things that matter are the view direction and the viewport extent. And both of these behave as expected, so the cameras you create are perfectly fine.
    Its like your normal parallel viewports (top/front/right): With zooming you only change the viewport extent, but you do not really move towards the model (the camera can never pass one object and see what's behind).

    Note: That does not explain why Rhino positions the camera as it does, but it explains why it doesn't matter :-)


    Hanno

  • 7. drape (Jul 25, 2009 01.58):

    I can't explain it either. Using your technique off adding points and also capturing the viewport extents and adding reference spheres at the target locations, i could visualize the change in cameras more easily. 1) There appears to be an almost hyperbolic change in the camera's position while the target changes in a linear fashion. 2) even though there is an unpexpected change, the views don't change meaning the extent of the view and it's center focus are the same. It looks the same.

    Note: these results is for a parallel projection camera. When testing for perspective it seems like a more expected result. Change the projection type to see the difference (change the 1 to a 2)

    Here is my strange test script. sloppy but it works:

    //

    Dim strOldTitle
    Dim strView, arrCamera, arrTarget
    Dim XCamera, yCamera, zCamera, xTarget, yTarget, zTarget
    Dim newYCamera, newYTarget

    ' create camera and set type of camera: parallel (1) or perspective (2)
    ' if parallel ViewCameraLens will work

    xCamera = 109.356
    yCamera = -78.468
    zCamera = 133.989

    xTarget = 360.157
    yTarget = 81.713
    zTarget = -106.498

    i = 1

    Do While i <= 37

    newYCamera = yCamera + (i*16)
    newYTarget = yTarget + (i*16)

    arrCamera = Array(xCamera, newYCamera, zCamera)
    arrTarget = Array(xTarget, newYTarget, zTarget )

    If IsArray(arrCamera) And IsArray(arrTarget) Then

    If i < 10 Then

    strOldTitle = Rhino.CurrentView
    Rhino.RenameView strOldTitle, "mold cam 0" & i
    strView = Rhino.CurrentView

    ElseIf i > 10 Then

    strOldTitle = Rhino.CurrentView
    Rhino.RenameView strOldTitle, "mold cam " & i
    strView = Rhino.CurrentView

    End If

    Rhino.ViewCameraTarget strView, arrCamera, arrTarget
    Rhino.ViewProjection strView, 1
    Rhino.ViewCameraLens strView, 50

    End If

    Rhino.AddNamedView strView

    Rhino.AddPoint arrCamera
    Rhino.AddSphere arrTarget, 1

    'Extract View Point Corners

    arrRect = Rhino.ViewNearCorners

    Rect = Array (arrRect(0), arrRect(1), arrRect(3), arrRect(2), arrRect(0))
    Rhino.AddPolyline Rect

    i = i + 1

    Loop

  • 6. Hanno (Jul 24, 2009 16.59):

    Hi,

    I did a quick check, and this seems a bit strange indeed. Your loop is fine, if you draw dots instead of cameras they are where they should be.
    Unfortunately I have never worked with cameras to that extent, so I have no hint what could be the problem... if you find out, be sure to post it!

    Regards

    Hanno

  • 5. drape (Jul 22, 2009 11.38):

    Habbo,

    That makes sense I will work on that. A question first: Below is a script I just wrote to make an array of parallel cameras spaced in Y by 16. The script works but the Camera values are not what they should be. However, the target values seem correct. Bug in my script or bug in rhino? ;) Seriously, if I am setting camera values but they are being ignored or changed, then why do dynamic cameras? Sommething is wrong.

    Regards,
    drape

    -----------------


    Dim strOldTitle
    Dim strView, arrCamera, arrTarget
    Dim XCamera, yCamera, zCamera, xTarget, yTarget, zTarget
    Dim newYCamera, newYTarget

    ' create camera and set type of camera: parallel (1) or perspective (2)
    ' if parallel ViewCameraLens will work

    xCamera = 109.356
    yCamera = -78.468
    zCamera = 133.989

    xTarget = 360.157
    yTarget = 81.713
    zTarget = -106.498

    i = 0

    Do While i <= 37

    newYCamera = yCamera + (i*16)
    newYTarget = yTarget + (i*16)

    arrCamera = Array(xCamera, newYCamera, zCamera)
    arrTarget = Array(xTarget, newYTarget, zTarget )

    If IsArray(arrCamera) And IsArray(arrTarget) Then

    If i < 10 Then

    strOldTitle = Rhino.CurrentView
    Rhino.RenameView strOldTitle, "mold cam 0" & i
    strView = Rhino.CurrentView

    ElseIf i > 10 Then

    strOldTitle = Rhino.CurrentView
    Rhino.RenameView strOldTitle, "mold cam " & i
    strView = Rhino.CurrentView

    End If

    Rhino.ViewCameraTarget strView, arrCamera, arrTarget
    Rhino.ViewProjection strView, 1
    Rhino.ViewCameraLens strView, 50

    End If

    Rhino.AddNamedView strView

    i = i + 1

    Loop

  • 4. Hanno (Jul 22, 2009 09.34):

    Hi,

    a nested array looks like this:

    myArray = Array( Array(1, 2, 3), Array(4, 5, 6) )

    This is an array containing two arrays. As usual, myArray(n) returns the nth element of the array. So if you say

    myVar = myArray(0)

    myVar contains Array(1, 2, 3). If you want to access the elements of the inner arrays directly, you can do

    myVar = myArray(0)(1)

    Now myVar contains 2 (element at position 1 of the element at position 0).
    You can play this as long as you like, nesting arrays inside arrays inside arrays inside arrays [...]

    This is a very powerful data structure, but can become quite complex.
    While experimenting with arrays, you can use the array_print method (part of my array library) to make array structures visible. This method can print nested arrays to the rhino command prompt.

    Hanno

  • 3. drape (Jul 21, 2009 06.32):

    Habbo,

    Thanks for you reply. Could you point me in the right direction to learn how to construct and parse nested arrays? Any example scripts, pseudocode etc. would be welcome. I will return the favor by posting a script which implements creating cameras dyncamilly from nested arrays.

  • 2. Hanno (Jul 16, 2009 10.17):

    Hi,

    that's exactly what I would do. Depending on how complex you like your data structures, you can either create separate lists for all parameters, like:

    arrViewNames = Array("Pers 01", "Pers 02")
    arrCameraLocations = Array(Array(10, 10, 10), Array(20, 20, 20))
    etc.

    and then use a for loop and always use arrViewNames(i) etc. to produce them.

    Or you could put all parameters per camera in one array, like:

    Array("Pers 01", Array(10, 10, 10), Array(0, 0, 0), 1, 50)

    and then create an array of the data arrays of all your cameras. This is a more flexible data structure (because you can grab all settings of one camera as one entity), but also more complex to implement.

    Hope that helps!

    Hanno

  • 1. drape (Jul 14, 2009 20.24):

    Hello,

    I'm trying to create a simple, comprehensive way to create multiple cameras in a script. Parameters would include: Camera and target locations, view name, projection type and lens size. This is the script I've written which makes one camera (rather awkwardly). How would folks make, let's say, 10 cameras dynamically? Would parameters be grouped together per camera in a list? Would a For loop be used to produce the cameras? Thanks.

    -----

    Dim strOldTitle
    Dim strView, arrCamera, arrTarget

    strOldTitle = Rhino.CurrentView

    Rhino.RenameView strOldTitle, "Pers 01"

    strView = Rhino.CurrentView

    arrCamera = Array(10, 10.0, 10.0)
    arrTarget = Array(0.0, 0.0, 0.0)

    ' create camera and set type of camera: parallel (1) or perspective (2)
    ' if parallel ViewCameraLens will work

    If IsArray(arrCamera) And IsArray(arrTarget) Then

    Rhino.ViewCameraTarget strView, arrCamera, arrTarget
    Rhino.ViewProjection strView, 1
    Rhino.ViewCameraLens strView, 50

    End If

    Rhino.AddNamedView strView

Recommend

Why are these buttons gray?