예제 #1
0
	def getMotionProxy(self, motion):
		if type(motion) == "":
			motion = Piavca.getMotion(str(motion))
		if motion == None:
			return None
		else:
			return MotionProxy(motion, self)
예제 #2
0
 def getMotionProxy(self, motion):
     if type(motion) == "":
         motion = Piavca.getMotion(str(motion))
     if motion == None:
         return None
     else:
         return MotionProxy(motion, self)
예제 #3
0
	def __call__(self, avatar):
		if self.motion == None:
			#print "script engine core", Piavca.Core.getCore()
			self.motion = Piavca.getMotion(self.motionName)
			if self.motion == None:
				print "Could not find motion", self.motionName
				return
			self.motion.Reference()
		if self.interrupt:
			avatar.interrupt_motion()
		avatar.play_motion(self.motion)
예제 #4
0
def saveAll(filename):
    core = Piavca.Core.getCore()
    motions = core.getMotionNames()
    #print motions
    motions = [Piavca.getMotion(motion) for motion in motions]

    avatars = core.getAvatarNames()
    #print avatars
    avatars = [core.getAvatar(avatar) for avatar in avatars]

    saveMotions(filename, motions=motions, avatars=avatars)
예제 #5
0
 def __call__(self, avatar):
     if self.motion == None:
         #print "script engine core", Piavca.Core.getCore()
         self.motion = Piavca.getMotion(self.motionName)
         if self.motion == None:
             print "Could not find motion", self.motionName
             return
         self.motion.Reference()
     if self.interrupt:
         avatar.interrupt_motion()
     avatar.play_motion(self.motion)
예제 #6
0
def saveAll(filename):
	core = Piavca.Core.getCore()
	motions = core.getMotionNames()
	#print motions
	motions = [Piavca.getMotion(motion) for motion in motions]
	
	avatars = core.getAvatarNames()
	#print avatars
	avatars = [core.getAvatar(avatar) for avatar in avatars]
	
	
	saveMotions(filename, motions=motions, avatars=avatars)
예제 #7
0
	def getMotionByName(self, name):
		if name[:10] == "__Type__::":
			typename = name[10:]
			cl = getattr(Piavca, typename)
			if type(cl) == types.TypeType and issubclass(cl, Piavca.Motion):
				motion =  cl()
				motion.thisown = False
				motion.Reference()
				return motion
			else:
				ValueError(typename+" is not a motion class")
		else:
			print "motion name", name, type(name)
			motion = Piavca.getMotion(str(name.encode("latin-1")))
			if motion == None:
				raise ValueError("no motion named" + str(name))
			else:
				return motion
예제 #8
0
 def getMotionByName(self, name):
     if name[:10] == "__Type__::":
         typename = name[10:]
         cl = getattr(Piavca, typename)
         if type(cl) == types.TypeType and issubclass(cl, Piavca.Motion):
             motion = cl()
             motion.thisown = False
             motion.Reference()
             return motion
         else:
             ValueError(typename + " is not a motion class")
     else:
         print "motion name", name, type(name)
         motion = Piavca.getMotion(str(name.encode("latin-1")))
         if motion == None:
             raise ValueError("no motion named" + str(name))
         else:
             return motion
예제 #9
0
	def __call__(self, avatar):
		mot = Piavca.getMotion(self.motionName)
		if mot == None:
			raise "could not find motion " + self.motionName
		avatar.add_background_motion(mot)
예제 #10
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))
예제 #11
0
	def getMotion(self, name=None):
		print "backend, getMotion, name = ", name
		if name == None:
			return self.motion.getMotion()		
		else:
			return  Piavca.getMotion(str(name.encode("latin-1")))
예제 #12
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))
예제 #13
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
예제 #14
0
 def getMotion(self, name=None):
     print "backend, getMotion, name = ", name
     if name == None:
         return self.motion.getMotion()
     else:
         return Piavca.getMotion(str(name.encode("latin-1")))
예제 #15
0
 def __call__(self, avatar):
     mot = Piavca.getMotion(self.motionName)
     if mot == None:
         raise "could not find motion " + self.motionName
     avatar.add_background_motion(mot)
예제 #16
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