예제 #1
0
	def setMotion(self, motionname):
		self.setTime(0.0)
		#print "motion name", motionname, type(motionname)
		motion = self.getMotionByName(motionname)
		#print "motion", motion
		if motion == None:
			raise ValueError("no motion named" + str(motionname))
		else:
			#print "motion", motion, "ownership", motion.thisown
			if motion.getName() == "":
				dialog_return = textEntryDialog (message="Please enter a name for this motion")
				motion_name = dialog_return.text.encode("latin-1")
				Piavca.loadMotion(motion_name, motion)
			motion.reset(True)
			self.motion = MotionProxy(motion, self)#motion
			self.submotion = self.motion
			#print "avatar", self.avatar
			if self.avatar:
				print "playing", self.avatar, self.motion.getMotion()
				self.avatar.playMotionDirect(self.motion.getMotion())
			self.resetRange()
			self.update()
예제 #2
0
 def setMotion(self, motionname):
     self.setTime(0.0)
     #print "motion name", motionname, type(motionname)
     motion = self.getMotionByName(motionname)
     #print "motion", motion
     if motion == None:
         raise ValueError("no motion named" + str(motionname))
     else:
         #print "motion", motion, "ownership", motion.thisown
         if motion.getName() == "":
             dialog_return = textEntryDialog(
                 message="Please enter a name for this motion")
             motion_name = dialog_return.text.encode("latin-1")
             Piavca.loadMotion(motion_name, motion)
         motion.reset(True)
         self.motion = MotionProxy(motion, self)  #motion
         self.submotion = self.motion
         #print "avatar", self.avatar
         if self.avatar:
             print "playing", self.avatar, self.motion.getMotion()
             self.avatar.playMotionDirect(self.motion.getMotion())
         self.resetRange()
         self.update()
예제 #3
0
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))
예제 #4
0
	def addMotion(self, motion):
		dialog_return = textEntryDialog (message="Please enter a name for this motion")
		motion_name = dialog_return.text.encode("latin-1")
		Piavca.loadMotion(motion_name, motion)
		self.update()
예제 #5
0
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))
예제 #6
0
    choice1.setSmooth(False)
    choice1.setAccumulateRoot(False)
    choice1.setWindowLength(window)
    for mot in submots:
        print mot
        choice1.addMotion(mot)
    loop1 = Piavca.LoopMotion(choice1)
    choice2 = Piavca.ChoiceMotionWithDefault()
    choice2.setWindowLength(window)
    choice2.addMotion(loop1)
    for mot in interruptions:
        print mot
        choice2.addMotion(mot)
    loop2 = Piavca.LoopMotion(choice2)
    return loop2, numMinima


if __name__ == "__main__":
    import os
    os.chdir("../../../Data/performing_presence/scenario2008/bill/")
    import Piavca.XMLMotionFile
    Piavca.XMLMotionFile.parse("Interruptions.xml")
    m, numMinima = InterruptableSequence(
        Piavca.getMotion("second_projections2_fully_labelled_megan"), [
            Piavca.getMotion(m)
            for m in ["Interruption" + str(i) for i in range(1, 5)]
        ])
    Piavca.loadMotion("interrupSeq", m)
    Piavca.XMLMotionFile.saveAll("InterrupSeq_output.xml")
    print "num splits", numMinima
예제 #7
0
 def addMotion(self, motion):
     dialog_return = textEntryDialog(
         message="Please enter a name for this motion")
     motion_name = dialog_return.text.encode("latin-1")
     Piavca.loadMotion(motion_name, motion)
     self.update()
예제 #8
0
	# the smooth transitioning function
	submots = [Piavca.SubMotion(seq, start, end) for start, end in zip(minima[:-1], minima[1:])]
	print submots
	choice1 = Piavca.SequentialChoiceMotion()
	choice1.setSmooth(False)
	choice1.setAccumulateRoot(False)
	choice1.setWindowLength(window)
	for mot in submots:
		print mot
		choice1.addMotion(mot)
	loop1 = Piavca.LoopMotion(choice1)
	choice2 = Piavca.ChoiceMotionWithDefault()
	choice2.setWindowLength(window)
	choice2.addMotion(loop1)
	for mot in interruptions:
		print mot
		choice2.addMotion(mot)
	loop2 = Piavca.LoopMotion(choice2)
	return loop2, numMinima
										
if __name__ == "__main__":
	import os
	os.chdir("../../../Data/performing_presence/scenario2008/bill/")
	import Piavca.XMLMotionFile
	Piavca.XMLMotionFile.parse("Interruptions.xml")
	m, numMinima = InterruptableSequence(Piavca.getMotion("second_projections2_fully_labelled_megan"), [Piavca.getMotion(m) for m in ["Interruption" + str(i) for i in range(1,5)]])
	Piavca.loadMotion("interrupSeq", m)
	Piavca.XMLMotionFile.saveAll("InterrupSeq_output.xml")
	print "num splits", numMinima