1

I'm the founder of SceneMax - a 3D scripting language since 2005. I want to add a scene rendering using one mesh object built with 3d package like 3ds max and split by octree algorithm for optimized performance.

Do you know where can I find an algorithm which takes a mesh .X file, splits it to nodes (octree) and knows how to render it? I want to add it to my engine. The engine is open source (google for SceneMax if you're interested).

tshepang
  • 12,111
  • 21
  • 91
  • 136

2 Answers2

4

There are several variations, but when building an octree, one approach is this:

  1. Start with one node (ie. a cube) encompassing your entire scene or object being partitioned.
  2. For each element in your scene/object (eg. a mesh, or a poly, or whatever granularity you're working to):
    1. Check if that element fits completely inside the node.
    2. If yes, subdivide the node into eight children, then recursively do Step 2 for each child.
    3. If no, then continue to the next node until there are no nodes left.
    4. Add the element to the smallest node that can contain it.

It's also common to stop recursion based on some heuristic, like if the size of the nodes or the number of elements within the node is smaller than a certain threshold.

See this Flipcode tutorial for some more details about building the octree.

Once you have the octree, there are several approaches you can take to render it. The basic idea is that if you can't "see" a node, then you can't see its children either, so everything inside that node (and its children) don't need to be rendered.

Frustum culling is easy to implement, and does the "can you see it?" test using your view projection's frustum. Gamedev.net has an article discussing frustum culling and some other approaches.

You can also go further and implement occlusion culling after frustum culling, which will let you skip rendering any nodes which are covered up by nodes in front of them, using the z-buffer to determine if a node is hidden. This involves being able to traverse your octree nodes from closest to furthest. This technique is discussed in this Gamasutra article.

MandyK
  • 1,201
  • 10
  • 11
  • 1
    I think the tricky part are the borders between two cubes. What do you do, if a poly is partially in two or more cubes? You can either add the poly to each of the involved cubes, decide that the poly belongs to one cube based on a measurement (like the area) or you can split the poly. – Stefan Schmidt Jan 12 '09 at 00:00
  • The gamedev.net link is dead – Gerard Sep 05 '14 at 14:03
0

It's important to first consider the types of mesh files that you will be having to support.

There are effectively 3 different kinds of objects. 1. Open natural terrain. This fits with a quadtree very well as an octree brings complexity that is unnecessary. There's little reason to introduce a 3rd dimension if it won't give you much performance gain. 2. Open terrain with many tall objects. This fits into an octree very well as an octree allows you to remove things on the vertical axis from rendering and a scene such as this has a lot of those. I honestly can't name any that fit into this off the top of my head. 3. Enclosed spaces or character models/static meshes. This fits very well into BSP trees. A BSP tree allows for objects that are fully onscreen, or enclosed spaces to only render as many polygons as needed.

I would recommend adding 1 and 3, assuming 1 is even a model type you need to support. #3 is very standard for first person shooters or character models and adding support for that may give you the best bang for your buck. The overall idea is to remove as much geometry from a render as possible, thus a quad tree for 95% of the outdoor terrain players game worlds have is perfect. An octree has uses, but less than you may think.

Each of these algroithms are relatively easy to write. For example I wrote an octree in 3 hours many years ago. Generally these are processed at load time, pieces of geometry being added to each square (if quad/octree) or to the tree (if BSP) and then rendering follows suit. There are a lot of great articles out there via a quick Google search that I will leave for your research. A quick note is that BSP tree's also have the ability to handle collision detection and are ideal candidates for character models and static meshes. Thus this is an algorithm that I would recommend taking your time on in order to ensure it is flexible enough for multiple uses.

Charles Clark
  • 153
  • 1
  • 2
  • 8