سؤال

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).

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top