Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Deform a meshes and transform along a curve (as a spine )

Discussion in 'General Graphics' started by Hamed_Kh, Sep 10, 2023.

  1. Hamed_Kh

    Hamed_Kh

    Joined:
    Sep 16, 2017
    Posts:
    1
    Hi everyone

    First of all, I'd better say I'm sorry due to my bad English Also I'm a totally beginner in the Unity forum so I probably post this issue in the wrong room, if so please guide me to the right forum subcategory.

    Anyway, I have a long road mesh with a lot of meshes , transform and other prefabs inside, I generated this long roads straight and I like to deform it along a curve spine and whenever this scene will be supposed to be loaded , this long road should be deform based on a curve ( among a few pre-defined curve) actually I want to make a variety of scene so that the player each time think that this scene is totally different.

    Nevertheless the question that I have is how could I deform the entire a node contain all of sub elements that I said along a curve so that the meshes completely follow the curve as a spine ( as if all sections of road are prependicular on the curve )

    Some people told me that it could be done by vertex shader and some other said that it could be implemented by displace each vertex one by one (it seems by this way a clone of the entire mesh should be prepared as a backup but it could consume the memory pointlessly), each one has its pros and cons. But I'm not familiar with such method.


    Is anyone can help me to clarify this method organasly and share some tutorial link or etc.


    Thanks a lot in advance
     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,741
    It could be done with a shader, but it would need a bit of setup as you would need to get the spline data into the shader, nt hard, and then you can deform the mesh in the usual way. One thing to note on doing that is you wont be deforming any colliders so that will need to be thought about. You could also do it by adding bones along the length of your road and skinning the entire mesh to those. Other solutions are to deform the mesh in a script and you can then also use the same script to deform collider proxy meshes, or add a mesh collider to the deformed mesh. And lastly you could do it by lofting the road from a spline and having objects link to the lofted surface. I have done the last two systems before for my own projects and they would fine, I even did as a test a simple track editor where pre made mesh objects were place along a spline and they deformed as they went.