02-20-2020, 01:09 AM
The second issue was because of a lack to the generator's Initialize method. So here the whole modified code
Code:
using UnityEngine;
using FluffyUnderware.Curvy;
using FluffyUnderware.Curvy.Generator.Modules;
using FluffyUnderware.Curvy.Generator;
using FluffyUnderware.Curvy.Shapes;
public class CurvyTest : MonoBehaviour
{
[ContextMenu("Test")]
public void Test()
{
// Create the generator and required build components
CurvyGenerator generator = CurvyGenerator.Create();
generator.AutoRefresh = false;
InputSplinePath wirePath = generator.AddModule<InputSplinePath>();
InputSplinePath crossPath = generator.AddModule<InputSplinePath>();
BuildShapeExtrusion buildShapeExtrusion = generator.AddModule<BuildShapeExtrusion>();
BuildVolumeMesh buildVolumeMesh = generator.AddModule<BuildVolumeMesh>();
CreateMesh createMesh = generator.AddModule<CreateMesh>();
// Create inputs to generator components
// Create the wire spline
CurvySpline wireSpline = CurvySpline.Create();
CurvySplineSegment controlPoint1 = wireSpline.Add();
controlPoint1.gameObject.transform.localPosition = new Vector3(0, 0, 0);
CurvySplineSegment controlPoint2 = wireSpline.Add();
controlPoint2.gameObject.transform.localPosition = new Vector3(0, 1, 0);
CurvySplineSegment controlPoint3 = wireSpline.Add();
controlPoint3.gameObject.transform.localPosition = new Vector3(1, 1, 0);
CurvySplineSegment controlPoint4 = wireSpline.Add();
controlPoint4.gameObject.transform.localPosition = new Vector3(1, 2, 0);
CurvySplineSegment controlPoint5 = wireSpline.Add();
controlPoint5.gameObject.transform.localPosition = new Vector3(1, 2, 1);
// Create the circle cross section
CurvySpline crossSpline = CurvySpline.Create();
CSCircle circle = crossSpline.gameObject.AddComponent(typeof(CSCircle)) as CSCircle;
circle.Radius = 0.005f;
circle.Count = 10;
circle.Refresh();
crossSpline.Refresh();
crossSpline.MaxPointsPerUnit = 10 / crossSpline.Length;
crossSpline.Refresh();
// Link the splines to the shape extruder
wirePath.Spline = wireSpline;
crossPath.Spline = crossSpline;
CGModuleInputSlot pathInput = buildShapeExtrusion.GetInputSlot("Path");
CGModuleInputSlot crossInput = buildShapeExtrusion.GetInputSlot("Cross");
CGModuleOutputSlot pathOutput = wirePath.GetOutputSlot("Path");
CGModuleOutputSlot crossOutput = crossPath.GetOutputSlot("Path");
pathInput.LinkTo(pathOutput);
crossInput.LinkTo(crossOutput);
// Set shape extruder parameters
buildShapeExtrusion.Resolution = 100;
buildShapeExtrusion.CrossResolution = 100;
// Link the mesh and mesh generator
CGModuleInputSlot volumeInput = buildVolumeMesh.GetInputSlot("Volume");
CGModuleOutputSlot volumeOutput = buildShapeExtrusion.GetOutputSlot("Volume");
volumeInput.LinkTo(volumeOutput);
CGModuleInputSlot meshInput = createMesh.GetInputSlot("VMesh");
CGModuleOutputSlot meshOutput = buildVolumeMesh.GetOutputSlot("VMesh");
meshInput.LinkTo(meshOutput);
// Save the mesh and destroy the components used to make it
generator.Initialize();
GameObject mesh = createMesh.SaveToScene(null);
Debug.Log(mesh);
}
public void Start()
{
Test();
}
}
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.