dulimarta / spherical-easel

https://spherical-easel.vercel.app
Other
3 stars 7 forks source link

Alternative to forcing an update to two instance #92

Open dickinson0718 opened 3 months ago

dickinson0718 commented 3 months ago

This is really an observation and not a issue -- something to think about. I know that I don't time this summer and I don't think you do either.

This might be better than EventBus.fire("update-two-instance",{}) when updating plottable objects that depend on other twoJs objects that must be updated before their dependent objects. We were having trouble updating the polygon fill because we needed the segments to be updated correctly by the two instance. There is a way to bind an event listener to an two js event.

Here is the (totally unhelpful) documentation.

Here is an example.

In the example, notice how the 'update' event is bound to the function in

two.bind('update', function(frameCount, timeDelta) {

  if (typeof timeDelta !== 'number') {
    return;
  }

  tot += timeDelta/300
  for (let i = 0; i < two.scene.children.length; i++) {
    const child = two.scene.children[i];
    child.rotation +=  timeDelta / 3000;
    child.height =  200 + 100*Math.sin(tot); 
    child.width =  200 - 100*Math.sin(tot); 
  }

});

We could bind a polygon.update() function to the update event and we can unbind it as well. We would have to manage what was bound to 'update` so that we don't slow down the execution.

I wrote this note so that next summer, I'll remember to think about this.