User rotatable object TS class?

This is more of a TypeScript question I guess.

I want to make a Rotatable or RotatableObject class in TS, such that users can rotate it around a specified axis using swipe or mouse click and drag.

I found this on the old forum:


https://playground.babylonjs.com/#1HXY4E#3

What would be the best way to approach this - Rotatable extends TransformNode class?

Is there a better way if I want it to be general purpose and modular?

I was having a similar problem in Typescript. What I’ve found the most success with is custom behaviours Use Mesh Behaviors (eg. dragging) - Babylon.js Documentation. You may have luck with the builtin behaviours being all you need.
I find this gives a really nice generic and re-usable way to add interactivity to a scene without having to extend base Babylon classes (implementing interfaces is much simpler in my opinion).

1 Like

Yup as @DisownedWheat said, this is definitely smthg I would resolve with behaviors to provide all the extra flexibility you need.

1 Like

Thanks @DisownedWheat and @sebavan. I played around with behaviours and that got me half the way but then I realized gizmos, which use behaviors, do most of what I want already, and there’s an option to customize them with my own geometry, so I just made a transparent sphere larger than my object and then rotationGizmo.setCustomMesh(transparentSphere).

1 Like