Projecting nurbs curve cv to a polygon mesh using python api

by denilson020898 posted 29 days ago | 3 comments

Is there a quick way to do that? I know maya has that feature, but I attempt to prevent maya creates history nodes. Even though I can delete it at the end.

Thanks

by vshotarov posted 29 days ago

Depending on how exactly you want the projection to work, I think you have to options.

  • The simpler one is to just get the closest point on the mesh using getClosestPoint

  • If you want an actual projection along a vector you can use something like the closestIntersection function. The way it would work is starting from your CV position you cast a ray in the specified direction and you get the first intersection with the mesh along this ray.

Hope that helps!

by denilson020898 posted 29 days ago

thanks.

one more question, can I use active camera's attributes to yield the ray?

It would be a clever solution to my problem.

by vshotarov posted 29 days ago

I suppose so. Not sure what the best way of getting the current active camera in your situation would be, but if you know the camera you can get it's forward vector (negative Z in Maya) and use that as the ray direction. You can get it from the camera's world matrix, where the third row of the matrix - elements [2][0], [2][1], [2][3] - are the Z axis and you just need to negate it.

Alternatively, you can get a projecting outwards vector that starts at the camera and goes through your CV by doing

directionVec = cvPos - cameraPos