It’s obvious how happy you are to have finally gotten your hands on some sample code which you can copy&paste into your project. Apparently, you haven’t gotten an understanding along the way of why it’s working for 90% and, by extension, why it’s not working for the remaining 10%.
Personally I consider this preliminary result regrettable, after all the effort by so many people willing to help. And I would like to put in a last effort:
1st, it helps to know that in a 1 geometry - 1 camera setup it makes no difference for the visual output if you move the geometry “x” units to one side or you move the camera the same “x” units to the opposite side. The only way to distinguish one from the other is with the help of a static reference geometry (I’ll come to that):
2nd, you need to be aware of the concept of the Commutative property. In various realms of math the concept of commutativity means, that you can exchange the order of operands or operators, without changing the final result. Prime examples for commutative operations are addition and multiplication:
a + b = b + a
a * b = b * a
By contrast, subtraction and division are not commutative:
a - b ≠b - a
a : b ≠b : a
In that light, the sequence of translation and rotation is not commutative. The results of a switch of sequence results in decidedly different outcomes:
Note, how in both variants the rotation is always performed about the coordinate origin, which is why I’d call the coordinate origin the “sweet spot” of rotation.
Coming back to @PavelBoytchev 's cool magic trick: if you peek behind the curtain, by inserting an AxesHelper at the coordinate origin, as a static reference geometry:
and then do some panning and rotating around you’ll see, that the geometry always remains centered about the sweet spot at the coordinate origin.
@PavelBoytchev 's rotation does
not involve an off-center geometry. The off-center-ness is being
simulated by panning the camera away from the center (see my first illustration in this post).
What’s the problem with this approach, you may ask? Really nothing much, as long as you limit yourself to
just one (1) off-center object which you want to rotate. As soon as you want to rotate two or more off-center objects, Pavel’s approach falls flat on its face. Because the “sweet spot” exists only
once.
I still think, that the TransformControls approach as linked by @Manthrax is the way better approach. But that’s stuff for a continuation post …
Sneak preview: you barely scratched the surface of the power displayed in that linked example.