I have a scene where I manually create and manage the selection octree, but since moving to BJS 4.0 the octree seems to be ignored - nothing gets culled, regardless of how I construct the octree or octreeBlocks.
My code basically looks like this:
// at init
scene._selectionOctree = new Octree(() => {})
scene._selectionOctree.blocks = []
// ... later when creating a chunk of world
var min = new Vector3( ... )
var max = new Vector3( ... )
var block = new OctreeBlock(min, max, undefined, undefined, undefined, () => {})
scene._selectionOctree.blocks.push(block)
From source diving it looks like maybe I need to add some kind of component to scene to tell BJS that octrees are being used? But I can’t find any sample code doing this, or docs on what changed.
A repo wouldn’t help here. ES6 Babylon apparently requires some new extra step to use a selection octree; an empty repo wouldn’t help figure out what it is.
Oh I see, you do not rely at all on the createOrUpdateMecanism in your case. So the automatic reference through createOrUpdateSubmeshesOctree or createOrUpdateSelectionOctree is not called.
Actually the code called in both those functions is:
let component = scene._getComponent(SceneComponentConstants.NAME_OCTREE);
if (!component) {
component = new OctreeSceneComponent(scene);
scene._addComponent(component);
}
Do you want me to wrap it in a public function for you ?
No idea - I just want to use a selection octree where I manually create and position the blocks. Is that currently possible to do with public methods, or is it not intended to be?
I understand what you were suggesting, but it looks to me like 4.0 has introduced some kind of “component” mechanic, that seems to touch lots of different features. Do other such features already have some way of getting initialized?
FooComponent.RegisterForScene would be fine here, but it would be best if there’s a consistent way of dealing with all “componentized” features.
They are all automatically initialized when you use a feature from its embedded method. Unfortunately using Octree manually is a bit edge case as it requires the component but can not initializes automatically as you are doing all the rest manually. It is probably only an issue with the octree system.