Home > Flex, Math > Papervision 3D Path Animation from 3ds max

Papervision 3D Path Animation from 3ds max

September 16, 2007

The previous experiments with path animation in Papervision 3D were interesting, but of little practical use as very few applications generate path information programmatically at runtime.  A more common workflow is to generate paths in a 3d application.  The latest addition to the Singularity parametric curve library is a 3D Bezier spline that is suitable for working with cubic spline paths generated from other applications.

The 2D bezier spline took knots (or CV’s) as inputs and automatically generated tangents.  The 3D version simply accepts CV, in-, and out-tangent information generated from a 3D package.  To test this spline with 3ds max, I wrote a simple MAXScript to export spline data to XML.  A Flex program reads the XML data (E4X is very cool) and transfers the data to the 3D Bezier spline.  An example is shown below,

whose exported XML is

<spline name=’Line01′ knots=’7′ closed=’true’>
 <knot x=’-123.018′ y=’53.5028′ z=’0.0′>
 <invec x=’-154.627′ y=’16.1465′ z=’0.0′ />
 <outvec x=’-91.4084′ y=’90.8591′ z=’0.0′ />
 </knot>
 <knot x=’-7.033′ y=’88.4169′ z=’-91.3649′>
 <invec x=’-77.1479′ y=’83.8192′ z=’-91.3649′ />
 <outvec x=’63.0819′ y=’93.0146′ z=’-91.3649′ />
 </knot>
 <knot x=’110.694′ y=’89.7132′ z=’0.0′>
 <invec x=’80.1177′ y=’107.975′ z=’0.0′ />
 <outvec x=’141.27′ y=’71.4514′ z=’0.0′ />
 </knot>
 <knot x=’161.098′ y=’-13.6597′ z=’0.0′>
 <invec x=’166.459′ y=’30.5072′ z=’0.0′ />
 <outvec x=’155.736′ y=’-57.8267′ z=’0.0′ />
 </knot>
 <knot x=’61.2687′ y=’-93.0454′ z=’-91.3649′>
 <invec x=’100.924′ y=’-86.7235′ z=’-91.3649′ />
 <outvec x=’21.6135′ y=’-99.3672′ z=’-91.3649′ />
 </knot>
 <knot x=’-49.5287′ y=’-89.2301′ z=’-91.3649′>
 <invec x=’-2.977′ y=’-116.816′ z=’-91.3649′ />
 <outvec x=’-96.0804′ y=’-61.6439′ z=’-91.3649′ />
 </knot>
 <knot x=’-154.02′ y=’-41.2029′ z=’0.0′>
 <invec x=’-145.71′ y=’-73.8184′ z=’0.0′ />
 <outvec x=’-162.33′ y=’-8.58747′ z=’0.0′ />
 </knot>
 </spline>

The online Papervision 3D demo contains two cameras. The first camera (static view) allows a marker to be visualized moving along the path. Since the Cubic Bezier spline supports arc-length parameterization, the marker moves along the path at constant velocity. The second camera is animated and looks at the origin from the point of view of the marker.

View the online demo here, which includes a link to download the Singularity package.

Categories: Flex, Math
  1. JT
    September 16, 2007 at 12:52 pm

    Will this be included in Papervision?

  2. September 17, 2007 at 6:44 am

    The 3D Bezier spline is still preliminary and the pipeline has only been tested with 3ds max. The code, however, is available for anyone to use, including the PV3D team 🙂

    regards,

    – jim

  3. December 15, 2007 at 9:20 am

    Hey Jim, thanks a lot for this example, it’s helped me tremendously with my camera animations. Unfortunately me and my colleagues aren’t working with 3dsmax, so the maxscript was no use. I was wondering however, why you chose to write a maxscript? After looking at your code I came up with this method to construct the spline data from a collada file itself:

    public static function createSplineFromCollada(inCollada : XML, inSplineID : String) : PV3DSpline {
      // define data source
      var node : XML = XMLList(inCollada..geometry.(@id == inSplineID + "-spline"))[0];
    
      // create spline instance
      var spline : PV3DSpline = new PV3DSpline();
      // set closed flag
      spline.closed = (node.spline.@closed == "1");
      // retrieve the list of serial x y z coordinates. 
      var coords : Array = node.spline.source.float_array.toString().split(" ");
        
      if (!spline.closed) {
        // if the spline is not closed, the array of coordinates start 
        // with the first knot and ends with the last knot, it's
        // respective in and out tangents are missing.
        // By adding a dummy value at the start and the end, the spline 
        // is drawn correctly again.
        coords = [0,0,0].concat(coords.concat([0,0,0]));
      }
        
      // use this iterator to add the tangents to the control points.
      var i : int = 0;
      while (coords.length) {
        var inVec : Array = coords.splice(0, 3);
        var knot : Array = coords.splice(0, 3);
        var outVec : Array = coords.splice(0, 3);
    
        var myX : Number = Number(knot[0]);
        var myY : Number = Number(knot[1]);
        var myZ : Number = Number(knot[2]);
              
        // add a knot to the list:
        spline.addControlPoint(myX, myY, myZ);
              
        myX = Number(inVec[0]);
        myY = Number(inVec[1]);
        myZ = Number(inVec[2]);
                
        // add the in tangent
        spline.inTangent(i, myX, myY, myZ);
              
        myX = Number(outVec[0]);
        myY = Number(outVec[1]);
        myZ = Number(outVec[2]);
              
        // add the out tangent
        spline.outTangent(i, myX, myY, myZ);	
          
        i++;			
      }
      return spline;
    }
    

    And the (stripped down) example of the collada file:

    
      
        
          
            
              -57.5 60 0 2.5 60 0 62.5 60 0 52.5 60 50 52.5 -0.000002 50 52.5 -60 50 62.5 -60 0 2.5 -60 0 -57.5 -60 0 -57.5 -60 50 -57.5 -0.000002 50 -57.5 60 50
              
                
                  
                  
                  
                
              
            
            
              
            
            
              
                BEZIER
              
            
          
        
    
    

    I haven’t tested it with that many splines, but it worked for the bezier ones I’m using in the project.
    Thanks, Eric-Paul.

  4. December 15, 2007 at 7:16 pm

    I have an older version of MAX and can not work with Collada-MAX. It was a fun experiment.

    regards,

    – jim

  5. January 9, 2008 at 9:25 am

    very intrsting

  6. June 19, 2008 at 6:05 pm

    I’m looking for a MaxScript like this … but I didn’t find it in the Singularity package? Is your script available?

  7. April 3, 2009 at 4:14 am

    Thanks for that link algorithmist 🙂

  1. September 18, 2007 at 2:58 pm
  2. September 18, 2007 at 3:40 pm
Comments are closed.
%d bloggers like this: