def readfile(self, filename): if filename[-4:] == ".cfg": self.avatar = Piavca.Avatar(filename[:-4]) else: Piavca.XMLMotionFile.parse(filename) if self.avatar == None: print self.getAvatarNames() print self.getMotionNames() if len(self.getAvatarNames()) > 0: self.setAvatar(self.getAvatarNames()[0]) self.frontend.update()
def readMotions(motions): mots = [] element_list = [] child_motion_list = [] for motion in motions: if motion.nodeType == minidom.Node.ELEMENT_NODE: #print "current node", motion.nodeName if motion.nodeName == "Avatar": name = str(motion.getAttribute("name")) if name == "": name = str(motion.getAttribute("Name")) if name == "": print "Avatar statement without a name" position = str(motion.getAttribute("position")) if position == "": position = str(motion.getAttribute("Position")) if position != "": position = str(position).strip() position = stringToValueList(position) position = ValueListToVec(position) else: position = Piavca.Vec() rotation = str(motion.getAttribute("rotation")) if rotation == "": rotation = str(motion.getAttribute("Rotation")) if rotation != "": rotation = str(rotation).strip() rotation = stringToValueList(rotation) rotation = ValueListToQuat(rotation) else: rotation = Piavca.Quat() avatar = Piavca.Avatar(name) #print "loaded avatar", name, position, rotation avatar.setRootPosition(position) avatar.setRootOrientation(rotation) for child in motion.childNodes: if child.nodeType != minidom.Node.ELEMENT_NODE: continue if child.nodeName != "Event": #print "expected a Event statement as a child of an avatar but got", child.nodeName continue name = str(child.getAttribute("name")) if name == "": name = str(child.getAttribute("Name")) if name == "": print "Event statement without a name" Piavca.addEvent(avatar, name) elif motion.nodeName == "Motion": #print "found a motion statement", motion for i in range(motion.attributes.length): #print motion.attributes.item(i).name, motion.attributes.item(i).nodeValue unknownAttrs = [] if motion.attributes.item(i).name != "name": unknownAttrs.append( (motion.attributes.item(i).name, motion.attributes.item(i).nodeValue)) name = str(motion.getAttribute("name")) if name == "": name = str(motion.getAttribute("Name")) if name == "": print "Motion statement without a name" else: #print "*"+name+"*" mot = Piavca.getMotion(name) #print mot if mot == None: print "could not find motion", name else: mots.append((mot, str(motion.nodeName), unknownAttrs)) #print "mots", mots elif motion.nodeName == "File": name = str(motion.getAttribute("name")) filename = str(motion.getAttribute("filename")) Paivca.loadMotion(name, filename) elif motion.nodeName == "Keyframes": for i in range(motion.attributes.length): #print motion.attributes.item(i).name, motion.attributes.item(i).nodeValue unknownAttrs = [] if motion.attributes.item(i).name != "name": unknownAttrs.append( (motion.attributes.item(i).name, motion.attributes.item(i).nodeValue)) name = str(motion.getAttribute("name")) mot = Piavca.KeyframeMotion() mot.thisown = False for child in motion.childNodes: if child.nodeType != minidom.Node.ELEMENT_NODE: continue if child.nodeName != "Key": print "expected a key statement as a child of a keyframe motion but got", child.nodeName continue key_type = str(child.getAttribute("type")) key_value = str(child.getAttribute("value")) key_time = float(child.getAttribute("time")) key_joint = str(child.getAttribute("joint")) if key_type == "FLOAT" or key_type == "Float" or key_type == "float": key_joint = Piavca.Core.getCore().getExpressionId( key_joint) else: key_joint = Piavca.Core.getCore().getJointId(key_joint) if key_joint == Piavca.Core.getCore().nullId: raise ValueError("Unknown Joint Id " + str(child.getAttribute("joint"))) Piavca.Core.getCore().addJointNameSet([key_joint]) if key_type == "FLOAT" or key_type == "Float" or key_type == "float": if mot.isNull(key_joint): mot.addFloatTrack(key_joint, 0.0) key_value = float(key_value) mot.setFloatKeyframe(key_joint, float(key_time), key_value) if key_type == "VEC" or key_type == "Vec" or key_type == "vec": if mot.isNull(key_joint): mot.addVecTrack(key_joint, Piavca.Vec()) valuelist = stringToValueList(key_value) key_value = ValueListToVec(valuelist) mot.setVecKeyframe(key_joint, float(key_time), key_value) if key_type == "QUAT" or key_type == "Quat" or key_type == "quat": if mot.isNull(key_joint): mot.addQuatTrack(key_joint, Piavca.Quat()) valuelist = stringToValueList(key_value) key_value = ValueListToQuat(valuelist) mot.setQuatKeyframe(key_joint, float(key_time), key_value) if name != "": Piavca.loadMotion(name, mot) else: try: #print "other motion types", motion.nodeName cl = getattr(Piavca, motion.nodeName) if type(cl) == types.TypeType and issubclass( cl, Piavca.Motion): #print "found motion type", motion.nodeName mot = cl() storedMotName = mot.getName() storedMotStr = str(mot) if mot == None: raise "could not create motion " + motion.nodeName continue mot.thisown = False unknownAttrs = [] for i in range(motion.attributes.length): if str( motion.attributes.item(i).name ) == "name" or str( motion.attributes.item(i).name) == "Name": name = str(motion.attributes.item(i).nodeValue) #print "========================motion name", name if name != "": Piavca.loadMotion(name, mot) continue attrName = motion.attributes.item(i).name attrValue = motion.attributes.item(i).nodeValue #print attrName, attrValue if not setAttribute(mot, attrName, attrValue): unknownAttrs.append((attrName, attrValue)) child_motion_list.append((mot, motion.childNodes)) mot.create() mots.append((mot, str(motion.nodeName), unknownAttrs)) else: raise str( motion.nodeName ) + " is not a motion type, its type is: " + str( type(cl)) # add to a "add list" instead, parse attributes into a dictionary except AttributeError, e: print "Attribute Error:", e elementName = motion.nodeName attrList = [] for i in range(motion.attributes.length): attrName = motion.attributes.item(i).name attrValue = motion.attributes.item(i).nodeValue attrList.append((attrName, attrValue)) element_list.append((elementName, attrList))
print filename try: Piavca.JointNames.importJointNames("Joints.txt") except IOError: print "could not open Joints file Joints.txt, will probably work anyway" try: Piavca.JointNames.importExpressionNames("Expressions.txt") except IOError: print "could not open Expressions file Expressions.txt, will probably work anyway" Piavca.Core.getCore().setHardware(False) print "creating avatar" avatar = Piavca.Avatar(filename) print "loaded avatar" if len(sys.argv) > 2: motion_name = sys.argv[2] else: motnames = Piavca.Core.getCore().getMotionNames() print motnames dialog_return = singleChoiceDialog(lst=motnames) motion_name = dialog_return.selection.encode("latin-1") #motion_name = "biped_mocap_final" mot = Piavca.Core.getCore().getMotion(motion_name) mot.Reference()
Piavca.JointNames.importJointNames("Joints.txt") except IOError: print "could not open Joints file Joints.txt, will probably work anyway" try: Piavca.JointNames.importExpressionNames("Expressions.txt") except IOError: print "could not open Expressions file Expressions.txt, will probably work anyway" (splitext, ext) = os.path.splitext(path) print "filename", splitext, "extention", ext if ext == ".conf": script_engine = ScriptEngine("character controller", filename, app) else: if ext == ".cfg": basename = os.path.basename(splitext) avatar = Piavca.Avatar(str(basename)) else: import Piavca.XMLMotionFile basename = os.path.basename(path) Piavca.XMLMotionFile.parse(basename) avatar = Piavca.Core.getCore().getAvatar(0) Piavca.setUpEventsGUI() print "loaded avatar" if len(sys.argv) > 2: motion_name = sys.argv[2] else: motnames = Piavca.Core.getCore().getMotionNames() print motnames dialog_return = singleChoiceDialog(lst=["None"] + motnames)
def __init__(self, name, filename, app=None, gui_thread=False): Piavca.TimeCallback.__init__(self, name) self.app = app self.gui_thread = gui_thread self.frame = None self.camera_pos = Piavca.Vec() self.camera_pitch = 0.0 self.camera_yaw = 0.0 loadDefaults() self.scripts = {} self.currentscript = {} self.starttimes = {} if pymediapresent or pyaudiopresent: self.soundEngine = SoundEngine() else: self.soundEngine = None inputfile = open(filename, "r") lines = inputfile.readlines() inputfile.close() gui_list = [] for line in lines: line = line.strip() commentpos = line.find("#") if commentpos >= 0: line = line[:commentpos] line = line.split() print line if len(line) <= 0: continue if line[0] == "soundpack": if len(line) == 2: spackname = line[1] else: spackname = line[2] if self.soundEngine != None: self.soundEngine.loadSounds(spackname) else: print "could not load sound packs as audio playback is not supported, please install pyaudio or pymedia" elif line[0] == "expressions": importExpressionNames(line[1]) elif line[0] == "joints": importJointNames(line[1]) elif line[0] == "avatar": print "avatar", line[1] print "start loading avatar" avatar = Piavca.Avatar(line[1]) print "finished loading avatar" i = 2 while i < len(line): if line[i] == "position" or line[i] == "pos": pos = Piavca.Vec(float(line[i + 1]), float(line[i + 2]), float(line[i + 3])) avatar.setRootPosition(pos) i = i + 3 elif line[i] == "rotation" or line[i] == "rot": angle = Piavca.degToRad(float(line[i + 1])) axis = Piavca.Vec(float(line[i + 2]), float(line[i + 3]), float(line[i + 4])) avatar.setRootOrientation(Piavca.Quat(angle, axis)) i = i + 4 i += 1 elif line[0] == "motionpack": if len(line) == 2: mpackname = line[1] else: mpackname = line[2] print "motionpack", mpackname MotionFile.readMotionFile(mpackname) elif line[0] == "script": if len(line) == 2: spackname = line[1] else: spackname = line[2] print "script pack", spackname self.loadScripts(spackname) elif line[0] == "camera": if line[1] == "position": self.camera_pos = Piavca.Vec(float(line[2]), float(line[3]), float(line[4])) elif line[1] == "vert_angle": self.camera_pitch = Piavca.degToRad(float(line[2])) elif line[1] == "horiz_angle": self.camera_yaw = Piavca.degToRad(float(line[2])) #elif line[1] == "rotation": # s self.camera_ori = Piavca.Quat(float(line[2]), Piavca.Vec(float(line[3], float(line[4], lfloat(ine[5])) elif line[0] == "GUI": print "gui" gui_list.append(line[1]) elif line[0] == "gui": print "gui" gui_list.append(line[1]) for gui_name in gui_list: self.GUI(gui_name) self.thisown = 0 Piavca.Core.getCore().registerCallback(self)