Forum

Author Topic: How to make the View become to Y up, -Z forward via python?  (Read 1946 times)

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
How to make the View become to Y up, -Z forward via python?
« on: March 22, 2023, 12:39:18 PM »
I was trying to make the view become to Y up. -z forward, I saw with the code "chunk.crs= None", the View will become to Y up, Z forward , not matter if there is model or not, I would like to change the crs, but it seems like there is no way to control it directly, so I was using the following code to adjust one of my model:
Code: [Select]
  import Metashape as ms
    import math
   
    chunk = ms.app.document.chunk
    camera = chunk.cameras[0]
   
   
    mv = ms.app.model_view
    vp = mv.viewpoint
    vp.fov = 90
   
   
    angle = math.radians(90)
    rotation_matrix_y = ms.Matrix([[math.cos(angle), 0, -math.sin(angle)], [0, 1, 0], [math.sin(angle), 0, math.cos(angle)]])
    rotation_matrix_z = ms.Matrix.Diag([-1, -1, 1])
   
    #rotation_matrix_y = ms.Matrix([[1, 0, 0], [0, 0, 1], [0, -1, 0]])
    #rotation_matrix_z = ms.Matrix([[1, 0, 0], [0, -1, 0], [0, 0, -1]])
    Ro = ms.Matrix([[0.9219497701513975, -0.02682517004569788, 0.38637938812753064],
                   [-0.020038763625087008, -0.9995662407242738, -0.021581898821031623],
                   [0.3867907305897642, 0.012154861429187487, -0.922087409128589]])

    Trans = ms.Matrix([[0.9219497701513972, -0.02682517004569788, 0.38637938812753064, -4.97564693876466],
                     [-0.020038763625087004, -0.9995662407242738, -0.021581898821031623, 0.27391026894569304],
                     [0.3867907305897641, 0.012154861429187487, -0.922087409128589, -0.8262636690645881],
                     [0.0, 0.0, 0.0, 1.0]])
   
    vp.rot = chunk.transform.matrix.rotation() * Ro * rotation_matrix_y * rotation_matrix_z
    center = (chunk.transform.matrix * Trans).translation()

 Its actually work but it only works for the model I tested, I would like to if there is simple like
Code: [Select]
chunk.crs=None  to adjust the View directly? 
 I guess maybe there is something that i might missed,Is anyone know this? Thanks in advance

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14816
    • View Profile
Re: How to make the View become to Y up, -Z forward via python?
« Reply #1 on: March 22, 2023, 03:57:43 PM »
Hello Jay,

Do you want to switch the coordinate system axes for the model space (i.e. for the chunk and all the related assets) or you would like to change the viewpoint of the Model view as Y-up and -Z-forward, for example, pointing on the region center?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to make the View become to Y up, -Z forward via python?
« Reply #2 on: March 23, 2023, 06:05:54 AM »
Hey Alexey,

Thanks for your reply

I think should be switch the coordinate system axes for the model space, the main purpose is use "Model>Transform Object>Rotate Object" adjusting the model become Y up, -Z forward, the code "Chunk.crs=None" turn the crs become to Y up, Z forward, it helped, but not easier enough for the guy who don't know this software, I would like make it easier enough  (to become Y up, -z forward directly)



Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14816
    • View Profile
Re: How to make the View become to Y up, -Z forward via python?
« Reply #3 on: March 23, 2023, 04:54:05 PM »
Hello Jay,

Can you please check, if the following script performs the required operation (rotation of the coordinate system from Z-up, Y-forward to Y-up, -Z-forward)?

Code: [Select]
doc = Metashape.app.document
chunk = doc.chunk
T = chunk.transform.matrix
s = T.scale()
S = Metashape.Matrix().Diag((s, s, s, 1))
xm = Metashape.Matrix( [[1,0,0,0],[0,0,1,0],[0,-1,0,0],[0,0,0,1]] )
chunk.transform.matrix = xm * S * T

Assuming, that the chunk is not referenced in any geographic/projected coordinate system (Local coordinates are fine).

If there are any reference points (cameras or markers with the input source coordinate values in the Reference pane), you need to uncheck them.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to make the View become to Y up, -Z forward via python?
« Reply #4 on: April 03, 2023, 06:41:06 AM »
Hey Alexey,
       
      Thanks for your reply, but after I tested, this is not really what I wanted, the thing I would like to do is Change the View of the coordinate, the directly change is the coordinate icon become to Y up -z forward while the "Chunk.crs=None" make it Y up Z forward

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: How to make the View become to Y up, -Z forward via python?
« Reply #5 on: April 03, 2023, 06:57:11 PM »
Jay,

maybe these lines of code could change your viewpoint to Y up, X left and Z down

Code: [Select]
chunk = ps.app.document.chunk
vp = ps.app.model_view.viewpoint
M = chunk.crs.localframe(vp.center).rotation()
vp.rot = M.inv() * ps.Matrix.Diag((-1,1,-1))
Best Regards,
Paul Pelletier,
Surveyor

Jay

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: How to make the View become to Y up, -Z forward via python?
« Reply #6 on: May 04, 2023, 05:30:01 AM »
Jay,

maybe these lines of code could change your viewpoint to Y up, X left and Z down

Code: [Select]
chunk = ps.app.document.chunk
vp = ps.app.model_view.viewpoint
M = chunk.crs.localframe(vp.center).rotation()
vp.rot = M.inv() * ps.Matrix.Diag((-1,1,-1))

Sorry for the late reply, Paulo, its works good for me, thank you very much.