"""
def find_closest_point(obj, pos):
    x, y, z = pos
    points = obj.ActivePrimitive.Geometry.Points
    count = points.Count
    points = points.PositionArray
    xx, yy, zz = points
    delta = [((x-xx[i])**2 + (y-yy[i])**2 + (z-zz[i])**2) for i in
xrange(count)]
    return delta.index(min(delta))

"""

results:
# brad: 2380 in 0.0239490809458 sec.
# alan: 2380 in 0.00761895761661 sec.
# jojo: 2380 in 0.00452239920537 sec.

jo





2012/5/2 Jens Lindgren <jens.lindgren....@gmail.com>

> Nice find Alan!
>
> /Jens
>
> On Wed, May 2, 2012 at 8:25 PM, Alan Fregtman <alan.fregt...@gmail.com>wrote:
>
>> Nice response man!
>>
>> A good way to paste code safely is to highlight it first:
>> http://tohtml.com/python/
>>
>> then copy from the browser and paste into Gmail while Rich Formatting
>> is enabled.
>>
>>
>> On Mon, Apr 30, 2012 at 2:19 PM, jo benayoun <jobenay...@gmail.com>
>> wrote:
>> > Hi Ahmidou,
>> > looks quite nice ! :)
>> >
>> > For your problem, I would go in c by reproducing a kinda structure that
>> > mimic FCurves ones like the following.
>> >
>> > """
>> > struct bezfragments {
>> >     double cps[4][3];
>> >     uint_t interp;
>> > };
>> >
>> > struct motionpath {
>> >     constchar_t *source;
>> >     ushort_t color[3];
>> >     uint_t flags;
>> >     uint_t nbezfragments;
>> >     struct bezfragments *[1];
>> > };
>> > """
>> >
>> > A MotionPath as a FCurve is a fixed length array of bezier curves with
>> some
>> > extra informations like the object which is the source, the color of the
>> > path and some other flags for ui convenience (selection mode, ...).
>> > You have the choice to represent your bezier segments by  pairing
>> control
>> > points by 3 or by 4, I dont think it makes a huge difference.
>> > This system coupled with a "MotionPathManager" will avoid you to have to
>> > query the softimage API each time you need to redraw your viewport as
>> your
>> > datas are cached in memory.
>> > Also, by subscripting to any event like "siOnValueChange", you will be
>> able
>> > to rebuild a motion path targeting just what you need. Also a good
>> point for
>> > perfs.
>> > Anyways .... Here is a little pysnippet (I dont have the possibility to
>> > write it in C right now) ! It should I hope answer to your first
>> question !
>> > :)
>> >
>> > jo
>> >
>> >
>> > """
>> > # Im quite sure gmail will eat my indent efforts so take care about
>> that !
>> > # Each key for each params must have a buddy on the others axes.
>> > # Create a cube, animate its pos's being sure a key is set at the same
>> frame
>> > for the three axes.
>> > #
>> >
>> > import random
>> >
>> >
>> > class BezFragment(object):
>> >     cpoints = tuple()
>> >     interp = int()
>> >
>> > class MotionPath(object):
>> >     source = str()
>> >     color = tuple()
>> >     bezfragments = tuple()
>> >
>> >
>> > def build_axis_data(param):
>> >     keys = tuple(param.Source.Keys)
>> >     res = list()
>> >     bfrag = None
>> >     i = 0
>> >
>> >     while i < (len(keys)-1):
>> >             cp = list()
>> >
>> >             key = keys[i]
>> >             nextkey = keys[i+1]
>> >             cp.append(round(key.Value, 1))
>> >             cp.append(round(key.Time, 1))
>> >             cp.append(round(key.Value + key.LeftTanX, 1))
>> >             cp.append(round(key.Time + key.LeftTanY, 1))
>> >             cp.append(round(nextkey.Value - key.RightTanY, 1))
>> >             cp.append(round(nextkey.Time - key.RightTanX, 1))
>> >             cp.append(round(nextkey.Value, 1))
>> >             cp.append(round(nextkey.Time, 1))
>> >
>> >             bfrag = BezFragment()
>> >             res.append(bfrag)
>> >             bfrag.interp = key.Interpolation
>> >             bfrag.cpoints = tuple(cp)
>> >
>> >             i += 1
>> >
>> >     return tuple(res)
>> >
>> >
>> > def build_motion_path(siobj):
>> >     x = build_axis_data(siobj.Kinematics.Local.posx)
>> >     y = build_axis_data(siobj.Kinematics.Local.posy)
>> >     z = build_axis_data(siobj.Kinematics.Local.posz)
>> >
>> >     mp = MotionPath()
>> >     mp.source = siobj.FullName
>> >     mp.color = (random.randint(120, 255), random.randint(120, 255),
>> >                             random.randint(120, 255),
>> >                             )
>> >     mp.bezfragments = tuple(zip(x, y, z))
>> >     return mp
>> >
>> >
>> > def log_bezfragment(bfrag):
>> >     msg = "{0}:({1}, {2})---o ({3}, {4})  ({5}, {6})o---({7}, {8})\n" \
>> >                 "         \______________________________________/"
>> >     print msg.format("", *bfrag.cpoints)
>> >     return None
>> >
>> >
>> > def log_obj_motionpath():
>> >     for obj in Application.Selection:
>> >         mp = build_motion_path(obj)
>> >
>> >         print "source: {0}".format(mp.source)
>> >         print "mp-color: {0}".format(mp.color)
>> >         for bezf in mp.bezfragments:
>> >             print "\ncp"
>> >             for xyz in bezf:
>> >                 log_bezfragment(xyz)
>> >     return None
>> >
>> >
>> > log_obj_motionpath()
>> >
>> > """
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > 2012/4/30 Ahmidou Lyazidi <ahmidou....@gmail.com>
>> >>
>> >> I think I got it :)
>> >>
>> >>
>> >> 2012/4/30 Halim Negadi <hneg...@gmail.com>
>> >>>
>> >>> Looks awesome Ahmidou, can't wait to play with it.
>> >>> Cheers,
>> >>> H.
>> >>>
>> >>>
>> >>> On Mon, Apr 30, 2012 at 4:44 PM, Ahmidou Lyazidi <
>> ahmidou....@gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> Well, as soon as I have resolved the tangent handle stuff :) I'm sure
>> >>>> it's simple, but I can't get it...
>> >>>>
>> >>>>
>> >>>> 2012/4/30 Philip Melancon <philip.melan...@modusfx.com>
>> >>>>>
>> >>>>> This is looking amazing, do you have an idea of when/how you plan to
>> >>>>> release this nice little piece of animation goodness? I know that
>> the
>> >>>>> animators I work with would kill for something like this!
>> >>>>>
>> >>>>> Philip Melancon
>> >>>>> Lead Crowd TD
>> >>>>> Modus FX
>> >>>>>
>> >>>>>
>> >>>>> On 4/30/2012 10:30 AM, Xavier Lapointe wrote:
>> >>>>>
>> >>>>> Whoa, this is awesome.
>> >>>>>
>> >>>>> I feel some animators out there are probably jubilating right now :)
>> >>>>>
>> >>>>> No virus found in this message.
>> >>>>> Checked by AVG - www.avg.com
>> >>>>> Version: 2012.0.1913 / Virus Database: 2411/4969 - Release Date:
>> >>>>> 04/30/12
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Ahmidou Lyazidi
>> >>>> Director | TD | CG artist
>> >>>> http://vimeo.com/ahmidou/videos
>> >>>>
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Ahmidou Lyazidi
>> >> Director | TD | CG artist
>> >> http://vimeo.com/ahmidou/videos
>> >>
>> >
>>
>>
>
>
> --
> Jens Lindgren
> --------------------------
> Lead Technical Director
> Magoo 3D Studios <http://www.magoo3dstudios.com/>
>
>

Reply via email to