let mesh = new Mesh(geometry, material);
mesh.onBeforeRender = () => console.log("in onBeforeRender function");
but the log line is only printed once when the mesh first gets into the camera viewing frustrum.
I expect this to be called every time I do renderer.render(scene, camera). Or does “render” mean something else? (I guess if I want to do something before renderer.render(), I don’t need Three’s help.)
Thanks for the reply. Yes the object is still visible. The objects in my scene do not move normally but the camera does. When I change some property of the object (like .color), the onBeforeRender gets called again.
(I am now just keeping track of tasks that need to be called before rendering in my own code.)
@jancellor we won’t be able to help you further without seeing your code. Can you share a minimal live example that demonstrates your problem? e.g. using Codepen or JSfiddle.
So I had a text element that I wanted to hide depending on the zoom level, as is typical in a mapping application. So just set mesh.visible accordingly in the onBeforeRender function right? Except an invisible mesh doesn’t render, obviously.
Actually, this would have been the same thing: if an object is rejected (at render time) because not in the frustum, onBeforeRender / onAfterRender won’t be called for it.