Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Viewport camera using Python Plugin #81

Open
mariolino007 opened this issue Nov 17, 2023 · 12 comments
Open

Create Viewport camera using Python Plugin #81

mariolino007 opened this issue Nov 17, 2023 · 12 comments

Comments

@mariolino007
Copy link

mariolino007 commented Nov 17, 2023

I am a beginner in Python programming, I am trying to create a new "camera viewport" with the following code, however I am having difficulty finding a way to assign the created viewport name, however I can't enter the X1, Y2, Z3 angles.

If anyone can help me I thank you very much.

is it possible to have more examples than those plublished at this address ?
https://tmontaigu.github.io/CloudCompare-PythonPlugin/examples.html

CC & Python together are amazing !!! Congratulations !!!


import pycc
from cccorelib import CCVector3d
new_viewport_object = pycc.cc2DViewportObject()
new_viewport_parameters = new_viewport_object.getParameters()
new_camera_center = CCVector3d(2023, 301, 610)
auto_update_focal = False
new_focal_distance = 600.5
new_pivot_point = CCVector3d(2028, 305, 485)
new_viewport_parameters.setCameraCenter(new_camera_center, auto_update_focal)
new_viewport_parameters.setPivotPoint(new_pivot_point, auto_update_focal)
new_viewport_parameters.computeDistanceToHalfWidthRation()
new_viewport_parameters.computeDistanceToWidthRatio()
new_viewport_parameters.computeViewMatrix()
new_viewport_parameters.computeWidthAtFocalDist()
new_viewport_object.setParameters(new_viewport_parameters)
pycc.GetInstance().addToDB(new_viewport_object)
print("Camera Center:", new_viewport_parameters.getCameraCenter())
print("Focal Distance:", new_viewport_parameters.getFocalDistance())
print("Pivot Point:", new_viewport_parameters.getPivotPoint())
print("Distance To Half Width Ratio:", new_viewport_parameters.computeDistanceToHalfWidthRation())
print("Distance To Width Ratio:", new_viewport_parameters.computeDistanceToWidthRatio())
print("View Matrix:", new_viewport_parameters.computeViewMatrix())
print("Width At Focal Dist:", new_viewport_parameters.computeWidthAtFocalDist())
@tmontaigu
Copy link
Owner

setting the name is as easy as new_viewport_object.setName("my name")

@mariolino007
Copy link
Author

mariolino007 commented Nov 18, 2023 via email

@tmontaigu
Copy link
Owner

What are these angles ?

@mariolino007
Copy link
Author

mariolino007 commented Nov 19, 2023 via email

@mariolino007
Copy link
Author

mariolino007 commented Nov 19, 2023 via email

@tmontaigu
Copy link
Owner

tmontaigu commented Nov 19, 2023

In that case I think the viewMat member of the paramerters could be what you are looking for

view_mat = pycc.ccGLMatrixd()
view_mat.initFromParameters(
    phi_rad=0.1,
    theta_rad=0.2,
    psi_rad=0.3,
    t3D=CCVector3d(0,0,0)
)

new_viewport_parameters.viewMat = view_mat;

@mariolino007
Copy link
Author

mariolino007 commented Nov 20, 2023

testing this code:

import pycc
from cccorelib import CCVector3d
new_viewport_object = pycc.cc2DViewportObject()
new_viewport_parameters = new_viewport_object.getParameters()
view_mat = pycc.ccGLMatrixd()
view_mat.initFromParameters(
    phi_rad=0.1,
    theta_rad=0.2,
    psi_rad=0.3,
    t3D=CCVector3d(2028,305,485)
)
new_focal_distance = 50
new_viewport_object.setName("camera1")
new_viewport_parameters.viewMat = view_mat;
pycc.GetInstance().addToDB(new_viewport_object)

all paramter of the viewport are all zero .......
With that modification were you able to set the angles instead ? Could you share the more complete code ?

@tmontaigu
Copy link
Owner

What do you mean they are zero ?

import pycc
from cccorelib import CCVector3d

new_viewport_object = pycc.cc2DViewportObject()
new_viewport_object.setName('my name')
new_viewport_parameters = new_viewport_object.getParameters()
new_camera_center = CCVector3d(2023, 301, 610)
auto_update_focal = False
new_focal_distance = 600.5
new_pivot_point = CCVector3d(2028, 305, 485)
view_mat = pycc.ccGLMatrixd()
view_mat.initFromParameters(
    phi_rad=0.1,
    theta_rad=0.2,
    psi_rad=0.3,
    t3D=CCVector3d(0,0,0)
)


new_viewport_parameters.setCameraCenter(new_camera_center, auto_update_focal)
new_viewport_parameters.setPivotPoint(new_pivot_point, auto_update_focal)
new_viewport_parameters.computeDistanceToHalfWidthRation()
new_viewport_parameters.computeDistanceToWidthRatio()
new_viewport_parameters.computeViewMatrix()
new_viewport_parameters.computeWidthAtFocalDist()
new_viewport_parameters.viewMat = view_mat;
new_viewport_parameters.setFocalDistance(new_focal_distance)

new_viewport_object.setParameters(new_viewport_parameters)

pycc.GetInstance().addToDB(new_viewport_object)

new_viewport_parameters = new_viewport_object.getParameters()

print("Camera Center:", new_viewport_parameters.getCameraCenter())
print("Focal Distance:", new_viewport_parameters.getFocalDistance())
print("Pivot Point:", new_viewport_parameters.getPivotPoint())
print("Distance To Half Width Ratio:", new_viewport_parameters.computeDistanceToHalfWidthRation())
print("Distance To Width Ratio:", new_viewport_parameters.computeDistanceToWidthRatio())
print("View Matrix:", new_viewport_parameters.computeViewMatrix())
print("Width At Focal Dist:", new_viewport_parameters.computeWidthAtFocalDist())
print("View Mat", view_mat.asArray())

I don't see any zero

@mariolino007
Copy link
Author

Now it seems to be working !!!
Many thanks !!!

@mariolino007
Copy link
Author

using angles is quite complicated, I am trying to use FromViewDirAndUpDir however I have an unexpected error ?

import pycc
from cccorelib import CCVector3d
forward_vector = CCVector3d(0, 0, -1)
up_vector = CCVector3d(0, 1, 0)
rotation_matrix = pycc.ccGLMatrixd.FromViewDirAndUpDir(forward_vector, up_vector)
TypeError: Unable to convert function return value to a Python type! The signature was
	(forward: cccorelib.CCVector3d, up: cccorelib.CCVector3d) -> ccGLMatrixTpl<double>
At:
  <string>(8): <module>

@tmontaigu
Copy link
Owner

Indeed there is a problem with this function, I will push a fix for that

@tmontaigu
Copy link
Owner

Fixed with #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants