@@ -41,7 +41,7 @@ namespace Ichni.Editor
|
||||
}
|
||||
|
||||
|
||||
public static void Lgp(int loop, Vector3 start, Vector3 end, bool Clear = false)
|
||||
public static void Lgp(int loop, Vector3 start, Vector3 end, bool Clear = false, bool offsetOrigin = false)
|
||||
{
|
||||
if (inspector.connectedGameElement == null || inspector.connectedGameElement.GetType() != typeof(Track))
|
||||
{
|
||||
@@ -54,10 +54,18 @@ namespace Ichni.Editor
|
||||
return;
|
||||
}
|
||||
Track track = (Track)inspector.connectedGameElement;
|
||||
List<PathNode> oldNodes = track.trackPathSubmodule.pathNodeList.ToList();
|
||||
List<PathNode> newNodes = new List<PathNode>();
|
||||
// 如果 Clear 且有旧节点,迁移变换
|
||||
|
||||
if (Clear)
|
||||
{
|
||||
if (offsetOrigin && oldNodes.Count > 0 && newNodes.Count > 0)
|
||||
{
|
||||
AdjustPathNodesToNearest(track, newNodes, oldNodes);
|
||||
}
|
||||
// 清除之前的PathNode
|
||||
foreach (var node in track.trackPathSubmodule.pathNodeList.ToList())
|
||||
foreach (var node in oldNodes)
|
||||
{
|
||||
EditorManager.instance.operationManager.CopyPasteDeleteModule.DeleteElement(node);
|
||||
}
|
||||
@@ -70,7 +78,38 @@ namespace Ichni.Editor
|
||||
float z = start.z + (end.z - start.z) * t;
|
||||
PathNode j = PathNode.GenerateElement("PathNode" + i.ToString(), Guid.NewGuid(), new List<string>(), true, track, true);
|
||||
j.transformSubmodule.originalPosition = new Vector3(x, y, z);
|
||||
newNodes.Add(j);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将原有 PathNode 的变换(位置、旋转、缩放)迁移到新生成的最近 PathNode 上
|
||||
/// </summary>
|
||||
public static bool AdjustPathNodesToNearest(Track track, List<PathNode> newNodes, List<PathNode> oldNodes)
|
||||
{
|
||||
foreach (var oldNode in oldNodes)
|
||||
{
|
||||
// 找到距离 oldNode 最近的新节点
|
||||
PathNode nearest = newNodes
|
||||
.OrderBy(n => Vector3.Distance(n.transformSubmodule.originalPosition, oldNode.transformSubmodule.originalPosition))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (nearest != null)
|
||||
{
|
||||
// 计算 oldNode 的变换(直接用欧拉角,不用四元数)
|
||||
Vector3 deltaPos = oldNode.transformSubmodule.originalPosition - oldNode.transformSubmodule.originalPosition;
|
||||
Vector3 deltaEuler = oldNode.transformSubmodule.originalEulerAngles - oldNode.transformSubmodule.originalEulerAngles;
|
||||
Vector3 deltaScale = oldNode.transformSubmodule.originalScale - oldNode.transformSubmodule.originalScale;
|
||||
|
||||
// 将变换应用到新节点
|
||||
nearest.transformSubmodule.originalPosition += deltaPos;
|
||||
nearest.transformSubmodule.originalEulerAngles += deltaEuler;
|
||||
nearest.transformSubmodule.originalScale += deltaScale;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user