Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

SplineMesh, the plugin to create curved content

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

  1. RFLG

    RFLG

    Joined:
    Feb 7, 2011
    Posts:
    124
    Hello everyone, I am experimenting with the plugin and I have to say: top-notch work! I have bought it at the first chance I got to support the project, because it is incredible usefull and because it is only fair :)

    Now, I did came across a question for a prototype I am working on and I couldn't quite figure out how if this plugin can be used for that or not (maybe I'm just being dense), so bear with me on this.

    What am I trying do to:
    • Consider a procedural cylinder with x height segments.
    • In runtime I want the mesh to "bend" y degrees
    • I want that y degree bend to take z seconds to occur (or frames)
    Can this be done with the plugin? If so, can anyone point me on the right direction to do it?

    Thanks for the help in advance!
     
  2. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Thanks for your kind words and generosity ! I'm not sure that I have correctly understood your need, but here is my best guess.

    - add the Spline component, place the two nodes and directions so that it is a straight line,
    - add the SplineMeshTiling component,
    - either add the mesh in SplineMeshComponent, or via a script if your procedural mesh is being built during play time,
    - create a script that moves the second node (and its direction) over time, to create the angle you need.

    About your math, I imagine that the rotation center should be in the middle of the two nodes but I may be wrong. In any way, the two directions should point toward the rotation center, and the directions lengths will define the curvature (smooth or hard angles).

    Hope it helps ! And if you like SplineMesh, please consider writing a short review on the store :)
     
  3. RFLG

    RFLG

    Joined:
    Feb 7, 2011
    Posts:
    124
    Hey, thanks for the advice ;)

    Ok, so, I got everything setup and I've created a script to move a node. At this stage I just want to get the process narrowed down, so I picked node[0]. Also, no actual math for bending stuff is there, just focused on getting it to move for now.

    Then I encountered two issues:

    1- I am moving the node's position and changing the direction by script, the position change does register on the inspector for the node, but it won't reflect on the mesh, nothing happens even if I move it into ludicrous coordinates. Am I missing some "refresh mesh" method call or something?

    Code to change the node position:

    Code (CSharp):
    1. IEnumerator Bend()
    2.     {
    3.         while(current_rot<target_rot)
    4.         {
    5.             current_rot++;
    6.  
    7.             Vector3 pos = target.nodes[0].Position;
    8.  
    9.             target.nodes[0].Direction = new Vector3(0, 1, 0);
    10.  
    11.             target.nodes[0].Position = new Vector3(pos.x, current_rot, pos.z);
    12.  
    13.             target.RefreshCurves();
    14.          
    15.  
    16.             yield return new WaitForSeconds(0.05f);
    17.         }
    18.     }
    2- When I setup the mesh and the two spline scripts, this is what shows on my editor window, I placed the nodes as a straigth line, but I get a feeling something is off :)



    Any ideas on what am I doing wrong?

    Thanks for the help!
     
    Last edited: May 10, 2020
  4. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Dont have much time now but quickly :
    1 - check "update in playmode" in splinemeshtiling
    2 - what's wrong here? Please try with only two nodes to start with.
     
  5. RFLG

    RFLG

    Joined:
    Feb 7, 2011
    Posts:
    124
    Thanks for the feedback. Tested your advice and progress is being made :)

    1-Is fixed, everything moves.
    2-I had 3 nodes and removed one, the mesh became a bit smoother but still messed up.

    To create the spline what I did was:

    1-Added you cylinder 3D model to the scene
    2-Added the spline component to it
    3-Positioned the spline so that it made a straight vertical line and I had one node at each cylinder cap
    4-Added the SplineMeshTiling component
    5-Geo got as the screenshot reveals.

    I did some experimenting and I got a closer shape if I placed the spline as horizontal instead of vertical, but still with artifacts. Feels as if the nodes have some strange rotation about them, I tried setting the rotate property on the nodes, but it just seems to make things worse :(

    Any advice guys? Thanks ;)
     
  6. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    please send me a screenshot, because I still don't know what the issue is. Note that if your spline line is vertical, you may encounter a twist of the cylinder, due to gimball lock. To fix this, just draw the up vectors with the option in Spline component, and turn up vectors the way you want.
     
  7. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Also:
    - you don't need to add the cylinder in the scene. The cylinder will be build and bend by SplineMeshTiling. Just insert your mesh into SplineMeshTiling
    - your mesh does not seem to be oriented correctly, and bending occur on the wrong axis. You must apply a rotation to the mesh in SplineMeshtiling to bend on the correct axis.

    It may be interesting for you to take a better look at the showcase scene to understand how the SplineMeshTiling component is used.
     
  8. ZinnZ

    ZinnZ

    Joined:
    May 3, 2019
    Posts:
    1
    Hello everyone, I am working a pipe project with spline mesh,
    Firstly Thanks for spling mesh, very useful asset.

    What am I trying do to:
    1- The project works with 3 nodes in the spline component.
    I move the 0.node object at runtime. What I want is that the particle at the end of the object is rotated according to the spline.
    I hope I mentioned in the screenshots below, was hopeful.


    https://drive.google.com/file/d/1KQvZLuos7sxBqysMGtH8Lm30k39rcJNQ/preview

     
  9. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Just get the spline tangent rotation of the last point in the spline like this:
    myParticleEmitter.transform.rotation = spline.GetSampleAtDistance(spline.Length).rotation;
     
  10. neuralscan

    neuralscan

    Joined:
    May 17, 2013
    Posts:
    2
    Hey there!

    Love the asset but I'm having a problem when duplicating. The splines act as if instanced, so if I want to make a copy and modify it all the existing ones change too.


    Of course, I can get around this by just creating a new spline but when filling out a level this is tedious - 'cos I'm using splines a LOT! Any idea what's up? If intended, can I change this behaviour?

    Cheers,
    Tom
     
  11. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Indeed, it may be a issue. You can easily fix it by deleting the generated content and generate it again by a disable/enable on the spline game object.

    To delete de generated content on many splines, you can search the key word "generated" in the hierarchy.
     
  12. neuralscan

    neuralscan

    Joined:
    May 17, 2013
    Posts:
    2
    Perfect, thanks a ton!
     
  13. TKDHayk

    TKDHayk

    Joined:
    Dec 22, 2015
    Posts:
    85
    Hi there, this is a very fun asset.

    Can I email you with a few questions about it?

    I'm using the "Tentacle growth" example. How can I make the tentacles stop growing once they've reached max length?

    How can I control the speed of growth, during growth?

    thank you very much, ill give 5 stars and purchase the paid version because its a very simple fun and flexible asset.
     
  14. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    The growing tentacle is only an example to show how to do things and inspire you. Start by duplicating it in your own script.

    The growth is controlled by a variable "time" going from 0 to 1, multiplied by the max scale and the distance on spline. It comes back to 0 when it reaches 1 to obtain a loop effect.

    Therefore, if you want it to grow then stay at the max scale, just remove the code that make the time reset.

    The time is increased each turn by a speed multiplied by Time.deltaTime. So changing the speed will immediately affect the growing speed, at any moment of the animation.

    If you want to have more control over the animation, you can easily replace the speed by a public AnimationCurve. This will allow you to slow down or accelerate the animation with ease in and ease out for example.

    Tell me if you need more details.
     
  15. TKDHayk

    TKDHayk

    Joined:
    Dec 22, 2015
    Posts:
    85

    Thank you, I'd love to be able to do that.

    I could not find a "time" nor a "speed "variable in any of the scripts I looked at (Spline.cs, ExampleGrowingRoot.cs, or MeshBender.cs). Which script are you referencing?

    However, I was able to stop the growth of the tentacle by changing the "rate" variable. I changed line 56 of "ExampleGrowingRoot.cs" from "rate --;" to "rate = 1;", and that stopped the loop effect :)

    As for changing the speed at run time, I cannot find the speed variable mentioned.

    Thanks
     
  16. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Ok sorry, I was not in front of the code and I was gussing from memory ^^

    So yes, this is not "time" but "rate". You already got that.

    For the speed, it's not actually the Time.deltaTime multiplied by a speed, but the Time.deltaTime divided by a duration. So I suppose what I told about changing the speed will apply to the duration, but I advise you to change this code to use a speed instead, it will be easier to make evolve.
     
  17. DroidekaMkII

    DroidekaMkII

    Joined:
    Jun 8, 2020
    Posts:
    1
    Hello there ^^
    The tool is really great to use, but I have a small problem that I've been fighting with for a few hours. The collision is reset to 'None' after starting to play, and so, the spline mesh never has any collision.

     
  18. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    SplineMesh does not allow for MeshCollider update. This is for performance reasons.

    MeshCollider are complex colliders that can be a big hiccup on the performances. When you build a MeshCollider from a mesh, Unity does a serious pre-processing job to optimise it so it can be ran as fast as possible by the physic engine. This work is called "cooking".

    Cooking takes time, and if SplineMesh is told to update the MeshCollider each frame, it may or may not hit the performances very hard. It depends mainly on the topology of the mesh to cook. I've made the choice not to provide the option, fearing that users would use it without understanding what they were asking for.

    Now, you totally can cook the MeshCollider each frame. Let's do it manually, rendez-vous in MeshBender.cs. There are three bending methods MeshBender.FillRepeat, MeshBender.FillOnce and MeshBender.FillStretch. At the end of each of these method, you will find a call to MeshUtility.Update. After that call, just add the following:
    Code (CSharp):
    1. if (TryGetComponent(out MeshCollider collider)) {
    2.     collider.sharedMesh = result;
    3. }
    Now, the MeshCollider shape will be cooked each time the mesh is bent. You have understood : be very carefull with the performance of this one.

    Edit: as a best practice, I suggest that you sow primitive colliders along your spline to produce a fast approximated physic shell for your mesh. ExampleSower may help you for that.
     
    DroidekaMkII likes this.
  19. Vivraan

    Vivraan

    Joined:
    Feb 2, 2018
    Posts:
    3
    I ran into a bug on v1.3.2 (using Unity 2019.4)
    upload_2020-6-16_11-51-46.png
    Seems like there's a bug in the triangulation of the generated mesh.
    Steps to reproduce:
    • Create a Spline object from the 3D Objects menu in the Hierarchy.
    • Attach a Spline Mesh Tiling component to the object.
    • Select a Mesh and a Material (it's a cube here but the error seems to be present for any mesh)
    • Move the point on the extreme end.
    I've also sent you an email from
    mshivam98 
    at
    gmail 
    dot
    com

    An all in all amazing asset, might consider paying up for it in the future!
     
  20. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    I guess it is only because you have your directions collapsed on that node. SplineMesh can't determine the tangent of the spline, and the mesh orientation is therefore messed up.

    Just change the direction value to fix that. You will have to use the inspector for that, because you won't be able to select the handle now they are overlapping.
     
  21. Yurijh

    Yurijh

    Joined:
    Nov 4, 2016
    Posts:
    7
    Hi everyone,

    I'm looking for a way to get the current direction vector (in local space) of the spline. I've built a road using the Spline Mesh Tiling component and I want to get the current direction vector of the spline from every point of the road.
    What can you suggest?
    Thanks in advance
     
  22. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    When you get any sample of the spline, the tangent vector at this sample is given by sample.Rotation * Vector3.forward.

    It's a world rotation, so you will have to convert it to local space from any transform you want.
     
  23. Yurijh

    Yurijh

    Joined:
    Nov 4, 2016
    Posts:
    7
    Thank you, that was just what I was looking for.
     
    methusalah999 likes this.
  24. TheKlikluk

    TheKlikluk

    Joined:
    Feb 10, 2020
    Posts:
    3
    I cant seem to be able to select nodes for some reason. Im using Version 2019.3.6 am I the only one with those issues?
    I already read that the alt+grab doesnt work anymore. And that would be fine honestly if I could manually create nodes. Feeling kinda lost ^^
     
  25. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    Please check if you have several inspector Windows opened, and if so please close all but one. Also be sure to run the latest SplineMesh version.

    This bug is supposed to be solved for some time now but it worth the try.
     
  26. S-U999

    S-U999

    Joined:
    Jun 3, 2015
    Posts:
    1
    I have the same problem with v 1.3.2. Duplicating an object that contains a generated mesh bender links the two copies. Deleting and regenerating seems to fix it though. Thanks for a great asset!!
     
    methusalah999 likes this.
  27. Yggdrazyl

    Yggdrazyl

    Joined:
    Jul 12, 2017
    Posts:
    6
    Hello ! I want to create some sort of cylinder shaped racetrack along a Bézier curve, so I thought your asset was the perfect fit. I do have a few questions :

    1/ How would you get the closest point on the curve from my character ? Alternatively, how would you get the normal from the curve to my character ? I would need that normal to orient my character towards the center of the cylinder.

    2/ I have already followed both Sebastian Lague's and Catlike's implementations of Bézier curves. Would it be possible to extrude the curves I drew through their APIs using your asset ?

    3/ Have you compared your solution to the other Bézier APIs, and mesh extruding APIs out there ? Googles gives me many results for "Unity curve extrusion" or "Unity Bézier extrusion", and I'm not sure which one would fit my needs the best. Especially, the one included in the Unity tools package ?
     
  28. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    316
    1/ use Spline.GetProjectionSample(). To orient your character, you should be able to use the up vector like this: thisSample.Rotation * Vector3.up.

    2/ If you want to draw splines with another asset, you can simply create a simple script that will iterate through the spline nodes and build a SplineMesh spline from it.

    3/ I know the a other solutions, but not sufficiently to list the main differences between them. I can tell that, among the free assets out there, SplineMesh is known as a robust and expandable API, with a precise GUI, a complete set of features and strong real-time performances , while also being more complicated to handle at first.

    Have fun bending things !
     
unityunity