• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

A clone of an active_view.camera

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 3 Posters 295 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    tomasz
    last edited by 25 Oct 2010, 13:00

    In my script I want to store an active_view.camera and restore it later on.

    When I use regular:

    stored_camera=Sketchup.active_model.active_view.camera
    ...
    modifying the view
    ...
    Sketchup.active_model.active_view.camera=stored_camera
    

    This does not restore camera, because the stored_camera just references the current_view.camera

    So I have done a copy of the camera object:

    stored_camera=Sketchup.active_model.active_view.camera.clone
    ...
    modifying the view
    ...
    Sketchup.active_model.active_view.camera=stored_camera
    

    This gives me an error:
    #<TypeError: reference to deleted Camera>

    I have tried Marshal::load(Marshal.dump(active_view.camera)) but the camera has no such a method.

    The question is : how can I successfully store current_view.camera?
    I know that it could be done by doing what Marshal is supposed to do, but we do not have access to all camera parameters (2p perspectives).

    Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 25 Oct 2010, 13:06

      Have you tried .dup ?

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • T Offline
        tomasz
        last edited by 25 Oct 2010, 13:10

        @thomthom said:

        Have you tried .dup ?

        Same thing. Object already deleted.

        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomasz
          last edited by 25 Oct 2010, 13:11

          I have found a solution, but will be thankful for a simpler, if such exists.

          I can create a temp_scene, make modifications to a view and then set selected_scene=temp_scene and delete it. Can be done with undo as well.

          Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 25 Oct 2010, 13:20

            If you remember the current camera's data then later on you can simply make a new camera using those ?
            camera = model.active_view.camera eye = camera.eye target = camera.target up = camera.up pers = camera.perspective? fov = camera.fov

            change stuff including the view's camera details...###

            new_camera = Sketchup::Camera.new(eye, target, up, pers, fov)
            The 'new_camera' is now a 'clone' of the original 'camera'...
            model.active_view.camera = new_camera
            now sets the camera back as it was initially...

            TIG

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomasz
              last edited by 25 Oct 2010, 13:30

              @tig said:

              If you remember the current camera's data then later on you can simply make a new camera using those ?

              @unknownuser said:

              I know that it could be done by doing what Marshal is supposed to do, but we do not have access to all camera parameters (2p perspectives).

              Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 25 Oct 2010, 14:10

                The 2pt perspective is not an accessible camera parameter.
                No more that Sketchup.send_action("viewTop:") or Sketchup.send_action("viewPerspective:") is... the camera settings only change for the eye/target/up when a '2pt Perspective' is evoked...
                A 2pt Perspective is a 3D view with perspective 'off' [parallel projection] with a specific eye point / target / up that gives no distortion in 3D when perspective is 'off' - therefore doesn't saving the settings I listed duplicate a 2pt anyway - IF the camera's view it is one, because the camera is set so ??
                If there were a Sketchup.send_action("viewPerspective2pt:") to set it [and there's not] then there's still no way of establishing if the view was in '2pt' anyway - other than the camera's parameters.....

                TIG

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tomasz
                  last edited by 25 Oct 2010, 19:08

                  @tig said:

                  The 2pt perspective is not an accessible camera parameter.

                  Unfortunately it is a camera parameter.
                  cx cy and Scale describe how much the 2d image has been shifted and zoomed in\out.
                  They are not being accessible from Ruby.


                  CameraProperties.png

                  Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 25 Oct 2010, 19:14

                    But it is a transient setting!
                    If you click in the view it evaporates...
                    It would be good if it were accessible but it is pretty transient...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    1 / 1
                    • First post
                      7/9
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement