from pathlib import Path
import poser
import wx
scene = poser.Scene()
letsdebug = False
def isvalid( actor , bodypart=False ): # a modified function of a Snarlygribbly routine
if not actor is None:
n = actor.Name().lower()
if n.endswith("con") or n.endswith("con 1"):
return False
data = [
'atmosphere','background','bodymorphs','centerofmass',
'faceroom','focusdistancecontrol','ground','grouping',
'universe'
]
for d in data:
if d in n:
return False
if actor.IsZone() or actor.IsBase() or actor.IsDeformer():
return False
if actor.IsLight() or actor.IsCamera():
return False
if actor.IsProp() or ( actor.IsBodyPart() and bodypart == True ):
return True
return False
def get_geometry( item ):
geomName = item.GeomFileName()
if (geomName and not geomName == ""):
geom = Path( geomName ).stem
geompath = Path( geomName ).parent.resolve()
return geom, geompath
def get_parent( item, parent = None ):
if item.IsFigure():
try:
parent = item.ParentActor()
except:
parent = None
if item.IsProp():
try:
parent = actor.Parent()
except:
parent = None
if letsdebug:
try:
print( f"{item.Name()}\n\t{parent.Name()}\t{isithair( item )}" )
except:
pass
if parent:
if parent.Name() == "Head" or parent.Name() == "Body":
return isithair( item, parent )
else:
return False
def isithair( item, parent = None ):
# set up list of valid materials
validmats = ( "bangs", "skullcap", "hair" )
# validnames = ( "hair", "hr" )
# set case independent names
itemname = item.Name().casefold()
parentname = parent.Name().casefold()
# check itemname and materials before relying on parent
if "hair" in itemname or itemname.startswith("hr"):
return True
if item.IsFigure():
for material in item.Materials():
if any( mat in material.Name() for mat in validmats ):
return True
if not parentname == "head" and not parentname == "Body":
return False
badnames = ("eye", "tongue", "teeth", "hat", "mask", "veil" )
try:
for actor in figure.Actors():
targetname = actor.InternalName().casefold()
return True if not any(badname in targetname\
for badname in badnames) else False
except:
if letsdebug:
print( item )
targetname = item.InternalName().casefold()
return True if not any(badname in targetname\
for badname in badnames) else False
for figure in scene.Figures():
hair = get_parent( figure )
if hair:
print(f"{get_geometry( figure )[0]}\n\t{get_geometry( figure )[1]}")
if letsdebug:
print ( figure.Name(), hair, figure.ParentActor().Name() )
for actor in scene.Actors():
hair = get_parent( actor )
if hair and isvalid( actor ):
print(f"{get_geometry( actor )[0]}\n\t{get_geometry( actor )[1]}")
if letsdebug:
print ( actor.Name(), hair, actor.Parent().Name() )