Spatial transform flaw!

Hi,



I’m back, sorry to be the bringer of bad news (again), worse in fact since I don’t have a fix this time ! :frowning:



I have just finished work on the spatial transform part of my exporter and found a serious flaw with spatial transforms. I noticed when testing out the rotation of two objects, they always rendered at the same position in space (0,0,0). I tested this out programmatically, and found that the spatial transformer was implicitly positioning any object attached to it, at 0,0,0.

To test this, I created two box objects, a static one at 0,0,0, and one attached to a spatial transformer at 5,5,5. I set a rotation transform on the spatial, when I tested the code both boxes where on top of each other. I had not set any position transform on the spatial.

To confirm, I detached the spatial transformer from the second box and as expected, it rendered at the correct position (obviously not rotating).

Unfortunately this impacts shared transforms, since all objects sharing the same transform will occupy the same position in space, irrespective of their local translations.

This problem does not affect the scale transform (the rotating box matched in scale with the static box, both boxes where > unity in size).



I will have a peak at the code for animation.SpatialTransformer, my gut tells me the fault may be with the interpolater.

Good news (I hope), I believe I have homed in on the fault :smiley:



In SpatialTransformer.fillTrans() where the translation extrapolation is performed, at lines

449 through to 455 there is a the following code fragment ::


if (start == keyframes.size()) { // if they are all null then fill
                // with identity
                for (int i = 0; i < keyframes.size(); i++)
                    ((PointInTime) keyframes.get(i)).look[objIndex]
                            .setTranslation(0,0,0);
                continue; // we're done so lets break
            }



I believe this is flawed, since for all null translations, all translations for all key frames, are set to 0,0,0. Thus any object using this transform, is translated to 0,0,0 if no translations have been set on it !

To test this out I modified the code, using the translation values of the objects, that had been previously stored in the pivots[] global :


if (start == keyframes.size()) { // if they are all null then fill
                // with identity
                for (int i = 0; i < keyframes.size(); i++)
                    ((PointInTime) keyframes.get(i)).look[objIndex]
                            .setTranslation(pivots[objIndex].getTranslation(null)); //Use original object translation.
                continue; // we're done so lets break
            }



This appears to correct the problem, but needs more testing to be sure.

Seems reasonable. I’ll look into making this change.

Ok, fix in. Modified a bit from your solution to avoid object creation. Please test with your test scenario to ensure all is well.

I have tested it with my test scenario, it tests out fine, thanks renanse.