Search Unity

Dreamteck Splines - Powerful and Flexible Spline Solution

Discussion in 'Assets and Asset Store' started by Dreamteck, May 11, 2016.

  1. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    233
    Thanks for the reply. I am using the method to get a SplineResult based on evaluating the spline, but the normal field returned is always (0,0,1). Which is probably correct for the way the spline is set up, but I need the normal of the mesh surface that was generated from the spline.

    To make things more clear, here is what the mesh looks like and how the spline mesh is configured. I added the red markup to show the normals I want to get.

    ramp.png
     
  2. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    149
    I get what you're saying. Even in your case, the normal value of the spline shouldn't be that. Click the little curve with the arrow button and you'll be able to see what the normals are of your spline control points. Theoretically, the normal of the mesh should be pretty close to the normal of the spline since you are just using a cube for your extrusion. Here is a sample of the code I'd use for this situation, where 0.4 is just an arbitrary value along the spline you wish to evaluate.:
    Code (CSharp):
    1. SplineMesh splineMesh = GetComponent<SplineMesh>();
    2.  
    3.             SplineResult sr = follower.computer.Evaluate(0.4);
    4.             sr = splineMesh.computer.Evaluate(0.4);
    5.  
    6.             pointNormal = sr.normal;
    Does this make sense? If your mesh was more complicated, I'd say a ray casting approach would probably be in order.
     
  3. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    233
    Sure enough the normals are all pointing in the Forward direction (0,0,1). I can drag the normal around, but it distorts the mesh. What would be the correct "Set Normals" type for this situation (e.g., At Camera, Calculate, etc). I assume I need to come up with the right combination of that along with settings in the Spline Mesh script.
     
  4. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    149
    Out of curiosity, what type of spline are you using? In my use cases, I start with my normals pointing in world up (0,1,0) and use a bezier spline and, in some cases, a linear. I really can't imagine that the spline type is the issue though. I suspect that the culprit is the starting orientation of your spline. You could just go into the spline you drew, select all points, set the normals to 0,1,0 and then it would likely be a matter of swapping the x and y values of the scale on the mesh you extruded (the values you put into the little red box in your image). Either that or just redraw the spline with normals up and then use that for your extrusion.
     
  5. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    233
    I'm using a B-Spline. I set the normals for all control points to (0,1,0) and swapped the x/y extrusion, and the ramp looks visually correct. But now I get (0,1,0) for the normal when I evaluate the spline at all points along the spline. Tried Bezier spline with same results.

    I would have expected the SplineResult normal values be based on the "curve" of the spline and not just interpolate between the control point normals, but it appears that is what is going on.
     
  6. EugeneJefferson

    EugeneJefferson

    Joined:
    Sep 5, 2016
    Posts:
    2
    i there) How I can easily create empty spaces between 2 points along the spline? For example I want empty space from second point to third and from 4th point to 5th)
     
  7. EugeneJefferson

    EugeneJefferson

    Joined:
    Sep 5, 2016
    Posts:
    2
    Okay) Just expanded DTS tools)
     
  8. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    149
    You expect correctly. I can tell you that, for me, I am getting the normal of the spline at the point along the spline that I am evaluation, not the normal of the control point. If you were to insert a point on the spline between 2 points where there is an obvious curve, does that new point have the normals that you would expect it to have or are they pointing solidly in one specific direction (like up or forward)?
     
  9. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    233
    Inserting a point still gives me a (0,1,0) normal:
    ramp_normals.png ramp_inspector.png
     
  10. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    149
    Okay. I may have figured this out. I created a new scene with only a Spline Computer in it at first. I then created a new spline (using B spline, as you did). I manually set the normals to 0,1,0 for all of the points in the inspector window (select all, set the values). I end up with a curve that looks like this:

    Screen Shot 2019-09-23 at 8.22.35 PM.png

    Next, I created an extrusion using a simple cube mesh. Like so:
    Screen Shot 2019-09-23 at 8.26.09 PM.png

    Finally, I select the spline, click the normals button, change the setting to "By Direction" and then click the "Set Normals" button (which I didn't realize was a button at first. I end up with this:

    Screen Shot 2019-09-23 at 8.28.37 PM.png

    I was afraid that this would wind up distorting the extruded mesh but it doesn't. Let me know if this works for you.
     
  11. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    233
    Clicking "Set Normals:" did the trick! Thank you very much for helping with this.

    It's confusing that the Set Normals is a button with the semi-colon there!

    Now the question is how I can compute the normal in script, as we allow in-game editing of the mesh control points. Basically find the function that corresponds to pressing "Set Normals:".

    Edit: Found the code in SplinePointNormalEditor.cs:

    double percent = (double)selected / (points.Length - 1);
    SplineResult result = computer.Evaluate(percent);
    points[selected].normal = Vector3.Cross(result.direction, result.right).normalized;
     
    Last edited: Sep 25, 2019
  12. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    149
    That's awesome! I agree that the set normals button isn't obvious. Us Alan's gotta stick together. Now that their game is released on the Apple Arcade, hopefully we'll be getting the 2.0 update.
     
  13. Polymerse

    Polymerse

    Joined:
    Mar 6, 2017
    Posts:
    6
    Hey I need a little help with something

    I have a spline with 1 junction splitting the spline into 4 possible paths.

    I want to have a single particle system send particles down each route randomly at the same speed. Almost like cars choosing a lane after all being in the same lane.

    How do i go about that?
     
  14. Polymerse

    Polymerse

    Joined:
    Mar 6, 2017
    Posts:
    6
    Also is there anyway to scale splines with the Unity transform tools? Cause it doesn't seem to be doing anything.
     
  15. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    149
    Scaling splines works fine for me. Can you share more info on what issues you are running into?
     
  16. Polymerse

    Polymerse

    Joined:
    Mar 6, 2017
    Posts:
    6
    figured that out, just needed it on local my bad!