Search Unity

[RELEASED] Curvy: Fast Spline Interpolation

Discussion in 'Assets and Asset Store' started by Jake-L, Feb 14, 2013.

?

Is it fine to release Curvy as a Unity 4.2 package?

Poll closed Dec 27, 2014.
  1. YES, I'm already using Unity 4

    103 vote(s)
    88.0%
  2. YES, but it should work in Unity 3.5 nevertheless

    7 vote(s)
    6.0%
  3. NO, I don't have Unity 4 installed and won't be able to access it in the AssetStore

    7 vote(s)
    6.0%
Thread Status:
Not open for further replies.
  1. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Thanks, I've added range check to the next version.
     
  2. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    Thanks,

    CreateSplineMesh creates 2d mesh, is there way to create extruded 3d mesh?
     
    Last edited: Aug 27, 2013
  3. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Custom shapes >should< support this. The new MeshBuilder (v1.52) definitely will support this.
     
  4. Ogien

    Ogien

    Joined:
    Nov 21, 2012
    Posts:
    165
    Yes it does reverse, but its stops at Spline Node CP000 even if Loop is turned on. Going forward loop works fine, its just the reverse that does not loop.
     
  5. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    I've checked again and no matter what I do it works like expected. I've sent you a private message for further investigation.
     
  6. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    is there way to get nearest point on spline (TF) from ray? i need to select point on spline using camera.ScreenPointToRay(Input.mousePosition)
     
  7. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    You can call Ray.GetPoint() to get a point in the scene and use GetNearestPointTF() with it. Another option would be to clone colliders using SplinePathCloneBuilder and use Physics.Raycast().
     
  8. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    or i found better solution, can project lines to 2d using camera.WorldToScreenPoint, and then use mouse point to line distance

    but is there way to do same but with curve and get TF?
     
    Last edited: Aug 31, 2013
  9. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    What exactly do you want to achieve? If you just want to click anywhere on the screen and get the nearest point on a spline, you should go the collider way. If the spline is flat on a plane you'll just need one collider to raycast against and call GetNearestPoint on the collision point.
     
  10. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    yes colliders are other option, but if spline changed then collider becomes missing, and if you try to resign it will not work sometimes(unity bug)

    i done it like this)
    Code (csharp):
    1. public class NP
    2. {
    3.     public Vector3 a;
    4.     public Vector3 b;
    5.     public Vector3 point;
    6.     public float tf;
    7.     public CurvySpline2 spline;
    8.     public CurvySplineSegment segment;
    9. }
    10.  
    11. np = splines.Where(a => !a.shape).SelectMany(a => a.Segments).Select(a => new NP { segment = a, a = camera.WorldToScreenPoint(a.Position), b = camera.WorldToScreenPoint(a.NextControlPoint.Position) })
    12.             .Where(a => screen.Contains(a.a)  screen.Contains(a.b))
    13.             .OrderBy(a => CurvySpline2.DistancePointLine(new Vector3(mpos.x, mpos.y, np == null ? 0 : (np.a.z + np.b.z) / 2), a.a, a.b)).FirstOrDefault();
    14.  
     
  11. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Oooohkay, might be the morning hour, but I don't fully understand the intention of that code (at least not without more context). So back to my original question: What exactly do you want to achieve?

    May I suggest to register in our support forum and elaborate on this topic (and maybe post an example scene there)?

    Thanks
    Jake
     
  12. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
  13. Kirienko

    Kirienko

    Joined:
    Apr 5, 2013
    Posts:
    37
    Hi,

    I have been looking in the documentation for a method or a way to get the curvature or radius of curvature of a given curve point but I can't find this.

    Thanks for the help.
     
  14. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Basically yes, but that's not the main purpose of Curvy. You might want to check out RageSpline, it's perfect for this way of level creation.
     
  15. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Isn't GetTangent() exactly what you want?
     
  16. Kirienko

    Kirienko

    Joined:
    Apr 5, 2013
    Posts:
    37
  17. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    If you take two tangents you can calculate the curvature for a given section easily, can't you? That's how MoveByAngle() works.
     
  18. Kirienko

    Kirienko

    Joined:
    Apr 5, 2013
    Posts:
    37
    Yes, I can use the tangents. Thank you!
     
  19. PassivePicasso

    PassivePicasso

    Joined:
    Sep 17, 2012
    Posts:
    100
    Excellent plugin, I've found numerous ways this plugin will assist me in developing my game.
    Easily one of the best purchases I've made on the asset store, and the response from the developer for resolving issues appears to be excellent.

    So I'll put it to the test!
    I am encountering an issue.

    If you create a spline with 3 points, with the locations (0,0,0), (1,0,0), (2,0,0), with 1 user value enabled, with the values (0,0,0), (0.25,0.25,0.25), (2,2,2) for each respective point.
    Then create a SplinePathMeshBuilder with default values, except the scale mode set to UserValue and Slot 0
    You'll notice that the Mesh is built without regarding the center point at (1,0,0)
    If you add any number of points between the first and last point, and modify the user values, no changes take effect even after refreshing the spline and the mesh builder.

    If you cause the spline to become curved to any degree, the user values for all points start functioning.
     
    Last edited: Sep 18, 2013
  20. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Hi PassivePicasso,

    thanks for your kind words!

    The issue you reported in fact isn't an issue but a feature request. Let me explain:

    By default Adaptive Extrusion is used, so mesh segments will be build when a certain curvation is reached. If the spline is a straight line, there's no reason for Adaptive Extrusion to add more segments, hence only the scale of the end points will be taking into account. If you make the spline curvy, lots of segments will be created and the respective scale of that positions will be used. As a solution, use FixedF or FixedDistance Extrusion for splines without curvation,

    I'll add a solution for this "problem" when reworking the MeshBuilder in v1.52. Perhaps an option to Adaptive Extrusion to take the scale into account or something like that.

    Jake
     
  21. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    I'm using and loving Curvy, however I have an issue where moving a camera along the spline does not have accurate results.

    What I am trying to do: I have a game where the camera is on rails. Player sits in chairs, stands up, walks around, etc.

    After trying a number of systems, Curvy seemed like the best option. So I lay out my splines, put the camera on it, and hit play. Problem is, the camera moves along the spline - but the rotations are inaccurate.

    To line things up properly, I put the Curvy spline node as a child of the camera, set its position and rotation to 0 / 0, then move and rotate the camera. When done, I move the Curvy spline back into the Spline object. This is working MOSTLY well - except for that final lineup.

    Check out the following two images... the first image shows how the camera should be lined up. I confirm this by making the camera a child of the Curvy spline node, and zeroing out its position and transform.
    $curvy_proper.png

    Now this second image is from gameplay. You can see it's close... but not accurate.
    $curvy_offset.png

    I should add the following bulletpoints:
    - The camera has no parent object (it's parent is the Scene itself)
    - I am using PlayMaker to do the movement (with the CurvyMoveAlongSpline action)
    - Set Orientation on the PlayMaker Action is set to True.
    - Approximate Position on the PlayMaker Action is set to False.
    - On the Spline itself, orientation is Tangent, Initial Up-Vector is ControlPoint, and Granularity is 360.

    I've played around with a bunch of options but what you see in the second image is the closest I have come. What do I have to do to make the in-game transform properly match the actual node transform?

    Thanks in advance!
     
  22. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Problem solved by pm/support forum (Link)
     
  23. PassivePicasso

    PassivePicasso

    Joined:
    Sep 17, 2012
    Posts:
    100
    Aha, yes, definitely not an issue, I misunderstood what the function of the extrusion mode was. FixedF and FixedDistance more appropriately handle what I'm doing.

    I've put a nice well deserved 5* rating up on the asset store for you.
     
  24. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    I'm considering buying this, I can't find info on easin out and pausing along the spline. Are these possible and how?
    I looked at the manual and this thread...
    thanks
     
  25. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    This functionality isn't builtin. However, there's a SplineWalker script that shows how to travel along a spline. It's easy to copy&paste that into your custom movement component and apply an easing to the speed property (using iTween or whatever), when you need it. Even build a spline controller from scratch is easy, getting position rotation from a spline just involves two methods and the example components are well documented.
     
  26. jathoo

    jathoo

    Joined:
    Feb 11, 2013
    Posts:
    29
    awesome asset .would love to have a video tutorial covering the brif things , i wanted to create something like subway suffers( not endless runner ), just the lane changes with swap /drag drop, i think i can do it with GetNearestPointTF ? , can i have bit more help/any video tutorial wud be helpful for more users ? :)
     
  27. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    After the update release we'll add some videos showing all editor features in detail. However, when it comes to understanding API and technical background, Documentation beats Videos by far. I advice you to dig into the package (see the examples, read the docs) and register in our support forum to ask questions about particular topics if needed.

    Btw, Lane Switching is part of the new EndlessRunner example scene that replaces the RailRunner example. Basically it's all about a clever setup and not that much Curvy related. So if you can swap your player between two line vectors in general, you just add Curvy to replace the boring vectors with some nice curves. In our example we simply solved the lane switching by dragging the player continously towards the point where he is supposed to be. So if the lane/spline changes, player gets dragged toward the new spline position.

    Jake
     
  28. jathoo

    jathoo

    Joined:
    Feb 11, 2013
    Posts:
    29
    Thanks a lot , how long will it take for the update release? :roll:
     
  29. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Hopefully next week
     
  30. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
  31. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Unfortunately not in the current version, but the new MeshBuilder will support this.

    Jake
     
  32. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    Awesome waiting for new version!
     
  33. DrewMedina

    DrewMedina

    Joined:
    Apr 1, 2013
    Posts:
    418
    I would buy this right now if ease in/out was added to the playmaker actions! I'm not a scripter so I'm limited to playmaker.
    Maybe some smart playmaker folks know a way?
     
  34. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    429
  35. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Thanks, Jean! I've already fixed this glitch in the custom actions update for 1.51.
     
  36. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi Jake.

    I want to use this package for creating roads on a map using the mesh extruder.

    How well does it handle overlapping triangles on tight turns on the road?
     
  37. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Hi Elias,

    Not at all in the moment, but handling this is on top of my roadmap for the next big release.
     
  38. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Ok. Good to know.

    Do you have an estimation for the next release date?
    I am using unity 3.5.7f.
     
  39. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    v1.51 is submitted to the Asset Store and should go live soon. Lots of changes under the hood, so please read the Upgrade notice !

    Time to advance

    Curvy now comes as a Unity 4.2.1 package! If you're still using 3.5.7, just download it from a free 4.2.1 install. The reason is simple: the vast majority of users are using 4.x now and we don't want to develop in an outdated engine anymore (mainly because UnityVS isn't very stable with 3.5.7).

    For now Curvy stays compatible to Unity 3.5.7!

    Unfortunately it seems impossible to import scenes and assets coming from a Unity 4 project in 3.5.7. So, if you're still using 3.5.7, you'll need to strip the Examples and Shapes folders and copy the rest in your 3.5.7 project. After that Curvy should work like expected!

    Release Notes



    As promised, the next update will exclusively focus on the SplinePathMeshBuilder!

    Jake
     
    Last edited: Oct 1, 2013
  40. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Jake,

    I've been researching path creation tools and Curvy looks like it may serve my needs but I thought I would check with you first before purchasing.

    I'm looking for a way to control the movement of an object along a curved path using user input, specifically touch input. Since the touch input is 2D, I'll need to translate the distance of the touch movement into distance traveled by the object along the path. In other words, by touching the screen the user will be moving the object along the path and controlling it's velocity.

    As an example, let's say I have a GUI slider control that the user can touch on the screen and drag back and forth along the x axis. Does Curvy provide either built in methods or access to variables or properties that will allow me to manually move an object along a path based upon the movement of the slider control. I realize I'll need to code the conversion of motion along the x axis in 2D space to object position along the path in 3D space. But I'll need to make sure I can manually position the object along the path and that i have access to the necessary methods/variables in Curvy.

    I hope that makes sense.

    If curvy does not provide the methods or variable access to manually control the position of an object along a path, can you theorize how that might be accomplished with your tool. If I have a starting point and you think it's possible, I can probably figure out the rest.

    Thanks for your time.

    As a side note, this has been requested in other forums with Waypoint tools, HoTween etc. I found discussion of this use case in the Simple Waypoint System forums. And you could make the same request with joystick controls etc. But the idea is the same. And that is to use user input to move the object along the path instead of having its movement automated using a tweening system.

    Allan
     
    Last edited: Oct 7, 2013
  41. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Hi Chaneya,

    positioning an object on a curve is a basic task that can be done either by using one of the scripts provided or calling the API directly. Basically you can choose between positioning by distance (feeding in a value between 0..Unit Length of Spline) or by TF (a percentage 0..1 over the total spline, based on the number of segments, not on length). Usually one uses positioning by distance, as it allowes movement at constant speed. Both terms are described here!

    In your example, you'll have an input percentage given by the slider (or calculated from a range etc..) that you can multiply with the spline's length to get the position:

    Code (csharp):
    1. float slider=0.25f; // <= any input, be it from a slider or a joystick etc...
    2. float distance=mySpline.Length*slider; // distance in world units
    3. transform.position=mySpline.InterpolateByDistance(distance); // set position
    4.  
    Note that internally Curvy works with TF, so all API methods using a unit distance internally convert the distance to TF. If you make multiple calls to the API you should consider converting distance to TF first for performance reasons:

    Code (csharp):
    1.  
    2. float slider=0.25f; // <= any input, be it from a slider or a joystick etc...
    3. float distance=mySpline.Length*slider; // distance in world units
    4. float tf=mySpline.DistanceToTF(distance); // convert distance to relative position
    5. transform.position=mySpline.Interpolate(tf); // set position
    6. transform.rotation=mySpline.GetOrientationFast(tf); // set rotation
    7.  
    Alternatively you can attach a SplineAlign or SplineWalker component, check "Use WorldUnits" and control the Distance property. All source is provided, so if you take a look into the provided components you'll see the same API calls as above.

    Cheers

    Jake
     
  42. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Jake,

    Thanks. I purchased Curvy.
    I was able to setup a prototype in just a few minutes to do what I described.

    Thanks for the wonderful support.

    Allan
     
  43. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Jake,

    Just a quick suggestion.

    My compliments on using individual scenes to demonstrate use cases/scenarios for your product. It's something I try to convince other tool makers to follow. It makes learning easier since it's in bite size pieces and you'll sell more if people can see the breadth of uses.

    You may want to consider providing an option in your sample scenes where movement can be accomplished in the other update loops. For instance, your CameraFollow scene uses the SpineWalker class which uses the Update loop to move the camera. Camera movement is always best done in the LateUpdate loop since the camera is typically following an object moving in the update loop. And if you are working with physics, depending on the case, fixedupdate may be the best option since it runs on a fixed clock unlike update that can fluctuate based upon game load. Movement inside fixedupdate may provide better collision detection although I haven't tested this using your tool.

    It's really just something I noticed with the scripts in your sample scenes. It's easy enough to place movement API/method calls in whatever loop fits your needs in one's own code. But I thought I would offer the suggestion.

    Allan
     
  44. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Hi Jake,

    Really enjoying playing with the new version. Curvy is getting more and more Awesome with each new release.

    While playing with the 2D Shape Mesh Creator in Curvy, I noticed that it's not doing so well in many of the shapes that I am making.
    It seems to be creating weird artifact lines in the created shapes.

    https://dl.dropboxusercontent.com/u/48378123/Curvy2DMeshProblem.png
    https://dl.dropboxusercontent.com/u/48378123/Curvy2DChecker.png


    The triangulation code could really benefit from a more robust implementation.

    I found a forum thread dedicated to this particular problem and they have some really cool solutions.

    Here is an excellent working example:
    http://javascript.poly2tri.googlecode.com/hg/index.html

    Here is the forum thread:
    http://forum.unity3d.com/threads/18...ine-to-mesh-questions-and-results#post1241211

    edit:
    Perhaps this might also be useful for the Curvy's Custom Mesh Extrusion because it can handle more complex custom shapes.
     
    Last edited: Oct 8, 2013
  45. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    That's a pretty good and easily implementable idea. I'll add this option to the SplineWalker / SplineWalkerFixed / SplineAlign components for the next update. Maybe to SplineWalkerCon as well, though it's general usefulness is quite limited compared to the others.
     
  46. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Thanks, I'm trying to create some tutorial videos to demonstrate the new editing features before I need to take a longer coding break (future beta tester will be born :)) E.g. constrain axis to X/Y and then just move the mouse and hit "G" to add additional points is just an incredible nice way to quickly create shapes.

    You're right, implementing a more solid Triangulator (that handles holes created by multiple splines!) is on my list. Nice find you've posted there. Though I need to check if their license allowes me to use their code or if I had to rewrite it myself from the theory paper behind it.

    The current problems with the custom mesh extrusion come from a suboptimal way to detect edges and handle vertex orders. It works now if you order vertices properly, but of course it should work for any mesh. This will be sorted in the next release.

    Jake
     
  47. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    The javascript example and most of what has been discussed in the unity forum link I sent seems to be using code from the Poly2Tri project.

    Here is the link to that project. I believe there is also licensing info.

    https://code.google.com/p/poly2tri/
     
  48. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Some ideas for future updates. These spline operations would really really cool in Curvy and would really help the creation 2D shapes for extrusions.

    http://docs.autodesk.com/3DSMAX/15/...0-824E-07BE9E5ACE3C.htm,topicNumber=d30e44852


    There are three Boolean operations:

    • UnionCombines two overlapping splines into a single spline, in which the overlapping portion is removed, leaving non-overlapping portions of the two splines as a single spline.
    • SubtractionSubtracts the overlapping portion of the second spline from the first spline, and deletes the remainder of the second spline.
    • IntersectionLeaves only the overlapping portions of the two splines, deleting the non-overlapping portion of both. Original splines (left), Boolean Union, Boolean Subtraction, and Boolean Intersection, respectively

    Mirror Mirrors splines along their length, width, or diagonally. Click the direction you want to mirror first so it is active, then click Mirror.
    • CopyWhen selected, copies rather than moves the spline as it is mirrored.
    • About PivotWhen on, mirrors the spline about the spline object's pivot point (see Pivot). When off, mirrors the spline about its geometric center. Mirrored splines
     
  49. Donkey111

    Donkey111

    Joined:
    Mar 17, 2013
    Posts:
    9
    Is there an easy way to set your keys equally distant apart but maintain the shape? I use the spline as a curved timer and its a little tricky.
     
  50. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    If you use a spline for a timer, why do you need the keys to be in an equal distance? If you interpolate the curve by distance (from 0 to Spline.Length), you'll get values at a constant speed. Besides that, I don't know a simple way to move a key and maintain the shape, this would involve some very tricky math, I think.
     
Thread Status:
Not open for further replies.