Search Unity

SplineMesh, the plugin to create curved content

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

  1. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    You may be correct in maya, but have an import issue. I suppose you have already tried that but just in case:
    - place your mesh in the scene to test if it is visible (correct culling) and at expected scale,
    - check if the origin of the mesh is inside the mesh (not at one kilometer ^^)
    - use a very big and a very low scale in SplineMeshTiling.

    If none of this helps, can you send me one of your mesh so I can test on my side? Here or via PM.
     
  2. ridethefader

    ridethefader

    Joined:
    Jun 17, 2019
    Posts:
    44
  3. vincewins

    vincewins

    Joined:
    Dec 19, 2016
    Posts:
    21
    I am currently trying to use SplineMesh with Unity 2019.2.15f, but I cannot rotate or scale nodes in the sceneview.
    I have seen how it should work in tutorial videos, but in my editor I have no plus or minus icon when having a node selected and also I cannot rotate or scale a node.
    Could it be that some hotkey or plugin is interfering? I have experienced something like that with ProBuilder and the UV Editor before.

    Also, it seems adding nodes uses the same control as camera orbiting, which is ALT. As soon as I click ALT I cannot select or drag a node.
    I have checked the "hotkeys"-menu of unity, but I did not find any hotkey related to SplineMesh.
    Is there anything I might be missing?
     
  4. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    You can't rotate or scale nodes in the scene view, only move them. This option has never been available.

    To rotate a node (change the curve tangent), you have to move one of the direction controls.

    To change scale, you have to edit scale value inside the inspector, after selecting the node.

    You can also change the node's up vector. There is an option in the inspector to draw the up control, which is hidden by default.

    About the alt hotkey, it has been disabled after unity changed the hotkey system in 2018. Now to add a node, you can use the "insert after selected" button inside spline inspector. That said, the hotkey may still exist in the code, and it was indeed hard coded.

    Hope it helps!
     
    vincewins likes this.
  5. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    @vincewins I admit that gizmos would be great to change rotation and scales directly from the scene view. As far as I remember, it is possible in the spline mesh tool of Unreal Engine 4, from which SplineMesh is inspired.

    I'm currently working on other projects, and I will only ensure the basic support and debugging for SplineMesh at the moment, but if you feel like adding these features yourself, I would be glad to integrate them via a github merge request or else.
     
    vincewins likes this.
  6. KSatyaAravind

    KSatyaAravind

    Joined:
    Dec 11, 2019
    Posts:
    4
    Hi I am trying to use spline mesh in android build but its not working like growing root,contortionist(not moving). Everything works while running in unity application. How to use it for android build. Is there any setting to update while building for android? or whats the solution?

    Thanks in advance
     
    Last edited: Dec 27, 2019
  7. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    To my knowledge, there is nothing special to do for an android build.

    Note that the showcase is not intended to be built at all and some features may cause issue in a build. This is due to the fact that the showcase priority is to present SplineMesh features as quickly as possible. For example, some update functions are called all the time even when you're not in play mode, which is a bad practice, not to reproduce into your own project.

    The Example[feature] classes are only examples and I invite you to write your own script by taking inspiration from them, not use them as-is
     
  8. Zhelatin

    Zhelatin

    Joined:
    Nov 19, 2016
    Posts:
    4
    Hello, i want to use SplineMesh tool for building roads. Unfortunately, it doesn't work :(
    I can't add or delete nodes, and it's always "no selected node" on the Spline component. Tested in Unity 2019.2.2f1 and 2019.2.17f1 with the same result.

    upload_2019-12-27_16-39-55.png

    What I'm doing wrong? Can you help me please?
     

    Attached Files:

  9. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    I've heard about that bug already, without being able to reproduce on my side. The two users that reported it were able to fix it by refreshing their unity install, as far as I know.

    The issue is that the selected node is always null (so you can't even add a node, because it is added after the selected one, which is null, hence the disable button). Problem is that nothing explains why the selectedNode variable is null at that moment.

    Can you please send me a scene in where the problem occur? I'm very interested in any information about that mysterious issue.
     
  10. Zhelatin

    Zhelatin

    Joined:
    Nov 19, 2016
    Posts:
    4
    Thank you for reply.
    I made a new unity install today, it doesn't help :(

    It's nothing special about a scene. I created a new scene in SplineMesh project from github, and added one spline object via GameObject->3D Object menu.
     

    Attached Files:

  11. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    The scene is working perfectly on my side and I have never been able to reproduce the bug. I'll dig into it some more soon. Sorry I can't help more.
     
  12. KSatyaAravind

    KSatyaAravind

    Joined:
    Dec 11, 2019
    Posts:
    4
    Hi I Appreciate for responding. I am new to the unity and coding part. As i was trying to achieve something like pipe extrude along the path at runtime. But its not happening for example growing root.This would be really great if you help me to find the solution.
     
  13. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    what exactly is not happening? and what exactly do you want to do?
     
  14. KSatyaAravind

    KSatyaAravind

    Joined:
    Dec 11, 2019
    Posts:
    4
    i was trying to achieve a pipe goes inside the tunnel which has curves. so i took contortionist example reference , Gave path, changed duration of speed to move and build basic android application. As i see in android phone there is no movement of the model. it is static not moving.
     
  15. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    The refresh is made as a callback to EditorApplication.update event. This event is raised everytime something is changed in the Unity editor, and as it changes something as a result, it is called again next frame recursively to enable animation in the editor directly. You shouldn't do any of this in your project, it was made only to create a wow effect in SplineMesh showcase scene.

    Obviously, all this is not available in a build, because the UnityEditor package is not included in shipped game. This package is included to your code only when you are launching your game from Unity editor.

    To make the contortionist example update correctly in a build, please go in ExampleContortAlong.cs, line 48 and change
    void EditorUpdate() {
    by
    void Update() {
    . This should do the trick.

    To avoid warning or error during build, you can also remove the reference to UnityEditor in the usings, at the top of the file.
     
    KSatyaAravind likes this.
  16. Zhelatin

    Zhelatin

    Joined:
    Nov 19, 2016
    Posts:
    4
    I was developing other project for contest during a couple of week and now i returned to my project with roads.
    Well, after some debugging and googling i finally figured out what's going on. The selection value doesn't sharing between OnSceneGUI and OnInspectorGUI, so in inspector it's always null. The solution which i found in this topic: https://forum.unity.com/threads/sharing-a-variable-between-onscenegui-and-oninspectorgui.452764/ is to declare the variable as static,
    So just change 'private SplineNode selection;' to 'private static SplineNode selection;' in SplineEditor script.
     
    Last edited: Jan 11, 2020
  17. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    This is very interesting and it makes kind of sense. Thanks you very much. I still can't figure out why the issue occur for so few users (I heard about that bug three times in two years).

    I will need to make some tests with that solution, as it may lead to issues when going from a spline to another?

    Thanks again for sharing that and have fun bending things !
     
  18. Zhelatin

    Zhelatin

    Joined:
    Nov 19, 2016
    Posts:
    4
    This solution doesn't lead to any issues or bugs. Anything works great, as i see.

    I suspect this bug appeared because i have another Instance of inspector tab (as you can see on my screenshot, i have 2 inspector tabs), but i'm not quite sure.

    I'm glad to help. Thx for this asset, it will save me a lot of time :)
     
    Last edited: Jan 12, 2020
  19. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Finaly I've been able to reproduce that bug. It's indeed because you have two inspector tabs. The selected node only appear in one inspector, while the other tell "no selected node"

    upload_2020-1-12_22-16-21.png

    The solution seems to work perfectly in my test cases. Now I need to tell that to the two other users ^^

    Thanks again. And if you enjoy SplineMesh, please consider writting a few words for it on the asset store ! it's gold to me.
     
  20. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    We have found some new clues about this bug. It occurs if you have more than one inspector tab in your Unity layout. The node is considered selected only on one tab, and not at all on the others. Could you please check that and tell me?
     
  21. Erfan_SheikhHoseini

    Erfan_SheikhHoseini

    Joined:
    Feb 7, 2019
    Posts:
    32
    hello, first of all this is an amazing asset and i love it so far. i don't know if am doing something wrong, but when i check is loop option it loops my spline but when i uncheck it my spline stays looped.
     
  22. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    If I remember correctly, the loop function will only bind the last node position/direction with the first. Unchecking this will stop this binding, but the last node will indeed remain in place. You can select it and move it at will.
     
  23. Erfan_SheikhHoseini

    Erfan_SheikhHoseini

    Joined:
    Feb 7, 2019
    Posts:
    32
    ok thank you that was my mistake,
    also a i have another question.



    how can i create something like this with this asset?
    in this example there are actually 2 cubes that are keyframed at the perfect time so when one goes out the other comes in
     
  24. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    You can do just that with splineMesh, but you will face a limitation. When you will ask for the cube to be partialy outside the spline, SplineMesh will complain about the interval being out of spline bounds. Whatever you do, SplineMesh will always draw the whole mesh.

    There is a number of workaround, though, all depends on your actual need. For example, you could make the spline a little longer, so that the cube could appear/disappear behind an obstacle. please give some details if you wish to have more precise solutions.
     
  25. vongsawat

    vongsawat

    Joined:
    Mar 26, 2014
    Posts:
    7
    Huh it was that exactly. So long as Unity starts with only one inspector open, the "no selected node" bug disappears. Changing the number of Inspectors from one to two, or two to one afterwards doesn't seem to affect the bug. Only matters how many at Unity start.

    As for not being able to manually edit numbers, fixed that with post #291
     
    methusalah999 likes this.
  26. unity_wvdBsmlMTIpFOQ

    unity_wvdBsmlMTIpFOQ

    Joined:
    May 22, 2019
    Posts:
    3
    Hello dear developer, I need your asset to construct interactible(with other objects) cable which will act like rope(as in your last example in demo), BUT I need close to 100 parts and it kills fps... is it possible to calculate spline movements easier?
     
    Last edited: Jan 24, 2020
  27. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    FPS drop are usually caused by an important number of vertices to bend. If you try to use the SplineMesh built-in cylinder mesh a hundred times on a single cable, then you may observe a FPS drop. The question is not the number of nodes in the spline, but the number of vertices per node. How many vertices for the total cable?

    Instead of using the detailled mesh for each spline segment, try to use it once for the whole spline. The result will be blocky, but it may resolve the problem. If so, you will have two options : use a cylinder with more vertices for the whole spline, or use a cylinder with les vertices for each segment (using interval parameter) . If the entire cable move each frame, the first solution will offer better perfs. If only parts of the cable move in a single frame, then the second solution will be better.

    Also, simulating many physical cables of 100 segments with collisions using joints in Unity can be pretty intense, regardless of SplineMesh. Please try to deactivate SplineMesh components to check if the lone physic simulation is not the culprit for your FPS drop. If so, you can try and implement a more suitable physic simulation like Verlet integration instead of joints.

    Finaly, you don't need anything else than SplineMesh here. Look at it simulating and bending this stupid 54k triangles rope using 40 joints, at 120fps on 4yo hardware.
    https://twitter.com/dumas181/status/1140937506201976832

    Hope it helps. Don't hesitate to give more info if it doesn't.

    Happy bending !
     
  28. unity_wvdBsmlMTIpFOQ

    unity_wvdBsmlMTIpFOQ

    Joined:
    May 22, 2019
    Posts:
    3
    I don't understand whats U mean saying that SplineMesh alone is enough- how can it simulate phisics without Rigidbodies? Tried lone Mesh on spline with similar result...
     
  29. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    To be clear, I was saying that SplineMesh has enough perfs to bend the described cable without issue. The physic simulation, however, is indeed outside of SplineMesh's scope.

    I understand that bending a single mesh leads to similar perf, which make me beleive that the perf loss is not situated in SplineMesh bending at all.

    To confirm that, please try deactivating SplineMesh components completly, as I asked in my previous message. This way you will easily find out if SplineMesh is responsible.

    Doing so, your cable won't be visible anymore of course, but you will still be able to see the colliders gyzmos.
     
  30. DavideLH

    DavideLH

    Joined:
    Feb 5, 2020
    Posts:
    2
    Hello,
    I am looking into SplineMesh and that's really cool! I have a problem though, and I am not sure if it's possible to solve it with this plug in. I have already created a mesh with another software and exported it in unity. Now I am trying to deform this mesh using some splines. I thought about "attaching" somehow the spline to my mesh and use it as a guide to deform my object. Probably the MeshBender script is useful for this purpose but I don't understand how to use it properly. Can you help me? Thank you!
     
  31. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    It's indeed the MeshBender that will do the work, but there is a more convenient script for that : SplineMeshTiling. It creates the MeshBender required to bend your mesh the way you want along the spline.

    So basically:
    - add the Spline component,
    - add SplineMeshTiling component,
    - set your mesh into SplineMeshTiling inspector
    - tweak rotation and scale to have your mesh correctly oriented/scaled

    Now your mesh is bend along the spline in real-time and you can draw whatever curves you want. Note that there are more options in SplineMeshTiling editor to better fit your needs. I suggest you to have a look to the showcase scene, where everything is explained and demo-ed.

    SplineMeshTiling is good in a lot of situations but it have limits, for the sake of simplicity. If you feel the need, you can create your own script by taking inspiration directly from SplineMeshTiling code.
     
    DavideLH likes this.
  32. DavideLH

    DavideLH

    Joined:
    Feb 5, 2020
    Posts:
    2

    Great! Thank you
     
    methusalah999 likes this.
  33. unwshd_elend

    unwshd_elend

    Joined:
    Mar 21, 2019
    Posts:
    23
    Its really a great asset! I would get the paid version actually :3
    Im making a racing game with the help of it. is there a reasonable way to calculate racer ranks on the spline?
    Can you help me? Thank you!
     
    methusalah999 likes this.
  34. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    For that you will need to get the closest point on the spline. There is now built-in method in SplineMesh but I've made one for a project of mine. Just add this snippet to the CubicBezierCurve.cs file:
    Code (CSharp):
    1.         public CurveSample GetClosestKnownSample(Vector3 point) {
    2.             CurveSample closest = null;
    3.             float minDistance = float.PositiveInfinity;
    4.             foreach(var sample in samples) {
    5.                 float distance = Vector3.Distance(sample.location, point);
    6.                 if (distance < minDistance) {
    7.                     minDistance = distance;
    8.                     closest = sample;
    9.                 }
    10.             }
    11.             return closest;
    12.         }
    13.  
    Now you just have to iterate through curves in your spline and find the closest. It's very fast but it may lack precision, as there are only 30 samples per curve, and no interpolation. Say a curve is 30 meters long, the method won't be more precise than a meter. If this is an issue, tell me so we can think of a slower but better approach.
     
  35. Gwemlin

    Gwemlin

    Joined:
    Feb 22, 2020
    Posts:
    3
    Hey so I'm not sure if this has been solved somewhere else but I cant change the direction of any node.
    The handles show up in the editor, but I can't interact with them at all. I've tried inputting values in the inspector but the values just revert right back whenever I press enter, so that doesn't work either. Is there any way to fix this?
     
  36. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Please check if you have added the SplineSmoother script. This script override the direction of node to smooth the spline for you. Handles are still visible, but you can't move them.
     
  37. Gwemlin

    Gwemlin

    Joined:
    Feb 22, 2020
    Posts:
    3
    Its kinda tedious and lacks control, but it does work... Thanks!
     
  38. unwshd_elend

    unwshd_elend

    Joined:
    Mar 21, 2019
    Posts:
    23
    No I've tried that and its not precise at all. is there a way to for example write a function that gets a vector3 and retruns the distance on spline.length based on that vector3?
     
  39. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    The method I passed returns the distance on the current curve. To find the distance on the entire spline, you simply have to cumulate curves length while you iterate.

    To gain precision you will have to use projection. Find the closest sample as described, then find the closest neighbor (either the previous or the next sample). Then you just have to project your point on the segment formed by the samples and get the distance of the projection.

    If you achieve to do this, I would be glad to integrate it to SplineMesh.
     
  40. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    What is tedious to you and which control would you like to have? I'm always happy to make SplineMesh evolve with users' suggestions.
     
  41. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    I've implemented the feature !

    It's live on the github repository and soon on the Asset Store.

    Have fun bending things !

    ProjectOnSpline.gif
     
    vincewins likes this.
  42. vincewins

    vincewins

    Joined:
    Dec 19, 2016
    Posts:
    21
    After importing the most recent update (by first deleting the SplineMesh folder and then importing it) into Unity 2019.3.3f1, I get these errors:
    Code (CSharp):
    1. Severity    Code    Description    Project    File    Line    Suppression State
    2. Error    CS0101    The namespace 'SplineMesh' already contains a definition for 'CurveSample'    Assembly-CSharp    <projectdir>\Assets\SplineMesh\Scripts\Bezier\CurveSample.cs    11    Active
    Code (CSharp):
    1. Severity    Code    Description    Project    File    Line    Suppression State
    2. Error    CS0433    The type 'CurveSample' exists in both 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'    Assembly-CSharp-Editor    <projectdir>\Assets\SplineMesh\Scripts\Editor\SplineExtrusionEditor.cs    41    Active
    Code (CSharp):
    1. Severity    Code    Description    Project    File    Line    Suppression State
    2. Error    CS0563    One of the parameters of a binary operator must be the containing type    Assembly-CSharp    <projectdir>\Assets\SplineMesh\Scripts\Bezier\CurveSample.cs    66    Active
    Do have an idea of what's going on?

    The image attached shows lines 66 - 72 of <projectdir>\Assets\SplineMesh\Scripts\Bezier\CurveSample.cs
     

    Attached Files:

    Last edited: Mar 1, 2020
  43. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    tl:dr: manually delete the file SplineSample.cs from your Spline folder.

    In the previous version, the class CurveSample was defined in a file with the wrong name "SplineSample.cs". I renamed it to math the class name CurveSample.cs. I have not anticipated the issue: the old file will not be overriden nor deleted upon the update of the plugin, and will remain in the folder causing the doublon. You need to delete this obsolete file manually.

    But it should not happen if you have deleted the SplineMesh folder before... please check the presence of this file and come back if the issue remains.

    The third error is most likely due to the said conflict.
     
    vincewins likes this.
  44. vincewins

    vincewins

    Joined:
    Dec 19, 2016
    Posts:
    21
    Thanks @methusalah999, it worked fine! :D
    One more question: Is there a possibility to create a spline path from a mesh (.obj|.fbx) somehow?
     
  45. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    I've made something like that. It was a spline made in 3DS Max, exported as a .obj.

    In a certain situation, the vertices of the exported mesh were ordered, so it was only a matter of iterating through them, and creating a spline node for each. In another situation, the vertices were not ordered so I had to write an algorithm to reorder them, by using their distances and angles.

    So yes, it is totaly possible and may even be trivial. It all depends on the input data. Tell me more if you need assistance.
     
    vincewins likes this.
  46. vincewins

    vincewins

    Joined:
    Dec 19, 2016
    Posts:
    21
    @methusalah999: I just started writing an Editor Extension for that purpose. Why don't you ship your solution with SplineMesh? Does it have flaws or anything or would it simply be considered bulge?
     
  47. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Phylosophicaly, SplineMesh does not include any code related to spline generation. The reason is that it's a vast subject, and if you start implementing something, you better implement the whole thing:
    - generate a spline from a set of points,
    - from a mesh,
    - by drawing on the surface of a terrain,
    - by setting hanging points for a cable,
    - by following the motion of a gameobject,
    - etc.

    The SplineSmoother component was a shy step in that direction. It almost allows to create a spline from a set of point, by computing directions automatically. I allowed myself because it didn't felt exactly like spline generation, and it was a most requested feature.

    Import a spline described in a mesh would be another step. But I feel it could indeed be a good addition to SplineMesh as an editor extension. The solutions I wrote was not production ready, and was dedicated to the very formats I was working with. To be shipped, such a tool should include a GUI allowing to adapt to at least the most general cases, to avoid users being frustrated by an existing tool that does not match what they beleive to be a common need. Not really a big deal, but it would require some time.

    I would take a serious look to any contribution on the subject, though, through github or else.
     
  48. jbvobling

    jbvobling

    Joined:
    Sep 26, 2017
    Posts:
    27
    Hi, after testing your plugin, I am trying to use the "Basic Pipe" in the Showcase.scene, by just changing the position and rotation of the start point and end point of the "Basic Pipe", the renderer will automatically update in the play mode. Is this possible in your plugin?

    Example reference for this would be the user is holding a rope on both hands.
     
  49. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Hi,

    If you want a rope hanging at extremity, please refer to the last example of the showcase. The rope is hanging on one extremity, it should be easy to fix the other.

    If you are not looking for a physic simulation, then I didn't understand your question. could you give more details?
     
  50. JasperByrne

    JasperByrne

    Joined:
    Jul 22, 2017
    Posts:
    7
    just wanted to thank you for this awesome code. I have a few issues in 2017 with the UI, but nothing that can't be worked around and i am finding it so useful in a project i'm working on.
     
    methusalah999 likes this.