######################################################################
#
#       PointEyes.py
#
#       Copyright (c) 2003 C. Cigas
#
#       craig@castironflamingo.com
#
#       Create a new prop and point the selected figure's eyes to it.
#
#       The selected figure must have a head, right eye and left eye
#       otherwise we bail.
#
#       If you want to change the target prop edit this line to point
#       at a different prop preset:
#
prp = ":Runtime:Libraries:Props:Prop Types:Ball.pp2"
#
#       Don't mess with anything below this line ...
#
import poser

fig = poser.Scene().CurrentFigure()
try:
        acth = fig.Actor("Head")
        actl = fig.Actor("Left Eye")
        actr = fig.Actor("Right Eye")
#
#       Get or create the target prop
#
        try:
                actp = poser.Scene().Actor(fig.Name() + " Eye Target")
        except:
                actd = []
                for act in poser.Scene().Actors():
                        actd.append(act.Name())
                poser.Scene().LoadLibraryProp(prp)
                for act in poser.Scene().Actors():
                        try:
                                actd.remove(act.Name())
                        except:
                                actp = act
                                break
                actp.SetName(fig.Name() + " Eye Target")
#
#       Parent, pointat and make it invisible
#
        actp.SetParent(poser.Scene().Actor("UNIVERSE"))
        actl.PointAt(actp)
        actl.Parameter("Point At").SetValue(1)
        actr.PointAt(actp)
        for mat in actp.Materials():
                mat.SetTransparencyMin(1)
                mat.SetTransparencyMax(1)
                mat.SetAmbientColor(0,0,0)
                mat.SetSpecularColor(0,0,0)
        actl.SetDisplayStyle(poser.kDisplayCodeTEXTURESHADED)
        actr.SetDisplayStyle(poser.kDisplayCodeTEXTURESHADED)
except:
        pass
