Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incorrect mesh alignment after extrusion on curved path
#1
Hi,

I have the following scenario:
- A spline path made of 2 points describing an arc (Bezier interpolation). Each point has "Auto Handles" OFF, and I manually set their Handle In & Out values to create an arc.
- A spline shape (the default 2D/Rectangle shape, the issue is more visible the wider this shape is - for example, width 20-)

I create a mesh using Shape extrusion > Volume mesh > Create mesh.
   


The problem is: the extruded mesh doesn't correctly align at the start & end positions:
   
In the image above, you can see the created mesh (in black) doesn't align correctly with the start. The red line is a reference of how it should align.

This is a problem because I'm building an editor where the player places several pieces together, and they should align perfectly with eachother. Currently they don't, and a gap is visible because of this issue.

How can I fix this? (I'm using the latest v8.8 btw)

Thanks!
Reply
#2
Hi,

Try setting all the parameters related to the spline/mesh details to a very high value, to see if this solves the issue. If it doesn't, please send me a scene with a reproduction case and I will check it.

Here is a list of the parameters I am thinking of:
Curvy Spline -> Cache Density
Curvy Spline -> Max Points Per Unit
Input Spline Path -> Use Cache (try with both values)
Shape Extrusion -> Path -> Resolution
Shape Extrusion -> Path -> Optimize (set to false)

I hope this helps.
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
Hi,

Doing this solved the issue:

Curvy Spline -> Cache Density ---> 100
Curvy Spline -> Max Points Per Unit ---> 100
Input Spline Path -> Use Cache ---> TRUE

The shape extrusion settings (Resolution & Optimize) don't seem to affect the resulting mesh, in terms of the problem we're discussing.... i.e, when using the above settings, any resolution and optimize on/off yields a correct result

But... isn't this overkill? Any value lower than 100 for "Cache Density" or "Max points per unit" brings back the issue...
Also: shouldn't a non-cached spline return a more correct result than the cached one?
Reply
#4
I agree, it is overkill, and the non-cached spline should not have the issue. Please send me the reproduction case, and I will try to come up with a fix or workaround that would be better. Sorry for the issue in the first place.
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
No problem, thanks for your help!
I just sent you a PM with the repro case.
Reply
#6
Hi,

After analyzing your repro case, I came to the conclusion that the shape of your spline is what creates the issue. For a Bezier to approximate perfectly a circle, and as far as I know, you need a Control Point every quarter of circle. Your half circle only has 2 CPs.
I modified your scene to use a circle spline that has a CP every 90°. I used the Range parameters of the Shape Extrusion module to use only half of the circle. In this case, even with default values and non cached spline, the gap is not visible.
I attached the scene.

Does this solve your issue?
Have a nice day.


Attached Files
.unity   SampleScene.unity (Size: 223.67 KB / Downloads: 1)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
Unfortunately not: the half circle was just an example to illustrate the issue, not that I needed a half circle explicitly for my usecase. In my game, all pieces are made of 2 control points, which can be moved by the player at runtime.

I just created another example scene that shows a more realistic use case: a straight piece (shown in green) placed right after a "S-Curve" piece (shown in red):
   

As you can see, there's a gap at the bottom (and an overlap at the top)
I'm attaching the scene to this post, in case you need it. Try moving the leftmost control point up & down (well, Z axis in the provided scene) to see the issue. No issue at all with 2 straight pieces, of course Smile

Then again, the problem disappears when using cache with a very high density, as discussed before. Or maybe the gap becomes so small that it's no longer noticeable, I don't know '^^


Attached Files
.unity   SampleScene_v2.unity (Size: 149.95 KB / Downloads: 1)
Reply
#8
You are right. The issue comes from how the tangent is computed in this case. I will post a fix here very soon.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
In file CurvySplineSegment.cs at line 1340, you will find this method:
public Vector3 GetTangent(float localF, Vector3 position, Space space = Space.Self)
In it, you will find this line
const float fIncrement = 0.01f;
Change the value to 0.001f, or even 0.0001f. You will get better results, but might see issues in small splines (around 1m length or less).
This is just a workaround. A real fix that I should implement is to set that value dynamically, depending on the length of the spline segment.
Did this fix the issue?
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
That fixed it! Smile

I changed it so that the fIncrement is a very small value only for the start & end localF:
Code:
float fIncrement = (localF == 0f || localF == 1f) ? 0.000001f : 0.01f;

This change meant that now "BuildShapeExtrusion.cs" logs this info message "Look rotation viewing vector is zero" when computing pathRotation (line 1002), which I fixed changing this:
Code:
Quaternion pathRotation = Quaternion.LookRotation(
                        path.Directions.Array[sample],
                        path.Normals.Array[sample]
                    );

to this:
Code:
Quaternion pathRotation = path.Directions.Array[sample] == Vector3.zero ? Quaternion.identity : Quaternion.LookRotation(
                        path.Directions.Array[sample],
                        path.Normals.Array[sample]
                    );


Thank you very much for your help! Heart

Edit: That same "Look rotation viewing vector is zero" is now thrown on other places that try to access the Directions Array, like in "BuildVolumeCaps.cs". I'm just applying the same modification shown above on all of them.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rasterized Path Range issue proton 5 19 6 hours ago
Last Post: _Aka_
  Adjust radius of generated mesh via script? Shackman 1 4 03-26-2024, 01:12 PM
Last Post: _Aka_
  Not seeing mesh extended after following YT PaulM 1 3 02-02-2024, 12:01 PM
Last Post: _Aka_
  Trigger Zones along Spline Mesh dlees9191 1 5 01-05-2024, 10:18 AM
Last Post: _Aka_

Forum Jump: