fenomas Posted March 30, 2015 Share Posted March 30, 2015 Hi, Considering a minecraft-style world, where "chunks" of static scenery are created and destroyed as the user moves around: Is it possible to manually manage the scene's octrees in order to keep picking fast? Notionally, I want to tell BJS: "Okay, I'm adding 50 meshes but they are all inside the following bounding box, so add a top-level octree and assume they're all in it." And then later: "Ok, everything in the octree I added before is now gone." Obviously I need to avoid processing the whole scene when doing this. Is this possible, or more broadly, is it the correct approach? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 30, 2015 Share Posted March 30, 2015 You can easily pick an OctreeNode and add whatever you want inside. The Octree structure is pretty simple (I hope:)) Quote Link to comment Share on other sites More sharing options...
fenomas Posted March 31, 2015 Author Share Posted March 31, 2015 You can easily pick an OctreeNode and add whatever you want inside. The Octree structure is pretty simple (I hope:)) 1. Do you mean OctreeBlock? 2. Are there any docs/code samples? From the API I can see vaguely what's going on but many details are unclear. 3. Once you construct an octree how do you tell the scene to use it? Only API I can find is the one for auto-creating one. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 31, 2015 Share Posted March 31, 2015 1. Yes sorry2. There is an usage doc here: http://doc.babylonjs.com/page.php?p=225613. If an octree is defined, the scene will automatically use it:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/babylon.scene.ts#L1179 Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 1, 2015 Author Share Posted April 1, 2015 Thanks for the replies As for docs, I meant are there any code samples involving manual creation of Octree or OctreeBlock instances - the docs only cover automatic creation. For example, both classes take in a creationFunc parameter, but what is it meant to be doing? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 1, 2015 Share Posted April 1, 2015 You're right this section need more doc Here are examples of the creationFunc:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Culling/Octrees/babylon.octree.ts#L98https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Culling/Octrees/babylon.octree.ts#L104 Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 2, 2015 Author Share Posted April 2, 2015 Okay, by digging through the source I was able to get this working. For posterity, the code runs along these lines: // octree for whole scene var octree = new BABYLON.Octree() octree.blocks = [] scene._selectionOctree = octree // branch block for area from 0..100, 0..100, 0..100 var bmin = new BABYLON.Vector3( 0, 0, 0) var bmax = new BABYLON.Vector3(100, 100, 100) var branch = new BABYLON.OctreeBlock(bmin, bmax) branch.blocks = [] octree.blocks.push(branch) // leaf block for area from 0..25, 0..25, 0..25 var min = new BABYLON.Vector3( 0, 0, 0) var max = new BABYLON.Vector3(25, 25, 25) var leaf = new BABYLON.OctreeBlock(min, max) branch.blocks.push(leaf) // add meshes to leaf leaf.entries.push(myMesh) DK: Having gotten it working, it didn't actually turn out to help performance like I'd thought...But I'll ask you about that in a separate thread. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 2, 2015 Share Posted April 2, 2015 feel free to add this to the documentation page if you will 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.