Monday, January 26, 2009

Flash 10, 3D and BSP Tree

Used a Binary Space Partitioning (BSP) Tree to sort the order of the triangles to be drawn on the screen using Flash 10 3D API.

http://psalmhundred.net/experiment/flash3d/coffee_table_bsp/
BSP Tree Component: BSPTree.swc
Updated BSPTree.swc: 01 Feb 2009. Resolved some bugs.
02 Feb 2009. optimised code
24 Feb 2009. changed code. using timer-based instead of loops to add triangles to tree nodes. to avoid script timeout limit.

1) Import package
import dmp.*;
2) Create a BSPTree object
var tree:BSPTree = new BSPTree();
3) Add the vertices and uvt data of the model
tree.add(vertices, uvt);
4) Sort by model composite transform or by camera location
tree.sortByModelTransform(compositeM, outVertices, outUVT);
OR
tree.sortByCameraLoc(cameraLoc, outVertices, outUVT);
5) Transform & project outVertices and outUVT to draw model

Source:
BSP Tree library
BSP Tree sample program

4 comments:

Unknown said...

Hello! I just found your BSP implementation, and it works very well!! I was wondering if you planed to share the source as well, and not just the SWC. Anyways, thanks a lot for this.

Boon said...

You are welcome, Arnaud :)
I will consider your suggestion putting up the source code. it's been more than a year since i touch this code. gotta tidy up and comment properly before putting it up.
thanks.

Ben said...

heya!

looks awesome!

have been looking at testing bsp sorting in my 3d engine but hadn't been able to get anything working correctly! so well done for getting this up and running! I wanted to plug your swc into my engine to try it out but I don't think they are compatible. If you did release the source that would be hugely appreciated as I think I wouldn't have to change much to get it compatible!

cheers for sharing your efforts!

Ben

Boon said...

thanks.