Static Batching for additive scene loading

Hi PlayCanvas gang,

How can one have static batching when loading additional scenes?

I have forked this project: https://developer.playcanvas.com/zh/tutorials/additive-loading-scenes/

Then I have set one van to static batching and the other van to dynamic batching. The static batched van doesn’t get rendered when loading the van scene additive.

Observe:

Here is the project: https://playcanvas.com/project/723629/settings

Any hints appreciated,
Rene

1 Like

Issued ticket on engine GIT: https://github.com/playcanvas/engine/issues/2455

Hi @dexter_deluxe,

Check my answer here: https://github.com/playcanvas/engine/issues/2455

Running the generate method from console or within the load function doesn’t resolve the issue.

SceneManager.prototype._loadSelectedScene = function () {
    if (!this._loadingScene) {
        this._loadingScene = true;
        this._loadSceneButton.active = false;
        
        // Remove the current scene that is loaded
        if (this.sceneRootEntity.children.length > 0) {
            // Assume that there is only one entity attached to the sceneRootEntity
            // which would be the loaded scene
            this.sceneRootEntity.children[0].destroy();
        }
    
        var self = this;
        var scene = this.app.scenes.find(this.sceneFilenameStrings[this._selectedSceneIndex]);
        this.app.scenes.loadSceneHierarchy(scene.url, function (err, loadedSceneRootEntity) {
            if (err) {
                console.error(err);
            } else {
                loadedSceneRootEntity.reparent(self.sceneRootEntity);    
                self._loadingScene = false;
                self._loadSceneButton.active = true;
                
                console.log("BATCHER: GENERATE");
                self.app.batcher.generate();
            }
        });
    }
};

It seems the issue isn’t with batching, but with the Static model component flag. There is some optimization there that breaks batching. If you disable that flag batching works as expected:

image

I am updating the github issue.

1 Like

Btw running the .generate() method indeed may not be required in your case since you are enabling those entities for the first time.

So I think the batcher will run once on its own.

1 Like

Hey @Leonidas,

just for clarification, could you tell me when it would be necessary to call .generate()? I’m assuming after spawning new models dynamically? We are also running a system, which disables/enables submeshes for collision and rendering, do you have any input on whether or not this might break batching?

Greetings,
Ciaviel

Hi @Ciaviel,

So I’ve run some tests to be sure how the batcher behaves now, it seems the engine has been updated at some point to automate some things. Making the following example work a bit differently:

https://developer.playcanvas.com/en/tutorials/static-batching/

If you run it, and open the profiler, you will notice that when you create new boxes they are automatically batched. There is no need to press the create batches button, as the engine now calls the batcher generate() method for any entity with a model component that is assigned to a batch group.

Same when enabling/disabling those entities, the batcher reruns automatically. You can confirm the fact by watching the profiler, the batching time will increase when doing that:

2 Likes