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 can use the inspector, by selecting a node and editing the values. You can also write a script that is setting values to your nodes, depending on what you are doing.

    Note that in the inspector, only the values of the selected node are editable. It's a bug of the UI.
     
  2. Roboserg

    Roboserg

    Joined:
    Jun 3, 2018
    Posts:
    83
    My question was how to do it automatically. Maybe I phrased my question incorrectly. I figured it out, the "spline smoother" component does exactly what I wanted - thank you again for the great asset!

    The QOL wish I would have is to see the spline nodes at all times in the editor. Right now if I select the mesh with a mouse it selects the mesh, not the parent object with the spline component. To see the spline nodes I have to manually find the "Extruder" gameobject in the inspector and select it, to see the spline nodes. It would be very convenient to see the nodes at all times.
     
  3. Roboserg

    Roboserg

    Joined:
    Jun 3, 2018
    Posts:
    83
    "Is loop" does not weld the vertices of the mesh. Is this not supported for extrusion?


    Also when selecting a node it's always world coordinates, even if I change it to local, the move axis are still in world space. Is there anything one can do about it?
     
    Last edited: Jan 10, 2021
  4. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    The loop feature should indeed mirror the start and end directions, resulting in a correct connexion of the extrusion. It it does fail for some reason, you can still change your end directions manually, so it matches the start one.

    Unfortunatly no, the move handle don't take the spline object rotation into account. You change this behavior easily by going into SplineEditor.cs, line 114 or so and make this change
    Code (CSharp):
    1. //Vector3 newPosition = spline.transform.InverseTransformPoint(Handles.PositionHandle(spline.transform.TransformPoint(selection.Position), Quaternion.identity));
    2. Vector3 newPosition = spline.transform.InverseTransformPoint(Handles.PositionHandle(spline.transform.TransformPoint(selection.Position), spline.transform.rotation));
    3.  
     
  5. Yanfundi

    Yanfundi

    Joined:
    Nov 25, 2018
    Posts:
    7
    I want to make a game like slither.io (basically a snake game but it's battle-royale, where players is put in a field and they eat points to grow their snake; try to survive by not bumping the snake head's into other snake) but in 3D. Is it possible to do it with this plugin? at first i though to try it with RopeBuilder, but the RopeBuilder mesh that was created by Spline doesn't move with the collider in Showcase scene and my testing scene. I need smooth snake movement like in slither.io, able to grow (prefer tiling instead of stretching), and collider to the snake body (so it can detect if the head has collide with other snake or points).

    I'm also wondering is it possible to attach animator to the body ? because i was thinking when the snake eats a power-up item, it plays an animation. (this is for skin snake like a train, boat, etc).
    thanks
     
  6. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    SplineMesh can do what you describe, but here are some random information.

    in slither.io, or the classic nibbles, the snake is not actually bent along a curve. It's more about making a head traveling through a map and "sowing" a body element at the previous place of the head, that will last a few moment. So the snake is not really moving, only growing and shrinking. Having a segmented snake and not a deformed mesh is easier. With segments, you are able to grow the snake more easily, while a mesh would be stretched, and loose tessellation eventually.

    Creating a growing snake that looks like in the game Snake Pass will be definitely harder (but fun !). You could use different meshes for the head, body and tail, and only have the body deformed or extruded, scaling its texture coordinate to make the texture repeat instead of stretch.

    At some point, the number of players in the screen, the length of the snakes, the number of vertices in the snake body may become a bit too much to be deformed each frame.

    You don't deform a mesh collider in play mode. Mesh colliders are computationally extensive and needs a lot of optimizations to run fast. Updating the mesh of a mesh collider would imply running these optimizations each frames, which would lead to very low performance. Instead, you have to place primitive colliders along the body of your snake, like spheres, capsules or boxes. You can use a mesh collider for the head and tail to obtain more precise collisions, if they are not deformed.

    Have fun bending things !

    Ben
     
  7. Yanfundi

    Yanfundi

    Joined:
    Nov 25, 2018
    Posts:
    7
    Thanks for the answer. I have a code that move & rotate the head, and then the collider of the body following the previous collider. But now I'm stuck. I don't know the math/algorithm on how to make the body mesh of the snake and implement it to Spline Mesh (for example if I use normal Spline, how to calculate the Position and Direction for each note). Do you have any guidance that I can follow? thank you so much!
     
  8. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Node are positionned on the snake path so position is not a problem. To compute directions, you can simply add the SplineSmoother component, that will compute automatically the nodes direction to smooth the path.
     
  9. Roboserg

    Roboserg

    Joined:
    Jun 3, 2018
    Posts:
    83
    Thanks for the answer. I would assume the loop feature for the extrusion would weld the vertices of the mesh, otherwise, there will be a visible seam. I take it it's not implemented yet, do you have plans to implement the welding of the endpoints in the future?
     
  10. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    If the start and end nodes have the same positions and mirrored directions, (which should be the case in loop mode), the start and end vertices should coincide exactly.

    To avoid seeing the texture changement, you should be able to set the V coordinate as a multiple value of the spline length.

    The normal smoothing should not be a problem if the connection does not have an extreme curvature.

    What kind of seam do you see?
     
  11. Yanfundi

    Yanfundi

    Joined:
    Nov 25, 2018
    Posts:
    7
    Thanks for the advice. I've Update() the position of each node and use the Smoothing and Mesh Tiling script (I change it a bit, so it isn't Static), It's working like I wanted to. But the performance drops significantly
    Without Spline.JPG
    Without any Spline script - around 1400 fps
    Spline Only.JPG
    Only with Spline - around 800 fps
    Spline and Smoothing.JPG
    Spline and Smoothing - around 300 fps
    Spline and Mesh Tiling.JPG
    Spline and Mesh Tiling - around 350 fps (but the mesh looks weird)
    Spline and Smoothing And Mesh Tiling.JPG
    Spline and Smoothing and Mesh Tiling - below 200 fps
    Do you have any suggestion on how to increase the performance? Thank You.
     
  12. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    You should not test the performance by looking at the FPS, but by looking at the duration of a task using the profiler. Deforming the built-in cylinder once a frame should not take 4ms on any recent CPU, but I don't see any issue in your script configuration. Just in case, please note that you don't have to ask for any refresh, because SplineMesh detects the changes in nodes itself and update only what is needed.

    Could you please run the showcas scene and tell me what kind of FPS you get? it features at least 4 cylinders updated each frame.
     
  13. Yanfundi

    Yanfundi

    Joined:
    Nov 25, 2018
    Posts:
    7
    I get 1000 fps running Showcase scene.
    I don't understand, what do you mean by "I don't have to ask for any refresh, because SplineMesh detects the changes in nodes itself and update only what is needed" ? is there a variable in the inspector that I need to tick off?
     
  14. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    A common mistake is to force the updating of the mesh after changing the spline, which generally leads to multiple update each frame and affects performances. In SplineMesh, a listening system ensures that all meshes that need to be bent again are bent every frame, and only them, so the user don't have to bother and just have to change the nodes property (in you case, the Position).

    The last example of the showcase is doing just what your SnakeMovement is doing. A rope driven by physics is hanging at a moving point. A SplineSmoother component manage the nodes' directions automatically. The script RopeBuilder just do this each frame:
    Code (CSharp):
    1. int i = 0;
    2. for each ropeSegment in ropeSegments {
    3.     spline.Nodes[i].position = ropeSegment.transform.position;
    4.     i++;
    5. }
    If you disable all other example in this scene, and ask the SplineMeshTiling to work in spline space (so the cylinder is deformed once for the whole spline, and not once per curve), then you will be in the exact same situation as in your snake game and the performances should be the same. If it's not, you will have to profile your code to see what is going on.

    As an example, here is 40 cylinders deformed at 120fps on a 5 years old Intel i5 https://twitter.com/dumas181/status/1140937506201976832
     
  15. aladdin518

    aladdin518

    Joined:
    Jan 15, 2021
    Posts:
    1
    thank you Methusalah99 for the wonderful tool. I am just wondering if you could implement a serial of sprite along the curve? I want to create an effect just like a particle trail along a curve. Any help would be much appreciated. thanks again.
     
  16. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    You can place anything you like along the spline by writing your own custom component, based on ExampleSower.

    Just iterate through the spline the way you like (distance, percentage of the total length, speed of a moving gameobject...) and get samples of the spline. Sample will contain the data you need, like position, orientation, up vector... to place whatever you like.
     
  17. Yanfundi

    Yanfundi

    Joined:
    Nov 25, 2018
    Posts:
    7
    I was just wondering about the rope. in the Showcase scene, the mesh of the rope doesn't follow the collider. Rope.gif
     
  18. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    That seem to be a problem with static batching. You should be able to solve that by deactivating the static batching in project settings -> player -> other

    Alternatively, you can modifty the SplineMeshTiling code like this at line 118 or so:
    Code (CSharp):
    1. if (childTransform == null) {
    2.     res = UOUtility.Create(name,
    3.         generated,
    4.         typeof(MeshFilter),
    5.         typeof(MeshRenderer),
    6.         typeof(MeshBender),
    7.         typeof(MeshCollider));
    8.     res.isStatic = !updateInPlayMode;  // <- add this line
    9. } else {
    10.     res = childTransform.gameObject;
    11. }
    12.  
     
  19. killica

    killica

    Joined:
    Sep 15, 2017
    Posts:
    3
    Thanks for sharing the plugin for free. I have an issue of Spline Mesh Tiling (script) not showing up the custom mesh. It shows the meshes from your example files, and also mesh primitives generated by unity. Is there something special about the meshes that can be used. I export fbx from blender and get mesh from that asset
     
  20. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Generally this is caused by:
    - the scale of the mesh being too high or to low. One way to test it is to place your model on the scene and check if the scale is in the same order of magnitude you are working on in Unity.
    - the mesh not being read/write. SplineMesh need to be able to read the vertices and you have to check the read/write option in the import settings of your mesh in Unity
     
    killica likes this.
  21. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    Is it possible to animate a spline (and in turn an object bent along it)?
     
  22. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    You won't be able to add spline nodes in your animation key frames, but you can use one game object for each node and animate them instead. A one-line script on these game objects will simply make the associated spline node follow the transform each frame.
     
  23. AIS_Rich

    AIS_Rich

    Joined:
    Mar 19, 2010
    Posts:
    43
    Hi, been using SplineMesh for quite a while and always works well. Currently on a project in 2019.4.1 and getting this problem I have not seen before. In the screenshot you can see that it is duplicating the nodes so a 3 node setup shows Nodes 0,1,2,0,1,2. I'm using it to place prefabs quickly so the result is that it is placing two prefabs stacked. Not showing any errors. Last version with no problems is 2019.1.1. Thanks for the help.
     

    Attached Files:

  24. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    I've observed that regression myself indeed, but as far as I know, it is only a visual issue. Nodes are not actually duplicated, but the list is displayed twice in the inspector. It seems to make it impossible to edit the nodes property in the list, but it is still possible to edit the properties of the selected node, which is displayed at the bottom of the list.

    Sorry I don't have time at the moment to dig more deep into it and push a fix. It's kind of frustrating because it must be no big deal.

    Of course, if your problem is different from what I described, please tell me a little more details about it.
     
  25. AIS_Rich

    AIS_Rich

    Joined:
    Mar 19, 2010
    Posts:
    43
    Thanks for the quick reply. It is as you describe. I should be able to work around this for now.
     
  26. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    Hi, I have a problem with meshes not showing in prefabs.

    I have a spline with with a tiling and smoothing script. When placed in a prefab which are spawned from a pool, the meshes wont show.
    If I edit a prefab not in a scene, the mesh wont show unless I first click on the spline object.

    What can I do about this?
     
  27. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    I'd like to create splines programmatically based on a set of points forming a 3D polyline. Do you have any curve-fitting code to obtain the best spline that fits the polyline given a specified tolerance?
     
  28. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    SplineMesh is based on cubic Bézier curves and may not be adapted to your situation. If you want a curve that is going through all points in a poly-line, you should use catmull-rom or polynomial curves, which are easy to implement.

    If you need to curve a poly-line that is not too much tessellated, though, you can use SplineMesh, creating a spline node for a selection (or all) point of the poly-line, and add the AutoSmoother component, which will compute tangents automatically.
     
  29. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    In the SplineMeshTiling class, you will find an attribute ExecuteInEditMode at line 17 or so. You can change that with the new attribute ExecuteAlways, which was introduced in 2018 and allow a script to be also executed in the prefab editor. It may solve your problem, but you may need to change that in more classes (like spline).

    That being said, I would advise against generating content during the prefab edition. When you generate content, game object are created under the spline objects. In the scene editor, if you change something in the parameters of your spline or tiling, these generated objects will often need to be destroyed and replaced by new ones. But Unity won't allow it as it will change the hierarchy of the prefab, which is forbidden since 2018.

    My suggestion is to prepare your splines and tiling inside the prefab editor, generate things only to test your parameters using by toggeling disable/enable, and remove manually the generated content before you save your prefab. Alternatively, you can also add something like that to avoid automatic generation of objects while you are in the prefab editor;
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.             // we don't update if we are in prefab mode
    3.             if (PrefabStageUtility.GetCurrentPrefabStage() != null) return;
    4. #endif
     
  30. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    Thanks for the quick reply. I don't need the points of the spline to go through all the vertices of the polyline necessarily. An approximation is fine. I tried adapting this code here to 3D vertices, but it yields splines with C1 continuity, whereas your composite Bezier curves require C2 continuity (since, I understand, each vertex only has one control point) so that tool isn't directly usable. I will try Douglas Peucker simplification on my polyline, then as you suggest, create a simple spline that runs through it and see what kind of smoothing AutoSmoother gives me.
     
    Last edited: Feb 5, 2021
  31. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    I have another question: I have a flat mesh (a polygon) and I was hoping to extrude it along a spline to create a volume but that doesn't seem to work. I get some bizarre shape. Does SplineMeshTiling expect a fully volumetric mesh to generate the object?

    This is what I'm doing:

    Code (CSharp):
    1. GameObject newVolume = new GameObject();
    2. Spline testSpline = newVolume.AddComponent<Spline>();
    3.  
    4. // calculate the centre of the polygon to place the spline (maybe that's not needed)
    5. Vector3 centroid = Vector3.zero;
    6. foreach (var vec in pointsList)
    7.      centroid += vec;
    8. centroid = centroid / pointsList.Count;
    9.  
    10. SplineNode sn0 = new SplineNode(centroid, centroid);
    11. Vector3 next = new Vector3(centroid.x, centroid.y + 0.2f, centroid.z);
    12. SplineNode sn1 = new SplineNode(next, next);
    13. Vector3 next2 = new Vector3(centroid.x+0.2f, centroid.y + 0.4f, centroid.z);
    14. SplineNode sn2 = new SplineNode(next2, next2);
    15. testSpline.AddNode(sn0);
    16. testSpline.AddNode(sn1);
    17. testSpline.AddNode(sn2);
    18.  
    19. SplineMeshTiling smt = newVolume.AddComponent<SplineMeshTiling>();
    20. smt.updateInPlayMode = true;
    21. smt.mesh = mesh;
    22. smt.material = material;
    23. SplineSmoother smoother = newVolume.AddComponent<SplineSmoother>();
    24. smoother.curvature = 0.3f;
     
  32. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    Wait, that's for editing prefabs, but it also happens in playmode. Do I need to disable/enable there too to make the spline to appear?
    Also, what is manually generated content? The spline mesh?
     
  33. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    So there appears to be a larger issue with SplineMeshTiling as the result of the extrusion seems to depend a lot on the base mesh.

    For example, this is a spline extrusion using the cylinder mesh in the demo. Looks good.

    SplineMesh - Demo Cylinder.jpg

    Now if I try extruding with the same spline but using the mesh of the default Unity cylinder, this is what I get:

    SplineMesh - Unity Cylinder.jpg

    I've tried applying different pre-extrusion rotations (90°, -90°) in the SplineMeshTiling parameters, but I always get garbage. Would be really great to know what's the problem there.

    Again, I want to extrude programmatically generated meshes via also script-defined splines so I'm very curious to know what are the conditions on the base mesh to generate the expected object along the spline path.
     
  34. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    There is no issue here. The cylinder provided with the asset includes layers of vertices for SplineMesh to deform. SplineMesh won't add vertices to deform along the spline tangent and you need to ensure that your mesh have enough vertices on that axes to allow SplineMesh to deform it with the smoothness you desire. The more vertices, the more computations.

    For this reason, the base cylinder mesh provided with Unity is not bendable at all: it lacks vertices between the bases.

    Also, There might be a misunderstanding about SplineMeshTiling. This component, as the name implies, will only tile existing meshes on a spline. It is not an extruder, but more of a bender. Therefore, it requires a volumetric mesh and not a 2D shape.

    If you wish to extrude a 2D shape, you will have to work with another component named SplineExtrusion. The job of this one is to start with a flat, simple polygon that is placed at the start of the spline, orthogonally to the tangent, and then extruded along the spline. This component include a drawer that allow you to create the 2D shape of the base and specify faces normals. If you wish to import points from another software, you will have to create your own script but it will be no big deal: SplineExtrusion is a tiny component and the complexity lies in ExtrusionSegment component, which you won't need to modify.
     
  35. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    There is no "manually generated content". I told to manually delete the generated content before saving the prefab, to avoid generated content to be saved. Generated content are objects generated by SplineMeshTiling for example, located under the spline object, and placed into a parent object named "generated by [...]" so you can easily search then and delete them.

    About your content not appearing in play mode, it is not normal and you don't have anything to do. If you are using SplineMeshTiling, the meshes are bent during the OnEnable method. So if both the object and component are active/enabled, the new meshes should be generated right away. It might be something with your pooling system not calling OnEnable somehow, or disconnecting the spline object with its generated content. It might also be a issue with the static batching, you can try and deactivate it in project settings -> player -> other.
     
  36. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    Ah yes, I see. I took the first basic example of the demos and thought it was extruding.

    Ok, so now I'm using SplineExtrusion and defining my base shape in shapeVertices. But again I get a weird extrusion:

    SplineMesh - Extrusion.jpg

    You said the base polygon should be oriented orthogonally to the tangent of the first spline node, right? That would make sense but as you can see, in my case for some reason the spline segment is contained in the plane, not orthogonal to it.
     
  37. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    !your problem here is that your directions control points are collapsed and coincide with the positions. SplineMesh won't be able to find any tangent. Just un-collapse the directions by dragging them around, or setting some values from the inspector.

    If you are using the AutoSmoother, the problem may come from the curvature value being zero, negative... just try with the default 0.3.
     
  38. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    Thanks again for your reply and help. Really appreciate.

    I made sure the control points didn't coincide with the nodes and the base surface is indeed properly oriented now, but when I extrude, I get a weird twist in the middle, like a cracker.

    SplineMesh - Extrusion2.jpg

    If I reduce the bend angle in the middle to make it look more like a cylinder, then the twist disappears. So there's a limit to node curvature when doing extrusions?
     
  39. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    A twist can occur when the spline is vertical due to a rotational effect named gimbal lock. Y and Z axis are too close to each other and SplineMesh lacks a data to know how to orient your mesh.

    In SplineMesh, you can specify the up vector at each nodes to avoid that. A checkbox is present in the Spline component to draw the up vector gyzmos and manipulate it. You can also specify your up vector in the inspector. Please go to the showcase scene and loot at the looping road to see an example.
     
  40. yodavid

    yodavid

    Joined:
    Dec 12, 2016
    Posts:
    25
    is there a basic tutorial for this asset? i understand it comes with example scripts and a demo scene, but since i'm not and advanced unity user i'm having difficulties with it. i'd appreciate if there was some 101 examples to follow and then i could pick up from there.

    what i'm going to use it for is this: i want a tentacle-like spline to be instantiated via script, having its two original nodes on specific positions, and then new nodes will be added (also via script of course), increasing the overall length. each node will have its own cross-section area.
     
  41. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    There is a video tutorial here. It is a little outdated, though. But there is no tutorial on how to write your own custom script.

    But here are the good news : SplineMesh is designed to be extanded and provide lots of Example scripts for inspiration, your need seems to be pretty easy to implement, and I'm always happy to help ^^

    Most examples in the showcase are using a static, non moving spline, so I suggest you jump directly at the RopeBuilder, which is the last example of the scene. In this script, the node positions are driven by rigidbodies, the node directions are automated using the AutoSmoothing component and this should be a good start.

    Some things to note before you start:
    - In SplineMesh, spline math is separated from the actual content placed along it.
    - When you add, remove or change nodes in any way, events are raised so the content will update automatically. You should never have to bother about updating things.
    - The SplineMeshTiling component is useful to bend a mesh along the spline. It can place one mesh along the whole spline, one mesh on each curve, with different modes : stretch, repeat or once.
    - If you need to place your mesh in a custom fashion, you can rewrite your own tiling script and work on intervals, as shown in ExampleContortAlong and ExampleGrowingRoot.
    - if you intend to move your node along a static curve like for a growing root, you will have a hard time replicating the exact curvature at each frame. It may not be intuitive but the curvature of the curve will change when the node position will change. It may be better to place the node at its final position when you add it, and have the mesh bent growing along it (as in ExampleGrowingRoot).
    - For a tentacle along the spline, you can stretch a single mesh along the spline but this will stretch the texture and lower the mesh smoothness as the spline grows. Alternatively, you can add as many meshes as it fit without stretching them to keep a correct texture scale and tessellation.

    If you tell me more about your need I can give more advice.
     
    Last edited: Feb 17, 2021
  42. yodavid

    yodavid

    Joined:
    Dec 12, 2016
    Posts:
    25
    could you provide me some simple code that creates a spline object then adds nodes to it with different cross section area? that would be a starting point for me. i know i might be able to find it in the provided examples, but there's a lot of things there and i end up getting lost in it hahah
     
  43. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    - RopeBuilder is a simple example of how to create and update spline nodes during play mode via script.
    - ExampleContortAlong and ExampleGrowingRoot are simple examples on how to grow a mesh along the spline using intervals.

    What do you call "cross section area" exactly?
     
    Last edited: Feb 17, 2021
  44. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    The up vectors in the looping road example are orthogonal to the road surface at their location, like normals. But if you don't have such an obvious case, such as when you want to create tubes, what is a good strategy to define the up vectors so that you get a smooth volume without any twists?
     
  45. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Indeed up vector con only be orthogonal to the tangent. A cylinder pipe does not have an actual top but you just have to pick a side. The only thing important for you is that the up remains consistent before, during and after the place where your spline get vertical, so SplineMesh can know explicitly how it is supposed to orient your pipe. Here are two examples.

    upload_2021-2-18_14-28-5.png

    To be clear, here is what happen when you don't specify explicit up vector. SplineMesh will use the orthogonal vector that is closest to the world up:

    upload_2021-2-18_14-42-49.png
     
    Last edited: Feb 18, 2021
  46. yodavid

    yodavid

    Joined:
    Dec 12, 2016
    Posts:
    25

    it's been difficult for me to understand even this simpler code. i'd like to do via code what i already do with the unity GUI. create 2 point tentacle then either stretch it or add a non colinear point
     
  47. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Here is some code to get inspiration from.

    Code (CSharp):
    1.  
    2. // first we adjust the node count in the spline, depending on the node we need for our tentacle
    3. while (spline.nodes.Count < tentaclePoints.Count) {
    4.     spline.AddNode(new SplineNode(Vector3.zero, Vector3.zero));
    5. }
    6. while (spline.nodes.Count > tentaclePoints.Count && spline.nodes.Count > 2) {
    7.     spline.RemoveNode(spline.nodes.Last());
    8. }
    9.  
    10. // we set the first node
    11. spline.nodes.First().Position = tentacleRootPosition;
    12.  
    13. // we set the other nodes. We can do this in the update method if the tentacle moves.
    14. int index = 1;
    15. foreach(var tentaclePoint in tentaclePoints){
    16.     spline.nodes[i].Position = tentaclePoint;
    17.     index++;
    18. }
     
  48. yodavid

    yodavid

    Joined:
    Dec 12, 2016
    Posts:
    25
    that code requires an object to be instantiated first, right?
     
  49. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    such a code goes into a new script, in the start and update methods. The same game object should hold a Spline component, which you get with GetComponent<Spline>(), and a AutoSmoother component if you wish to get automatic direction for your nodes.
     
  50. yodavid

    yodavid

    Joined:
    Dec 12, 2016
    Posts:
    25
    i'm getting all sorts of errors trying to implement it this way. you're trying to help, but this is not working.