Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best practice for mass-object instancing along 100km spline (railways) plus streaming
#1
Hello there,

I'd like to find out if there is a good way to use Curvy for instancing of objects along very long splines (100km+) in combination with World Streamer.

In our current workflow we are creating railway sleepers in an external 3D Suite and import the instanced geometry via .fbx export/import in chunks of 50.000 objects per import. This process takes forever and the result is very hard on the applications performance.

One of our team mebers has been using Curvy for this in the past but the cooking times were not handleable anymore at some point. So I'd like to give it a chance again with a best practise.

- can someone please give hints on how to realise a performant way to create geometry instances every 60cm on a 100km Spline with curvy?
- would it be possible to use GPU instancing or other methods to increase performance?
- is there a limitation for the number of control points? The raw data that I'm getting are linear splines with CPs every 2m in dxf format. When reducing the number of CPs, precision has to stay within a few cm.


There are areas where I have up to 16 lanes each with sleepers every 60cm for kilometers. It is very dense geometry and the draw calls are just insane (30-60k with all the other stuff). But this is a secondary issue. First up I'd like to improve on the geometry creation process which currently takes days due to export/import workflows.

Greetz, Bodo
Reply
#2
Hi,
There are a lot of trails that I need to follow to give you a complete answer. I will for now answer just partially, and will try to enrich my answer as soon as I test more things.
I am assuming that you are instancing the objects via the Curvy generator (CG for short), using the Volume Spots module.

1- how much time does it take for you to generate the 50 000 object via Curvy. I tried with cubes, and it took few seconds, but I guess in your case it takes a lot more.

2- Each one of those thousands of objects gets renamed by Curvy Generator, to make it easier to work with them. You might want to skip that renaming step. It will save you CPU time and memory. Go to CGModule.AddManagedResource, and comment the RenameResource method call.

3- Are you working with prefabs? When instancing prefabs using CG, that prefab link gets broken. This is something that I will fix in the next update. A user told me that keeping that prefab link should speed up the instanciation process. I haven't tested this yet.

4- the Curvy Generator is here to make things easier to work with. That ease of use comes with CPU overhead. If you want are willing to sacrifice the ease of work, just create your own script that will sample points on the spline and place objects on them. If you don't know where to start with this let me know.

5- About GPU instancing, I had a discussion with a user in Unity's forum about this. Please read the posts starting from this one: https://forum.unity.com/threads/released...st-4157050

6- The is no limitation on the number of Control Points

Please let me know if you have any other questions.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
Hey,

thanks for the quick response! The person responsible for the curvy integration is not available anymore for our team and I want to find out, if Curvy could be an alternative for our current workflow, which I described earlier. Since I do not have any knowledge about Curvy or the Curvy generator system, I would like to find out what possible limitations are before diving into the tools. I do have some years of experience with Houdini and am not entirely new to procedural content creation. So I think I will understand what you are saying.

I got informed that curvy had been used here for example for mass-instancing of railway sleepers along splines but that it got too slow to work with at certain spline lengths that we are dealing with.

1- the sleepers have <300 triangles for LOD0 and <100 for LOD1. I don't know how long the build times get when 200.000 of those objects have to be cooked along a 115.000m long spline. But that's basically an anwer I'd like to get..

2- Great, there's potential for cooking time optimization

3- Yes, we make use of LOD prefabs. Do you have a roadmap for upcoming development of curvy?

4- perhaps that would be an option. I imagine to do many more things with curvy later - for example include cooking of large parts of the railway system. But for now, quickly placing those sleeper is my first goal.

5- read it. So it's a shader thing and I need to find out if -once the sleepers are instanced/placed- I could perhaps assign the GPU Instancer to the prefab and let this take care of the insane amount of draw calls.

6- this is an entirely different topic. We get the input splines as .dxf files, attach dummy objects to each point on the curve, export those objects as fbx files, put those points into a curvy spline container, where they get named and re-create the spline. Is there a better way? It expects JSON, right?

Best, Bodo
Reply
#4
Hi,
1- With 300 poly objects, it took 15s to instantiate 100.000 one, and 35s to instantiate 200.000
3- Sorry, I have no public roadmap. But the next update is already submitted to the Asset store. It should take few days to be validated. It has in it the modification I spoke about.
4- quickly placing the sleepers can be done with a custom script. I will try to make one this weekend.
6- The import functionality of Curvy expects JSON file. You can also create a script that takes as inputs the dummy objects, and fills a spline with control points at the dummy objects' positions using the API. Let me know if you need more help regarding this.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
4- I ended up writing that custom script. It took 2.5s to instantiate the 200.000 seconds. The script is very minimalistic. Any customization should be done via code. It instanciates the objects at every cache point of the spline. Here it is:

Code:
using FluffyUnderware.Curvy;
using UnityEngine;

public class TTT : MonoBehaviour
{
   public GameObject GameObject;
   public CurvySpline Spline;

   void Start()
   {
       //int count = 0;
       for (int segmentIndex = 0; segmentIndex < Spline.Count; segmentIndex++)
       {
           var segment = Spline[segmentIndex];
           for (var cachePointIndex = 0; cachePointIndex < segment.Approximation.Length; cachePointIndex++)
           {              
                GameObject.Instantiate(GameObject, segment.Approximation[cachePointIndex], Quaternion.LookRotation(segment.ApproximationT[cachePointIndex]));

               //count++;
           }
       }
       //Debug.Log(count);

   }
}

The code executes at Start for my test purpose. Feel free to make it execute elsewhere
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
Hello there,

first up thank you very much for the clarification and script example! We are now trying to adjust the instanciation script in a way that it places the instances at the same location as the spline points -currently they start at 0,0,0 world coordinates.

Next to that we are thinking about how to automize the spline creation. Our base data is typically a long linear spline < with points every 2m. Currently we are resampling it to 60cm (sleeper distance), spawn cubes at every point, delete the spline and export those cubes as .fbx - In Unity the inverse process takes place: taking cubes out of the fbx prefab into a scene, putting them into a curvySpline container > curvySpline > use the instanciation script to spawn sleepers.

Is this the optimal workflow or could we do the resampling in curvy (going down from 2m point distance to 60cm for the instancing)?

Attached is a typical .fbx file with cubes at resampled spline point positions. How would you produce the curvySpline from that file?

Personally I'd prefer to take out all those in-between steps: find a tool that takes the georeferenced .dxf AutoCAD files and converts the spline in there into JSON format for direct curvy input. So far I haveen't found anything that can do this yet.

Best regards,
Bodo


Attached Files
.zip   ICE-Spline.zip (Size: 1.86 MB / Downloads: 1)
Reply
#7
(09-13-2019, 12:12 PM)bs@vectorvision.de Wrote: first up thank you very much for the clarification and script example!
You are welcome

(09-13-2019, 12:12 PM)bs@vectorvision.de Wrote: We are now trying to adjust the instanciation script in a way that it places the instances at the same location as the spline points -currently they start at 0,0,0 world coordinates.
Just convert the positions from the spline's local space to the global space, using the spline's transform method TransformPoint

(09-13-2019, 12:12 PM)bs@vectorvision.de Wrote: Personally I'd prefer to take out all those in-between steps: find a tool that takes the georeferenced .dxf AutoCAD files and converts the spline in there into JSON format for direct curvy input. So far I haveen't found anything that can do this yet.
I must admit that I am a complete noob when it comes to the software and formats you are referencing. You will probably not find a ready made tool, but (assuming a prior knowledge of the dxf format and/or scripting inside AutoCAD) making the converting script should be easy, especially that your splines are linear (no Bezier handles to carry about)
Here is an example of a linear spline with 3 CPs
Code:
{
   "Array": [
       {
           "Name": "Curvy Spline",
           "Interpolation": 0,
           "ControlPoints": [
               {
                   "Position": {
                       "x": -6.764999866485596,
                       "y": 46.47700119018555,
                       "z": 8.006999969482422
                   }
               },
               {
                   "Position": {
                       "x": 2.3410000801086427,
                       "y": 46.47700119018555,
                       "z": 19.66699981689453
                   }
               },
               {
                   "Position": {
                       "x": 9.489999771118164,
                       "y": 46.47700119018555,
                       "z": 13.96500015258789
                   }
               }
           ]
       }
   ]
}


(09-13-2019, 12:12 PM)bs@vectorvision.de Wrote: Is this the optimal workflow or could we do the resampling in curvy (going down from 2m point distance to 60cm for the instancing)?
You can define the sampling distance in Curvy. Please read this: https://curvyeditor.com/documentation/sp...ple_points
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
(09-13-2019, 12:30 PM)_Aka_ Wrote:
(09-13-2019, 12:12 PM)bs@vectorvision.de Wrote: We are now trying to adjust the instanciation script in a way that it places the instances at the same location as the spline points -currently they start at 0,0,0 world coordinates.
Just convert the positions from the spline's local space to the global space, using the spline's transform method TransformPoint

We tried this. The problem is that the instances always take over the position of the spline control points and a transformation of the spline itself does not provide a solution. My question therefore is: How can the control points be transformed into the global coordinate system?
Reply
#9
Where deos the problem happen? Is the imported spline wrong, or is the objects created along the spline wrong? If it is the later, try this (in the loop of the script I send you):

GameObject.Instantiate(GameObject, Spline.transform.TransformPosition(segment.Approximation[cachePointIndex], Quaternion.LookRotation(Spline.transform.TransformPosition(segment.ApproximationT[cachePointIndex])));

It should work. If not, please send me a simple example project so I can see what is wrong
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#10
(09-18-2019, 06:48 PM)_Aka_ Wrote: Where deos the problem happen? Is the imported spline wrong, or is the objects created along the spline wrong? If it is the later, try this (in the loop of the script I send you):

GameObject.Instantiate(GameObject, Spline.transform.TransformPosition(segment.Approximation[cachePointIndex], Quaternion.LookRotation(Spline.transform.TransformPosition(segment.ApproximationT[cachePointIndex])));

It should work. If not, please send me a simple example project so I can see what is wrong

Unfortunately it doesn't work. Here ist a little Unity project for you to understand the problem.

https://we.tl/t-WDsXdhP1WZ
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Refresh spline doesn't seem to be working dazz777 2 41 11-08-2019, 09:01 PM
Last Post: dazz777
  Same Spline Extrusion with variable width MarioBag 5 631 11-04-2019, 01:56 PM
Last Post: _Aka_
  Change curvy gizmos to show direction of spline Horibe 1 39 11-01-2019, 07:02 PM
Last Post: _Aka_
  Deform mesh on the spline Nico_CL 3 160 10-09-2019, 04:10 PM
Last Post: _Aka_

Forum Jump: