作者:Luca Pataracchia,Autodesk(原 Alias)Toronto Support
此程序将读取 ASCII 文件(使用显式路径),并为指定对象 ($objectName) 设置转换值的关键帧。
必须使用以下格式排布文件:
frameNumber Xtranslation Ytranslation Ztranslation
例如:
7 2 4 6 10 3.7 3.6 9.3 20 7.4 5.7 3.9 24 4.2 6.789 2.457 32 16.2 3.45 9.75
该脚本是如何从 ASCII 文件中导入动画的示例。该程序可根据需要导入的动画类型进行更改。您必须修改该脚本以适合 ASCII 文件的格式。
global proc getAnim(string $fileName, string $objectName)
{
//open the file for reading
$fileId=`fopen $fileName "r"`;
//get the first line of text
string $nextLine = `fgetline $fileId`;
//while $nextline is not emtpy(end of file) do the following
while ( size( $nextLine ) > 0 ) {
//tokenize(split) line into separate elements of an array
string $rawAnimArray[];
tokenize ($nextLine, " ",$rawAnimArray);
//place each element of the array into separate variables
print $rawAnimArray;
float $frame=$rawAnimArray[0];
float $x=$rawAnimArray[1];
float $y=$rawAnimArray[2];
float $z=$rawAnimArray[3];
//change the currentTime and set keys for tx, ty, tz
currentTime $frame ;
setAttr ($objectName+".tx") $x;
setKeyframe ($objectName+".tx");
setAttr ($objectName+".ty") $y;
setKeyframe ($objectName+".ty");
setAttr ($objectName+".tz") $z;
setKeyframe ($objectName+".tz");
//get the next line in the ascii file.
$nextLine = `fgetline $fileId`;
}
//close file
fclose $fileId;
}