Jump to content

registerBeforeRender runs once


Pryme8
 Share

Recommended Posts

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 {
    . . .
}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...