Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable Mix Shape Interpolation Not Spanning Entire Input Spine
#3
I apologize, I can't send the scene, but I can send the code used to generate / reproduce this issue:

I have two custom shape classes
Code:
using FluffyUnderware.Curvy;
using UnityEngine;

namespace CustomShapes {
  [CurvyShapeInfo("Custom/ShapeA")]
  [RequireComponent(typeof(CurvySpline))]
  [AddComponentMenu("Custom/ShapeA")]
  public class ShapeA : CurvyShape2D {

#if UNITY_EDITOR
    protected override void OnValidate() {
      base.OnValidate();
    }
#endif

    protected override void Reset() {
      base.Reset();
    }

    protected Vector3[] ControlPoints() {
      Vector3[] crossPoints = new Vector3[] {
        new Vector3(-0.254f, 0.0127f / 2f + 0.01f, 0),
        new Vector3(-0.05159375f, 0.0127f / 2f, 0),
        new Vector3(0.05159375f, 0.0127f / 2f, 0),
        new Vector3(0.254f, 0.0127f / 2f + 0.01f, 0),
        new Vector3(0.254f, -0.0127f / 2f + 0.01f, 0),
        new Vector3(0.05159375f, -0.0127f / 2f, 0 ),
        new Vector3(-0.05159375f, -0.0127f / 2f, 0),
        new Vector3(-0.254f, -0.0127f / 2f + 0.01f, 0)
      };
      return crossPoints;
    }

    protected override void ApplyShape() {
      base.ApplyShape();
      Vector3[] controlPoints = ControlPoints();
      PrepareSpline(CurvyInterpolation.Linear, CurvyOrientation.Dynamic);
      PrepareControlPoints(controlPoints.Length);
      for (int i = 0; i < controlPoints.Length; i++) {
        Spline.ControlPointsList[i].transform.localPosition = controlPoints[i];
      }
    }
  }
}

Code:
using FluffyUnderware.Curvy;
using UnityEngine;

namespace CustomShapes {
  [CurvyShapeInfo("Custom/ShapeB")]
  [RequireComponent(typeof(CurvySpline))]
  [AddComponentMenu("Custom/ShapeB")]
  public class ShapeB : CurvyShape2D {

#if UNITY_EDITOR
    protected override void OnValidate() {
      base.OnValidate();
    }
#endif

    protected override void Reset() {
      base.Reset();
    }

    protected Vector3[] ControlPoints() {
      Vector3[] crossPoints = new Vector3[] {
        new Vector3(-0.254f, 0.0127f / 2f, 0),
        new Vector3(-0.05159375f, 0.0127f / 2f, 0),
        new Vector3(0.05159375f, 0.0127f / 2f, 0),
        new Vector3(0.254f, 0.0127f / 2f, 0),
        new Vector3(0.254f, -0.0127f / 2f, 0),
        new Vector3(0.05159375f, -0.0127f / 2f, 0 ),
        new Vector3(-0.05159375f, -0.0127f / 2f, 0),
        new Vector3(-0.254f, -0.0127f / 2f, 0)
      };
      return crossPoints;
    }

    protected override void ApplyShape() {
      base.ApplyShape();
      Vector3[] controlPoints = ControlPoints();
      PrepareSpline(CurvyInterpolation.Linear, CurvyOrientation.Dynamic);
      PrepareControlPoints(controlPoints.Length);
      for (int i = 0; i < controlPoints.Length; i++) {
        Spline.ControlPointsList[i].transform.localPosition = controlPoints[i];
      }
    }
  }
}

And a function that creates the whole thing:
Code:
public void GenerateVolume() {
    GameObject parent = new GameObject("Parent");
    parent.transform.localPosition = Vector3.zero;

    GameObject splineObject = new GameObject("Spline");
    splineObject.transform.parent = parent.transform;
    splineObject.transform.localPosition = Vector3.zero;

    GameObject shapeAObject = new GameObject("ShapeA");
    shapeAObject.transform.parent = parent.transform;
    shapeAObject.transform.localPosition = Vector3.up * 0.1f;

    GameObject shapeBObject = new GameObject("ShapeB");
    shapeBObject.transform.parent = parent.transform;
    shapeBObject.transform.localPosition = Vector3.up * 0.2f;

    CurvySpline spline = splineObject.AddComponent<CurvySpline>();
    Vector3[] splinePoints = new Vector3[] {
      new Vector3(-0.508f, 0, 0),
      new Vector3(0.508f, 0, 0)
    };
    spline.Add(splinePoints);

    CustomShapes.ShapeA shapeA = shapeAObject.AddComponent<CustomShapes.ShapeA>();
    CustomShapes.ShapeB shapeB = shapeBObject.AddComponent<CustomShapes.ShapeB>();

    CurvyGenerator generator = parent.AddComponent<CurvyGenerator>();
    generator.ShowDebug = true;
    generator.AutoRefresh = true;

    InputSplinePath inputSplinePath = generator.AddModule<InputSplinePath>();
    InputSplineShape inputSplineShapeA = generator.AddModule<InputSplineShape>();
    InputSplineShape inputSplineShapeB = generator.AddModule<InputSplineShape>();
    ModifierVariableMixShapes mixShape = generator.AddModule<ModifierVariableMixShapes>();
    BuildShapeExtrusion shapeExtrusion = generator.AddModule<BuildShapeExtrusion>();
    BuildVolumeMesh volumeMesh = generator.AddModule<BuildVolumeMesh>();
    CreateMesh createMesh = generator.AddModule<CreateMesh>();

    shapeExtrusion.CrossIncludeControlPoints = true;
    shapeExtrusion.CrossResolution = 100;
    shapeExtrusion.Resolution = 100;
    shapeExtrusion.Optimize = false;
    shapeExtrusion.CrossOptimize = false;

    Keyframe[] keys = new Keyframe[4];

    keys[0] = new Keyframe(0, 1);
    keys[0].inTangent = 0f;
    keys[0].outTangent = 0f;

    keys[1] = new Keyframe(0.2f, -1);
    keys[1].inTangent = 0f;
    keys[1].outTangent = 0f;

    keys[2] = new Keyframe(0.8f, -1);
    keys[2].inTangent = 0f;
    keys[2].outTangent = 0f;

    keys[3] = new Keyframe(1, 1);
    keys[3].inTangent = 0f;
    keys[3].outTangent = 0f;

    AnimationCurve animationCurve = new AnimationCurve(keys);
    mixShape.MixCurve = animationCurve;

    inputSplinePath.Spline = spline;
    inputSplinePath.Path.LinkTo(shapeExtrusion.InPath);

    inputSplineShapeA.Shape = shapeA.Spline;
    inputSplineShapeB.Shape = shapeB.Spline;

    inputSplineShapeA.OutShape.LinkTo(mixShape.InShapeA);
    inputSplineShapeB.OutShape.LinkTo(mixShape.InShapeB);
    mixShape.OutShape.LinkTo(shapeExtrusion.InCross);
    shapeExtrusion.OutVolume.LinkTo(volumeMesh.InVolume);
    volumeMesh.OutVMesh.LinkTo(createMesh.InVMeshArray);
  }

It's worth noting that changing the Path Range on the Shape Extrusion module to something like 0.98 can get it pretty close. But I suspect that's not a fix all and will require eyeballing by hand for every scenario (which won't work for me).
Reply


Messages In This Thread
RE: Variable Mix Shape Interpolation Not Spanning Entire Input Spine - by Diasporism - 04-20-2021, 02:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy discards Input Spline Range VoltDriver 3 5 11-28-2023, 07:14 PM
Last Post: _Aka_
  "MetaData" Of Entire Spline Heightmap SAMYTHEBIGJUICY 3 6 10-16-2023, 08:42 AM
Last Post: _Aka_
  Skip Input Mesh if spline has too much bend Zilk1 3 9 09-27-2023, 09:45 PM
Last Post: _Aka_
  I want to improve the performance of Variable Mix Shapes yanke 7 8 07-27-2023, 09:15 PM
Last Post: _Aka_

Forum Jump: