thcmedia / papervision3d

Automatically exported from code.google.com/p/papervision3d
0 stars 0 forks source link

DAE animations: TransformStackChannels3D: better bake() #253

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

TransformStackChannels3D's bake() creates keys at a fixed interval.
This can either bee too corse or too fine, depending on the animation.

Besides, especially for long animations it takes a long time + huge amount 
of memory is wasted. My implementation of bake(), bakeSparse() only adds
keys for every keyframe in any of the channels of the original animation.

classes affected
------------------------------------------------------------------
org.papervision3d.core.animation.channel.transform.TransformStackChannels3D
org.papervision3d.core.animation.channel.Channel3D
org.papervision3d.objects.parsers.DAE
------------------------------------------------------------------

new method for  
org.papervision3d.core.animation.channel.transform.TransformStackChannels3D
:
------------------------------------------------------------------

  public function bakeSparse() : MatrixChannel3D
  {
    var baked : MatrixChannel3D = new MatrixChannel3D(null);
    var time : Number;
    var i:int, j:int, k:int;
    var curves : Array;
    var keys : Array;
    var keypoints : Array = new Array();

    // accumulate all keypoints of all curves in this array
    keypoints.push(startTime);

    for(i = 0; i < channels.length; i++)
    {
      curves = channels[i].curves;
      for(j = 0; j < curves.length; j++)
      {
        keys = curves[j].keys
        for(k = 0; k < keys.length; k++)
        {
          time = keys[k].input;
          if (keypoints.indexOf(time) < 0)
            keypoints.push(time);
        }
      }
    }
    // sort keypoints
    keypoints.sort();

    curves = new Array(12);

    for(i = 0; i < 12; i++)
    {
      curves[i] = new Curve3D();
    }

    for(i = 0; i < keypoints.length; i++)
    {
      time = keypoints[i];
      update(time);

      curves[0].addKey(new LinearCurveKey3D(time, transform.n11));
      curves[1].addKey(new LinearCurveKey3D(time, transform.n12));
      curves[2].addKey(new LinearCurveKey3D(time, transform.n13));
      curves[3].addKey(new LinearCurveKey3D(time, transform.n14));

      curves[4].addKey(new LinearCurveKey3D(time, transform.n21));
      curves[5].addKey(new LinearCurveKey3D(time, transform.n22));
      curves[6].addKey(new LinearCurveKey3D(time, transform.n23));
      curves[7].addKey(new LinearCurveKey3D(time, transform.n24));

      curves[8].addKey(new LinearCurveKey3D(time, transform.n31));
      curves[9].addKey(new LinearCurveKey3D(time, transform.n32));
      curves[10].addKey(new LinearCurveKey3D(time, transform.n33));
      curves[11].addKey(new LinearCurveKey3D(time, transform.n34));
    }

    for(i = 0; i < 12; i++)
    {
      baked.addCurve(curves[i]);  
    }

    return baked;
  }

------------------------------------------------------------------

this needs access to Channel3D's curves, which is done by adding a getter 
method to org.papervision3d.core.animation.channel.Channel3D:
------------------------------------------------------------------

  public function get curves() : Array
  {
    return _curves;
  }

------------------------------------------------------------------

i use bakeSparse() in org.papervision3d.objects.parsers.DAE. to do that 
replace the following in method buildAnimatedTransforms():
------------------------------------------------------------------
  if(bakeChannels)
  {
    var sampleDuration : Number = 0.1;
    var numSamples : int = (multiChannel.endTime - multiChannel.startTime) 
/ sampleDuration;

    var matrixChannel : MatrixChannel3D = multiChannel.bake(numSamples);
------------------------------------------------------------------
with
------------------------------------------------------------------
  if(bakeChannels)
  {
    var matrixChannel : MatrixChannel3D = multiChannel.bakeSparse();
------------------------------------------------------------------

please, can someone check in these changes?

thanks,
  --stefan--

Original issue reported on code.google.com by stefa...@gmx.at on 3 Feb 2010 at 7:03

GoogleCodeExporter commented 8 years ago
i just noticed that you can upload files here:

this is the patch to accomplish the above (+ fix to issue #252)

Original comment by stefa...@gmx.at on 3 Feb 2010 at 7:30

Attachments: