Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Spline Mesher - Fences, pipes, path, roads and more!

Discussion in 'Assets and Asset Store' started by StaggartCreations, Mar 25, 2024.

  1. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Last edited: Apr 8, 2024
    fullerfusion and iDerp69 like this.
  2. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Asset is now live! A 50% launch discount will run until April 9th.



    This thread may be used for support, report issues and suggest improvements :)
     
    fullerfusion likes this.
  3. Concresence

    Concresence

    Joined:
    Feb 7, 2020
    Posts:
    1
    Hi, I'm testing Spline Mesher and so far its pretty good and it looks like it will work well for the road system I'm creating for my game. Its a minor issue but I did notice at one point the side mesh separated out from the road mesh. Not sure how that happened but I couldn't see a way to realign them automatically. If there is a way they can be realigned please let me know. Thanks Alexi
     
  4. shabadava

    shabadava

    Joined:
    Jul 31, 2019
    Posts:
    2
    does this work on unity 2021?
     
  5. launemax

    launemax

    Joined:
    Feb 14, 2013
    Posts:
    17
    Can the Spline be changed at Runtime or only in Editor?
     
  6. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Would you mind sharing a screenshot or two? I'm not sure what you mean by "side mesh", that being a mesh offset to the left/right of the spline?

    Not officially, it's not a version I'm developing or testing for. But I've imported it into a 2021 project and there's no compile errors, and all the functionality seems to work as it should!

    Splines aren't officially supported in 2021, so you can't install the package. It's possible to do this manually in the Package Manager by choosing "Add package by name" under the "+" icon:
    upload_2024-3-27_10-32-12.png

    All the functionality sits in runtime code, so that's certainly possible. If you were to programmatically alter a spline, one that's also assigned to a (or more) Spline Mesher component, the mesh updates as well.
     
    launemax likes this.
  7. moonNightElf

    moonNightElf

    Joined:
    Oct 23, 2022
    Posts:
    2
    Is it suitable for ancient city walls? For example, the Great Wall of China
     
  8. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    I don't see why not, a mesh is a mesh. Though you'd probably want to break it up into segments, rather than creating single a 21.000+ km spline :p
     
  9. tmryl

    tmryl

    Joined:
    Dec 25, 2018
    Posts:
    3
    Hello, are there any videos going through setup and use for some basic use cases like the ones in the demo scene?
     
  10. WaveParadigm

    WaveParadigm

    Joined:
    Feb 10, 2018
    Posts:
    7
    I love this!! Evaluating if we'll be able to move off of our current Spline solution onto this in Unity 2022. It has most of what I need (I LOVE the ability for it to intelligently cast down and mold itself to other collision!), with one exception: there are cases in our game where we need to know if our character is Overlapping a Spline.

    Since you can't just turn a mesh collider into a trigger without making it Convex, the way we accomplish this with our current tool is to use a variant of the mesher that actually spawns each individually deformed piece of the generated mesh as its own game object, with its own collider. Each of these, on its own, can be made a convex trigger collider, and they all report their collisions to their parent, which lets us know that the player is intersecting with the Spline.

    Is there any way to accomplish this with the tool as it exists? If not, would an option to spawn each segment of the Spline as its own game object be possible? I'm pretty sure this is our only barrier to adoption :D
     
  11. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Good point! Everything in the demo scene is indeed outlining a particular use case or feature, but I realize now that isn't obvious.

    What I'll do is add a piece of 3D text to each object with a short description to clarify.

    Awesome, glad to hear it!

    The ability to spawn a mesh in segments (individual Mesh Renderers) is something that's on the wishlist. It's particularly useful to divide up very large meshes (eg. a guard rail along a long road).

    Though spawning actual objects along a spline can already be achieved using the "Spline Instantiate" component. Here's an example of a cube prefab being repeated along the mesh:

    upload_2024-3-29_10-4-30.png

    You can access this component by importing the Samples from the Spline package :)
    upload_2024-3-29_10-3-27.png
     
  12. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    If this asset proved to be beneficial please do consider leaving a review, this in an invaluable way to support future development and helps make complementary updates possible! :)
     
  13. WaveParadigm

    WaveParadigm

    Joined:
    Feb 10, 2018
    Posts:
    7
    I've continued work on integrating Spline Mesher - things have gone reasonably well, but I've run into some more QOL challenges or actual blockers:

    1. I'm encountering a rather frustrating issue with a Water Spline setup I've created where, once I turn it into a Prefab (so that I can make waterways throughout my levels), if I draw a spline and then run the game, then exit the game, and then ever touch the Spline again, the entire mesh vanishes and I get hit with constant
    Code (CSharp):
    1. [Physics.PhysX] cleaning the mesh failed
    2. 0x000001b3f70f9193 (Mono JIT Code) sc.modeling.splines.runtime.SplineMesher:CreateCollider () (at D:/Development/Unity/ProjectName/Assets/SplineMesher/Runtime/SplineMesher.cs:234)
    3. 0x000001b3f70f4613 (Mono JIT Code) sc.modeling.splines.runtime.SplineMesher:Rebuild () (at D:/Development/Unity/ProjectName/Assets/SplineMesher/Runtime/SplineMesher.cs:188)
    The entire thing permanently locks up and I become unable to do anything with it until I destroy it and place a new one. Performing identical steps with an un-prefab'd version of the same object results in no issue, as far as I can tell, but I'd very much like to use Prefabs. I've been unable to lock down an exact repro for this (it always happens to the actual asset I've made, but attempts to start from scratch and to narrow down what precisely is causing the issue is not yielding results. Maybe it's something to do with the precise models I'm using? I've attached them.)

    2. Because I use multiple SplineMeshers that all reference the same base Spline, the Scaling feature becomes borderline unusable - since scale data is on a per-SplineMesher basis, and multi-selecting each SplineMesher and trying to use the Scale tool doesn't work the way you'd expect, and there doesn't seem to be a way to copy/paste scale data from SplineMesher to SplineMesher, you end up needing to manually do your best to make all of the different meshes line up with regards to Scale, which seems extremely difficult if not impossible. Certainly not a smooth workflow.

    3. And, the previously aforementioned inability to spawn submeshes - while the Spline Instantiate method is working at a baseline (thank you for the suggestion!) it also renders the idea of using the SplineMesher's scale mesh functions moot, since you can't scale the instances to match at various points along the spline.

    Unfortunately I'm not yet at a point where I'm confident to integrate this tool - in spite of how nice it is to get started with. Any suggestions on the above?
     

    Attached Files:

  14. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Valuable insights! :)

    The error you're getting directs at the point where the collision-mesh is assigned to the Mesh Collider. Internally, it gets post-processed by the physics engine, but I take whatever it was receiving is invalid. Something happened that causes an invalid mesh to be created (nothing caught by existing safety checks). I can only reproduce the same error by manually setting all the scale data to (0,0,0), which causes a mesh to be created with all vertices bunched up on the same point, creating degenerate triangles. So I assume it's related to that. Your meshes certainly look in order!

    On that note: I'll be sure to implement a safety check in the Scale tool, to check for such invalid scale data, and reset them. Scale data is normally added automatically, to ensure that is exists for every spline. But I can imagine it's possible to unintentionally circumvent this.

    A useful debugging option is to reset the scale data through the context menu:
    upload_2024-4-1_14-42-23.png

    About the scale, I can see how it may be difficult to work with if you're looking to make compound geometry. Adding support for multi-selection editing to the tool is rather straightforward fortunately, yet definitely something that hadn't occurred to me.

    There's a simple auxiliary component that can be made to copy the scale data from one component to another. See this script.

    For the box colliders, example components are often useful, but specific functionality does require specific code. The easiest way I think is a post-processing script can go over all the collider objects and scale them using the scale data. Here's an example component that does this.

    Splines are very extendible so I want to encourage people to create addons tailored to their specific needs. With use case reaching far and wide tools would blow in complexity trying to cater to them all. I've extended the documentation with a "Scripting" section, and linked a couple of example code snippets that hopefully prove useful.

    Thank you for your feedback so far!
     
    WaveParadigm likes this.
  15. WaveParadigm

    WaveParadigm

    Joined:
    Feb 10, 2018
    Posts:
    7
    Thank you so much for your reply! Your guidance was extremely helpful.

    I was able to add some code that forwards the scale of one SplineMesher to all the rest, and it did the job nicely!

    Your tip about Reset Scale helped me pin down the issue with my one prefab. I think in the process of turning it into a Prefab, some bad ScaleData had made its way into the Components. Everything worked fine upon first placement but upon entering and exiting play mode, that bad ScaleData ultimately broke something. I seem to have been able to re-Prefab the object with properly cleared ScaleData, and the issue has gone away.

    Next up is getting the collider scaling working and I should be good to go! Happy to have given 5 stars already. :D
     
  16. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Pleased to say that Spline Mesher is proving to be a coveted tool on people's belt! It shot straight up to the top 5 assets on the store.

    I've finished a sizeable update, based on feedback and more extensive testing, which will be available shortly.

    The "Scripting" section of the documentation now has a link to several helper/example scripts.

    Two particularly useful components are the "Attach Transform To Spline" and "Spline Junction" components. Which can be used to aid in road systems, or attaching a separate mesh to the start/end of a spline. This sort of functionality seems to be requested, but it is something I am hesitant to include or facilitate in this asset's scope, as they revolve around creative use of the Splines API specifically, not mesh generation.

    1.1.0

    Added:
    - Demo scene, text description to each object explaining what is being achieved.
    - Inspector UI enhancements.
    - Option to regenerate the mesh on Start(), required when prefabbing procedural meshes.

    Changed:
    - Component no longer targets a Mesh Filter reference directly, now an output GameObject may be specified (automatically upgrades).
    - Improved mesh generation performance by 120-300%.
    - C#, static rebuilding events are now regular 'Action' delegates.
    - Scale tool now validates data points and resets them if a scale of 0 was found.
    - Scale tool now supports multi-selection editing.
    - A Spline Mesher component no longer requires 2 default scale data points. If no scale data is found, a default scale is assumed.

    Fixed:
    - Issue with geometry not generating for multiple splines if it uses more than 1 material.
    - Vertex normals not being accurately rotated if the deformation scale was negative.
    - Vertices at the very start/end of the spline possibly being deformed.
    - Using a Box-shape collider with +1 subdivisions no longer shifts the collider when using the "Spacing" parameter.
    - Mesh rotation not taking effect for a custom collider input mesh.

    Example of the new inspector UI:
    sm_component.jpg
     
    Last edited: Apr 5, 2024
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
  18. moonNightElf

    moonNightElf

    Joined:
    Oct 23, 2022
    Posts:
    2
    I want to use it with the Easy Build System to allow players to create roads, rivers, bridges, and city walls. Can the two be compatible?
     
  19. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Based on the videos, possibly. I think the first question you'd need answered is if it can create splines using its interaction system.

    The game Farm Folks recently implemented something similar using Spline Mesher, so by all means it is possible :)
     
  20. LukasSacher

    LukasSacher

    Joined:
    May 2, 2019
    Posts:
    16
    Hey, first of all, thanks for providing the community with amazing assets! I find myself using more and more of them.
    I'm using this to spawn obstacles that match my terrain shape.

    Is there a feature to have start/end meshes?
    Imagine a bridge with start and end segments that provide ramps for the player to walk up or down the bridge.
     
  21. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Glad to hear it's proving useful!

    You can use this Attach Transform To Spline component to attach separate meshes/prefabs to the start/end of a spline. https://gyazo.com/a574e2fb348697445df2e857a4a13f29
     
  22. LukasSacher

    LukasSacher

    Joined:
    May 2, 2019
    Posts:
    16
    Thanks for pointing me to there. I will try it and let you know how it went.
     
  23. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Version 1.1.1 is now available! This mainly focuses on some quality-of-life improvements, such as quick access to options for creating a new spline mesh.

    Added:
    - Rebuild Trigger flags, sets which sort of events cause the mesh to be regenerated.
    upload_2024-4-29_17-7-43.png
    - Public C# function to create a spline from an array of positions (CreateSplineFromPoints).
    - Added a context menu option to the Spline Container component to quickly set up a default Spline Mesher.
    - Option under GameObject/3D Object to create a new spline mesh.

    Changed:
    - QOL: Whenever the component needs to adds MeshFilter to the output object, it will also add a Mesh Renderer component if needed.
    - Extra failsafes when importing into versions older than Unity 2022.3 without the Splines package installed.
    - Context menu functions have been moved to a new Gear button in the inspector
    - Sections in the inspector now behave as an accordion, expanding one closes all others.

    Removed:
    - Deprecated the "Rebuild on Start()" option (replaced by Rebuild Triggers flags).
     
    LukasSacher likes this.
  24. Funtyx

    Funtyx

    Joined:
    May 3, 2017
    Posts:
    39
    Please tell me if it is possible to add a prefab as a source. You don't always need a generated mesh. Sometimes you need to make a fence from prefab with lod. Spline Instatiate can work with prefab. Please add this function.
     
  25. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    You already seem familiar with the Spline Instantiate component, I would recommend using that, as it does exactly what you're describing.
     
  26. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,289
    Pleased to announce that I've opened a Discord server. It will serve as a centralized place to find announcements, discussions and support/feature request forums. Though Unity threads, such as this one, will still be monitored. And documentation will remain up to date. Moving forward, my attention will be focused on the server, in order to streamline continued support :)



    - Join -
    In order to access support channels and feature requests, your invoice number is required. You can find this on your Order History page.