Jump to content

Manually managing octrees


fenomas
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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