def parentalCheck(self, ent): children = [] while 1: try: qprim = ent.prim except AttributeError: # we come here when parent has no EC_opensimprim component break if qprim.ParentId != 0: #~ r.logInfo("Entity had a parent, lets pick that instead!") # get the parent entity, and if it is editable set it to ent. # on next loop we get prim from it and from that we get children. temp_ent = naali.getEntity(qprim.ParentId) if not editable(temp_ent): # not a prim, so not selecting all children break else: ent = temp_ent else: #~ r.logInfo("Entity had no parent, maybe it has children?") # either we get children or not :) But this is the 'parent' in either case children = qprim.GetChildren() break return ent, children
def on_entity_visuals_modified(self, entid): #print "MediaURLHandler got Visual Modified for:", entid for texture_uuid, mediaurlview in self.texture2mediaurlview.iteritems(): if mediaurlview is None: continue submeshes = r.getSubmeshesWithTexture(entid, texture_uuid) if submeshes: # This doesent work. Seems to be right in theory but some entitys textures are not updated # especially when there are multiple entitys with same mediurl texture """ # Don't reapply if submeshes are the same for this entity try: if mediaurlview.entid_to_submeshes[entid] == submeshes: print "Already have submeshes for ", str(entid) print " >> Present: ", mediaurlview.entid_to_submeshes[entid] print " >> Found : ", submeshes return except KeyError, e: print " Adding new submeshes to ent id to map for ", str(entid) print " >> ", submeshes mediaurlview.entid_to_submeshes[entid] = submeshes """ # Check if we need to create the playback widget if mediaurlview.playback_widget == None: mediaurlview.create_playback_widget() r.applyUICanvasToSubmeshes(entid, submeshes, mediaurlview.playback_widget, mediaurlview.refreshrate) mediaurlview.load_url() else: r.applyUICanvasToSubmeshes(entid, submeshes, mediaurlview.playback_widget, mediaurlview.refreshrate) # Get entity for id and hook to Touchable signals entity = naali.getEntity(entid) self.connect_touchable(mediaurlview, entity)
def on_mouseleftpressed(self, mouseinfo): if not self.editing: return if mouseinfo.IsItemUnderMouse(): return if not self.selection_box_inited: self.init_selection_box() if mouseinfo.HasShiftModifier() and not mouseinfo.HasCtrlModifier( ) and not mouseinfo.HasAltModifier(): self.on_multiselect(mouseinfo) return self.dragStarted( mouseinfo) #need to call this to enable working dragging self.left_button_down = True results = [] results = r.rayCast(mouseinfo.x, mouseinfo.y) ent = None if results is not None and results[0] != 0: id = results[0] ent = naali.getEntity(id) if not self.manipulatorsInit: self.manipulatorsInit = True for manipulator in self.manipulators.values(): manipulator.initVisuals() if ent is not None: if editable(ent): r.eventhandled = self.EVENTHANDLED if self.manipulator.compareIds( ent.id ): # don't start selection box when manipulator is hit self.manipulator.initManipulation(ent, results, self.sels) self.usingManipulator = True else: if self.active is None or self.active.id != ent.id: #a diff ent than prev sel was changed if not ent in self.sels: self.select(ent) elif self.active.id == ent.id: #canmove is the check for click and then another click for moving, aka. select first, then start to manipulate self.canmove = True else: self.hideManipulator() # Start box select if nothing was hit? :P cant follow the logic here... self.selection_rect_startpos = (mouseinfo.x, mouseinfo.y) self.selection_box.Show() self.canmove = False self.deselect_all()
def deleteObject(self): if self.active is not None: for ent in self.sels: #r.logInfo("deleting " + str(ent.id)) ent, children = self.parentalCheck(ent) for child_id in children: child = naali.getEntity(int(child_id)) #~ self.worldstream.SendObjectDeRezPacket(child.id, r.getTrashFolderId()) #~ if len(children) == 0: self.worldstream.SendObjectDeRezPacket(ent.id, r.getTrashFolderId()) #~ else: #~ r.logInfo("trying to delete a parent, need to fix this!") self.manipulator.hideManipulator() #self.hideSelector() self.deselect_all() self.sels = []
def on_mouseleftpressed(self, mouseinfo): if not self.windowActive: return if mouseinfo.IsItemUnderMouse(): return if mouseinfo.HasShiftModifier() and not mouseinfo.HasCtrlModifier() and not mouseinfo.HasAltModifier(): self.on_multiselect(mouseinfo) return self.dragStarted(mouseinfo) #need to call this to enable working dragging self.left_button_down = True results = [] results = r.rayCast(mouseinfo.x, mouseinfo.y) ent = None if results is not None and results[0] != 0: id = results[0] ent = naali.getEntity(id) if not self.manipulatorsInit: self.manipulatorsInit = True for manipulator in self.manipulators.values(): manipulator.initVisuals() if ent is not None: if not self.manipulator.compareIds(ent.id) and editable(ent): #ent.id != self.selection_box.id and r.eventhandled = self.EVENTHANDLED found = False for entity in self.sels: if entity.id == ent.id: found = True if self.active is None or self.active.id != ent.id: #a diff ent than prev sel was changed if self.validId(ent.id): if not found: self.select(ent) elif self.active.id == ent.id: #canmove is the check for click and then another click for moving, aka. select first, then start to manipulate self.canmove = True self.manipulator.initManipulation(ent, results, self.sels) self.usingManipulator = True else: self.selection_rect_startpos = (mouseinfo.x, mouseinfo.y) self.canmove = False self.deselect_all()
def on_multiselect(self, mouseinfo): if not self.editing: return results = [] results = r.rayCast(mouseinfo.x, mouseinfo.y) ent = None if results is not None and results[0] != 0: id = results[0] ent = naali.getEntity(id) found = False if ent is not None: for entity in self.sels: if entity.id == ent.id: found = True if not found: self.multiselect(ent) else: self.deselect(ent) self.canmove = True
def on_multiselect(self, mouseinfo): if self.windowActive: results = [] results = r.rayCast(mouseinfo.x, mouseinfo.y) ent = None if results is not None and results[0] != 0: id = results[0] ent = naali.getEntity(id) found = False if ent is not None: for entity in self.sels: if entity.id == ent.id: found = True if self.validId(ent.id): if not found: self.multiselect(ent) else: self.deselect(ent) self.canmove = True
def handle_entity_created(self, ent, changetype): # fun fact: since we are called for every entity and # self.finished checked only every "update" event, # this often cleans up >1 test objects (in case any # are left over from failed tests) ent_id = ent.Id ent = naali.getEntity(ent.Id) try: p = ent.netpos.Position except AttributeError: if 0: print "skip unplaceable entity" else: if 0: print "placeable entity created: pos", p.x(), p.y(), p.z() # for some reason z coord ends up as 22.25 if p.x() == 42.0 and p.y() == 42.0 and int(p.z()) == 22: r.logInfo("found created test prim, deleting (finished=%s)" % self.finished) r.getServerConnection().SendObjectDeRezPacket( ent_id, r.getTrashFolderId()) self.finished = True
def on_entity_visuals_modified(self, entid): #print "MediaURLHandler got Visual Modified for:", entid for texture_uuid, mediaurlview in self.texture2mediaurlview.iteritems( ): if mediaurlview is None: continue submeshes = r.getSubmeshesWithTexture(entid, texture_uuid) if submeshes: # This doesent work. Seems to be right in theory but some entitys textures are not updated # especially when there are multiple entitys with same mediurl texture """ # Don't reapply if submeshes are the same for this entity try: if mediaurlview.entid_to_submeshes[entid] == submeshes: print "Already have submeshes for ", str(entid) print " >> Present: ", mediaurlview.entid_to_submeshes[entid] print " >> Found : ", submeshes return except KeyError, e: print " Adding new submeshes to ent id to map for ", str(entid) print " >> ", submeshes mediaurlview.entid_to_submeshes[entid] = submeshes """ # Check if we need to create the playback widget if mediaurlview.playback_widget == None: mediaurlview.create_playback_widget() r.applyUICanvasToSubmeshes(entid, submeshes, mediaurlview.playback_widget, mediaurlview.refreshrate) mediaurlview.load_url() else: r.applyUICanvasToSubmeshes(entid, submeshes, mediaurlview.playback_widget, mediaurlview.refreshrate) # Get entity for id and hook to Touchable signals entity = naali.getEntity(entid) self.connect_touchable(mediaurlview, entity)
def highlightChildren(self, children): for child_id in children: child = naali.getEntity(int(child_id)) self.highlight(child) self.soundRuler(child)
if 0: print "Testing event sending, camera for now..."# , r.SwitchCameraState hmm = r.sendEvent(r.SwitchCameraState) print "test done?", hmm if 0: print "Testing camera swap..." hmm = r.switchCameraState() #print hmm if 0: #get entity #idnum = new_id idnum = naali.getCamera().id print "Getting entity id", idnum, e = naali.getEntity(idnum) print "got:", e #print dir(r) #rotate(e) #move(e) if 0: #test avatartracking, works :) try: a = naali.getUserAvatar() except ValueError: print "could find the user avatar" else: print "<:::", print "Avatar pos:", a.placeable.Position, print ":::>" """
if 0: print "Testing event sending, camera for now..." # , r.SwitchCameraState hmm = r.sendEvent(r.SwitchCameraState) print "test done?", hmm if 0: print "Testing camera swap..." hmm = r.switchCameraState() #print hmm if 0: #get entity #idnum = new_id idnum = naali.getCamera().id print "Getting entity id", idnum, e = naali.getEntity(idnum) print "got:", e #print dir(r) #rotate(e) #move(e) if 0: #test avatartracking, works :) try: a = naali.getUserAvatar() except ValueError: print "could find the user avatar" else: print "<:::", print "Avatar pos:", a.placeable.Position, print ":::>" """