Pryme8 Posted March 30, 2016 Share Posted March 30, 2016 What would cause a registerBeforeRender() to only fire once? I thought this is how to set up something that fires before every frame render. Quote Link to comment Share on other sites More sharing options...
OMAR Posted March 30, 2016 Share Posted March 30, 2016 registerBeforeRender() DOES fire before EVERY frame . Can you please show us how you actually implemented this function? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted March 30, 2016 Share Posted March 30, 2016 Never had a problem. FYI, there are 2 types of BeforeRender, ones on scene & each mesh can have one. I actually no longer use a mesh version for morphing & skeletal interpolation. Reason is a mesh beforerender runs for every camera that the mesh can be scene in every frame. Running more than once per frame can cause problems for me. This is for an extension though, so an application will probably know in advance how many cameras there are gonna be. Since have sinned by not providing a PG, no clue on your problem. Here is the constructor of my QI.Mesh subclass & first line of render method: /** * @constructor - Args same As BABYLON.Mesh, except that using a source for cloning requires there be no shape keys * @param {string} name - The value used by scene.getMeshByName() to do a lookup. * @param {Scene} scene - The scene to add this mesh to. * @param {Node} parent - The parent of this mesh, if it has one * @param {Mesh} source - An optional Mesh from which geometry is shared, cloned. * @param {boolean} doNotCloneChildren - When cloning, skip cloning child meshes of source, default False. * When false, achieved by calling a clone(), also passing False. * This will make creation of children, recursive. */ constructor(name: string, scene: BABYLON.Scene, parent: BABYLON.Node = null, source?: Mesh, doNotCloneChildren?: boolean) { super(name, scene, parent, source, doNotCloneChildren); if (source && source._shapeKeyGroups.length > 0) throw "QI.Mesh: meshes with shapekeys cannot be cloned"; this._engine = scene.getEngine(); this._povProcessor = new PovProcessor(this, false); // do not actually register as a beforeRender, use this classes & register below // tricky registering a prototype as a callback in constructor; cannot say 'this.beforeRender()' & must be wrappered var ref = this; // using scene level before render, so always runs & only once per frame, incase there are multiple cameras scene.registerBeforeRender(function(){ref.beforeRender();}); } // ============================ beforeRender callback & tracking ============================= public beforeRender() : void { . . . } Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2016 Author Share Posted March 30, 2016 http://www.babylonjs-playground.com/#22OE8Q#12 A lot of comments are missing because this is just a temporary playground, the real one I am keeping clean and making sure my incremental values of the pg are set so the person following my tutorial can just go to the next one. so if some of this seems like it its extra ignore it. The line where the register is 122 Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 30, 2016 Share Posted March 30, 2016 You need to input a function, not a function call. Try without the () . What you do is call this function and register the value returned from it. So it's only called once Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2016 Author Share Posted March 30, 2016 Thank you Raan this worked Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2016 Author Share Posted March 30, 2016 how do I pass arguments with it then? Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 30, 2016 Share Posted March 30, 2016 Well, this is a javascript question function loop(arg) { return function() { console.log(arg); } } scene.registerBeforeRender(loop("foo")); You could also use the bind method. jerome 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 30, 2016 Author Share Posted March 30, 2016 thats brilliant. wow man wow. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.