MoI discussion forum
MoI discussion forum

Full Version: Getting camera view and restore it

From: Samba Oleg (SAMBA_OLEG)
6 May 2019   [#1]
Hello,

maybe I am to stupid, but I just cannot figure out how to read out the camera position of a specific view and restore this view later via a hotkey. I need to restore these views for a documentation project where is use MOI4 beta (since the MOI3 always crashes because of the complexity of my models). I would be grateful if someone could help me out. I have no coding experience at all.

Thanks a lot in advance.
From: Death
6 May 2019   [#2] In reply to [#1]
Not sure if this is it, but I'd set these values to whatever you need:




Image Attachments:
temp.png 


From: Michael Gibson
6 May 2019   [#3] In reply to [#1]
Hi Samba, MoI does not currently have a view save/restore type function built in, it is something that I want to add in the future though.

In a pinch you could use what is described here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=5981.2

- Michael
From: Samba Oleg (SAMBA_OLEG)
7 May 2019   [#4]
Thank you Death, but I already tried these settings, but it can't exactly reproduce the viewport settings.

Thank you Michael,

I could solve my problem reading the threads.

My solution now is to

1) Get the Position with a script using a hotkey:

script:var v = moi.ui.mainWindow.viewpanel.getViewport('3D'); moi.copyTextToClipboard( 'Camera=' + v.cameraPt.toString() + '\r\nTarget=' + v.targetPt.toString() );

The result is:

Camera=407,04,-682,82,-230,78
Target=62,01,-44,72,-21,64

2) Replace some commas with points:-(((

Camera=407.04,-682.82,-230.78
Target=62.01,-44.72,-21.64

3) Edit the script for the camera:

script: camPt=moi.VectorMath.createPoint(407.04,-682.82,-230.78);targetPt=moi.VectorMath.createPoint(62.01,-44.72,-21.64);moi.ui.getActiveViewport().reset();moi.ui.getActiveViewport().setCameraAndTarget(camPt,targetPt);

4) Enter the script using TAB.

It works, but is not very comfortable.
From: Michael Gibson
7 May 2019   [#5] In reply to [#4]
Hi Samba, maybe try this method instead:
http://moi3d.com/forum/index.php?webtag=MOI&msg=6962.13

Is that any better?

- Michael
From: Samba Oleg (SAMBA_OLEG)
8 May 2019   [#6] In reply to [#5]
Hi Michael,

this makes it a lot easier. Thank you very much.
From: Michael Gibson
8 May 2019   [#7] In reply to [#6]
Hi Samba, you're welcome!

Also if you're going to that particular dialog frequently you can set up a shortcut key for showing it. Put this in as the command part for the shortcut key:

script: moi.ui.createDialog( 'moi://ui/ViewAngleDialog.htm' );

- Michael
From: Samba Oleg (SAMBA_OLEG)
9 May 2019   [#8] In reply to [#7]
Thanks again for this hint!

This will speed it up a lot. I have so many different view in my documentation.

Is there any change to automate the process of converting the given coordinates into a reusable format without changing comma to dots and spaces?


Result of the 1st script:

Camera=407,04,-682,82,-230,78
Target=62,01,-44,72,-21,64

Needed Values for the dialog box:

407.04 -682.82 -230.78
62.01 -44.72 -21.64

Samba
From: Michael Gibson
9 May 2019   [#9] In reply to [#8]
Hi Samba, do the different fields in the dialog not use commas for the decimal separator when you first open it? It is supposed to if your operating system language settings have that set.

Does this work where the numbers are separated by spaces? :

script: function str(pt) { return moi.ui.formatCoordinate(pt.x,2) + ' ' + moi.ui.formatCoordinate(pt.y,2) + ' ' + moi.ui.formatCoordinate(pt.z,2); } var v = moi.ui.mainWindow.viewpanel.getViewport('3D'); moi.copyTextToClipboard( 'Camera=' + str(v.cameraPt) + '\r\nTarget=' + str(v.targetPt) );

Let me know if that still isn't quite right.

- Michael
From: Samba Oleg (SAMBA_OLEG)
10 May 2019   [#10] In reply to [#9]
Hi Michael,

I always get the commas as the decimal separator. This is the return of the last script:

Camera=10,24 -20,48 10,24
Target=0 0 0

My system is set to German.

Samba
From: Michael Gibson
10 May 2019   [#11] In reply to [#10]
Hi Samba, and that doesn't work to put in those comma decimal separator values in the dialog?

Here's another version that should make period decimal separators:

script: function str(pt) { return moi.ui.formatCoordinate(pt.x,2).replace(',', '.') + ' ' + moi.ui.formatCoordinate(pt.y,2).replace(',', '.') + ' ' + moi.ui.formatCoordinate(pt.z,2).replace(',', '.'); } var v = moi.ui.mainWindow.viewpanel.getViewport('3D'); moi.copyTextToClipboard( 'Camera=' + str(v.cameraPt) + '\r\nTarget=' + str(v.targetPt) );

- Michael
From: Samba Oleg (SAMBA_OLEG)
10 May 2019   [#12] In reply to [#11]
Hi Michael,


it's a bit funny. The extended view angle dialog shows the camera and target position with commas on my system, but it only accepts the coordinates with a period decimal separator.

So, the last script solved the problem for me.

Thank you very much for spending so much time.


Samba