评估从 C++ 中 max 导出的 3d 样条线程序
我的 C++ 程序需要访问在 3ds Max (2011) 中构建的 3D 样条线。 我找到了一个简单的 maxscript 可以导出这些样条线作为 XML 文件 - 示例如下:
<spline name='Line001' knots='5' closed='true'>
<knot x='-4.67297e-005' y='0.0' z='0.0'>
<invec x='-0.000144482' y='-600.0' z='-1.52588e-005' />
<outvec x='5.10227e-005' y='600.0' z='1.52588e-005' />
</knot>
<knot x='6.17511e-005' y='800.0' z='500.0'>
<invec x='7.92357e-005' y='800.0' z='100.0' />
<outvec x='4.42666e-005' y='800.0' z='900.0' />
</knot>
<knot x='-66.0574' y='1000.0' z='900.0'>
<invec x='-66.0574' y='700.0' z='900.0' />
<outvec x='-66.0573' y='1300.0' z='900.0' />
</knot>
<knot x='323.651' y='1300.0' z='4.57764e-005'>
<invec x='323.651' y='1600.0' z='200.0' />
<outvec x='323.651' y='1000.0' z='-200.0' />
</knot>
<knot x='-0.000152032' y='-700.0' z='-200.0'>
<invec x='-0.00014329' y='-700.0' z='-400.0' />
<outvec x='-0.000160774' y='-700.0' z='-1.52588e-005' />
</knot>
</spline>
我的问题是 - 在我的 C++ 程序中访问和评估此样条线的最简单(也是最轻量级)的方法是什么?我知道如何解析 XML 中的数据,但从那时起我就迷失了。我需要能够a)评估沿该3D样条线的点,并b)计算描述该点切线的向量(如果可能)。我知道有一些库可用于此类事情,但我不确定哪个是最合适的 - 特别是就上述格式而言(结,每个都有一个 invec 和 outvec)。
My C++ program requires access to 3D splines that have been constructed in 3ds Max (2011). I have found a simple maxscript that exports these splines as XML files - an example as follows:
<spline name='Line001' knots='5' closed='true'>
<knot x='-4.67297e-005' y='0.0' z='0.0'>
<invec x='-0.000144482' y='-600.0' z='-1.52588e-005' />
<outvec x='5.10227e-005' y='600.0' z='1.52588e-005' />
</knot>
<knot x='6.17511e-005' y='800.0' z='500.0'>
<invec x='7.92357e-005' y='800.0' z='100.0' />
<outvec x='4.42666e-005' y='800.0' z='900.0' />
</knot>
<knot x='-66.0574' y='1000.0' z='900.0'>
<invec x='-66.0574' y='700.0' z='900.0' />
<outvec x='-66.0573' y='1300.0' z='900.0' />
</knot>
<knot x='323.651' y='1300.0' z='4.57764e-005'>
<invec x='323.651' y='1600.0' z='200.0' />
<outvec x='323.651' y='1000.0' z='-200.0' />
</knot>
<knot x='-0.000152032' y='-700.0' z='-200.0'>
<invec x='-0.00014329' y='-700.0' z='-400.0' />
<outvec x='-0.000160774' y='-700.0' z='-1.52588e-005' />
</knot>
</spline>
My question is - what would be the simplest (and most lightweight) approach to accessing and evaluating this spline in my C++ program? I know how to parse the XML for the data but from then onwards I am currently lost. I need to be able to a) evaluate a point along this 3D spline and b) calculate a vector describing the tangent at this point (if possible). I understand there are libraries available for this sort of thing, but I'm unsure of which is most appropriate - particularly in terms of the format described above (knots, each with an invec and outvec).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 3ds Max 已经在计算这些曲线,因此您可以按照您需要的分辨率将“烘焙”曲线导出到 XML,我猜这将是每帧一个点。
如果您更喜欢评估应用程序中的曲线,那么贝塞尔曲线(我猜这些是)非常容易计算,无需外部库的帮助。看看维基百科上的 De Casteljau 算法,特别是描述几何的部分解释,比公式更容易掌握。
Since 3ds Max is already computing these curves, you could export the 'baked' curves to XML at the resolution that you need them, which I'm guessing will be one point per frame.
If you prefer to evaluate the curves in your application, then Bézier curves (which I'm guessing these are) are pretty easy to compute without the help of an external library. Take a look at the De Casteljau's algorithm on Wikipedia, in particular the section that describes the geometric interpretation, which is a lot easier to grasp than the formulas.