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
Question question about the local position brucezhu99 4 78 09-18-2021, 12:02 PM
Last Post: _Aka_
  Question about generator Mos Def 6 1,286 02-12-2021, 08:25 AM
Last Post: _Aka_
  2D Terrain Question monotonic 5 1,512 01-01-2021, 07:32 AM
Last Post: _Aka_
  Pre-Purchase question discofever 1 642 11-03-2020, 12:15 PM
Last Post: _Aka_

Forum Jump: