예제 #1
0
	def setValue(self, val):
		angle = Piavca.radToDeg(val.getAngle())
		axis = val.getAxis()
		MultiParamEntry.setValue(self, [angle, axis[0], axis[1], axis[2]])
예제 #2
0
def saveMotions(filename, motions, element = None, doc = None, avatars=[]):
	writeout = 0
	if element == None:
		impl = minidom.getDOMImplementation()
		doc = impl.createDocument("", "PiavcaMotions", None)
		element = doc.documentElement
		writeout = 1
	
	allPiavca = Piavca.__dict__
	#print allPiavca
	
	members_to_ignore = ["getQuatValueAtTime", "getVecValueAtTime", "getFloatValueAtTime", "getQuatValueAtTimeInternal", 
						"getVecValueAtTimeInternal", "getFloatValueAtTimeInternal", "getMotionLength"]
	
	for avatar in avatars:
		avatar_el = doc.createElement("Avatar")
		avatar_el.setAttribute("name", avatar.getName())
		avatar_el.setAttribute("position", str(avatar.getRootPosition()))
		q = avatar.getRootOrientation()
		angle = q.getAngle()
		axis = q.getAxis()
		avatar_el.setAttribute("rotation", str(angle) + " " + str(axis))
		
		events = Piavca.getEvents(avatar)
		for event in events:
			el = doc.createElement("Event")
			el.setAttribute("name", event)
			avatar_el.appendChild(el)
			
		element.appendChild(avatar_el)
	
	for motion in motions:
		motiontype = None
		motiontypes = []
		motiontypename = "unknown"
		for key in allPiavca.keys():
			if type(allPiavca[key]) == types.TypeType and isinstance(motion, allPiavca[key]):
				motiontypes.append(allPiavca[key])
				if motiontype == None or issubclass(allPiavca[key], motiontype):
					motiontype = allPiavca[key]
					motiontypename = key
		#print name, "is a", motiontypename
		if motiontype == None:
			print "Motion is of unknown type"
			continue
		if motiontype == Piavca.KeyframeMotion:
			print "don't save keyframe motions"
			continue
		#print motion.getName(), motiontypename
		el = doc.createElement(motiontypename)
		#el.setAttribute("name", name)
		#print motion.__dict__
		ignorelist = set(["getStartTime", "getMotion", "getMotion1", "getMotion2"])
		for mtype in motiontypes:
			for key in mtype.__dict__.keys():
				if key[:3] == "get":
					#print key
					if key in ignorelist:
						continue
					if hasattr(motion, "set" + key[3:]):
						#print key
						method = getattr(motion, key)
						value = method()
						if type(value) == Piavca.Quat:
							value = str(Piavca.radToDeg(value.getAngle())) + " " + str(value.getAxis())
						else:
							value = str(value)
						if key[-len("JointId"):] == "JointId" or key[-len("ExpressionId"):] == "ExpressionId" or key[-len("TrackId"):] == "TrackId":
							value = Piavca.Core.getCore().getTrackName(method())
							
						# don't save empty names, it screws things up
						if key[3:] != "Name" or value != "":
							# check if its  a quaternion
							
							el.setAttribute(key[3:], value)
		motionlist = []
		if hasattr(motion, "getNumMotions"):
			n = motion.getNumMotions()
			for i in range(n):
				m = motion.getMotionByIndex(i)
				if m == None:
					continue
				m = Piavca.getRealMotionType(m)
				motionlist.append(m)
		elif hasattr(motion, "getMotion1"):
			m = motion.getMotion1()
			if m != None:
				m = Piavca.getRealMotionType(m)
				motionlist.append(m)
			m = motion.getMotion2()
			if m != None:
				m = Piavca.getRealMotionType(m)
				motionlist.append(m)
		elif hasattr(motion, "getMotion"):
			m = motion.getMotion()
			if m != None:
				m = Piavca.getRealMotionType(m)
				motionlist.append(m)
				
		for m in motionlist:
			if m.getName() != "":
				sub_el = doc.createElement("Motion")
				sub_el.setAttribute("name", m.getName())
				el.appendChild(sub_el)
			else:
				saveMotions(filename, [m], el, doc)
				
		element.appendChild(el)
		
	file = open(filename, "w")
	doc.writexml(file, "", "\t", "\n")
	file.close()
예제 #3
0
	def pushCameraPosition(self):
		angle = self.cameraRot.getAngle()
		axis = self.cameraRot.getAxis()
		glRotatef(Piavca.radToDeg(angle), axis[0], axis[1], axis[2])
	   	glTranslatef(self.cameraPos[0], self.cameraPos[1], self.cameraPos[2])
예제 #4
0
def saveMotions(filename, motions, element=None, doc=None, avatars=[]):
    writeout = 0
    if element == None:
        impl = minidom.getDOMImplementation()
        doc = impl.createDocument("", "PiavcaMotions", None)
        element = doc.documentElement
        writeout = 1

    allPiavca = Piavca.__dict__
    #print allPiavca

    members_to_ignore = [
        "getQuatValueAtTime", "getVecValueAtTime", "getFloatValueAtTime",
        "getQuatValueAtTimeInternal", "getVecValueAtTimeInternal",
        "getFloatValueAtTimeInternal", "getMotionLength"
    ]

    for avatar in avatars:
        avatar_el = doc.createElement("Avatar")
        avatar_el.setAttribute("name", avatar.getName())
        avatar_el.setAttribute("position", str(avatar.getRootPosition()))
        q = avatar.getRootOrientation()
        angle = q.getAngle()
        axis = q.getAxis()
        avatar_el.setAttribute("rotation", str(angle) + " " + str(axis))

        events = Piavca.getEvents(avatar)
        for event in events:
            el = doc.createElement("Event")
            el.setAttribute("name", event)
            avatar_el.appendChild(el)

        element.appendChild(avatar_el)

    for motion in motions:
        motiontype = None
        motiontypes = []
        motiontypename = "unknown"
        for key in allPiavca.keys():
            if type(allPiavca[key]) == types.TypeType and isinstance(
                    motion, allPiavca[key]):
                motiontypes.append(allPiavca[key])
                if motiontype == None or issubclass(allPiavca[key],
                                                    motiontype):
                    motiontype = allPiavca[key]
                    motiontypename = key
        #print name, "is a", motiontypename
        if motiontype == None:
            print "Motion is of unknown type"
            continue
        if motiontype == Piavca.KeyframeMotion:
            print "don't save keyframe motions"
            continue
        #print motion.getName(), motiontypename
        el = doc.createElement(motiontypename)
        #el.setAttribute("name", name)
        #print motion.__dict__
        ignorelist = set(
            ["getStartTime", "getMotion", "getMotion1", "getMotion2"])
        for mtype in motiontypes:
            for key in mtype.__dict__.keys():
                if key[:3] == "get":
                    #print key
                    if key in ignorelist:
                        continue
                    if hasattr(motion, "set" + key[3:]):
                        #print key
                        method = getattr(motion, key)
                        value = method()
                        if type(value) == Piavca.Quat:
                            value = str(Piavca.radToDeg(
                                value.getAngle())) + " " + str(value.getAxis())
                        else:
                            value = str(value)
                        if key[-len("JointId"):] == "JointId" or key[-len(
                                "ExpressionId"):] == "ExpressionId" or key[
                                    -len("TrackId"):] == "TrackId":
                            value = Piavca.Core.getCore().getTrackName(
                                method())

                        # don't save empty names, it screws things up
                        if key[3:] != "Name" or value != "":
                            # check if its  a quaternion

                            el.setAttribute(key[3:], value)
        motionlist = []
        if hasattr(motion, "getNumMotions"):
            n = motion.getNumMotions()
            for i in range(n):
                m = motion.getMotionByIndex(i)
                if m == None:
                    continue
                m = Piavca.getRealMotionType(m)
                motionlist.append(m)
        elif hasattr(motion, "getMotion1"):
            m = motion.getMotion1()
            if m != None:
                m = Piavca.getRealMotionType(m)
                motionlist.append(m)
            m = motion.getMotion2()
            if m != None:
                m = Piavca.getRealMotionType(m)
                motionlist.append(m)
        elif hasattr(motion, "getMotion"):
            m = motion.getMotion()
            if m != None:
                m = Piavca.getRealMotionType(m)
                motionlist.append(m)

        for m in motionlist:
            if m.getName() != "":
                sub_el = doc.createElement("Motion")
                sub_el.setAttribute("name", m.getName())
                el.appendChild(sub_el)
            else:
                saveMotions(filename, [m], el, doc)

        element.appendChild(el)

    file = open(filename, "w")
    doc.writexml(file, "", "\t", "\n")
    file.close()
예제 #5
0
 def pushCameraPosition(self):
     angle = self.cameraRot.getAngle()
     axis = self.cameraRot.getAxis()
     glRotatef(Piavca.radToDeg(angle), axis[0], axis[1], axis[2])
     glTranslatef(self.cameraPos[0], self.cameraPos[1], self.cameraPos[2])