Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.Splines;
- namespace sc.modeling.splines.runtime.auxiliary
- {
- //Sample the Spline Mesher's scale data
- public class SampleSplineMesherScale : MonoBehaviour
- {
- public SplineMesher splineMesher;
- [Space]
- public float position;
- [Space]
- public Vector3 outputScale;
- private Vector3 splinePoint;
- private void OnValidate()
- {
- if (!splineMesher) return;
- //For this example, just reading from the 1st spline
- int splineIndex = 0;
- //Disregard, this is just to calculate the position of the gizmo cube!
- float splineLength = splineMesher.splineContainer.Splines[splineIndex].CalculateLength(splineMesher.splineContainer.transform.localToWorldMatrix);
- splinePoint = splineMesher.splineContainer.Splines[splineIndex].EvaluatePosition(position / splineLength);
- //Convert position to world-space
- splinePoint = splineMesher.splineContainer.transform.TransformPoint(splinePoint);
- //If there are no data points for the spline
- if (splineMesher.scaleData[splineIndex].Count == 0)
- {
- outputScale = Vector3.one;
- }
- else
- {
- UnityEngine.Splines.Interpolators.LerpFloat3 float3Interpolator = new UnityEngine.Splines.Interpolators.LerpFloat3();
- outputScale = splineMesher.scaleData[splineIndex].Evaluate(splineMesher.splineContainer.Splines[splineIndex], position, splineMesher.scaleData[splineIndex].PathIndexUnit, float3Interpolator);
- }
- }
- private void OnDrawGizmosSelected()
- {
- Gizmos.DrawCube(splinePoint, outputScale);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement