Notifications
Clear all
[Closed] Octree problem
Page 3 / 3
Prev
Jun 25, 2011 6:52 am
(
struct EasyNodeData (node, handle, intersects = #())
/********** create node set *********************/
with redraw off with undo off
(
delete objects
gc()
seed 1
t1 = timestamp()
m1 = heapfree
t0 = timestamp()
nodes = for k=1 to 10000 collect
(
n = box pos:(1000*(random [-1,-1,-1] [1,1,1])) length:(random 10 50) width:(random 10 50) height:(random 10 50) name:("b" + k as string)
EasyNodeData node:n handle:(getHandleByAnim n)
)
format "CREATE... nodes:% time:% memory:%
--
" nodes.count (timestamp() - t1) (m1 - heapfree)
gc()
select (for n in nodes collect n.node)
)
/********** find intersections ******************/
t1 = timestamp()
m1 = heapfree
bmin = selection.min
bmax = selection.max
cell = pow (1.0*nodes.count) (1./3)
cell_size = cell*[1,1,1]/(bmax - bmin)
local buffer = #()
for n in nodes do
(
dmin = 1 + (n.node.min - bmin)*cell_size
dmax = 1 + (n.node.max - bmin)*cell_size
dmin = [floor dmin.x, floor dmin.y, floor dmin.z]
for x = dmin.x to dmax.x do
for y = dmin.y to dmax.y do
for z = dmin.z to dmax.z do
(
if buffer[x] == undefined do buffer[x] = #()
if buffer[x][y] == undefined do buffer[x][y] = #()
if buffer[x][y][z] == undefined do buffer[x][y][z] = #()
append buffer[x][y][z] n
)
)
t2 = timestamp()
m2 = heapfree
format "BUFFER... nodes:% time:% memory:% cell:%
" nodes.count (t2 - t1) (m1 - m2) cell
local source, target
local done = #()
for x = 1 to buffer.count where buffer[x] != undefined do
for y = 1 to buffer[x].count where buffer[x][y] != undefined do
for z = 1 to buffer[x][y].count where buffer[x][y][z] != undefined do
(
for n=1 to buffer[x][y][z].count-1 do
(
source = buffer[x][y][z][n]
for k=n+1 to buffer[x][y][z].count do
(
target = buffer[x][y][z][k]
if (intersects source.node target.node) do
(
append source.intersects target
append target.intersects source
)
)
)
)
t3 = timestamp()
m3 = heapfree
format "COMPUTE... nodes:% time:% memory:% cell:%
" nodes.count (t3 - t2) (m2 - m3) cell
format "COMPLETE... nodes:% time:% memory:%
" nodes.count (t3 - t1) (m1 - m3)
intersected = for n in nodes where n.intersects.count > 0 collect n.node
format " intersected:%
" intersected.count
clearselection()
)
probably the optimal grid cell size might have more sense.
EDIT:
the node’s handle which I use in the structure doesn’t make any sense it this case. It’s a remainder of some other experiments :).
Page 3 / 3
Prev