Or take it a step further:
I would consider migrating the whole library to typescript and adding the rxjs library.
With rxjs you will be able to subscribe to different changes such as position changes etc
Also you will be able to know which type of messages are emitted from different events and be able to thorttle messages and buffer them
As mentioned here #15545 three.js
will not be converted to TS. The library provides type declaration files for the core and example JS code which should be sufficient for TS users.
Also you will be able to know which type of messages are emitted from different events and be able to thorttle messages and buffer them
You can implement the same logic with JS, just differently (e.g. put the message type information in the event object). However, I don't think this stuff is necessary in the engine.
Ha, interesting discussion. At some point three.js started to create actual objects and send them as events, right now they are of form:
{
type:"add"
}
but the reason why I know is, I re-populate my scene every frame, because of custom culling mechanism, and I found, via profiling, that three.js was generating a decent amount of 🗑 garbage, so I thought to myself 🤔
"hey, three.js is usually super good at keeping GC to a minimum, what gives?"
turns out - new event objects. Now I bypass scene.add
and manipulate children
property directly.
My point is - I would prefer not to see more of an event framework in three.js, it's just about too heavy from my perspective as is. 🏋️♀️
"hey, three.js is usually super good at keeping GC to a minimum, what gives?"
turns out - new event objects.
This is interesting -- I hadn't considered that. Classes like OrbitControls create objects once and reuse them to dispatch events. It seems like that would be a reasonable improvement to the add
and remove
events in Object3D?
It seems like that would be a reasonable improvement to the add and remove events in Object3D?
I think so, too. I'm not sure if there was a specific reason to create new objects. Reusing event objects for both methods seems to make more sense.
Anyway, we've got sidetracked. The issue itself can be closed.
The idea of reusing event objects is important and should be discussed in another topic (it has nothing to do with TS).
Most helpful comment
This is interesting -- I hadn't considered that. Classes like OrbitControls create objects once and reuse them to dispatch events. It seems like that would be a reasonable improvement to the
add
andremove
events in Object3D?