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

SplineMesh, the plugin to create curved content

Discussion in 'Assets and Asset Store' started by methusalah999, Dec 14, 2017.

  1. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    42
    for some reason this is what Im getting. I attached the script, maybe I added the lines wrong?
    upload_2023-2-23_20-14-22.png
     

    Attached Files:

  2. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    42
    upload_2023-2-23_22-16-5.png upload_2023-2-23_22-16-30.png
    I made sure the decal went the same length as the rail itself in blender and it worked perfectly! thanks for the help there! This is a massive boost in asset creation and unity work flow. It'd be great if I could get your repeat stretch code working because that'd be the last step. I cant see where the scale value would actually affect the scale, it seems like it only gets implemented in determining the distances of each mesh apart from each other
     
  3. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    42
    I switched
    float distance = (vert.position.x - source.MinX + offset) + scale;
    for
    float distance = (vert.position.x - source.MinX + offset) * scale;

    and also removed
    offset += source.Length * scale;
    and this is the result:

    it seems to have gotten it working! thanks so much for this this is so cool! it has an error where seemingly at the exact length where the gap would be 0 anyway it throws out upload_2023-2-25_12-47-5.png
    I'll try to look into this but for the most part its doing exactly what I need! thanks again this is so cool
     
  4. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    42


    The flickering in and out issue seemed to be a similar floating point issue that I had experienced when I was trying to find a gap clearing solution. I fixed it by changing
    offset += source.Length;
    to
    offset += source.Length - (.000001f);
    there is an issue where when the scale x is smaller than .1 so Im sure theres a smarter way around this but I dont think I'll ever scale an object that small on a spline so I'm gonna call it done.

    and as you can see the decal spline followers sync up perfectly. thank you so much methuselah 999, I really didnt think I'd get this working. In my source comment when I said I deleted a bunch of complaining, part of it was how issues with 2dspriteshape killed my interest in a 2d project so this really was a lifesaver. Heres the altered meshbender script for anyone that's interested in doing something like this
     

    Attached Files:

    methusalah999 likes this.
  5. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    When I edit a node's scale in the Showcase scene, I can see the Spline Extrusion updating in real time. But when I do it in another scene, it doesn't update in real time as I change the value. I have to deselect the object and select it again for it to take effect. Why is this happening? Am I missing something?
     
  6. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    To be updated during play time, in the SplineMeshTiling you need to check "update in play mode".

    If you wrote your own component, you will have to check that you didn't set your generated as static, or they will be batched with the rest of the static elements of the scene and won't be modifiable.
     
  7. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    Sorry. I think I wasn't clear with my problem. I have a gameobject with the Spline component and Spline Extrusion. I don't need it to update in play mode.What I meant was that I needed to update in edit mode as I change the values from the inspector. I can modify any value from the inspector but the changes won't show unless I deselect the object and select it again. But this isn't the case in the Showcase scene. In that scene I was able to modify any value and see it reflected in the scene view instantly. So that's why I'm wondering if I'm missing something in my scene.
     
  8. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    Is there a way to change the layer of the meshes generated by Spline Extrusion? If I change them, they just revert to Default when entering play mode.
     
  9. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    I though there were a logic to make the generated objects having the same layer than the parent but I don't find it in the code. However, you can simply add a line in SplineExtrusion.GenerateMesh with
    go.layer = gameObject.layer;
    , something like that.

    Please remember that SplineMesh is designed so you can (and should) expand it whenever you have some specific needs. This is because splines can be used in a huge variety of ways and use cases. I preferred this approach instead of very complexe component offering tons of options. The code of the high level API is designed to be very simple and I encourage you to copy/paste the SplineExtrusion as a MySplineExtrusion script and change it to fit your needs.
     
    jRocket likes this.
  10. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    Is there an easy way to modify the ExampleSower script so that the prefab isn't generated in some segments of the spline? I'm using it to place trees along a river. But at one point I have a waterfall and don't want trees to be generated along the vertical part of the waterfall.
     
  11. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    Sure thing, you just have to add a test whether or not the object should be generated in the loop, using the rules you want.

    For example here, I only generate a pillar if there is not road below https://twitter.com/methusalah0/status/1087493276863737857
     
  12. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    How could I make it not generate the object when the path goes down the waterfall? I'm sorry, I'm kind of a beginner..
     
  13. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    For example, here in the code, if the CurveSample is too close from a waterfall, you just continue to the next iteration.

    Code (CSharp):
    1. while (distance <= spline.Length) {
    2.     CurveSample sample = spline.GetSampleAtDistance(distance);
    3.  
    4.     if(/*sample is far enough from all waterfalls*/){
    5.         GameObject go;
    6.         go = Instantiate(prefab, generated.transform);
    7.         (...)
    8.     }
    9.     distance += spacing + UnityEngine.Random.Range(0, spacingRange);
    10. }
    Please remember that ExampleSower is only an example. It is strongly advised to only take inspiration from the example code and write your own.
     
  14. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    I noticed that on the Showcase scene, nothing will update outside of Edit mode unless I have 10 - Spline enabled. That has the Example Follow Spline script. What does that script have that allows the splines to update in edit mode and how can I add that to my own scripts?
     
  15. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    When the game is not playing, there is no game loop running. You can still have a constant refresh of the editor with two conditions. First you need to have the attribute [ExecuteInEditMode] on your MonoBehavior class, and you need to ask the scene window to "always refresh" by selecting the option in the post-process menu at the top right corner.

    The 10th example forces the scene window to refresh because it makes it dirty as often as possible so whenever it is activated, the scene will refresh even if you didn't select "Always refresh".

    All SplineMesh Example are designed to refresh this way in the editor without the game running, so that you can test things and see the result right away. But this is not a best practice for your actual project at all and I would advise against it in most situations:
    - it will put your CPU at work constantly,
    - it will change the serialized data of your scene and prefabs and force you to save again constantly,
    - it may cause various issues in the prefab editor,

    It's generally better to react to data changes instead, like with OnValidate method.
     
  16. fullerfusion

    fullerfusion

    Joined:
    Dec 2, 2018
    Posts:
    22
    I have a question. The last update we had to the Spline Mesh asset was on April 1, 2021. Do you plan to make any significant updates to this asset or are you finished? I ask because I want to know what are the benefits of using this asset vs the Spline package released from Unity in 2022 LTS?
     
  17. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    I'm not working on SplineMesh anymore. But it is an open-source project so feel free to contribute. Adaptation of the mesh processing logic to the Unity Spline package is also totally doable... but will Unity update their package? That would be a first.
     
  18. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    How can I get the CurveSample closest to a GameObject? I want to rotate my gameObject so that it matches the Up of the spline as it moves. I'm trying using

    CurveSample sample = spline.GetProjectionSample(transform.position);
    transform.localRotation = sample.Rotation;

    But it's not quite working. It does rotate as I move it along the spline, but it doesn't match the Up of the spline.
     
  19. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    sample.Rotation
    is not the up vector but the tangent direction of the spline at that point. Also, sample data is in world space I believe. You should be able to get what you want with something like
    transform.rotation = Quaternion.LookRotation(sample.forward, sample.up)
     
  20. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    sample doesn't have a definition for forward. Could I use my transform's forward?
     
  21. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    yeah it's tangent, sorry
     
  22. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    14
    Thanks! It didn't work right away because my spline object wasn't at 0,0,0. So I had to do this:
    Code (CSharp):
    1. CurveSample sample = spline.GetProjectionSample(transform.position - spline.transform.position);
    2. transform.rotation = Quaternion.LookRotation(sample.tangent, sample.up);
     
  23. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    So the samples are in local space? I though they were not.

    Your solution will only work if the spline object is not rotated then. If your spline object also has non-zero rotation or scale, you can use
    sline.transform.InverseTransformPoint(otherTransform.position)
    instead.

    Glad you figured things out. Have fun bending things!
     
  24. bunp

    bunp

    Joined:
    Feb 21, 2019
    Posts:
    70
    upload_2023-6-8_16-41-34.png

    How do I physically grab and manipulate these red handles? I can use the transform gizmo but I cannot rotate, scale it in any way.

    EDIT: Suddenly as if because I made this forum post, now it lets me select them by simply clicking on them. This was not the case before this post. I despise computers sometimes.
     
  25. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    You indeed have to clic on the red squares to select the nodes or the control points. There is no rotation or scaling gizmo, though, you only translate the control points to produce the curves you want. I think someone made a pull request to have a rotation gizmo on the nodes but I don't think I've included it in the project yet.

    There is another gizmo to control the up vector, that is displayed when you check the "show up" option.
     
  26. hchan8

    hchan8

    Joined:
    May 25, 2023
    Posts:
    1
    Hi, I having trouble with the Contort Along. I trying to have multiple lines (4) that follow it own lines however, even I start the game, all of them frozen. Yet, outside of the game play, it work just fine. It might due me using the same script for all of them. But I don't what I need to change so it each can follow it's own spline.
     
  27. zevonbiebelbrott

    zevonbiebelbrott

    Joined:
    Feb 14, 2021
    Posts:
    118
    How does this work? Is it vertex displacement? Or a shader?
    Im asking because I made an IK fishing rod, in order to bend the tip realistically towards the fishing line, if there is tension.
    But I have tried some other solutions(including this one) and often a problem is that I cannot find the new position of the rod tip, after bending or deforming.

    Is it possible using splinemesh, to get a specific vertex position on the deformed mesh?
    If thats possible I can use that displaced vertex world position to figure out where to move the rope to as the rod tip bends towards it... with the IK rig its easy, just have the rope follow the last bone.

    I also need this spline to be able to rotate freely, so that the tip of the rod that follows the spline/bezier curve can follow/lookAt the fiishing line, and bend correctly towards it.

    This is what it looks like now with an IK rig, however using the SplineMesh, the curving is a lot better, but i cannot figure out how to rotate the spline curve correctly or how to get the new position of the bent rod tip.
    itReallyDoBeLikeThat.png
    Is it possible with this asset? I cannot get it figured out. If anyone can help, I appreciate it!

    Thanks!
     
  28. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    There is a confusion here, It won't work with SplineMesh the same way than a bone to rotate. SplineMesh uses Bezier curves so you don't bend the rod by rotating things. Instead, you move the tip of the rod to where it should be (toward the hook at the end of your wire I guess) and you also move the direction points to control the curvature of the rod. So you always know where the tip of the rod is because you decide it
     
    zevonbiebelbrott likes this.
  29. LillyInverse

    LillyInverse

    Joined:
    Aug 6, 2022
    Posts:
    1


    For some reason it doesn't look like a tentacle. Also there is an error at the bottom. What am I doing wrong?
     
  30. mangeshjsh

    mangeshjsh

    Joined:
    Nov 27, 2023
    Posts:
    2
    Dear Meth,
    I want to use the splinemesh package for my project. Can you please guide me to some step by step tutorials on how to use splinemesh. Also, can this package be used in VR mode to draw splines by using hand gestures or using some pen like tool in VR? Kindly help. I want to draw splines in VR using hand gestures and then to create mesh out of it again by using hand gestures or some pen like tool in VR. Please help.
     
  31. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    640
    Indeed SplineMesh can be used for that. Just add nodes as the gesture gesture goes, for exemple whenever the controller travels more than 10 cm. Add the SplineSmoother component to automate the curvature.

    However, Bézier curves may not be the best solution though. They are good to fine tune the curvature, while you only want to have a smooth way through way points. Catmul-rom may be better suited to compute the best smoothing. SplineMesh only support cubic Bézier curves.
     
  32. mangeshjsh

    mangeshjsh

    Joined:
    Nov 27, 2023
    Posts:
    2

    Dear Meth,
    Thank you for your reply. Can you please point me to any step by step tutorials on how to use splinemesh.

    Thanks
    Mangesh
     
  33. Kairros

    Kairros

    Joined:
    May 10, 2022
    Posts:
    1
    I have made only 4 nodes and the spline break, no tiling and mesh is broken.
    Any idea why ?

    upload_2024-3-13_18-48-36.png