A clone of an active_view.camera
-
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). -
Have you tried
.dup
? -
-
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.
-
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 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).
-
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 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.
-
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...
Advertisement