Skip to content

Instantly share code, notes, and snippets.

@sasame
Created January 8, 2024 15:55
Show Gist options
  • Select an option

  • Save sasame/d138088c70b370365e99a559049b1cb1 to your computer and use it in GitHub Desktop.

Select an option

Save sasame/d138088c70b370365e99a559049b1cb1 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Splines;
using UnityEditor;
public static class DSplineUtilMenu
{
[MenuItem("Spline/FreezeTransform")]
public static void FreezeTransform()
{
var o = Selection.activeGameObject;
if (o)
{
var splineContainer = o.GetComponent<SplineContainer>();
if (splineContainer)
{
var mat = o.transform.localToWorldMatrix;
foreach(var spline in splineContainer.Splines)
{
for(int idKnot =0;idKnot<spline.Count;++idKnot)
{
var k = spline[idKnot];
var newKnot = k.Transform(mat);
spline[idKnot] = newKnot;
}
}
o.transform.localPosition = Vector3.zero;
o.transform.localRotation = Quaternion.identity;
o.transform.localScale = Vector3.one;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment