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 That and computation time.
I’d like to propose a different approach to clearing rotation.
The original method in question:
override public function pushModelViewProjection( camera: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.copyFrom( sceneTransform );
mvp.append( camera.inverseSceneTransform );
comps = mvp.decompose();
rot = comps[1];
rot.x = rot.y = rot.z = 0;
mvp.recompose( comps );
mvp.append( camera.lens.matrix );
mvp.copyColumnTo( 3, _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(rawData, 0, true);
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