Beispiel #1
0
 def setPosition(self,position=None,orientation=None,velocity=None,angular_speed=None,axis=None,force=False):
     objloc = pbSiri.ObjLoc()
     if position is not None:
         for i in range(3):
             objloc.position.append(position[i])
     if velocity is not None:
         for i in range(3):
             objloc.velocity.append(velocity[i])
     if orientation is not None:
         total = 0
         for i in range(4):
             total += orientation[i]*orientation[i]
         total = total**.5
         for i in range(3):
             objloc.orientation.append(orientation[i]/total)
     if angular_speed is not None:
         objloc.angular_speed = angular_speed
     if axis is not None:
         total = 0
         for i in range(3):
             total += axis[i]*axis[i]
         total = total**.5
         for i in range(2):
             objloc.rotational_axis.append(axis[i]/total)
     if force:
         objloc.update_flags = pbSiri.ObjLoc.FORCE
     body = pbSiri.MessageBody()
     body.message_names.append("SetLoc")
     body.message_arguments.append(objloc.SerializeToString())
     header = pbHead.Header()
     header.destination_space = util.tupleFromUUID(self.spaceid)
     header.destination_object = util.tupleFromUUID(self.objid)
     HostedObject.SendMessage(util.toByteArray(header.SerializeToString()+body.SerializeToString()))
Beispiel #2
0
    def sendNewProx(self):
        print "sendprox2"
        try:
            print "sendprox3"
            body = pbSiri.MessageBody()
            prox = pbSiri.NewProxQuery()
            prox.query_id = 123
            print "sendprox4"
            prox.max_radius = 1.0e+30
            body.message_names.append("NewProxQuery")
            body.message_arguments.append(prox.SerializeToString())
            header = pbHead.Header()
            print "sendprox5"
            header.destination_space = util.tupleFromUUID(self.spaceid);
            print dir(HostedObject)
            print "time locally ",HostedObject.GetLocalTime().microseconds();

            from System import Array, Byte
            arry=Array[Byte](tuple(Byte(c) for c in util.tupleFromUUID(self.spaceid)))
            print "time on spaceA ",HostedObject.GetTimeFromByteArraySpace(arry).microseconds()
            #print "time on spaceB ",HostedObject.GetTime(self.spaceid).microseconds()
            header.destination_object = util.tupleFromUUID(uuid.UUID(int=0))
            header.destination_port = 3 # libcore/src/util/KnownServices.hpp
            headerstr = header.SerializeToString()
            bodystr = body.SerializeToString()
            HostedObject.SendMessage(util.toByteArray(headerstr+bodystr))
        except:
            print "ERORR"
            traceback.print_exc()
Beispiel #3
0
 def sawAnotherObject(self,persistence,header,retstatus):
     if DEBUG_OUTPUT: print "PY: sawAnotherObject called"
     if header.HasField('return_status') or retstatus:
         return
     uuid = util.tupleToUUID(header.source_object)
     myName = ""
     for field in persistence.reads:
         if field.field_name == 'Name':
             if field.HasField('data'):
                 nameStruct=pbSiri.StringProperty()
                 nameStruct.ParseFromString(field.data)
                 myName = nameStruct.value
     if DEBUG_OUTPUT: print "PY: Object",uuid,"has name",myName
     if myName[:6]=="Avatar":
         rws=pbPer.ReadWriteSet()
         se=rws.writes.add()
         se.field_name="Parent"
         parentProperty=pbSiri.ParentProperty()
         parentProperty.value=util.tupleFromUUID(uuid);
         se.data=parentProperty.SerializeToString()
         header = pbHead.Header()
         header.destination_space=util.tupleFromUUID(self.spaceid);
         header.destination_object=util.tupleFromUUID(self.objid);
         header.destination_port=5#FIXME this should be PERSISTENCE_SERVICE_PORT
         HostedObject.SendMessage(header.SerializeToString()+rws.SerializeToString());
Beispiel #4
0
 def popUpMsg(self, s):
     body = pbSiri.MessageBody()
     body.message_names.append("EvaluateJavascript")
     msg = 'popUpMessage("' + s  + '", 10, 10);'
     if DEBUG_OUTPUT: print "PY:", msg
     body.message_arguments.append(msg)
     header = pbHead.Header()
     header.destination_space = util.tupleFromUUID(self.spaceid)
     header.destination_object = util.tupleFromUUID(self.objid)
     HostedObject.SendMessage(util.toByteArray(header.SerializeToString()+body.SerializeToString()))
Beispiel #5
0
    def getPosition(self,position=0,orientation=0,velocity=0,angular_speed=0,axis=0,objid=None):
        if not objid: objid = self.objid
        locReq = pbSiri.LocRequest()
        flags = position*1 + orientation*2 + velocity*4 + axis*8 + angular_speed*16
        body = pbSiri.MessageBody()
        body.message_names.append("LocRequest")
        body.message_arguments.append(locReq.SerializeToString())
        header = pbHead.Header()
        header.destination_space = util.tupleFromUUID(self.spaceid)
        header.destination_object = util.tupleFromUUID(objid)
        print "PY debug A"
##        header.id=util.tupleFromUUID(self.objid)
        header.id=12345
        print "PY debug B"
        HostedObject.SendMessage(util.toByteArray(header.SerializeToString()+body.SerializeToString()))
Beispiel #6
0
    def reallyProcessRPC(self,serialheader,name,serialarg):
        print "Got an RPC named",name
        header = pbHead.Header()
        header.ParseFromString(util.fromByteArray(serialheader))
        if name == "RetObj":
            HostedObject.AsyncWait(self.dailyPrint,Sirikata.Runtime.Time(8000000));
            retobj = pbSiri.RetObj()
            #print repr(util.fromByteArray(serialarg))
            try:
                retobj.ParseFromString(util.fromByteArray(serialarg))
            except:
                pass
            self.objid = util.tupleToUUID(retobj.object_reference)
            print "sendprox1"
            self.spaceid = util.tupleToUUID(header.source_space)

            print self.spaceid
            self.sendNewProx()
            self.setPosition(angular_speed=0,axis=(0,1,0))
        elif name == "ProxCall":
            proxcall = pbSiri.ProxCall()
            proxcall.ParseFromString(util.fromByteArray(serialarg))
            objRef = util.tupleToUUID(proxcall.proximate_object)
            if proxcall.proximity_event == pbSiri.ProxCall.ENTERED_PROXIMITY:
                myhdr = pbHead.Header()
                myhdr.destination_space = util.tupleFromUUID(self.spaceid)
                myhdr.destination_object = proxcall.proximate_object
                dbQuery = util.PersistenceRead(self.sawAnotherObject)
                field = dbQuery.reads.add()
                field.field_name = 'Name'
                dbQuery.send(HostedObject, myhdr)
            if proxcall.proximity_event == pbSiri.ProxCall.EXITED_PROXIMITY:
                pass
Beispiel #7
0
    def sendNewProx(self):
        try:
            body = pbSiri.MessageBody()
            prox = pbSiri.NewProxQuery()
            prox.query_id = 123
            prox.max_radius = 1.0e+30
            body.message_names.append("NewProxQuery")
            body.message_arguments.append(prox.SerializeToString())
            header = pbHead.Header()
            header.destination_space = util.tupleFromUUID(self.spaceid)

            from System import Array, Byte
            arry=Array[Byte](tuple(Byte(c) for c in util.tupleFromUUID(self.spaceid)))
            header.destination_object = util.tupleFromUUID(uuid.UUID(int=0))
            header.destination_port = 3 # libcore/src/util/KnownServices.hpp
            headerstr = header.SerializeToString()
            bodystr = body.SerializeToString()
            HostedObject.SendMessage(util.toByteArray(headerstr+bodystr))
        except:
            print "PY: ERORR"
            traceback.print_exc()
Beispiel #8
0
    def reallyProcessRPC(self,serialheader,name,serialarg):
        print "Got an RPC named",name
        header = pbHead.Header()
        header.ParseFromString(util.fromByteArray(serialheader))
        if name == "RetObj":
            retobj = pbSiri.RetObj()
            #print repr(util.fromByteArray(serialarg))
            try:
                retobj.ParseFromString(util.fromByteArray(serialarg))
            except:
                pass
            self.objid = util.tupleToUUID(retobj.object_reference)
            print "sendprox1"
            self.spaceid = util.tupleToUUID(header.source_space)

            print self.spaceid
            self.sendNewProx()
            self.setPosition(angular_speed=0, axis=(0,1,0))
        elif name == "ProxCall":
            proxcall = pbSiri.ProxCall()
            proxcall.ParseFromString(util.fromByteArray(serialarg))
            objRef = util.tupleToUUID(proxcall.proximate_object)
            if proxcall.proximity_event == pbSiri.ProxCall.ENTERED_PROXIMITY:
                myhdr = pbHead.Header()
                myhdr.destination_space = util.tupleFromUUID(self.spaceid)
                myhdr.destination_object = proxcall.proximate_object
                dbQuery = util.PersistenceRead(self.sawAnotherObject)
                field = dbQuery.reads.add()
                field.field_name = 'Name'
                dbQuery.send(HostedObject, myhdr)
            if proxcall.proximity_event == pbSiri.ProxCall.EXITED_PROXIMITY:
                pass
        elif name == "JavascriptMessage":
            s = "".join(chr(i) for i in serialarg)
            if DEBUG_OUTPUT: print "PY", name, s
            tok = s.split()
            if tok[1]=="placeObject":
                painting = tok[2]
                if not painting in self.paintings:
                    print "PY ERROR painting-->" + painting + "<--", type(painting), "paintings:", self.paintings.keys()
                x = float(tok[5])
                y = float(tok[6])
                z = float(tok[7])
                qx = float(tok[8])
                qy = float(tok[9])
                qz = float(tok[10])
                qw = float(tok[11])
                print "PY:   moving", painting, self.paintings[painting], "to", x, y, z, "quat:", qx, qy, qz, qw
                self.setPosition(objid=self.paintings[painting], position = (x, y, z), orientation = (qx, qy, qz, qw) )
Beispiel #9
0
    def reallyProcessRPC(self,serialheader,name,serialarg):
        print "Got an RPC named",name
        header = pbHead.Header()
        header.ParseFromString(util.fromByteArray(serialheader))
        if name == "RetObj":
            retobj = pbSiri.RetObj()
            #print repr(util.fromByteArray(serialarg))
            try:
                retobj.ParseFromString(util.fromByteArray(serialarg))
            except:
                pass
            self.objid = util.tupleToUUID(retobj.object_reference)
            print "sendprox1"
            self.spaceid = util.tupleToUUID(header.source_space)

            print self.spaceid
            self.sendNewProx()
            self.setPosition(angular_speed=0, axis=(0,1,0))
        elif name == "ProxCall":
            proxcall = pbSiri.ProxCall()
            proxcall.ParseFromString(util.fromByteArray(serialarg))
            objRef = util.tupleToUUID(proxcall.proximate_object)
            if proxcall.proximity_event == pbSiri.ProxCall.ENTERED_PROXIMITY:
                myhdr = pbHead.Header()
                myhdr.destination_space = util.tupleFromUUID(self.spaceid)
                myhdr.destination_object = proxcall.proximate_object
                dbQuery = util.PersistenceRead(self.sawAnotherObject)
                field = dbQuery.reads.add()
                field.field_name = 'Name'
                dbQuery.send(HostedObject, myhdr)
            if proxcall.proximity_event == pbSiri.ProxCall.EXITED_PROXIMITY:
                pass
        elif name == "CameraMessage":
            s = "".join(chr(i) for i in serialarg)
            if DEBUG_OUTPUT: print "PY: CameraMessage:", s
            print "PY:   moving painting1 =", self.paintings["painting1"]
            self.setPosition(objid=self.paintings["painting1"], position = (0, 0, .3))
Beispiel #10
0
    def reallyProcessRPC(self,serialheader,name,serialarg):
        if DEBUG_OUTPUT: print "PY: Got an RPC named",name, "pid:", os.getpid(), "id:", id(self)
        header = pbHead.Header()
        header.ParseFromString(util.fromByteArray(serialheader))
        if name == "RetObj":
            retobj = pbSiri.RetObj()
            #print repr(util.fromByteArray(serialarg))
            try:
                retobj.ParseFromString(util.fromByteArray(serialarg))
            except:
                pass
            self.objid = util.tupleToUUID(retobj.object_reference)
            self.spaceid = util.tupleToUUID(header.source_space)

            self.sendNewProx()
        elif name == "ProxCall":
            proxcall = pbSiri.ProxCall()
            proxcall.ParseFromString(util.fromByteArray(serialarg))
            objRef = util.tupleToUUID(proxcall.proximate_object)
            if proxcall.proximity_event == pbSiri.ProxCall.ENTERED_PROXIMITY:
                myhdr = pbHead.Header()
                myhdr.destination_space = util.tupleFromUUID(self.spaceid)
                myhdr.destination_object = proxcall.proximate_object
                dbQuery = util.PersistenceRead(self.sawAnotherObject)
                field = dbQuery.reads.add()
                field.field_name = 'Name'
                dbQuery.send(HostedObject, myhdr)
            if proxcall.proximity_event == pbSiri.ProxCall.EXITED_PROXIMITY:
                pass
        elif name == "JavascriptMessage":
            s = "".join(chr(i) for i in serialarg)
            if DEBUG_OUTPUT: print "PY JavascriptMessage:", name, s
            tok = tokenize(s)

            if tok[0]=="inventory":                
                if tok[1]=="placeObject":
                    painting = tok[2]
                    if not painting in self.objects:
                        print "PY ERROR painting-->" + painting + "<--", type(painting), "objects:", self.objects.keys()
                    x = float(tok[5])
                    y = float(tok[6])
                    z = float(tok[7])
                    qx = float(tok[8])
                    qy = float(tok[9])
                    qz = float(tok[10])
                    qw = float(tok[11])
                    if DEBUG_OUTPUT: print "PY moving", painting, self.objects[painting], "to", x, y, z, "quat:", qx, qy, qz, qw
                    self.setPosition(objid=self.objects[painting], position = (x, y, z), orientation = (qx, qy, qz, qw) )

                elif tok[1]=="saveState":
                    tok = tokenize(s,4)
                    filename = tok[2]
                    description = tok[3]
                    moodstring = tok[4]             #this will be remainder of string, not a token
                    print "PY: saveState", filename, "description:", description, "mood:", moodstring
                    self.saveStateArt={}
                    for art, uid in self.objects.items():
                        if art[:8]=="artwork_":
                            print "  PY: save", art, uid
                            self.saveStateArt[uid]={"name":art}
                            self.getPosition(objid=uid, position=1, orientation=1)
                    self.saveStateFile=filename
                    #if DEBUG_OUTPUT:
                    #    description += " TIMESTAMP:" + str(time.ctime())
                    self.saveStateDesc=description
                    self.saveStateMood = moodstring

                elif tok[1]=="loadState":
                    data = unHex(tok[2])
                    arts = pkl.loads(data)
                    if DEBUG_OUTPUT: print "loadState:", arts
                    for art in arts:
                        if "pos" in art:
                            pos = art["pos"]
                            rot = art["rot"]
                            nam = art["name"]
                            uid = self.objects[nam]
                            self.setPosition(objid=uid, position = pos, orientation = rot,
                                 velocity = (0,0,0), axis=(0,1,0), angular_speed=0)
                        else:
                            mood = arts[-1]
                    body = pbSiri.MessageBody()
                    body.message_names.append("SetLightMood")
                    msg = mood
                    if DEBUG_OUTPUT: print "PY: loadState set lighting mood-->" + mood + "<--", " len:", len(mood)
                    body.message_arguments.append(msg)
                    header = pbHead.Header()
                    header.destination_space = util.tupleFromUUID(self.spaceid)
                    header.destination_object = util.tupleFromUUID(self.objid)
                    HostedObject.SendMessage(util.toByteArray(header.SerializeToString()+body.SerializeToString()))

            elif tok[0]=="funmode":
                if self.mode=="funmode":            #else silently ignore
                    if tok[1]=="fire":
                        if not self.gameon:
                            return
                        t = time.time()
                        if t - self.lastfire < 0.5:
                            return
                        self.lastfire=t
                        if DEBUG_OUTPUT: print "PY: fire the cannon!", s, "id:", id(self)
                        ammo = tok[2] + "_" + str(self.ammoNum)
                        self.ammoNum = (self.ammoNum+1) % self.ammoMod
                        retire = tok[2] + "_" + str(self.ammoNum)
                        self.setPosition(objid=self.objects[retire], position = (0, -10, 0), orientation = (0, 0, 0, 1),
                                         velocity = (0, 0, 0), axis=(0,1,0), angular_speed=0)
                        x = float(tok[3])
                        y = float(tok[4])
                        z = float(tok[5])
                        qx = float(tok[6])
                        qy = float(tok[7])
                        qz = float(tok[8])
                        qw = float(tok[9])
                        zx = float(tok[10])                          ## we fire down -Z axis (camera view direction)
                        zy = float(tok[11])
                        zz = float(tok[12])
    ##                    ox=-zx; oy=-zy; oz=-zz
                        ox=0; oy=1; oz=0
                        offset = 0.5                                 ## move ammo out from inside avatar
                        x += ox*offset
                        y += oy*offset
                        z += oz*offset
                        vel = 7.0                                   ## initial ammo velocity
                        vx = -zx*vel
                        vy = -zy*vel
                        vz = -zz*vel
                        if DEBUG_OUTPUT: print "PY: rot:", qx, qy, qz, qw, "axis:", zx, zy, zz, "pos+off:", x, y, z, "vel:", vx, vy, vz
                        self.setPosition(objid=self.objects[ammo], position = (x, y, z), orientation = (qx, qy, qz, qw),
                                         velocity = (vx, vy, vz), axis=(0,1,0), angular_speed=0)
                    elif tok[1]=="timer":
                        t = time.time()-self.timestart
                        if t > self.lasttime+1.0:
                            self.lasttime+=1.0
                            if DEBUG_OUTPUT: print "PY: timer tick, time now:", self.lasttime
                            self.updateBanner()

            elif tok[0]=="reset":
                if self.mode=="funmode" or self.mode=="flythru":
                    if DEBUG_OUTPUT: print "PY: funmode/flythru reset paintings"
                    hexed = FUNSTATE if self.mode=="funmode" else FLYSTATE
                    arts = pkl.loads(unHex(hexed))
                    count = 0
                    for art in arts:
                        if "pos" in art:
                            pos = art["pos"]
                            rot = art["rot"]
                            nam = art["name"]
                            if nam in self.objects:
                                count +=1
                                uid = self.objects[nam]
                                if self.mode=="funmode":
                                    if nam=="artwork_32":       #must you?
                                        pos = (-5, 0, 3)
                                        rot = (.71, 0, 0, .71)
                                    print "funmode_debug art:", nam, pos
                                    self.setPosition(objid=uid, position = pos, orientation = rot,
                                         velocity = (0,0,0), axis=(0,1,0), angular_speed=0)
                                else:
                                    self.setPosition(objid=uid, position = pos, orientation = rot)
                    if DEBUG_OUTPUT: print "PY debug: total artwork repositioned:", count
                    if self.mode=="flythru":
                        if DEBUG_OUTPUT: print "PY: flythru reset"
                        self.reset_flythru()
                    else:

                        self.arthits=set()
                        self.oldhits=0
                        print "PY debug: reset hits:", self.oldhits, self.arthits, id(self)
                        i=0
                        for ammo in self.objects:
                            if DEBUG_OUTPUT: print "PY checking for ammo:", ammo
                            if ammo[:5] == "ammo_":
                                if DEBUG_OUTPUT: print "PY ------- found ammo"
                                uid = self.objects[ammo]
                                self.setPosition(objid=uid, position = (i,-10,0), orientation = (0,0,0,1),
                                     velocity = (0,0,0), axis=(0,1,0), angular_speed=0)
                                i+=1
                        self.reset_funmode()
                elif self.mode=="curator":
                    if DEBUG_OUTPUT: print "PY: curator reset"
                    self.reset_curator()

                elif self.mode=="critic":
                    if DEBUG_OUTPUT: print "PY: curator reset"
                    self.reset_critic()

                else:
                    print "PY ERROR: unknown mode", self.mode

##                if self.mode=="flythru":
##                    if DEBUG_OUTPUT: print "PY: flythru reset"
##                    self.reset_flythru()

            elif tok[0]=="flythru":
                if tok[1]=="animation":
                    door = "b7_firedoor_door"
                    left = "entry_door_01"
                    right = "entry_door_02"
                    if tok[2]=="gallery_open_start":
                        print "PY: Gallery doors open start"
                        if door in self.objects:
                            print "    -- got the door!", self.objects[door]
                            zmove = 1.0/float(tok[3])
                            xmove = zmove * -.08
                            self.setPosition(objid=self.objects[door], velocity = (xmove,0,zmove))
                    elif tok[2]=="gallery_open_finish":
                        if door in self.objects:
                            self.setPosition(objid=self.objects[door], velocity = (0,0,0))
                        print "PY: Gallery doors open finish"
                    elif tok[2]=="front_open_start":
                        print "PY: front doors open start"
                        if left in self.objects and right in self.objects:
                            speed = 1.0/float(tok[3])
                            self.setPosition(objid=self.objects[left], axis = (0,1,0), angular_speed=speed)
                            self.setPosition(objid=self.objects[right], axis = (0,1,0), angular_speed=-speed)
                    elif tok[2]=="front_open_finish":
                        print "PY: front doors open finish"
                        if left in self.objects and right in self.objects:
                            self.setPosition(objid=self.objects[left], axis = (0,1,0), angular_speed=0)
                            self.setPosition(objid=self.objects[right], axis = (0,1,0), angular_speed=0)

            else:
                if DEBUG_OUTPUT: print "PY: unknown JavascriptMessage:", tok

        elif name == "BegCol":
            collision = pbPhy.CollisionBegin()
            collision.ParseFromString(util.fromByteArray(serialarg))
            other = util.tupleToUUID(collision.other_object_reference)
            if not other in self.arthits:
                if other in self.objects.values():
                    oname = self.objects.keys()[self.objects.values().index(other)]
                    if oname[:8]=="artwork_":
                        self.arthits.add(other)
                        print "hit another painting! score now", len(self.arthits), id(self)
                        if len(self.arthits) > self.oldhits:
                            self.score = len(self.arthits)
##                            self.popUpMsg('game: ' + str(int(self.gamenum)) + ' score: ' + str(len(self.arthits)) )
                            self.oldhits=len(self.arthits)
                            self.updateBanner()
                else:
                    print "PY debug: unknown object:", other

        elif header.reply_id==12345:
            if DEBUG_OUTPUT: print "PY: response to our location query.  Dunno why it has no name"
            loc = pbSiri.ObjLoc()
            loc.ParseFromString(util.fromByteArray(serialarg))
            pos = (loc.position[0], loc.position[1], loc.position[2])
            rot = pbj2Quat(loc.orientation)
            uid = util.tupleToUUID(header.source_object)
            art = self.saveStateArt[uid]["name"]
            self.saveStateArt[uid]["pos"]=pos
            self.saveStateArt[uid]["rot"]=rot
            done = True
            for i in self.saveStateArt.values():
                if not "pos" in i:
                    done = False
                    break
            if done:
                arts = [i for i in self.saveStateArt.values()]
                arts.append(self.saveStateDesc)
                arts.append(self.saveStateMood)
                #if DEBUG_OUTPUT: print "           PY save art done:", arts
                #fname = self.saveStateFile.replace(" ", "_").replace('"',"")
                #f = open("art/" + fname, "w")
                #pkl.dump(arts, f)
                #f.close()
                #cmd = "python domail.py " + fname
                #print "PY test sendmail-->"+ cmd + "<--"
                #os.system(cmd)
                data = pkl.dumps(arts)
                print "PY: will hexify this data %s" % (data)
                hexart=hexify(data)
                blog.saveMuseum(self.saveStateFile, self.saveStateDesc, hexart)