def switchMaterialsImage(path, objectName): obj = None # Search each active scene to find the object with given name for scene in logic.getSceneList(): if objectName in scene.objects: obj = scene.objects[objectName] break if obj is None: print('Object ' + objectName + ' not found.') return """Create a new Dynamic Texture""" # Get the reference pointer (ID) of the internal texture ID = texture.materialID(obj, STARTING_MATERIAL) # Create a texture object objectTexture = texture.Texture(obj, ID) # Create a new source with an external image newSource = texture.ImageFFmpeg(path) # The texture has to be stored in a permanent Python object # NOTE(kgeffen) logic.texture is instantiated in startup.py # NOTE(kgeffen) Each object with a dynamic texture has its # own texture stored with key = that object's name logic.texture[objectName] = objectTexture # Update/replace the texture logic.texture[objectName].source = newSource logic.texture[objectName].refresh(False)
def init(controller): """ Init, run until socket is connected """ # run once per frame if controller.sensors[0].positive and controller.sensors[1].positive: ### SOCKET DEFINITION # run once # if not hasattr(logic, 'socket'): # define socket, set socket parameters logic.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) logic.socket.setblocking(0) timeOut = 0.001 logic.socket.settimeout(timeOut) # bind socket (run until binded) host = '127.0.0.1' port_rcv = 10000 logic.socket.bind((host,port_rcv)) print('bind socket: IP = {} Port = {}'.format(host, port_rcv)) controller.owner['SocketConnected'] = True ### IMAGE TEXTURE # get screen object obj = logic.getCurrentScene().objects['VideoScreen'] # get the reference pointer (ID) of the texture ID = texture.materialID(obj, 'MAVideoMat') # create a texture object logic.texture = texture.Texture(obj, ID)
def main(): cont = logic.getCurrentController() owner = cont.owner if "Video" in owner: video = owner["Video"] video.refresh(True) else: #Insert material name. mat = "Movie" matID = texture.materialID(owner, "MA" + mat) video = texture.Texture(owner, matID) owner["Video"] = video #Insert path to movie file. movie_path = "" path = logic.expandPath('//' + movie_path) video.source = texture.VideoFFmpeg(path) video.source.play()
def set_video(): gl.plane = gl.all_obj["Video"] # identify a static texture by name matID = texture.materialID(gl.plane, 'MAblack') # create a dynamic texture that will replace the static texture gl.my_video = texture.Texture(gl.plane, matID) # define a source of image for the texture, here a movie try: film = "Astrophotography-Stars-Sunsets-Sunrises-Storms.ogg" movie = "./video/" + film print('Movie =', movie) except: print("Une video valide doit être définie !") try: s = os.path.getsize(movie) print("Taille du film:", s) except: print("Problème avec la durée du film !") gl.my_video.source = texture.VideoFFmpeg(movie) gl.my_video.source.scale = False # Infinite loop gl.my_video.source.repeat = -1 # Vitesse normale: < 1 ralenti, > 1 accélère gl.my_video.source.framerate = 1.4 # quick off the movie, but it wont play in the background gl.my_video.source.play()
def main(): cont = logic.getCurrentController() owner = cont.owner # Insert material name material_name = "Stock Mode Button" matID = texture.materialID(owner, "MA" + material_name) tex = texture.Texture(owner, matID, 0) click = cont.sensors["Click"] mouse_over = cont.sensors["Mouse Over"] if click.positive and mouse_over.positive: objects = logic.getCurrentScene().objects props = objects["Properties"] stock_mode = props["Stock Mode"] if stock_mode == "Stock All": new_stock_mode = "Stock Pick" image_path = "stock_pick.png" else: new_stock_mode = "Stock All" image_path = "stock_all.png" props["Stock Mode"] = new_stock_mode os.chdir(logic.expandPath("//")) tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def main(): cont = logic.getCurrentController() owner = cont.owner message = owner.sensors["Message"] if message.positive: subject = message.subjects[0] matID = texture.materialID(owner, "MA" + "Stage Card") tex = texture.Texture(owner, matID, 0) cwd = logic.expandPath("//") os.chdir(cwd) os.chdir("../../2D Art Files/UI Textures/Stage Card Textures") texture_path_dict = { "-2": "/Rock_Concert_card.png", "-1": "/game_test_card.png", "0": "/random_stage_card.png", "1": "/Belair_Estate_card.png", "2": "/Sunset_Pier_card.png", } texture_path = texture_path_dict[subject] new_cwd = os.getcwd() image_path = new_cwd + texture_path tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def init(controller): """ Init, run until socket is connected """ # run once per frame if controller.sensors[0].positive and controller.sensors[1].positive: ### SOCKET DEFINITION # run once # if not hasattr(logic, 'socket'): # define socket, set socket parameters logic.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) logic.socket.setblocking(0) timeOut = 0.001 logic.socket.settimeout(timeOut) # bind socket (run until binded) host = '127.0.0.1' port_rcv = 10000 logic.socket.bind((host, port_rcv)) print('bind socket: IP = {} Port = {}'.format(host, port_rcv)) controller.owner['SocketConnected'] = True ### IMAGE TEXTURE # get screen object obj = logic.getCurrentScene().objects['VideoScreen'] # get the reference pointer (ID) of the texture ID = texture.materialID(obj, 'MAVideoMat') # create a texture object logic.texture = texture.Texture(obj, ID)
def playVideo(obj, video_path): matID = texture.materialID(obj, 'IMplaceholder.jpg') logic.video = texture.Texture(obj, matID) movie = logic.expandPath(video_path) logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.play()
def main(): cont = logic.getCurrentController() owner = cont.owner secondary = owner.sensors["Secondary"] if secondary.positive and owner["Character Selected"]: owner["Character Selected"] = False objects = logic.getCurrentScene().objects select_character_text = objects["Select Character Text"] select_character_text.text = "SELECT CHARACTER" character_portrait_glow = objects["Character Portrait Glow"] character_portrait_glow.visible = False character_portrait = objects["Character Portrait"] matID = texture.materialID(character_portrait, "MA" + "Character Portrait") tex = texture.Texture(character_portrait, matID, 0) # Specify path to image. os.chdir(logic.expandPath("//")) os.chdir("../Rendered Images/Character Portraits") cwd = os.getcwd() image_path = cwd + "/black.png" tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def __init__(self, ob, basedir, name, length): self._object = ob self._basedir = basedir self._length = length + 1 # get the reference pointer (ID) of the texture ID = texture.materialID(self._object, 'IM{0}'.format(name)) # create a texture object self._texture = texture.Texture(self._object, ID)
def __init__(self, obj, old_tex): ''' obj = objet concerné old_tex = texture originale new_tex = nouvelle texture ''' self.obj = obj self.old_tex = old_tex # ID de la texture existante self.ID = texture.materialID(obj, 'IM' + old_tex) # Sauvegarde de l'objet python dans le Game Logic self.obj_texture = texture.Texture(obj, self.ID)
def __init__(self, obj, old_tex): ''' obj = objet concerné old_tex = image de la texture originale, ex "danseur2.png" new_tex = "//textures/perso.png" ''' self.old_tex = old_tex # ID de la texture existante self.ID = texture.materialID(obj, 'IM' + old_tex) # Sauvegarde de l'objet python dans le Game Logic self.obj_texture = texture.Texture(obj, self.ID)
def __init__(self, ob, filepath, name): self._object = ob # get the reference pointer (ID) of the texture ID = texture.materialID(self._object, 'IM{0}'.format(name)) # create a texture object self._texture = texture.Texture(self._object, ID) # define the source once and for all self._texture.source = self._getSource(filepath)
def initWorld(cont): obj = cont.owner scene = G.getCurrentScene() matID = VT.materialID(obj, 'MAvideo') G.video = VT.Texture(obj, matID) video_source = VT.ImageMirror(scene,scene.active_camera,obj,matID) video_source.background = (68,68,68,255) G.video.source = video_source G.video.refresh(False)
def __init__(self, obj, old_tex): ''' obj = blendr object old_tex = old texture new_tex = new texture. ''' self.obj = obj self.old_tex = old_tex # Existing texture ID self.ID = texture.materialID(obj, 'IM' + old_tex) # Save python object in GameLogic self.obj_texture = texture.Texture(obj, self.ID)
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, obname, imgname): if obname is None or imgname is None: raise ValueError('no object name or image name given') if not obname in logic.getCurrentScene().objects: raise IndexError('requested object not found') self.__state = 'STOP' gameobject = logic.getCurrentScene().objects[obname] # -- Get the material that is using our texture img = "IM{0}".format(imgname) matID = texture.materialID(gameobject, img) # -- Create the video texture self._texture = texture.Texture(gameobject, matID)
def init_pub(): cont = G.getCurrentController() obj = cont.owner matID = VT.materialID(obj, 'MApub') G.video = VT.Texture(obj, matID) S1 = G.expandPath("//circuits/circuitdesertlau3/pub.avi") video_source = VT.VideoFFmpeg(S1) video_source.repeat = -1 video_source.scale = True video_source.flip = True G.video.source = video_source G.video.source.play()
def __init__(self, scene, objects, name): obj = objects.get('Dummy.{0}'.format(name)) # get the reference pointer (ID) of the texture mat_id = VT.materialID(obj, 'MAVR.{0}'.format(name)) # create a texture object self._texture = VT.Texture(obj, mat_id) # create a new source camera = scene.objects.get('Camera.{0}'.format(name)) source = VT.ImageRender(scene, camera) # update/replace the texture self._texture.source = source self._texture.refresh(False)
def __init__(self, obname, imgname): if not obname in logic.getCurrentScene().objects: raise IndexError self.__file = None self.__state = 'STOP' self.__loop = False gameobject = logic.getCurrentScene().objects[obname] # -- Get the material that is using our texture if imgname: img = "IM{0}".format(imgname) print("image: ", gameobject, img) matID = texture.materialID(gameobject, img) # -- Create the video texture self.video = texture.Texture(gameobject, matID)
def __init__(self, scene_main, scene_projection, name): obj = scene_projection.objects.get('Plane.{0}'.format(name)) # get the reference pointer (ID) of the texture mat_id = VT.materialID(obj, 'IM{0}'.format(name)) # create a texture object self._texture = VT.Texture(obj, mat_id) # create a new source camera = scene_main.objects.get('Camera.{0}'.format(name)) source = VT.ImageRender(scene_main, camera) #source.background = (180, 90, 144, 10) # update/replace the texture self._texture.source = source self._texture.refresh(False)
def __init__(self, obname, imgname): if not obname in logic.getCurrentScene().objects: raise IndexError self.__file = None self.__state = "STOP" self.__loop = False gameobject = logic.getCurrentScene().objects[obname] # -- Get the material that is using our texture if imgname: img = "IM{0}".format(imgname) print("image: ", gameobject, img) matID = texture.materialID(gameobject, img) # -- Create the video texture self.video = texture.Texture(gameobject, matID)
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 initWorld(cont): obj = cont.owner matID = VT.materialID(obj, 'MAvideo') G.video = VT.Texture(obj, matID) if sys.platform == 'darwin': print( 'webcam grabbing for FFMmpeg not supported on OSX at the moment (the backend for video texture)' ) return elif sys.platform == 'win32': video_source = VT.VideoFFmpeg('cam', 0, 20.0, 640, 480) else: # linux video_source = VT.VideoFFmpeg('/dev/video0', 0, 20.0, 640, 480) G.video.source = video_source G.video.source.play()
def Render2Texture(ncam,nobj,nimg): scene = logic.getCurrentScene() obj = getObject(nobj) key = nobj + '_cam' if hval(key) == True: gval(key).refresh(True) else: print("Link(",key,"):",ncam,nobj,nimg) cam = getObject(ncam) matID = texture.materialID(obj,'IM'+nimg) if hasattr(obj,'channel') == True: ch = obj['channel'] else: ch = 0 tex = texture.Texture(obj, matID, ch) tex.source = texture.ImageRender(scene,cam) sval(key,tex)
def main(): cont = logic.getCurrentController() owner = cont.owner mouse_over = cont.sensors["Mouse Over"] if mouse_over.positive: name = owner.name[:-7] if name == "Stage1": image_name = "/game_test_card.png" elif name == "Stage2": image_name = "/Rock_Concert_card.png" elif name == "Stage3": image_name = "/Belair_Estate_card.png" elif name == "Stage4": image_name = "/Sunset_Pier_card.png" else: image_name = "/no_stage_card.png" objects = logic.getCurrentScene().objects stage_card = objects["Stage Card"] matID = texture.materialID(stage_card, "MA" + "Stage Card") tex = texture.Texture(stage_card, matID, 0) # Specifying the path to the image. cwd = logic.expandPath("//") os.chdir(cwd) os.chdir("../../2D Art Files/PNG/UI PNG/Stage Cards PNG") new_cwd = os.getcwd() image_path = new_cwd + image_name tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def createTexture(cont): """Create a new Dynamic Texture""" obj = cont.owner # get the reference pointer (ID) of the internal texture ID = texture.materialID(obj, 'IMoriginal.png') # create a texture object object_texture = texture.Texture(obj, ID) # create a new source with an external image url = logic.expandPath("//newtexture.jpg") new_source = texture.ImageFFmpeg(url) # the texture has to be stored in a permanent Python object logic.texture = object_texture # update/replace the texture logic.texture.source = new_source logic.texture.refresh(False)
def initWorld(cont): obj = cont.owner matID = VT.materialID(obj, 'MAvideo') G.video = VT.Texture(obj, matID) url = G.expandPath("//media/trailer_400p.ogg") video_source = VT.VideoFFmpeg(url) video_source.repeat = -1 video_source.scale = False G.video.source = video_source G.video.source.play() # SOUND sound = cont.actuators["a_sound"] cont.activate(sound) G.sound = sound
def createTexture(cont): """Create a new Dynamic Texture""" object = cont.owner # get the reference pointer (ID) of the internal texture ID = texture.materialID(obj, 'IMoriginal.png') # create a texture object object_texture = texture.Texture(object, ID) # create a new source with an external image url = logic.expandPath("//newtexture.jpg") new_source = texture.ImageFFmpeg(url) # the texture has to be stored in a permanent Python object logic.texture = object_texture # update/replace the texture logic.texture.source = new_source logic.texture.refresh(False)
def createTexture(cont): """Create a new Dynamic Texture""" obj = cont.owner # get the reference pointer (ID) of the texture ID = VT.materialID(obj, 'IMoriginal.png') # create a texture object texture = VT.Texture(obj, ID) # create a new source url = G.expandPath("//media/newtexture.jpg") new_source = VT.ImageRender(G.new_scene, G.camera) new_source.background = (180, 90, 144, 255) # the texture has to be stored in a permanent Python object G.texture = texture # update/replace the texture texture.source = new_source texture.refresh(False)
def main(): cont = logic.getCurrentController() own = cont.owner MAT = texture.materialID(own, 'MASINTEL') logic.video = texture.Texture(own, MAT) movie = logic.expandPath('//sintel2.mp4') logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.scale = True logic.video.source.flip = True logic.video.source.repeat = 0 logic.video.source.play() sound = cont.actuators["movie_sound"] cont.activate(sound) logic.sound = sound print('Playing Film. Enjoy!')
def main(): cont = logic.getCurrentController() owner = cont.owner # Insert material name. material_name = "Stock Mode Button" matID = texture.materialID(owner, "MA" + material_name) tex = texture.Texture(owner, matID, 0) click = cont.sensors["Click"] mouse_over = cont.sensors["Mouse Over"] if click.positive and mouse_over.positive: objects = logic.getCurrentScene().objects properties = objects["Character Select Properties"] stock_mode = properties["Stock Mode"] if stock_mode == "Stock All": new_stock_mode = "Stock Pick" image_path = "stock_pick.png" else: new_stock_mode = "Stock All" image_path = "stock_all.png" properties["Stock Mode"] = new_stock_mode cwd = logic.expandPath("//") os.chdir(cwd) path_extension = "../../2D Art Files/PNG/UI PNG/" os.chdir(path_extension) # Applies and refreshes the new texture. tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def main(): cont = logic.getCurrentController() own = cont.owner MAT = texture.materialID(own, 'MAflashback_video') logic.video = texture.Texture(own, MAT) movie = logic.expandPath("//flashback.ogg") logic.video.source = texture.VideoFFmpeg(movie) #logic.video.source.scale = True logic.video.source.flip = True logic.video.source.repeat = 0 logic.video.source.play() sound = cont.actuators["movie_sound"] cont.activate(sound) logic.sound = sound #print('Playing Film. Enjoy!') print (movie)
def main(): cont = logic.getCurrentController() own = cont.owner MAT = texture.materialID(own, 'MAflashback_video') logic.video = texture.Texture(own, MAT) movie = logic.expandPath("//flashback.ogg") logic.video.source = texture.VideoFFmpeg(movie) #logic.video.source.scale = True logic.video.source.flip = True logic.video.source.repeat = 0 logic.video.source.play() sound = cont.actuators["movie_sound"] cont.activate(sound) logic.sound = sound #print('Playing Film. Enjoy!') print(movie)
def updateTexture(animated=False): print('animated: ', animated) obj = logic.scene.objects['Sphere'] ID = texture.materialID(obj, 'MAsky') objectTextures = texture.Texture(obj, ID) # create a new source with an external image if animated: source = texture.VideoFFmpeg(logic.mvb.bgImage) else: source = texture.ImageFFmpeg(logic.mvb.bgImage) # the texture has to be stored in a permanent Python object logic.skyTexture = objectTextures logic.skyTexture.source = source logic.skyTextureAnimated = animated if animated: logic.skyTexture.source.repeat = -1 logic.skyTexture.source.play() logic.skyTexture.refresh(True)
def initWorld(cont): object = cont.owner matID = texture.materialID(object, 'MAvideo') logic.video = texture.Texture(object, matID) url = logic.expandPath("//media/trailer_400p.ogg") video_source = texture.VideoFFmpeg(url) video_source.repeat = -1 video_source.scale = True logic.video.source = video_source logic.video.source.play() # SOUND import aud device = aud.device() factory = aud.Factory(url) handle = device.play(factory) logic.sound = handle
def updateTexture(animated = False): print('animated: ', animated) obj = logic.scene.objects['Sphere'] ID = texture.materialID(obj, 'MAsky') objectTextures = texture.Texture(obj, ID) # create a new source with an external image if animated: source = texture.VideoFFmpeg(logic.mvb.bgImage) else: source = texture.ImageFFmpeg(logic.mvb.bgImage) # the texture has to be stored in a permanent Python object logic.skyTexture = objectTextures logic.skyTexture.source = source logic.skyTextureAnimated = animated if animated: logic.skyTexture.source.repeat = -1 logic.skyTexture.source.play() logic.skyTexture.refresh(True)
def main(cont): # only proceed if we are warping if not cont.sensors['trigger_warp_script'].positive: return own = cont.owner own_pos = Vector(own.worldPosition) sce = GameLogic.getCurrentScene() blendFiles = GameLogic.getBlendFileList('//') blendFiles += GameLogic.getBlendFileList('//levels') blendFiles = dict([(b, None) for b in blendFiles]).keys() blendFiles = list(blendFiles) # py3 has its own dict_keys type blendFiles.sort() for b in blendFiles[:]: # get rid of this file if 'portal_world' in b: blendFiles.remove(b) if 'library' in b: blendFiles.remove(b) print(blendFiles) totFiles = len(blendFiles) if not totFiles: print('No levels found!') return # radius for paintings to be displayed in exhibit r = 11 theta = 0 # starting angle for first painting totFiles = float(totFiles) logic.texture = len(blendFiles)*[2] pos_xy = [0,0,0] for i,f in enumerate(blendFiles): theta = 2*pi* (i/totFiles) pos_xy[2] = 1.8 pos_xy[0] = r*cos(theta) pos_xy[1] = r*sin(theta) # dynamically change texture actu_add_object = cont.actuators['add_dyn_portal.00'+str(i+1)] actu_add_object.instantAddObject() new_portal = actu_add_object.objectLastCreated ID = texture.materialID(new_portal,'MAMyMaterial.00' +str(i+1)) object_texture = texture.Texture(new_portal,ID) url = logic.expandPath('//' + f[0:-6] + '.jpg') new_source = texture.ImageFFmpeg(url) logic.texture.append(object_texture) object_texture.source = new_source object_texture.refresh(False) new_portal.worldPosition = pos_xy d,new_vect,local = new_portal.getVectTo((0,0,1)) new_portal.alignAxisToVect(new_vect,0) new_portal.alignAxisToVect(new_vect,1) new_portal.alignAxisToVect(new_vect,2) new_portal['portal_blend'] = '//' + f own.endObject() # may as well distroy, wont use anymore
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
++++++++++++++++++++++ Example of how to replace a texture in game with a video. It needs to run everyframe """ import bge from bge import texture from bge import logic cont = logic.getCurrentController() obj = cont.owner # the creation of the texture must be done once: save the # texture object in an attribute of bge.logic module makes it persistent if not hasattr(logic, "video"): # identify a static texture by name matID = texture.materialID(obj, "IMvideo.png") # create a dynamic texture that will replace the static texture logic.video = texture.Texture(obj, matID) # define a source of image for the texture, here a movie movie = logic.expandPath("//trailer_400p.ogg") logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.scale = True # quick off the movie, but it wont play in the background logic.video.source.play() # you need to call this function every frame to ensure update of the texture. logic.video.refresh(True)
++++++++++++++++++++++ Example of how to replace a texture in game with a video. It needs to run everyframe """ import bge from bge import texture from bge import logic cont = logic.getCurrentController() obj = cont.owner # the creation of the texture must be done once: save the # texture object in an attribute of bge.logic module makes it persistent if not hasattr(logic, 'video'): # identify a static texture by name matID = texture.materialID(obj, 'IMvideo.png') # create a dynamic texture that will replace the static texture logic.video = texture.Texture(obj, matID) # define a source of image for the texture, here a movie movie = logic.expandPath('//trailer_400p.ogg') logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.scale = True # quick off the movie, but it wont play in the background logic.video.source.play() # you need to call this function every frame to ensure update of the texture. logic.video.refresh(True)
++++++++++++++++++++++ Example of how to replace a texture in game with a video. It needs to run everyframe """ import bge from bge import texture from bge import logic cont = logic.getCurrentController() obj = cont.owner # the creation of the texture must be done once: save the # texture object in an attribute of bge.logic module makes it persistent if not hasattr(logic, 'video'): # identify a static texture by name matID = texture.materialID(obj, str(obj.meshes[0].materials[0])) # create a dynamic texture that will replace the static texture logic.video = texture.Texture(obj, matID) # define a source of image for the texture, here a movie #movie = logic.expandPath('/home/sio2/projectroom/signature_vases/code/videoblender/capture.avi') #movie = logic.expandPath('') logic.video.source = texture.VideoFFmpeg('/dev/video0',0) logic.video.source.scale = True logic.video.source.flip = True # quick off the movie, but it wont play in the background logic.video.source.repeat = 3 logic.video.source.play()