Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gap between spline mesh segments
#1
Hello,

I am making a railway track using a Curvy spline. In runtime, I add a new segment with a mouse click, and then use the generator to make a mesh for this segment. 

Then I can move the cursor to a new position and click the mouse button, and another curvy segment is added here and the mesh generator makes another rail mesh that connects to the previous one.

My problem is that there are visible gaps between the mesh segments. Here is an image:

[Image: YWUSKvk]

I am using a Bezier splines, and have set the handles for the control points in code, which gives a smooth spline. But the gaps are still there between the segments.

Is there a way to not have the gaps? I saw in Example scene 12 - Train there are no gaps between the rails. How was this done? I am using the same cross-section spline, the same material, and the same generator, but I am getting these gaps.

I think the problem may be that I cannot move the position of the 'Handle In' arm on the control point of the segment where the mesh has already been generated. This is because that segment of track has already been placed on the terrain by the player, and so the spline shape needs to be fixed for that segment.
Reply
#2
Hi
I don't see an obvious reason based on your post. Can you please send me a reproduction case?
Thanks
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(07-27-2022, 02:00 PM)_Aka_ Wrote: Hi
I don't see an obvious reason based on your post. Can you please send me a reproduction case?
Thanks

Hello - Thank you - I will send you my Unity Project. How shall I do that - send you a zip file?
Reply
#4
Hi
Depending on the size of the zip, you can either send it by email (click on the "Contact Us" hyperlink at the bottom of the page), or upload it somewhere and send me the link via private message or email.
Thanks
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Hi
Thank you for the reproduction case.
From what I can see, the issue is due to minor imprecision in the computation of the tangents/handles. One can pursue fixing the imprecision, but I am thinking about a simpler solution: generate the track as a single mesh. When done like that, no gaps appear. This solution has two variants: either generating the whole track as a single mesh at each update of the spline, or keep your current solution when putting spline CPs (left clicks) and generate the whole spline only at the end of the spline drawing process (right click).

Compared to your solution, the downside of the one I suggest is of course lesser performance, but I am wondering if in your scenario the cost of generating the whole track as a single mesh is really a problem. This is a genuine question, since I don't know what are your constraints. As I can see from what you shared with me, the setup of your generator can be optimize if some conditions are met. For example, avoid generating the mesh collider when drawing the spline (I guess at that point no physics interactions are supposed to happen?). Also, you can avoid generating the UV2 coordinates, as long as you don't need them for light-map baking.
Also, this page might be helpful in the optimization process: https://curvyeditor.com/documentation/performancetips/start

Did this help?
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
Hello, 

Thank you for looking into this, and for your suggestions. 

Your idea of generating a single mesh would be ideal, but unfortunately I cannot do this, as I need each track mesh segment to be a similar length.

The reason for this is that the player will be able to delete parts of the track, by clicking on them. I need this ability for the player if they make a mistake, or want make changes later.

Also tracks will be able to be joined together by the player.

So I will have to try and fix the imprecision of the tangents/handles. Do you have any suggestions?

Thank you for the suggestions about optimizations. I have not got round to that yet, as I am still trying to get the basics working. But your suggestions will be very useful when I do!
Reply
#7
Hi
  1. I have a more precise tangent computing code that in my tests removed the gap between meshes in some cases, but other cases still have the gap, but less visible it seems. Give it a try:
    Go to the following method in CurvySplineSegment
    Code:
    public Vector3 GetTangent(float localF, Vector3 position, Space space = Space.Self)
    and add the following at its start
    Code:
    if (Spline.Interpolation == CurvyInterpolation.Bezier)
                    return CurvySpline.BezierTangent(threadSafeLocalPosition.Addition(HandleOut),
                        threadSafeLocalPosition,
                        threadSafeNextCpLocalPosition,
                        threadSafeNextCpLocalPosition.Addition(cachedNextControlPoint.HandleIn),
                        localF).normalized;
    As you can see if you check the code, the current implementation is computing the tangent by computing the delta between two very close points. The code above uses a specific implementation for Bezier splines.
  2. The handles you compute seem weird to me. It seems that, at least in some cases, the spline's first CP has a zero length handle, while the second one has a non zero length handle. This leads to a stretched spline, which you can notice from the UVs being stretched at the end of the mesh. Maybe solving this will solve the gap in mesh.
  3. This is not a solution, but as long as you are trying to fight the issue, it might be wise to set to false the Optimize parameter in the Shape Extrusion module, under the Path tab. Once the problem solved, you might then set Optimize back to true, and see if there are any regressions
  4. FYI, the tangents are computed when the mesh is rasterized in the Input Spline Path module. The equivalent class is InputSplinePath. The rasterization happens in its base class, SplineInputModuleBase, in its GetSplineData method. Look for the calls to InterpolateAndGetTangent in that method, that's where things happen.
    Those tangents are then used by the Shape Extrusion module to make the mesh volume. Look for BuildShapeExtrusion.Refersh(), and specifically its usage of path.Directions (the list of tangents of each rasterized point).
  5. To go back to the unique mesh solution: you know your use case better than me, so you are probably right when you say that this solution is not fit for your use case. But please allow me to add some points that might make that solution viable in your eyes. If these points are invalid, you don't need to take the time to explain to me why:
    You can use the Split parameter in the Volume Mesh module to split that single mesh into different meshes. The split meshes will not have the issue. The issue seems to come from using different extrusions with different splines. Single spline -> Single mesh extrusion -> Split Volume -> Different meshes with no gaps
    About joining track, you can concatenate your different track splines into one spline, then generate a single extrusion out of it.

I hope this helped
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
Hello. Thank you for your detailed message - I appreciate all your help. I really have a much better understanding of the inner workings of the system.

I apologise for the delay in getting back and letting you know you have answered my problem.

Point 2 explains why I was getting stretched UVs - I did not realise that would happen when you have no handle.
Reply
#9
Hi

Glad that I helped. No worries about the delay, it's completely fine, take all the time you need.

About the missing handles on only one side, it's like you stretch a lot the spline. To see it visually, what you can do is to activate the cache points (approximations) in the View Settings, and then play with the spline handles and see how they change, and how they can be packed or stretched at some points of the spline. These cache points are distributed evenly using the mathematical formula of the spline.
The following video can help you understand better:
https://www.youtube.com/watch?v=rP0zuAEoVJw

If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#10
(07-31-2022, 08:22 PM)_Aka_ Wrote: Hi
  1. I have a more precise tangent computing code that in my tests removed the gap between meshes in some cases, but other cases still have the gap, but less visible it seems. Give it a try:
    Go to the following method in CurvySplineSegment
    Code:
    public Vector3 GetTangent(float localF, Vector3 position, Space space = Space.Self)
    and add the following at its start
    Code:
    if (Spline.Interpolation == CurvyInterpolation.Bezier)
                    return CurvySpline.BezierTangent(threadSafeLocalPosition.Addition(HandleOut),
                        threadSafeLocalPosition,
                        threadSafeNextCpLocalPosition,
                        threadSafeNextCpLocalPosition.Addition(cachedNextControlPoint.HandleIn),
                        localF).normalized;
    As you can see if you check the code, the current implementation is computing the tangent by computing the delta between two very close points. The code above uses a specific implementation for Bezier splines.
  2. The handles you compute seem weird to me. It seems that, at least in some cases, the spline's first CP has a zero length handle, while the second one has a non zero length handle. This leads to a stretched spline, which you can notice from the UVs being stretched at the end of the mesh. Maybe solving this will solve the gap in mesh.
  3. This is not a solution, but as long as you are trying to fight the issue, it might be wise to set to false the Optimize parameter in the Shape Extrusion module, under the Path tab. Once the problem solved, you might then set Optimize back to true, and see if there are any regressions
  4. FYI, the tangents are computed when the mesh is rasterized in the Input Spline Path module. The equivalent class is InputSplinePath. The rasterization happens in its base class, SplineInputModuleBase, in its GetSplineData method. Look for the calls to InterpolateAndGetTangent in that method, that's where things happen.
    Those tangents are then used by the Shape Extrusion module to make the mesh volume. Look for BuildShapeExtrusion.Refersh(), and specifically its usage of path.Directions (the list of tangents of each rasterized point).
  5. To go back to the unique mesh solution: you know your use case better than me, so you are probably right when you say that this solution is not fit for your use case. But please allow me to add some points that might make that solution viable in your eyes. If these points are invalid, you don't need to take the time to explain to me why:
    You can use the Split parameter in the Volume Mesh module to split that single mesh into different meshes. The split meshes will not have the issue. The issue seems to come from using different extrusions with different splines. Single spline -> Single mesh extrusion -> Split Volume -> Different meshes with no gaps
    About joining track, you can concatenate your different track splines into one spline, then generate a single extrusion out of it.

I hope this helped
Have a nice day

Hello, I have been working on making train tracks using Curvy, and I am now trying to fix the issue in this thread again. The problem is that there are gaps between mesh segments of the tracks.

I tried some of your suggestions, but could not fix the issue. As you say in point 5, the problem seems to be that I am using different extrusions from different splines. 

However, I need different splines, as the player can place the train tracks at runtime. So I need a way for the player to add new track segments to the ends of existing tracks. 

The whole train network may end up being very big, so I cannot turn it all into a single spline to make a single mesh extrusion.

I am now trying to fix the problem by using catmull rom splines, and using connectors to join them and setting each segment's follow up to that of the other segment. However, this still leaves small gaps between the meshes.

Do you have any ideas on how I can get Curvy working to make the tracks from different splines to join without gaps?

Here is the code I am using to set the spline follow ups in the connection:

Code:
cpConnectingTo[0] = connectorUnderCursor.splineSegment;

                    CurvySplineSegment[] cpsToConnect = new CurvySplineSegment[2];

                    cpsToConnect[0] = cpConnectingTo[0];

                    cpsToConnect[1] = activeCP;

                    CurvyConnection theConnection = CurvyConnection.Create(cpsToConnect);

                    cpsToConnect[0].SetFollowUp(cpsToConnect[1], ConnectionHeadingEnum.Auto);

                    cpsToConnect[1].SetFollowUp(cpsToConnect[0], ConnectionHeadingEnum.Auto);


                    theConnection.gameObject.transform.SetParent(connectionsHolder.transform, true);
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adjust radius of generated mesh via script? Shackman 1 3 03-26-2024, 01:12 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_
  Keeping a fixed spline length jh092 3 16 02-21-2024, 06:25 AM
Last Post: Primrose44

Forum Jump: