Sprite3D.pushModelViewProjection // todo: find better way

Software: Away3D 4.x

Avatar
Alexander Seifert, Moderator
Posted: 20 August 2012 10:00 AM   Total Posts: 129

Hi!

Not sure if this is actually a bug, feature or support request. However, Sprite3D causes quite some overhead memory wise as it constantly feeds the Garbage Collector in pushModelViewProjection.

I believe it is save to assume that this is related to the decompose/recompose approach used to clean out rotation from the transformation matrix. I even go as far as to assume that this is also what the infamous

// todo: find better way 

is referring to wink That and computation time.

I’d like to propose a different approach to clearing rotation.

The original method in question:

override public function pushModelViewProjectioncamera:Camera3D ):void {
 
var comps:Vector.<Vector3D>;
 var 
rot:Vector3D;
 if( ++
_mvpIndex == _stackLen {
  _mvpTransformStack[_mvpIndex] 
= new Matrix3D();
  ++
_stackLen;
 
}

 
// todo: find better way
 
var mvp:Matrix3D _mvpTransformStack[_mvpIndex];
 
mvp.copyFromsceneTransform );
 
mvp.appendcamera.inverseSceneTransform );
 
comps mvp.decompose();
 
rot comps[1];
 
rot.rot.rot.0;
 
mvp.recomposecomps );
 
mvp.appendcamera.lens.matrix );
 
mvp.copyColumnTo3_pos );
 
_zIndices[_mvpIndex] = -_pos.z;

My proposition:

override public function pushModelViewProjection(camera:Camera3D):void {
 
if (++_mvpIndex == _stackLen{
  _mvpTransformStack[_mvpIndex] 
= new Matrix3D();
  ++
_stackLen;
 
}
 
var mvp:Matrix3D _mvpTransformStack[_mvpIndex];
 
mvp.copyFrom(sceneTransform);
 
mvp.append(camera.inverseSceneTransform);
 
 var 
rawData:Vector.<Number> = Matrix3DUtils.RAW_DATA_CONTAINER;
 
mvp.copyRawDataTo(rawData0true);
 
 
mvp.identity();
 
mvp.appendScale(Math.sqrt(rawData[0] rawData[0] rawData[4] rawData[4] rawData[8] rawData[8]),
  
Math.sqrt(rawData[1] rawData[1] rawData[5] rawData[5] rawData[9] rawData[9]),
  
Math.sqrt(rawData[2] rawData[2] rawData[6] rawData[6] rawData[10] rawData[10])
 );
 
mvp.appendTranslation(rawData[3]rawData[7]rawData[11]);
 
 
mvp.append(camera.lens.matrix);
 
mvp.copyColumnTo(3_pos);
 
_zIndices[_mvpIndex] = -_pos.z;

To be honest, I haven’t benchmarked it yet. But at least in theory I believe this should reduce overhead a little in clearing rotation. What do you think?

Cheers!
Alex

 Signature 
signature_image

http://www.deltastrike.org

   

Avatar
Alexander Seifert, Moderator
Posted: 20 August 2012 10:08 AM   Total Posts: 129   [ # 1 ]

*update*

Just took a look at memory consumption. Garbage Collector remains put, seems like there’s nothing to be collected in there anymore =)

 Signature 
signature_image

http://www.deltastrike.org

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X