I've found the TVMesh.SetMeshCenter to be a little flaky in some circumstances (ie: wheels on a physics vehicle) and limiting in that there isn't a corresponding function for TVActor, so I figured why not sidestep that and use a matrix based approach.
My approach- Load asset at the origin
- Get BoundingBox of the asset
- Calculate and store an offset vector based on the max and min values returned from the BoundingBox
- Each SetMatrix:
- translate the passed matrix by the offset vector to get a translation matrix
- invert the translation matrix
- multiply the translation matrix by the original matrix that was to be set
- set the new matrix
In general this works ok with position and rotation, assuming I don't fiddle with the scale of the asset after it has been loaded. The moment the scale changes on the incoming matrix, my theoretical centre stays where it was, but the distance between it and the asset increases:
Before scale
After scale
The custom centre is represented by the axis.
Im speculating that I need to re-calculate the bounding box each time scale changes to re-calculate the position offset. There must be a better way? Any ideas?
Edit: Calculating the BoundingBox each setmatrix now works correctly with scale. Im still interested to hear alternative ideas though