可以把场景移动到原点去k动作,然后可以恢复到ue4的位置
-- 定义全局变量
global CenterPoint = undefined
global averageCenter = [0,0,0]
-- 定义对话框
rollout restoreRollout "定序器>FBX>MAX"
(
button CreateButton "建立中心点" width:150 height:30
button saveIntButton "保存初始变换>txt" width:150 height:30 enabled:false
button ResetButton "复位到原点" width:150 height:30 enabled:false
button saveOriginButton "保存原点变换>txt" width:150 height:30 enabled:false
button LoadIntButton "txt>恢复初始变换" width:150 height:30 enabled:false
button LoadOriginButton "txt>恢复原点变换" width:150 height:30 enabled:false
radiobuttons targetAxis width:97 height:16 labels:#("零转动","转到-Y轴") default:1 columns:2 enabled:false
fn CreateCenterPoint =
(
-- 获取用户选择的所有物体
selectedObjects = getCurrentSelection()
--初始化averageCenter不能少,否则for循环体里就有两次位置叠加
averageCenter = [0,0,0]
-- 计算选择的物体的平均中心点
for obj in selectedObjects do
(
averageCenter += obj.position
)
averageCenter /= selectedObjects.count --计算平均点
-- 创建一个帮助器对象作为平均中心点
CenterPoint = point pos:averageCenter
CenterPoint.size = 10000
CenterPoint.name="CenterPoint"
-- 将选择的物体作为平均中心点的子物体
for obj in selectedObjects do
(
obj.parent = $CenterPoint
)
)
fn SaveIntTransformData obj =
(
-- 获取当前Max文件的路径
MaxPath = maxFilePath
MaxName = trimright maxfilename ".max"
-- 获取CenterPoint的transform数据
CenterPointPositiion = obj.transform.position
CenterPointRotation=quatToEuler (obj.transform.rotation as quat)
CenterPointScale=obj.transform.scale
-- 初始化textToWrite变量
textToWrite = ""
-- 构建要写入的文本内容
textToWrite += "Position:" + CenterPointPositiion as string + "\n"
textToWrite += "Rotation(Euler):" + CenterPointRotation as string + "\n"
textToWrite += "Scale:" + CenterPointScale as string
-- 构建完整的文件路径
outputFilePath = maxPath +MaxName+ "_Int.txt"
-- 创建文本文件并写入内容
-- 检查文件是否存在
if doesFileExist outputFilePath then (
-- 如果文件存在,则以追加模式打开文件
outputFile = openFile outputFilePath mode:"w"
-- 写入内容到文件
format "%" textToWrite to:outputFile
) else(
-- 如果文件不存在,则创建新文件
outputFile = createFile outputFilePath
-- 写入内容到文件
format "%" textToWrite to:outputFile
)
-- 关闭文件
close outputFile
)
fn ResetTransformData =
(
if isValidNode($CenterPoint) then
(
-- 将平均中心点移动到坐标原点
$CenterPoint.position = [0,0,0]
-- 让平均中心点的 x 轴对齐到世界坐标的 y 轴
if (targetAxis.state ==1) do(
$CenterPoint.rotation = eulerangles 0 0 0 --保持默认朝向平移中心点
)
if (targetAxis.state ==2) do(
$CenterPoint.rotation = eulerangles 0 0 -90 --把中心点的x轴对齐向世界坐标的负y轴
)
)
else
(
messagebox "Error: CenterPoint 物体不存在."
destroyDialog restoreRollout
)
)
fn SaveOriginTransformData obj =
(
-- 获取当前Max文件的路径
MaxPath = maxFilePath
MaxName = trimright maxfilename ".max"
-- 获取CenterPoint的transform数据
CenterPointPositiion = obj.transform.position
CenterPointRotation=quatToEuler (obj.transform.rotation as quat)
CenterPointScale=obj.transform.scale
-- 初始化textToWrite变量
textToWrite = ""
-- 构建要写入的文本内容
textToWrite += "Position:" + CenterPointPositiion as string + "\n"
textToWrite += "Rotation(Euler):" + CenterPointRotation as string + "\n"
textToWrite += "Scale:" + CenterPointScale as string
-- 构建完整的文件路径
outputFilePath = maxPath +MaxName+ "_Origin.txt"
-- 创建文本文件并写入内容
-- 检查文件是否存在
if doesFileExist outputFilePath then (
-- 如果文件存在,则以追加模式打开文件
outputFile = openFile outputFilePath mode:"w"
-- 写入内容到文件
format "%" textToWrite to:outputFile
) else(
-- 如果文件不存在,则创建新文件
outputFile = createFile outputFilePath
-- 写入内容到文件
format "%" textToWrite to:outputFile
)
-- 关闭文件
close outputFile
)
fn LoadIntTransformData obj =
(
-- 获取当前Max文件的路径
maxPath = maxFilePath
MaxName = trimright maxfilename ".max"
-- 构建txt文件路径
txtFilePath = maxPath + MaxName+"_Int.txt"
-- 检查文件是否存在
if doesFileExist txtFilePath then
(
-- 读取txt文件内容
txtFile = openFile txtFilePath mode:"r"
while not eof txtFile do
(
--先把被旋转的欧拉角归零这样下面的位移等数据才能正确读取
$CenterPoint.rotation=(eulerAngles 0 0 0)
-- 逐行读取文本文件内容
line = readline txtFile
-- 提取位置、旋转和缩放数据
if matchPattern line pattern:"Position:*" then
(
positionStr = substituteString line "Position:" ""
position = execute positionStr
obj.position = position
)
else if matchPattern line pattern:"Rotation(Euler):*" then
(
rotationStr = substituteString line "Rotation(Euler):" ""
rotation = execute rotationStr
obj.rotation = rotation as quat -- 将欧拉角转换为四元数
)
else if matchPattern line pattern:"Scale:*" then
(
scaleStr = substituteString line "Scale:" ""
scale = execute scaleStr
obj.scale = scale
)
)
close txtFile
)
else
(
print "文本文件不存在!"
)
)
fn LoadOriginTransformData obj =
(
-- 获取当前Max文件的路径
maxPath = maxFilePath
MaxName = trimright maxfilename ".max"
-- 构建txt文件路径
txtFilePath = maxPath + MaxName+"_Origin.txt"
-- 检查文件是否存在
if doesFileExist txtFilePath then
(
-- 读取txt文件内容
txtFile = openFile txtFilePath mode:"r"
while not eof txtFile do
(
--先把被旋转的欧拉角归零这样下面的位移等数据才能正确读取
$CenterPoint.rotation=(eulerAngles 0 0 0)
-- 逐行读取文本文件内容
line = readline txtFile
-- 提取位置、旋转和缩放数据
if matchPattern line pattern:"Position:*" then
(
positionStr = substituteString line "Position:" ""
position = execute positionStr
obj.position = position
)
else if matchPattern line pattern:"Rotation(Euler):*" then
(
rotationStr = substituteString line "Rotation(Euler):" ""
rotation = execute rotationStr
obj.rotation = rotation as quat -- 将欧拉角转换为四元数
)
else if matchPattern line pattern:"Scale:*" then
(
scaleStr = substituteString line "Scale:" ""
scale = execute scaleStr
obj.scale = scale
)
)
close txtFile
)
else
(
print "文本文件不存在!"
)
)
on CreateButton pressed do (
CreateCenterPoint()
saveIntButton.enabled = true
CreateButton.enabled = false
)
on saveIntButton pressed do (
SaveIntTransformData $CenterPoint
ResetButton.enabled = true
targetAxis.enabled = true
saveIntButton.enabled = false
)
on ResetButton pressed do (
ResetTransformData()
saveOriginButton.enabled = true
ResetButton.enabled = false
)
on saveOriginButton pressed do (
SaveOriginTransformData $CenterPoint
LoadIntButton.enabled = true
)
on LoadIntButton pressed do (
LoadIntTransformData $CenterPoint
LoadOriginButton.enabled = true
ResetButton.enabled = true
)
on LoadOriginButton pressed do(
LoadOriginTransformData $CenterPoint
CreateButton.enabled = false
ResetButton.enabled = true
)
)
-- 创建对话框
createDialog restoreRollout