I have a class that extends Mesh and makes extensive use of the bounding box world properties. (.extendSizeWorld,.minimumWorld,.maximumWorld,centerWorld). I don’t have a good sense of the best way to make sure they are not stale. Right now I am extending everything that affects these properties so I can update cached boundinginfo but this is a NASTY way to do things.
Any thoughts about doing this with observables? Or any other suggestions?
The easiest way is probably to override the AbstractMesh._updateBoundingInfo function, because it is only called when the bounding info needs to be updated (ie. when it is dirty due to past operations).
Oh man. Hear ya. I used in live in the East Bay near San Francisco and the bread, pastries and coffee there are superb! I can get good coffee here. We have a few independent roasters. But no top-notch bakers, I’m afraid.
public _updateBoundingInfo(){
const mesh = super._updateBoundingInfo();
// don't do this
//this.bounding= this.getBoundingInfo().boundingBox;
// do this
this.bounding= this._boundingInfo!.boundingBox;
return mesh;
}
Calling getBoundingInfo in my override recurses, I think. Does this mean that the zillion places where I go:
mesh.refreshBoundingInfo();
const boundingBox = mesh.getBoundingInfo().boundingBox;
are redundant? Need to give the docs a good read.
You should be able to remove all the code where you track a change in the bounding info and simply do what you need to do on a bounding info change in _updateBoundingInfo.
Yes, you should use this._boundingInfo instead of this.getBoundingInfo() in _updateBoundingInfo because calling this.getBoundingInfo() can lead to a call to _updateBoundingInfo (depending on the _boundingInfoIsDirty value).
No, this is how it should be done. getBoundInfo will only do some work if it’s necessary, otherwise it will return this._boundingInfo directly.
[EDIT] In fact, you can probably avoid calling refreshBoundingInfo (and save some perf) as you don’t pass parameters to it. If you want to take into account the skeleton / morph of the meshes, you would need to pass true for the corresponding parameter, and in that case you would need to call refreshBoundingInfo to be sure the computed bounding info takes these vertex changes into account.