Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guide to custom placing stuff on spline
#1
So while I love the curvy generator, I do think its a bit too heavy and complicated for what I ultimately wish to do. 

I just want to align walls along the spline, and I was hoping you could guide me on a simple way to get started doing this manually.

This is because I want control of the pooling and type of objects and performance is key. I also just think it'd be simpler if I could write my own.
Reply
#2
As far as I know, this extension is used for moving object along a spline. It can be used for spawning objects along the spline.

If You need something like building environment in real-time (gameplay) try
https://assetstore.unity.com/packages/templates/systems/easy-build-system-45394
or something similar.

Also there is this:
https://forum.unity.com/threads/wip-easy-to-use-and-simple-spline-tool.829602/
Reply
#3
(09-30-2023, 01:28 PM)velikizlivuk Wrote: As far as I know, this extension is used for moving object along a spline. It can be used for spawning objects along the spline.

If You need something like building environment in real-time (gameplay) try
https://assetstore.unity.com/packages/templates/systems/easy-build-system-45394
or something similar.

Also there is this:
https://forum.unity.com/threads/wip-easy-to-use-and-simple-spline-tool.829602/


Heya! I appreciate the links. I already have this asset so was hoping for a way to use this rather than just use another one.
Reply
#4
(09-30-2023, 07:54 AM)Lupos Wrote: So while I love the curvy generator, I do think its a bit too heavy and complicated for what I ultimately wish to do. 

I just want to align walls along the spline, and I was hoping you could guide me on a simple way to get started doing this manually.

This is because I want control of the pooling and type of objects and performance is key. I also just think it'd be simpler if I could write my own.

You can place objects without using Curvy Generators (CG for short). CG is a tool that makes object placement and other operations usable without coding, but nothing stops you from making your own code that will use Curvy Splines API to accomplish the same things as the CG, in your own way.

Placing objects is simple, just use CurvySpline.Interpolate, CurvySpline.GetTangent, and CurvySpline.GetOrientationFast to retrieve all the needed data from a spline, then use them to place a wall or any other object.

This explanation includes only placement. Mesh deformation or extrusion are another subject.

I hope this helped.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#5
Thank you! This def helped for sure, and I'll def be taking a look.

(10-02-2023, 08:13 PM)_Aka_ Wrote: This explanation includes only placement. Mesh deformation or extrusion are another subject.

This is something I'm interested which curvy generator doesn't handle for me. Having custom objects that also have there mesh deform. Keeping the objects behaviours while also deforming is something I'm trying to achieve. 

What would you suggest I do to handle this?
Reply
#6
You can deform objects that you place individually via Curvy Generator. The following video tutorial shows that in its first half. The second half is about deforming meshes that are placed automatically on a spline.
https://www.youtube.com/watch?v=eP6QEn9SFoM
Other than that, the mesh deforming code is public, and you can call it in your own code, for example a custom Curvy Generator module. The method is DeformMesh.DeformMeshes(...)
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#7
(10-05-2023, 02:07 PM)_Aka_ Wrote: You can deform objects that you place individually via Curvy Generator. The following video tutorial shows that in its first half. The second half is about deforming meshes that are placed automatically on a spline.
https://www.youtube.com/watch?v=eP6QEn9SFoM
Other than that, the mesh deforming code is public, and you can call it in your own code, for example a custom Curvy Generator module. The method is DeformMesh.DeformMeshes(...)

Sorry for the late response. I appreciate all your amazing help. 
The problem I'm having is that DeformMesh requires all sorts of parameters such as 

List<CGVMesh> inputMeshes,
            SubArray<CGSpot> inputSpots,
            SubArray<CGSpot> outputSpots,
            [NotNull] CGVMesh[] outputMeshes,
            [NotNull] CGPath path,
            bool stretchToEnd,
            ThreadPoolWorker<CGSpot> threadPoolWorker

its rather difficult to understand the steps needed to get all this data in my own custom setup. I was hoping you could provide me some steps to get this data.

From my understanding I need to rasterize the spline first, then generate volume spots for it from the game objects I plan to use as well convert the meshes from the gameobjects into CGVMeshes.


Where would you suggest I begin?


It's very overwhelming having to deal with the curvygenerator both from a coding perspective and from a editor/creator perspective.
I need rather specific control of my objects being generated along with them being able to curve and sadly curvygenerator doesn't offer me that.

For starters it seems have a 1 frame delay when refreshing things that seemingly breaks a lot of the editor code I'm trying to do at runtime. It also doesn't let me work with my own specfic custom types, I'm forced to inject my stuff on top after the objects refresh.

I've provided an example of the editor I'm trying to build. I was having way too much trouble getting the intersection code working with curvygenerator and was forced to write my own solution.



I currently generate the walls with this primitive solution

Code:
        private void GenerateWalls()
        {
            if (!IsSetup) return;
            if (spline == null) return;
            if (blockPool == null) return;

            var curvySpline = spline.CurvySpline;
            if (!curvySpline.IsInitialized) return;

            var blockIndex = 0;
            var splineDistance = spline.Distance;
            SplineSpawnSegment = Mathf.Max(splineDistance - 1, 0f);
            if (splineDistance <= 1f)
            {
                ReleaseExtraInstances(blockIndex);
                return;
            }


            BlockCount = Mathf.CeilToInt(SplineSpawnSegment);

            var emptyBlockSpace = (SplineSpawnSegment - BlockCount);

            var padding = emptyBlockSpace / 2f;
            var paddingOffset = padding / 2f;

            const float blockScale = 1f;
            var blockModifiedScale = blockScale + padding;

            var distanceOnSpline = blockScale;
            while (blockIndex < BlockCount)
            {
                var block = GetBlock(blockIndex);
                if (blockIndex == 0 || blockIndex == BlockCount - 1)
                {
                    var scale = block.LocalScale;
                    scale.z = blockModifiedScale;
                    block.LocalScale = scale;
                    distanceOnSpline += paddingOffset;

                    block.SetBoundJoint(blockIndex == 0 ? spline.GetFirstJoint() : spline.GetLastJoint());
                }
                else
                {
                    block.LocalScale = Vector3.one;
                    block.SetBoundJoint(null);
                }

                var tf = curvySpline.DistanceToTF(distanceOnSpline);
                var position = curvySpline.InterpolateFast(tf, Space.World);
                var rotation = curvySpline.GetTangentFast(tf, Space.World);
                block.CachedTransform.SetPositionAndRotation(position,
                    rotation != Vector3.zero ? Quaternion.LookRotation(rotation) : Quaternion.identity);

                distanceOnSpline += block.CachedTransform.localScale.z / 2f + blockScale / 2f;
                blockIndex++;
            }

I just want to know what steps I can take to help make the walls curve.
Reply
#8
Hi Lupos,
Sorry I haven't answered you yet. You should have an answer in the next 24h.
Thanks for your patience, and have a nice day.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#9
Hi again,

I see three scenarios to implement your editor:

A - Have your editor be just an UI that controls Curvy Generators (CGs for short) that do the actual work.
B - Do not use CGs, but use the relevant methods/code from the CG code. This implies that you will have to convert data from and to data formats used by the CG, such as CGSpot and SubArray<> (the later which exists to make CGs performant).
C- Do not use CGs, nor use its methods, but extract specific parts of its code, and modify it to be compatible with your data format.


I recommand scenario A, but you said you prefer to not follow this path for performance and simplicity reasons. My question is: Have you witnessed any significant performance issue? CG is not perfect, and sure has room for optimization, but a lot of work was done to make it performant, and supports frequent updates. If you witnessed any performance issue that makes you exclude scenario A, please let me know, so I can try to fix it.

Scenarios B gives you more freedom, but need way more work due to the data format conversion. By following this path, I feel like you will be swimming against the current, by trying to reproduce yourself what the CG does already.

Scenario C needs that you dig deep in the code, and understand it so that you know what code exactly you need to extract.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#10
(11-18-2023, 06:16 AM)Lupos Wrote: List<CGVMesh> inputMeshes,
            SubArray<CGSpot> inputSpots,
            SubArray<CGSpot> outputSpots,
            [NotNull] CGVMesh[] outputMeshes,
            [NotNull] CGPath path,
            bool stretchToEnd,
            ThreadPoolWorker<CGSpot> threadPoolWorker

its rather difficult to understand the steps needed to get all this data in my own custom setup. I was hoping you could provide me some steps to get this data.

From my understanding I need to rasterize the spline first, then generate volume spots for it from the game objects I plan to use as well convert the meshes from the gameobjects into CGVMeshes.


Where would you suggest I begin?

If you want to follow the path of scenario B, which I don't recommand, the parameters you listed are commented and have their types commented, but as a small summary:
  • CGVMesh  is the equivalent of Mesh
  • CGSpot  is the equivalent of Transform + an index of the object to use the transform on.
  • CGPath  has no equivalent in vanilla Unity, it's the list of points making a spline, result of its rasterization.
  • SubArray<> is part of an array. This class exists to be able to reuse arrays easily instead of creating/destroying them every time.
  • ThreadPoolWorker<> handles multi-threading.

To see how spots are created, check the InputSpots module.
To see how CGPath is created, check the InputSplinePath module.
To see how a CGVMesh is converted to a normal mesh, check the CreateMesh module, and especially the WriteVMeshToMesh method.

I hope this helped.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Method of scattering objects along spline joebain 1 3 11-26-2024, 03:20 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 5 13 10-29-2024, 10:19 AM
Last Post: _Aka_
  Mesh deform - baby guide jmh1804 7 11 08-22-2024, 07:18 AM
Last Post: _Aka_
  Nested Spline Volume Spot Instantiation merobbins5 3 7 07-26-2024, 09:58 AM
Last Post: _Aka_

Forum Jump: