Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Curvy 2 - the ultimate spline solution

Discussion in 'Assets and Asset Store' started by Jake-L, Sep 29, 2015.

  1. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    You achieve that using the API. You can write something like:
    Code (CSharp):
    1. foreach (Transfrom transform in yourTransformsList)
    2. {
    3.   float someTfValue = // retrieve the stored TF value associated to this transform
    4.   transform.position = yourSpline.Interpolate(someTfValue, Space.World);
    5.   //update the stored TF while handling looping using % 1 to keep values between 0 and 1
    6. }
    You get the idea?
     
  2. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Freznosis likes this.
  3. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    Is there a way to pick which side of the spline a new point is added? For eample, I want to add a new point at the beginning of the spline which would make the new point CP0000. The new point is always created at CP0001 or CP0002 when I have CP0000 selected during "Draw Spline" creation. If I have no points selected, then it gets created at the back or "last index" of the spline by default. Nothing for the front?
     
  4. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi,
    I am assuming you are asking about adding CPs in the editor only, and not throug the API:
    When creating a new CP via the toolbar, it is added either after the selected CP or at the end. No way to create it at the start in one click. You can though reorder CPs after they are created. You can move CP in the hierarchy as you please, then click on the Tools then Synchronise From Hierarchy button in the toolbar
    https://curvyeditor.com/documentation/toolbar#submenu_s_content2
    This this answer your question?
     
    Freznosis likes this.
  5. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    Hi! I just added Curvy to Unity 2020.1.0f1 and I got these two errors:


    Assets/Packages/DevTools/Editor/PropertyDrawers.cs(569,55): error CS0104: 'MinAttribute' is an ambiguous reference between 'FluffyUnderware.DevTools.MinAttribute' and 'UnityEngine.MinAttribute'
    Assets/Packages/DevTools/Editor/PropertyDrawers.cs(568,34): error CS0104: 'MinAttribute' is an ambiguous reference between 'FluffyUnderware.DevTools.MinAttribute' and 'UnityEngine.MinAttribute'


    Bought the plugin a lot of time ago, time for me to use it again as I need the most performant spline solution possible- I'll be using splines a lot!

    EDIT: I guess renaming everything called "MinAttribute" in "MinimumAttribute" solved the issue. It still triggered an API Update, is this normal?
     
  6. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi,
    Unity 2018.3 added a class with the same name than a Curvy class, thus creating the conflict. This was fixed in Curvy 4.1.0. So to fix this, just get the latest Curvy version. Remove your Curvy folders, and reinstall it. This is something you should do each time you update Curvy (and other assets in general) because when you import a Unity package (which is basically what happens when you update), the package only adds files, and can't remove existing files that are not necessary anymore.
    Let me know if you still have issues.
     
  7. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    Thanks for the reply! I downloaded Curvy for the first time in this project just yesterday so it was already up to date to version 7.1.3.
     
  8. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Well, that's surprising. Can you check please that in the file with the error, ProperyDrawer.cs, you indeed have this line of code at line 21:
    using MinAttribute = FluffyUnderware.DevTools.MinAttribute;
    This line is their to solve the conflict, by specifying that when the code refers to MinAttribute, it is referring to the one from DevTools.
    If the line of code is indeed there, and you still have an error, then either send me your reproduction case, or if you prefer not, rename the class like you suggested and accept the API Upgrade.
     
  9. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    Sorry for replying late! Problem solved, it was indeed an older version. My bad! :oops:

    I believe the Package Manager decided not to download the new version, and just imported the one that I downloaded years ago (how??), still saying that it was up to date at 7.1.3. My fault was to completely ignore the Curvy popup that appears on project launch, where the correct version number is. Have a laugh at this log:
    [Curvy] Upgrading project settings from 2.1.3 to 7.1.3
     
  10. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    2.1.3! You are an elder :D
    2.1.3 Was the last released version by the asset's previous owner. I hope you will enjoy all the work that I put in there since, and the upcoming work (version 7.1.4 is being validated by the asset store right now)
     
    DanjelRicci likes this.
  11. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
  12. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    I'm creating a spline dynamically in the scene and then run an object on it with the Spline Controller. Is there a way to move an object to a spline if the spline is built away from the object?
     
  13. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    I managed to answer my own question by simply adding another point at the objects current location.

    Another issue I'm having. I'm using a line renderer and want to show the line only from the object to the end of the line.

    I'm getting the relative position and making a curve out of it but the line renderer acts really weird. and draws ahead and then falls behind as the object progresses. The line renderer start at the same position and end at the same position though.

    Code (CSharp):
    1.  
    2.             AnimationCurve curve = new AnimationCurve();
    3.  
    4.             var position = SplineController.RelativePosition;
    5.  
    6.             UnityEngine.Debug.Log(Controller.RelativePosition);
    7.  
    8.             curve.AddKey(0.0f, 0.0f);
    9.             curve.AddKey(position-.000001f, 0.0f);
    10.             curve.AddKey(position, 0.0f);
    11.             curve.AddKey(position+.000001f, 1.0f);
    12.             curve.AddKey(position+.000002f, 1.0f);
    13.             curve.AddKey(1.0f, 1.0f);
    14.  
    15.             lineRenderer.widthCurve = curve;
     
  14. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi

    Can you try please to use Controller.AbsolutePosition / Controller.Spline.Length instead of Controller.RelativePosition? I didn't try it myself, but I think it will solve the issue.

    More about this: RelativePosition, which is member of all the controllers, has a particularity that can be confusing. As explained here: https://curvyeditor.com/documentation/controllers#position_mode
    "Relative positions are values from 0 to 1. For splines, relative position is the TF while for paths and volumes it is the ratio of the total length"
    I am planning to fix that in the next big update.

    Please let me know if it worked.
    Have a nice day
     
  15. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    452
    Is there a way to disable Curvy's data harvesting and phoning home? I don't see an option in the editor prefs to disable it.
     
  16. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi
    There are no editor preference to disable that, but you can remove the following files to deactivate it:
    - AnnouncementsFetcher.cs: the code in this file checks a server, at most once every 24h, to see if there are any message to display to the user
    - Metrics.cs: the code in this file sends to a sever the following anonymized information:
    * Curvy version
    * Unity version
    * Scripting runtime version
    * A random number associated with the used device and whether this is the first time this user information is send
    This information is send every-time a new combination of Curvy, Unity and Scripting runtime version is used.
    All servers are running on open source software.
    The metrics are used to help me decide when Curvy Splines should drop old Unity features/versions, and when to use new Unity features. This is the information you would expect from a marketplace's back-office, but unfortunately Unity's Asset Store do not provide such basic information.
    If I may ask, what was the reason that made you ask your question? Is it because of privacy concerns or network usage?
    Since no personal data is collected, I didn't think the data collection would bother people and thus did not think about adding an editor preference for that. So I am curious about your reason so that I reevaluate that decision.
    Thanks
     
  17. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    214
    Is this just in editor mode or does the reporting remain active in builds?
     
  18. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    just in editor mode
     
    blacksun666 likes this.
  19. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    I'm trying to read position and rotation from a Spline, but the result is very offset from the actual position of the spline in the scene. This started happening lately, after I created a second Spline in the scene. The first one was working good, the second one never worked even after recreating that from scratch; now for some reason neither is working, both return offset readings. Is something wrong, or did I miss some checks?
     
  20. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi,
    I am guessing that your are using methods the CurvySpline.GetNearestPointTf and the such. Those methods return by default a data in the spline's local position. Those methods have an optional parameter that allows you to choose in which space, local or global, the returned results are. If my guessing is wrong, then please explain to me in detail what you do, or send me a reproduction case.
    Have a nice day
     
  21. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    Unfortunately even changing those parameters doesn't fix it, but it makes sense because this was already working before, without using those extra parameters at all.
    I can't really send the project now so I fear it won't be easy to reproduce this, but this is more or less what I have:

    - Create a single Spline in the scene, in my case more than 2000 units long (not sure this is related)
    - Use
    GetNearestPointTF
    in a script to get the nearest point, maybe draw it with
    OnDrawGizmos
    : it returns the correct point
    - Create a new Spline that follows closely the first one
    - Using the same code as before, read the closest point from the new Spline: it returns a wrong position
    - Change the code again to read the first Spline: it works again

    I have not yet tested this from scratch on a new scene, but only on my scene with all the other game related stuff- I will investigate more.
     
  22. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Try it on a new scene, that way you will either find what is wrong, or have a reproduction case to send me.
    Also, does moving all the CPs of your second spline let's say 5 meters towards negative x, while moving the spline 5 meters towards positive x to cancel the movement, make the returned wrong position move?
     
  23. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    I created a new scene, created a new Spline, and it's reading the wrong position right out of the box. I suppose something is wrong with points caching at this point.

    Yeah, it definitely does.
     
  24. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Ok. Send me please the scene and the script you used to get the position, and I will take a look at this first thing tomorrow.
     
  25. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    308
    Ok, it was my fault once again. ‍-_-
    In brief, my first spline was at 0,0,0, but not the second one... This probably caused the "wrong" initial reading because the default mode is Local and I wasn't aware of, or downright forgot it. Then I moved the second spline back at 0,0,0- or at least I thought I did, but for whatever reason this wasn't saved in the scene so I continued checking on a Spline not placed at origin point, and of course the reading was wrong for my supposition. I then created the new scene paying no attention to where the Spline was created (in fact, not at origin) and it was indeed wrong again for me. I realized all of this when preparing the UnityPackage.

    So yeah now my Splines are at origin point and all is fine. That's 2 times out of 2 where I messed up in some way with Curvy, I owe excuses!
     
    Last edited: Feb 10, 2021
  26. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Don't worry, I have bad memory so I already forgot about the first time
    :D
    The reason the local coordinates are the default one is that computing the global coordinates needs additional operations, and thus cost more CPU. So the initial decision was to make the faster version the default one. In hindsight, I would not made any version the default one, and made obligatory to define which coordinate system to use at each method call.
     
    DanjelRicci likes this.
  27. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Hello, I just started to use Curvy (v 7.1.4).
    First impression is very good I have generated some road with generators but I got some problems.

    1. My road has ending/beginning same size. Can I make it so it will change its width along the spline ?
    So I can connect roads of different sizes together or just add some variation to road width in the middle.

    2. My transforms (points of spline) don't dictate the direction of handles. Transforms orientations are just ignored, can I somehow make handle in/out respect current point transform orientation ?
    This would be quite helpful when aligning endings with world objects.
     
  28. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Update:
    OK I have found the Scale on shape extrusion.
    Now my problem is that UV are scaled with my road, so my bricks are bigger the wider is the road.
    Can I somehow do it that my texture is going to tile instead of stretching ?
     
  29. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi

    You have the control over stretching and tiling in the Volume Mesh module: https://curvyeditor.com/documentation/generator/modules/volumemesh

    This isn't unfortunately an option in the editor. You can enforce a link between the rotation of a transform and a control point's handles using the API though. It's not complicated.
    In case you were not aware of this, if you hold shift while rotating a control point, you will rotate its handles.
    If you set the Bake Orientation option in a control point's inspector to true, the transform of the control point will be oriented automatically to align with the control point's tangent and normal.
    By combining those two options/operations, rotating the handles will modify the tangent/normal, which will rotate the control point. Not exactly what you asked, but might be helpful.

    I hope this helped.
    Have a nice day
     
  30. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    In VolumeMesh I do have Keep Aspect checkbox but I don't have any more choices like in your documentation:

    Non of choices below are present:
    • Off - No Aspect correction is applied
    • ScaleU - U is scaled to keep texel size proportional
    • ScaleV - V is scaled to keep texel size proportiona
     
  31. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    And as I see in your tutorial

    Those options also are not present.
    Please give me some answers I don't know if those options are hidden or should I extend this component myself.
     
  32. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi
    You are right, Keep Aspect is just a boolean in the editor. The three options were replaced with a boolean in Curvy 2.0.0. Since I became owner of Curvy Splines at the 2.1.3 version, I don't know much about that choice. Looking at the commits' history, didn't help in understanding the reason behind that choice.
    I hope this helped.
    Have a nice day
     
  33. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Will not be easy now.

    Do I have to extend it by myself ? Or are you planning to do something about this ? This is an important feature.

    Another question.
    Just today I wanted to place side bricks along my road. I have used Rasterize Path / Input GameObjects / Volume Spots / Create GameObject /

    I connected the bounds from GameObjects to VolumeSpots.

    Problem is that objects are not spawned uniformly. On the sharper curve there are bigger gaps between bricks.
    This prevents me from having continuous side bricks, even when messing around with Space After/Space Before in VolumeSpots
     
  34. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Sorry if I misunderstand something, but isn't setting the UV Scale to a smaller value (less than 1) doing what you need?

    Can you please send me the reproduction case? Please do not share publicly any link containing Curvy Splines. Thanks
     
  35. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    For now check the screenshot.

    There is one bezier curve spline (invisible) in the middle of the road - this one creates cobbled stone road. As you can see I have used scale modifier so my road is wider the further it goes from the right side. Problem is that the texture is also stretching with it and I would like my texture to keep it's aspect ratio. So all those UVScale parameters will scale it but it is still going to be more and more stretched the further the road goes. It is the problem you know about those parameters that disappeared with the new version.

    Actually I have checked the source and this enum is still there but in the code it is just not used.

    Secondary, I have used this modifier (2 times) that will shift main spline by some value, and by this way I have created this two sides of the road, as you can see I'm not using scale factor along the spline to keep road borders distance constant.
    I have used spawning of objects at the bottom and red border at the top. As you can see the bottom border that is made out of bricks have gaps between them, and the bigger the curve the bigger the gap. At the right side bricks are very close to each other.
    Below the image is a graph that spawns the bricks.

     
  36. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Thanks for the additional information, I see now. I will give you an answer later today.
     
  37. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    About the placement issue, I have a fix.

    I am not sure how you placed objects in your graph, since there are multiple ways to do that. The way that meets your needs is not to translate the placed objects in the Translation section of the Volume spots module (method A), but to use a Path Relative Translation module to translate the path itself (method B). If you try method B, you will notice that it doesn't work. This is due to a bug. To fix the bug:
    • Open Curvy\Base\CG Modules\ModifierPathRelativeTranslation.cs
    • Insert the following between lines 86 and 87: data.Recalculate();
    Sorry for that bug.

    I attached a scene showcasing both methods, so you can see the difference, and see how the modules are setup.

    Will keep you updated about the aspect ratio issue soon.
     

    Attached Files:

  38. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Changing script worked.
    I was using PathRelativeTranslation from the beginning.

    How is the orientation of the game objects calculated ?
    Right now I guess it is a orientation of the spline at point of spawning.
    It would be a good idea to have this option for continuous chain of objects touching each-other at the center of edges. So on curves the origin of object would be not exactly on the spline but the objects chain would be more smooth. Right now my bricks are a little toothed to each-other. So instead of taking one point from spline you would have to reconsider two points on the spline for each object, points at the end of the bounds of object. Naturally two neighbor objects would share one point.

    Thanks I will be waiting for aspect ratio.
    Best regards.
     
  39. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Sorry, I should have deduced that from your previous message.

    Yep, it works the way you guessed it.

    Wouldn't bricks need to be bend to touch its neighbors on both sided?
    If yes, then this is a feature that is part of the next big update. I am working on it.
    If not, could you please send me a simple visual explanation?

    After digging some more, I think I see what to do now. This will take some time to implement, but will send you a custom version of Curvy Splines with the modification as soon as I can.
     
  40. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Imagine that bricks are lines. Instead of keeping center of a line on a spline we would keep endings (both).
    In the point when one line ends second line starts.

    In case of GameObject those endings would be on the extents of the bounds along the spline.

    In place where spline curves - GameObjects bounds would intersect it's corners a little, but the anchor of it's relative rotation would be at the same point.


    BTW: What is Cross Base on Volume Spots do. When I use it it rolls the gameobjects around the spline.
     
  41. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Ok, I see what you mean. You want this
    upload_2021-3-2_17-2-28.png
    instead of this
    upload_2021-3-2_17-2-41.png

    Because of the intersections, it's not something that I like, but I admit it can have it's use in some cases. Having it as an option will have some value. I added it to the todo list, but it is not on the top of it, so don't expect this in the near future.

    Until then, you can always use the API to achieve this effect for these specific cases. For example the code placing the train wagons in the example scene 12 does something very similar to what you described. It places the wheels on the path instead of the wagon's center

    I am advancing well regarding the aspect ratio thing. I should have something to show tomorrow.
     
    koirat likes this.
  42. mutp

    mutp

    Joined:
    Oct 1, 2018
    Posts:
    79
    I'd like to make the box collider of a generated spline mesh bigger than the size of the mesh. Is this possible within the Generater itself?
    upload_2021-3-13_21-27-8.png

    Basically, is it possible to adjust the size of the box collider here.
     
  43. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    Hi
    The box collider always fits the bounding fox of the mesh.
    You can modify the code to make the box collider bigger. The method where the box collider is setup is CGMeshResource.UpdateCollider, which is created in CreateMesh.UpdateColliders. The actual line to change is the following:
    boxCollider.size = Filter.sharedMesh.bounds.size;
    Did this help?
     
  44. mutp

    mutp

    Joined:
    Oct 1, 2018
    Posts:
    79
    It helps a bit but I would like to have had the option in the UI of the Generator window itself so that I can apply it only for those objects that need it.
     
  45. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    You can add that in the UI by modifying the code of CreateMesh.cs. By looking at any other existing option in the UI, for example IsTrigger, you should be able to add a new option in the UI.
    That additional box collider size option is not something I consider for now to be part of the official release. If I see that there are a lot of demand for it, I will consider it.
     
    mutp likes this.
  46. mutp

    mutp

    Joined:
    Oct 1, 2018
    Posts:
    79
    I was able to add this functionality, thanks for the help. Also, I wanted to know how to make a track that has a dynamic width. Essentially, I want to create a sort of funnel like road but I'm unable to dynamically change width in the generator.
    upload_2021-3-16_22-43-5.png
     
  47. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
  48. EvilDingo

    EvilDingo

    Joined:
    May 7, 2011
    Posts:
    190
    How do you detect the curve of the spline from something traveling on it? I know objects can follow the spline, but is there any way to tell how much the spline is curving in one direction or another relative to the object?
     
  49. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    You can do that by computing the angle of the spline's tangent at two close points, one a bit before the object and one a bit after it for example. Basically (code might not compile):

    Code (CSharp):
    1. var t1 = spline.GetTangentByDistance(controller.AbsolutePosition - 0.1f)
    2. var t2 = spline.GetTangentByDistance(controller.AbsolutePosition + 0.1f)
    3. Vector3.Angle(t1, t2)
    If your spline is not planar, you will have to handle the projection of the tangents
     
  50. mutp

    mutp

    Joined:
    Oct 1, 2018
    Posts:
    79
    I'm able to scale using the MultiplierX value in ShapeExtrusion modifier. However, I now need to place objects (pink walls) along the boundary of this scaled Mesh (track).

    upload_2021-3-27_17-41-41.png

    To scale, I"m doing
    upload_2021-3-27_17-42-18.png

    and to place the objects
    upload_2021-3-27_17-42-38.png

    However, they don't respond to the scaled portion of the mesh.