[Bf-python] multi ray cast proposal

Kesten Broughton solarmobiletrailers at gmail.com
Sat Nov 26 04:49:10 CET 2011


Dima, are you still working on the multi-raycast idea?

I did some more digging.  Blender calls bullet to do the heavy duty work of
ray-casting.
I recall from my days working with a game team, there was a fair bit of
time spent reducing and optimizing the ray-casts cause it was slowing
things down.

Bullet does a raycast in two steps:

1.  Broadphase culling
2.  Ray intersections

In the broadphase, the octree of game objects is culled according to axis
aligned bounding boxes.  There are a lot of .cpp files involved and most of
the functions are inlined (optimization)
The end result is an array of likely candidates for intersection.  I'm not
sure yet, but i think the object list is ordered by aabbs so the nearest
candidate will get tested first.

In the second step, each object is tested for intersection.

Doing a multi-cast from python would inevitably require the broadphase
culling at every step.  For under say 20 objects that's probably ok. but if
you have, say, 100 objects, you really don't want to be doing the
broadphase cull 100 times.  It would be fun to do some profiling to find
out the ratio of step1/step2 as a function of n objects.

My guess is for most users, a python multicast would be fine.  But looking
forward for a game-engine solution, what we really want is for bullet to
give blender the object-kebab when the multi cast is called.

kesten

On Sun, Nov 20, 2011 at 3:19 AM, Dima Glibitsky <dima.glib at gmail.com> wrote:

> > I think this could be added as a helper function, written in python in
> > 'bpy_extras', see -
> >
> http://www.blender.org/documentation/blender_python_api_2_60_4/bpy_extras.object_utils.html
> >
> > It can just do multiple ray casts and step forward each time, casting
> > from a new point, this is all we would do if it was written in C.
> > eg:
> >  bpy_extras.object_utils.ray_cast_multi(..., limit=-1),  where -1 is
> > unlimited intersections. returns a list of results from ray_cast()
>
> That may be a viable option... But when proposing this, I was
> concerned about accuracy -- stepping forward may skip some polygons,
> if they intersect the ray almost (or exactly) at the same point.
>
> It would be even better if raycast could accept a Python callback
> function -- which can be used both for filtering and for collecting
> the required intersection data :)
>
>
>
> > As for a way to disable undo - calling operators from a script
> > shouldn't be calling undo. at least calling operators within an
> > operator wont undo.
>
> That doesn't seem to be the case: I created a new .blend, loaded
> Operator Simple from templates and changed main() function to this:
> [CODE]
> def main(context):
>    mode_prev = context.active_object.mode
>    bpy.ops.object.mode_set(mode='OBJECT')
>    bpy.ops.object.mode_set(mode=mode_prev)
> [/CODE]
> When I run the operator in editmode, "Toggle Editmode" is recorded in
> undo history (tested in 4950_bf_trunk_win32_r41956).
> The same thing seems to happen when calling other operators too (e.g.
> Join or Convert)
>
>
>
> > As for what you are requesting - a way to fake an ID selector, I'm not
> > sure about it, can see you might want it but think this adds too much
> > functionality into the UI, perhaps this could be done as a new
> > property type. bpy.props.* instead.
>
> I vote for new property type :-)
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>



-- 

Kesten Broughton
President and Technology Director,
Solar Mobile Trailers
kesten at solarmobiletrailers.com
www.sunfarmkitchens.ca <http://www.sunfarmkitchens.ca>
512 701 4209
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20111125/0b915aa3/attachment.html>


More information about the Bf-python mailing list