Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Noob Question
#1
So, this is probably the easiest thing ever, but I can't seem to figure it out.
I'm trying to make some code that'll connect 2 objects together with a noodle, like in all the node editors.
Here's my code so far:
Code:
using UnityEngine;
using FluffyUnderware.Curvy;


namespace Connections {
public class Connection : MonoBehaviour {
        private CurvySpline myspline;
        public void SetPosition(Vector2 start, Vector2 end) {
            if (!myspline) myspline = CurvySpline.Create();
            myspline.Clear();
            myspline.Add(
                start,
                new Vector3(start.x + ((end.x - start.x) * (float)0.2), start.y, 0),
                new Vector3(end.x + ((start.x - end.x) * (float)0.2), end.y, 0),
                end);
            myspline.Refresh();
        }
    }
}


This works, and I can see the splines appear in the editor.
I can't figure out how to take my new spline and build a mesh around it with code.
I know how to add the mesh in the editor, but I need this to be pure code that updates and changes constantly during runtime.

My question is:
What code do I need to add to this to give it a mesh?
Reply
#2
Hi
You need to do the via the API the equivalent of the needed steps via editor, which is to add setup a Curvy Generator that does a shape extrusion. You can find an example of such code in InfiniteTrack, a class used in the InfiniteTrack example scene. Look for its method called buildGenerator.
Does this answer your question?
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
An example should be perfect. Thanks, @_Aka_.
I looked at a few examples, but couldn't find the one that did it with code.
Reply
#4
(09-03-2021, 07:06 PM)Wyldhunt Wrote: An example should be perfect. Thanks, @_Aka_.
I looked at a few examples, but couldn't find the one that did it with code.

I copied the content of said method here:
Code:
            // Create the Curvy Generator
            CurvyGenerator gen = CurvyGenerator.Create();
            gen.AutoRefresh = false;
            // Create Modules
            InputSplinePath path = gen.AddModule<InputSplinePath>();
            InputSplineShape shape = gen.AddModule<InputSplineShape>();
            BuildShapeExtrusion extrude = gen.AddModule<BuildShapeExtrusion>();
            BuildVolumeMesh vol = gen.AddModule<BuildVolumeMesh>();
            CreateMesh msh = gen.AddModule<CreateMesh>();
            // Create Links between modules
            path.OutputByName["Path"].LinkTo(extrude.InputByName["Path"]);
            shape.OutputByName["Shape"].LinkTo(extrude.InputByName["Cross"]);
            extrude.OutputByName["Volume"].LinkTo(vol.InputByName["Volume"]);
            vol.OutputByName["VMesh"].LinkTo(msh.InputByName["VMesh"]);
            // Set module properties
            path.Spline = TrackSpline;
            path.UseCache = true;
            CSRectangle rectShape = shape.SetManagedShape<CSRectangle>();
            rectShape.Width = 20;
            rectShape.Height = 2;
            extrude.Optimize = false;
#pragma warning disable 618
            extrude.CrossHardEdges = true;
#pragma warning restore 618
            vol.Split = false;
            vol.SetMaterial(0, RoadMaterial);
            vol.MaterialSetttings[0].SwapUV = true;

            msh.Collider = CGColliderEnum.None;
            return gen;
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
Works great. Thanks!
Reply
#6
Glad to hear that. If and when you feel like it, please leave a review for the asset, that helps a lot
Have a nice weekend
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie Question: Uniformly increase spacing between volume spots? SAMYTHEBIGJUICY 1 5 09-01-2023, 03:38 PM
Last Post: _Aka_
  I have a question about curvySpline haifeng.huang 12 32 07-14-2023, 09:34 AM
Last Post: _Aka_
  Question about generator Mos Def 7 1,807 04-10-2023, 10:20 PM
Last Post: _Aka_
Question Connection Question dazz777 1 121 11-22-2021, 01:42 PM
Last Post: _Aka_

Forum Jump: