SOP quadtrees

   2467   0   0
User Avatar
Member
51 posts
Joined: 10月 2006
Offline
I'm experimenting with spatial data structures in SOP. Briefly, I want to do the following:
1) given some polygonal geometry and some control parameters, apply a spatial partitioning scheme and store the resulting structure with the geometry;
2) visualize the generated structure;
3) perform queries against the structure and visualize the results;

I'm posting my solution below, so maybe someone would like to comment on this, or in case it will be useful for someone.

Some details:
This is all in the context of collision detection for static game environments.
That is, given collision model for a scene, I want to be able to generate acceleration structure, improve it interactively by simulating common types of collision queries and tweaking some parameters, then export the result for real-time use.
The attached scene uses quad-trees for simplicity, but the general idea is the same for other tree-like structures - octrees, kd-trees, BSP and all sorts of BVH. Basically, the biggest question for me was how to encode these hierarchical structures in SOP.
My solution encodes the tree using geometry attributes. New points are generated to represent tree nodes, polygon lists are encoded in existing primitives, some meta info is stored in detail attributes.

Initially, I was considering using Node.setUserData() available in Hou11, to associate a string-encoded tree with a node. But this attribute-based method seems to be better on every account, any comments on this?

Some illustrations:
SOP_qtree1: “Quad-tree Viz” is a SOP Python operator that generates quadtree for the input geometry, maximum depth for the tree can be selected here, it also provides some simple visualization by coloring polygons according to their depth in the tree (lighter color means deeper in the tree);
SOP_qtree2: view_lvl node is a Delete with simple expression that allow to visualize all polygons at particular level in the tree;
SOP_qtree3: “Quad-tree Check” is another Python operator that checks a sphere against the model, using generated quad-tree to select only those polygons that may be colliding with the sphere; “Check Color” is used to visualize polygons that pass the broad-phase test with the tree, “Hit Color” visualizes polygons the sphere actually intersects with. This node also records the number on polygons that passed the broad-phase test in “nbCk” detail attribute. The sphere can be moved around and results will be updated in real-time;

Attachments:
SOP_qtree1.jpg (99.1 KB)
SOP_qtree2.jpg (142.1 KB)
SOP_qtree3.jpg (114.4 KB)
qtree_test.zip (63.0 KB)

  • Quick Links