xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
714 stars 286 forks source link

Trigger transform event for model position or rotation #1631

Open hamza-hajji opened 1 month ago

hamza-hajji commented 1 month ago

Is your feature request related to a problem? Please describe. I often want to listen to transform (position, rotation...) change for a model, but I don't find a triggered event for that

Describe the solution you'd like Maybe an event, like eye for camera that listens to eye property change, for example

const sceneModel = xktLoader.load({
  id: "myModel",
  src: "./models/whatever.xkt",
  saoEnabled: true,
  edges: true,
  dtxEnabled: true,
});

sceneModel.on('position', (newPos) => {
// do my thing
})
sceneModel.on('rotation', (newPos) => {
// do my thing
})
sceneModel.on('scale', (newPos) => {
// do my thing
})

Describe alternatives you've considered I make it work currentyl with rendered event

viewer.scene.on('rendered', () => {
  // sync models with their position and rotation
});

But it causes a lot of lagging even after debounce

Thank you

MichalDybizbanskiCreoox commented 4 weeks ago

Hi @hamza-hajji , Michał from Creoox here. Thank you for your feature request, we'd like to understand the motivation better. What would be a use-case for this user-initiated state change broadcast?

hamza-hajji commented 3 weeks ago

Hi Michał, thanks for your response, about the motivation: based on your linkedin post (https://www.linkedin.com/posts/xeolabs_testing-xeokits-upcoming-dynamic-model-realign[…]tm_content=feedcontent&utm_medium=g_dt_web&utm_campaign=copy) we would like to listen the event when a user moves a model to align it in order to display for example arrow the direction the user move the model

If we align the models every time we move a model with model.position = [...], we have to copy paste it all over the codebase, it's better to listen to that change once, and align all the time

model.on('position', (newPos) => {
  alignedModel.position = newPos;
})