def run(self): from bge import texture if self.file_map != None: self.file_map.seek(0) w = 0 h = 0 if self.file_map.size() == 640*480*4: w = 640 h = 480 elif self.file_map.size() == 320*240*4: w = 320 h = 240 elif self.file_map.size() == 160*120*4: w = 160 h = 120 if w > 0 and h > 0: if self.img_w != w or self.img_h != h: self.image_texture.source = texture.ImageBuff() self.image_texture.source.filter = texture.FilterRGBA32() buf = self.file_map.read(w*h*4) self.image_texture.source.load(buf, w, h) self.image_texture.refresh(True)
def __init__(self, image_name, feed_2): import sys import bge from bge import texture import tempfile cont = bge.logic.getCurrentController() own = cont.owner try: matID = texture.materialID(own, image_name) except: print("Delicode NI mate Tools Error: No texture with name: " + image_name) pass try: self.image_texture = texture.Texture(own, matID) if feed_2: filename = "NI_mate_shared_map2.data" else: filename = "NI_mate_shared_map1.data" file = open(tempfile.gettempdir() + "/" + filename, "rb") if sys.platform.startswith('darwin') or sys.platform.startswith( 'Linux'): self.file_map = mmap.mmap(file.fileno(), 0, mmap.PROT_READ, mmap.ACCESS_READ) else: self.file_map = mmap.mmap(file.fileno(), 0, None, mmap.ACCESS_READ) file.close() self.file_map.seek(0) buf = self.file_map.read(640 * 480 * 4) self.image_texture.source = texture.ImageBuff() self.image_texture.source.filter = texture.FilterRGBA32() self.image_texture.source.load(buf, 640, 480) if feed_2: print("Delicode NI mate Tools replacing " + image_name + " with live feed 2") else: print("Delicode NI mate Tools replacing " + image_name + " with live feed 1") except Exception as e: print("Delicode NI mate Tools Error: Couldn't open NI mate feed " + tempfile.gettempdir() + "/" + filename) print("Reason: %s" % e) self.file_map = None pass
def __init__(self, image_name, sensor_num, feed_2): import sys import bge from bge import texture import tempfile cont = bge.logic.getCurrentController() own = cont.owner img_w = 0 img_h = 0 try: matID = texture.materialID(own, image_name) except: print("Delicode NI mate Tools Error: No texture with name: " + image_name) pass try: self.image_texture = texture.Texture(own, matID) filename = "NI_mate_shared_map" if feed_2: filename = filename + str(2*(sensor_num-1)+2) else: filename = filename + str(2*(sensor_num-1)+1) filename = filename + ".data" file = open(tempfile.gettempdir() + "/" + filename, "rb") if sys.platform.startswith('darwin') or sys.platform.startswith('Linux'): self.file_map = mmap.mmap(file.fileno(), 0, mmap.PROT_READ, mmap.ACCESS_READ) else: self.file_map = mmap.mmap(file.fileno(), 0, None, mmap.ACCESS_READ) file.close() self.file_map.seek(0) w = 0 h = 0 if self.file_map.size() == 640*480*4: w = 640 h = 480 elif self.file_map.size() == 320*240*4: w = 320 h = 240 elif self.file_map.size() == 160*120*4: w = 160 h = 120 if w > 0 and h > 0: buf = self.file_map.read(w*h*4) self.image_texture.source = texture.ImageBuff() self.image_texture.source.filter = texture.FilterRGBA32() self.image_texture.source.load(buf, w, h) self.img_w = w self.img_h = h if feed_2: print("Delicode NI mate Tools replacing " + image_name + " with sensor " + str(sensor_num) + " live feed 2") else: print("Delicode NI mate Tools replacing " + image_name + " with sensor " + str(sensor_num) + " live feed 1") except Exception as e: print("Delicode NI mate Tools Error: Couldn't open NI mate feed " + tempfile.gettempdir() + "/" + filename) print("Reason: %s" % e) self.file_map = None pass