Motive Batch Processor是一个独立的独立Windows应用程序,基于新的NMotive脚本和编程API构建,可用于通过IronPython或C#脚本处理一组Motive Take文件。虽然批处理器包含一些示例脚本文件,但它主要用于利用用户编写的脚本。
初始功能包括脚本访问文件I / O,重建,使用Motive现有编辑工具的高级Take处理以及数据导出。即将推出的版本将提供对轨道,通道和帧级信息的访问,以便根据各个标记重建数据创建清理和标记工具。
Motive Batch Processor Scripts使用NMotive .NET类库,您还可以使用NMotive类编写在此应用程序之外运行的.NET程序和IronPython脚本。NMotive程序集安装在全局程序集缓存中,也位于assemblies
Motive安装目录的子目录中。例如,64位Motive安装程序中包含的程序集的默认位置是:
C:\ Program Files \ OptiTrack \ Motive \ assemblies \ x64
Motive批处理器的完整源代码也随Motive一起安装,位于:
C:\ Program Files \ OptiTrack \ Motive \ MotiveBatchProcessor \ src
欢迎您使用源代码作为起点在NMotive框架上构建您自己的应用程序。
目录
使用
要求
- 使用NMotive API的批处理器脚本。(C#或IronPython)
- 要被处理的Takes文件
步骤
- 启动Motive批处理器。它可以从“开始”菜单,“Motive”安装目录或“Motive”中的 数据管理窗格 启动。
- 首先,选择并加载批处理器脚本。可以在
[Motive Directory]\MotiveBatchProcessor\ExampleScripts\
文件夹中找到各种管道的示例脚本。 - 加载将使用导入的脚本处理的捕获的Takes(TAK)。
- 单击处理Takes以批量处理Take文件。
重建管道
- 在批处理器中运行重建管道时,必须使用ImportMotiveProfile方法加载重建设置。从Motive中,导出 用户配置文件 并确保其包含重建设置。然后,在运行重建或轨迹处理器管道之前,将此用户配置文件导入批处理器脚本,以便可以使用正确的设置来重建3D数据。有关更多信息,请参阅TakeManipulation文件夹中的示例脚本。
类参考
可以 Help
在Motive安装目录的子目录中找到Microsoft编译的HTML(.chm)格式的类引用。帮助文件的默认位置(在64位Motive安装程序中)是:
C:\Program Files\OptiTrack\Motive\Help\NMotiveAPI.chm
C#脚本
Motive批处理器可以运行C#和IronPython脚本。下面是C#脚本格式的概述,以及示例脚本。
C#脚本格式
有效的批处理器C#脚本文件必须包含实现该 ItakeProcessingScript
接口的单个类。该接口定义了一个函数:
Result ProcessTake( Take t, ProgressIndicator progress )
.
Result, Take, and ProgressIndicator
是 NMotive
命名空间中定义的所有类。Take对象 t
是NMotive Take
类的一个实例。这是正在处理的事情。该 progress
对象是NMotive的一个实例, ProgressIndicator
允许脚本使用进度和消息更新Batch Processor UI。批处理器C#脚本的一般格式是:
using NMotive; // any other using statements public class MyCSharpScript : ITakeProcessingScript { public Result ProcessTake(Take t, ProgressIndicator progress) { Result scriptResult; // Script processing code here progress.SetMessage(“Done processing take “ + t.Name); progress.SetProgress( 100 ); return scriptResult; } }
C# 示例
在该 [Motive Directory]\MotiveBatchProcessor\ExampleScripts\
文件夹中,有多个C#(.cs)示例脚本,演示如何使用NMotive处理各种不同的管道,包括跟踪数据导出和其他后处理工具。请注意,您的C#脚本文件必须具有“.cs”扩展名。
包含的示例脚本管道:
- ExporterScript - BVH, C3D, CSV, FBXAscii, FBXBinary, TRC
- TakeManipulation - AddMarker, DisableAssets, GapFill, MarkerFilterSCript, ReconstructAutoLabel, RemoveUnlabeledMarkers, RenameAsset
批处理器脚本C#示例(ExporterScript-C3D.cs):将take导出为C3D格式。
using System; using System.IO; using NMotive; /// <summary> /// Motive Batch Processor script for exporting a take file to C3D format. /// </summary> public class C3DExportScript : ITakeProcessingScript { /// <summary> /// The <c>ProcessTake</c> function is from the <c>ITakeProcessingScript</c> interface. /// Exports the given take to C3D format. The exported file is in the same /// directory as the take file, and has the same name, but with a '.c3d' file extension. /// </summary> /// <param name="take">The take to export.</param> /// <param name="progress">Progress indicator object.</param> /// <returns>The result of the export process.</returns> public Result ProcessTake(Take take, ProgressIndicator progress) { // Construct an NMotive C3D exporter object with the desired // options. We will write C3D data for markers and assets. C3DExporter exporter = new C3DExporter { //-== C3DExporter Class ==- ColonNameSeparator = false, RenameUnlabeledMarkers = false, Units = LengthUnits.Units_Centimeters, UseTimeCode = true, UseZeroBasedFrameIndex = true, WriteFingerTipMarkers = false, WriteUnlabeledMarkers = false, XAxis = Axis.Axis_NegativeX, // Axis_PositiveX, Axis_NegativeX YAxis = Axis.Axis_PositiveZ, // Axis_PositiveY, Axis_NegativeY ZAxis = Axis.Axis_PositiveY // Axis_PositiveZ, Axis_NegativeZ }; // Construct the output C3D file. The output file will be co-located with the // take file and have the same name as the take file, but with a '.c3d' extension. string outputFileName = Path.GetFileNameWithoutExtension(take.FileName) + ".c3d"; string outputDirectory = Path.GetDirectoryName(take.FileName); string outputFile = Path.Combine(outputDirectory, outputFileName); // Do the export and return the Export functions result object. progress.SetMessage("Writing to File"); progress.SetProgress( (float)0.1 ); return exporter.Export(take, outputFile, true); } }
IronPython 脚本
IronPython 是Python编程语言的一种实现,可以使用.NET库和Python库。除了C#脚本之外,批处理器还可以执行有效的IronPython脚本。
IronPython 脚本格式
您的IronPython脚本文件必须导入clr模块并引用NMotive程序集。此外,它必须包含以下功能:
def ProcessTake(Take t, ProgressIndicator progress)
以下说明了典型的IronPython脚本格式。
#import sys and clr modules import sys import clr # Add a reference to the NMotive assembly clr.AddReference("NMotive") # Import everything from sys and NMotive. from System import * from NMotive import * # Define the ProcessTake function. def ProcessTake(take, progress): # Take processing code here . . . # return result object
IronPython 脚本示例
在该 [Motive Directory]\MotiveBatchProcessor\ExampleScripts\
文件夹中,有一些示例脚本,演示如何使用NMotive处理各种不同的管道,包括跟踪数据导出和其他后处理工具。请注意,您的IronPython脚本文件必须具有“.cs”扩展名。
批处理器脚本IronPython示例(TrimAndFilter.py):
以下脚本执行除去Tails操作,然后执行过滤/平滑操作。如果两个操作都成功,则保存结果。
import sys import clr # Add a reference to the NMotive assembly clr.AddReference("NMotive") from System import * # Import everything from NMotive. from NMotive import * def ProcessTake(take, progress): # Set the message to be displayed next to to the progress bar in the # Motive Batch Processor UI. progress.SetMessage('Triming tails...') # Create an NMotive TrimTails object to perform the tail trimming operation. tailTrimming = TrimTails() # pass the progress object to the trim tails object. It will update # progress that will be rendered in the UI. tailTrimming.Progress = progress # Set trail trimming options. tailTrimming.Automatic = True tailTrimming.LeadingTrimSize = 4 tailTrimming.TrailingTrimSize = 4 # And execute the trimming process. trimResult = tailTrimming.Process(take) # If trimming failed for some reason the Success field of the returned # NMotive Result object will be false and the Message field will contain # information about the failure. The Message field of the returned Result # object will be displayed in the UI. if not trimResult.Success: # If trimming failed, return without saving the take. return trimResult # Starting the filtering process... progress.SetMessage('Filtering...') # Create the NMotive filter object. filtering = Filter() # We are going to use the progress bar to display the progress of each # individual operation, so reset the progress bar to zero and pass the # the progress object to the filtering object. progress.SetProgress(0) filtering.Progress = progress # Set the cutoff frequency and filter. filtering.CutOffFrequency = 8 # Hz filteringResult = filtering.Process(take) if not filteringResult.Success: # If filtering failed, return without saving the take. return filteringResult # If we get here trimming and filtering succeeded. Save the take file. progress.SetMessage('Saving take...') fileSaveResult = take.Save() if fileSaveResult != FileResult.ResultOK: return Result(False, 'File save failed') return Result(True, '')