Jump to content
Sign in to follow this  
raincole

How to snap an object to another precedurally?

Recommended Posts

Say I have a cone and a sphere:

61cfb42659b7e_Screenshot2022-01-01092845.png.55ab5bd506ab9367d8036348f5c7aabf.png

I'd like to snap the cone to the closest point on the sphere, along the direction {0, -1, 0}. Like this:

61cfb43e30102_Screenshot2022-01-01092857.png.0ea681f44d426423d322df0d847d84a5.png

I know Ray SOP, but it snaps every point to the sphere:

61cfb4461fa0a_Screenshot2022-01-01092911.thumb.png.e2f57147ca619ac3eb35fa5463b8a627.png

I'd like to keep the cone as a cone. Is there a node to do this procedurally?

Share this post


Link to post
Share on other sites
Posted (edited)
21 hours ago, konstantin magnus said:

Add a point underneath, ray and match its position.

match_ray_top.hiplc

Thank you!

But I'd like to know how to make it more generic. For example when the ray I cast doesn't align with the world axes (e.g. {0.811, 0.32, 0.48}). I'm trying to make something just like Ray but only ray the closest point, and translate the rest of the geo accordingly. Is it possible?

Edited by raincole

Share this post


Link to post
Share on other sites

Hi rain,

isolate the closest point and apply its offset vector to all other points. 

vector pos = point(1, 'P', 0);
vector rest = point(1, 'rest', 0);
vector delta = pos - rest;
v@P += delta;

 

object_snap.hipnc

Share this post


Link to post
Share on other sites

Here are some ideas.

  • calculate the closest distance to geo for all points and calculate attributes (closest point on target geo or ray projected point, Normal optionally ...)
  • find best point (closest point)
  • add the target point of the best point (add attributes if needed)
  • substract closest point (source) to move object to center (reorient optionally using the direction to center point of the object and up vector the point with highest y-value for example)
  • move geo to target point (reorient geo optionally using N,up) 

snap_closest_point.hipnc

  • Thanks 1

Share this post


Link to post
Share on other sites

Compute N and  up for the destination surface, i.e on its points; somehow create the destination point on the surface - it could be a ray, scatter, attribute transfer - anything that interpolates N and up

Create your object with the part you want facing the object towards Z, then put a Match Size: Justify Z: min, the other Justify value depends on your geometry, make sure the tip of your object is on the origin.

Then copy to points SOP.

 

ctp.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×