/// <summary> /// Returns the fader level for a specific Bezier-curve parameter /// </summary> /// <param name="u">The curve parameter</param> /// <param name="i">the index of the control point in check</param> /// <param name="cptsNum">The number of control points</param> /// <returns>Float</returns> public static float FaderBezier(float u, int i, int cptsNum) { int n = cptsNum - 1; float faderLvl = Mathf.Pow(u, i) * Mathf.Pow(1 - u, n - i) * NurbsUtils.Factorial(n) / (NurbsUtils.Factorial(i) * NurbsUtils.Factorial(n - i)); return(faderLvl); }
/// <summary> /// Initializes the surface instance /// </summary> public void Initialize() { meshFilter = GetComponent <MeshFilter>(); if (transforms == Transforms.FromParent) { GetControlPointsFromTranssform(); } else { } knotsU = NurbsUtils.Knots(countU, degreeU); knotsV = NurbsUtils.Knots(countV, degreeV); mesh = new Mesh(); mesh.name = gameObject.name + "_surface"; mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; UpdateSurface(); }
public override void OnInspectorGUI() { EditorGUILayout.LabelField("Curve Settings:", EditorStyles.boldLabel); myTarget.type = (CurveType)EditorGUILayout.EnumPopup("Curve Type:", myTarget.type); switch (myTarget.type) { case CurveType.NURBS: myTarget.degree = EditorGUILayout.IntField("Degree:", myTarget.degree); break; default: break; } myTarget.resolution = EditorGUILayout.FloatField("Resolution:", myTarget.resolution); myTarget.transforms = (Transforms)EditorGUILayout.EnumPopup("Control Points Provider:", myTarget.transforms); switch (myTarget.transforms) { case Transforms.AsList: EditorGUILayout.PropertyField(controlPointTransforms, new GUIContent("Control Point Transform"), true); break; case Transforms.FromParent: EditorGUILayout.PropertyField(controlPointsParent, new GUIContent("Control Points Parent")); break; } myTarget.initializeOnStart = EditorGUILayout.Toggle("Initialize On Start:", myTarget.initializeOnStart); myTarget.autoUpdate = EditorGUILayout.Toggle("Auto-Update:", myTarget.autoUpdate); if (myTarget.type == CurveType.NURBS) { EditorGUILayout.PropertyField(knots, new GUIContent("Knots"), true); if (GUILayout.Button("Get Knot Vector:")) { switch (myTarget.transforms) { case Transforms.AsList: myTarget.knots = NurbsUtils.Knots(myTarget.controlPointTransforms.Length, myTarget.degree); break; case Transforms.FromParent: myTarget.knots = NurbsUtils.Knots(myTarget.controlPointsParent.childCount, myTarget.degree); break; } } } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Initializes the Curve /// </summary> public void Initialize() { lineRenderer = GetComponent <LineRenderer>(); lineRenderer.useWorldSpace = false; if (transforms == Transforms.FromParent) { GetControlPointsFromTransform(); } else { if (controlPointTransforms != null && controlPointTransforms.Length != 0 && (controlPoints == null || controlPoints.Length == 0)) { GetControlPointsFromTransforms(); } } knots = NurbsUtils.Knots(controlPoints.Length, degree); UpdateCurve(); }