Snap Mesh Object to Surface

Hello,

My goal with this code:

Take a vehicle object made of meshes and have the bottom of the tires snap to a roadway surface, so the vehicle is perfectly oriented on top of the surface. This can be a very tedious task if done manually for many vehicles over many positions. I would like the vehicle to snap down in only the Z-direction from a top view. Any thoughts on internal Rhino commands which would be useful to do this?

Thanks,
Martin

Hi Martin - by this do you mean you’d like to make a script that does this? Is the roadway planar, or nearly level at least?

-Pascal

Hello Pascal,

I apologize for being unclear. Yes, I was thinking of making a script to do this. I would say that generally the roadway is nearly level, but does have some crowning because the surface is generated from scan data of an actual roadway.

The biggest issue I am having is the logic for a Rhino command which I can use the bottom extents of the meshed tires and snap them to the roadway surface. I have considered generating points at the lower extents and using the “ProjectPointToSurface” and having the script delete the generated points after snapping the vehicle.

I appreciate any thoughts on how I can do this.

Martin

Hi Martin - you’ll probably want to get the bounding box of the car and use the lowest point from this as the starting point for your move. I’ll attach a py file that I have - I can’t remember what state it is in but it may be of some use.

MoveProjectEach.py (3.0 KB)

-Pascal

Pascal,

Thanks! I will certainly look this over and see what I can do.

Martin

Pascal,

The code is awesome. With a few adjustments on the orientation, I can get it to work for me.

I am encountering one issue, where the target object (roadway) is a block instance instead of a surface/roadway. The block instance of the roadway is comprised of a point cloud and surface, but generally the point cloud is hidden with only the surface showing. Any thoughts as to how I can work with a block instance?

Martin

Hi Martin - the cheap way out is to BlockEdit, select the surface, copy to clipboard, exit the block editing and then paste the surface and use that as the temporary target.

-Pascal

Pascal,

I figured that would be the case.

Another problem I am encountering is with the bounding box. Since the bounding box is relative to the world coordinates and not the vehicle (block instance) object, I am not able to correctly orient the object onto the roadway surface. My initial thought was to use the bounding box of the imported (and referenced) object and determine the lowest point from the bounding box. Then determine the distance between that lowest point and the roadway surface, and calculate the needed angle of rotation from the law of cosines.

I do know the vector that the vehicle is currently facing relative to the world coordinate system.

I am a little stuck as to how I can determine what angle is needed. This comes back to my question as to how I can possibly add a point to the lowest location on the vehicle (block instance). Any thoughts on this?

Martin

Hi Martin - are all the cars coming in aligned in some way ortho to the world? If so, you can draw a curve down the center of the road, then you can estimate a heading from the tangent of that curve at the location nearest the car when it plops down.

-Pascal

Pascal,

I am writing it for vehicles that have already been places and oriented in a top view along the surface, but are floating about the roadway. The script would, ideally, project them in the z-direction to the surface, and then rotate the vehicles about the center of gravity sphere within the vehicle geometry to have the tires oriented along the surface. These vehicles would have all types of orientations, and would not always be ortho to the world.

I added a portion in my code which took a user input which is able to determine the current heading and roll angle of the vehicle. I am trying to work on a code that will orient the vehicle’s pitch and roll angles, so that the tires are properly sitting on the surface.

Martin

Hi Martin - if the basic un-manipulated block is oriented to the world in some predictable way, then it might pay to insert a new copy at the insertion point of the one you’re working on - then you’ll have a known base orientation to work from - something like using a curve tangent as a target location and orientation could then work.

-Pascal

Pascal,

I understand what you’re getting at by having a base orientation to work from, but I am unsure how to work with the base orientation (lets say the vehicle comes in at 0 degrees facing along the X-axis and no roll) in the position I want, and then have the vehicle rotate so all the wheels are aligned with the surface of the roadway.

I attached this image to help illustrate what I mean. Let’s assume this roadway has a downgrade and this vehicle is oriented in the base orientation that you were speaking of. I am trying to find out how to orient the vehicle to snap onto the roadway surface via a script instead of manually orienting it.

Martin

Hi Martin - just thinking out loud but imagine for now the insertion point is at the center of the base of the vehicle.

I’m thinking that you have a curve on the roadway and that you can determine what location on that curve you want the car on. Get a curve tangent vector there, and transform the initial ‘base’ block from its insertion point and vector 1,0,0 (say) to the new point and the tangent vector.

Something like that but then adjust in the surface normal direction to correct for the actual insertion point elevation or whatever, but I think you’d get it pretty close.

-Pascal

Hi @pascal,

Can’t write the code now, but for similar thing what works quite well is:

  1. Get car bbox
  2. get its 3 lowest points out of 4
  3. project these on target objects
  4. for each projection find upper-most one.
  5. Use Orient3d from source to 3 resulting projected points.

–jarek

Hi Jarek - something like that might work as well - my understanding is that the car may not be oriented correctly going in, apart from not conforming to the slope, it is also not pointed along the road… I was trying to come up with a way to point it down the road - then some jiggling like you suggest might be a great way to finish off. But I might have misunderstood and be solving an non-existent problem…

-Pascal

1 Like

Pascal and Jarek,

I believe between these two suggestions that I may get it to work. I greatly appreciate the support!

Martin