def main(): imgDetectorX = 64 * 5 imgDetectorY = 36 * 5 imgPickupX = 256 imgPickupY = 144 if hasattr(GameLogic, 'detector') and hasattr(GameLogic, 'pickup'): GameLogic.detector.refresh(True) GameLogic.pickup.refresh(True) GameLogic.detector_png = list(GameLogic.detector.source.image) GameLogic.pickup_png = list(GameLogic.pickup.source.image) thread = Worker(None) thread.run(imgDetectorX, imgDetectorY, imgPickupX, imgPickupY) else: scene = GameLogic.getCurrentScene() screen1 = scene.objects['Screen1'] screen2 = scene.objects['Screen2'] detectorcamera = scene.objects['DetectionCamera'] pickupcamera = scene.objects['PickupCamera'] GameLogic.detector = bge.texture.Texture(screen1, 0, 0) GameLogic.pickup = bge.texture.Texture(screen2, 0, 0) GameLogic.detector.source = VideoTexture.ImageRender( scene, detectorcamera) GameLogic.detector.source.capsize = (imgDetectorX, imgDetectorY) GameLogic.detector_png = GameLogic.detector.source.image[:] GameLogic.pickup.source = VideoTexture.ImageRender(scene, pickupcamera) GameLogic.pickup.source.capsize = (imgPickupX, imgPickupY) GameLogic.pickup_png = GameLogic.pickup.source.image[:]
def init_video(video_obj, blank_obj): matID = VT.materialID(video_obj, 'MAvideo') G.video = VT.Texture(video_obj, matID) url = G.expandPath("//media/trailer_400p.ogg") video_source = VT.VideoFFmpeg(url) video_source.repeat = -1 video_source.scale = True video_source.flip = True G.video.source = video_source G.video_screen = video_obj G.video_blank = blank_obj G.video_screen.visible = False
def _setup_video_texture(self): """ Prepare this camera to use the VideoTexture module. Extract the references to the Blender camera and material where the images will be rendered. """ for child in self.blender_obj.children: # The camera object that will produce the image in Blender if 'CameraRobot' in child.name: camera = child # The object that contains the material where the image is rendered if 'CameraMesh' in child.name: screen = child # Considering it consists of a single mesh mesh = child.meshes[0] # Get the material name for material in mesh.materials: material_index = material.getMaterialIndex() mesh_material_name = mesh.getMaterialName(material_index) if 'MAScreenMat' in mesh_material_name: material_name = mesh_material_name try: logger.debug("\tCAMERA: %s" % camera.name) logger.debug("\tSCREEN: %s" % screen.name) logger.debug("\tMATERIAL: %s" % material_name) except UnboundLocalError as detail: logger.error(""" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR: The video camera could not be properly initialized. The children object could not be found. Best solution is to re-link the camera. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! """) return (False) # Get the reference to the scene scene = GameLogic.getCurrentScene() # Link the objects using VideoTexture if not hasattr(GameLogic, 'cameras'): GameLogic.cameras = {} mat_id = VideoTexture.materialID(screen, material_name) GameLogic.cameras[self.name()] = VideoTexture.Texture(screen, mat_id) GameLogic.cameras[self.name()].source = \ VideoTexture.ImageRender(scene, camera) # Set the focal length of the camera using the Game Logic Property camera.lens = self.image_focal # Set the background to be used for the render GameLogic.cameras[self.name()].source.background = self.bg_color # Define an image size. It must be powers of two. Default 512 * 512 GameLogic.cameras[self.name()].source.capsize = \ [self.image_width, self.image_height] logger.info("Camera '{0}': Exporting an image of capsize: {1} pixels". \ format(self.name(), GameLogic.cameras[self.name()].source.capsize)) logger.info("\tFocal length of the camera is: %s" % camera.lens)
def getVisual(camera_name, max_dimensions): global scn global camera_array src1 = VideoTexture.ImageRender(scn, scn.objects[camera_name]) #src1 = VideoTexture.ImageViewport(scn, scn.objects[camera_name]) src1.capsize = max_dimensions[0],max_dimensions[1] imX,imY = src1.size image_np = np.copy(VideoTexture.imageToArray(src1) ).reshape((imY, imX, 4)) image_np = image_np[::-1,:,:] return image_np
def main(): cont = bge.logic.getCurrentController() obj = cont.owner novideo = cont.actuators["novideo"] try: import VideoTexture print('Playing video. Enjoy!') except: cont.activate(novideo) print('Video failed to play. :(') #if not hasattr(bge.logic, 'video'): matID = VideoTexture.materialID(obj, 'IMplaceholder.jpg') bge.logic.video = VideoTexture.Texture(obj, matID) movie = bge.logic.expandPath("//../textures/videos/team_aurora_intro.ogg") bge.logic.video.source = VideoTexture.VideoFFmpeg(movie) #bge.logic.video.source.scale = True bge.logic.video.source.play() print(movie)
def main(): cont = bge.logic.getCurrentController() obj = cont.owner novideo = cont.actuators["novideo"] try: import VideoTexture print ('Playing video. Enjoy!') except: cont.activate(novideo) print ('Video failed to play. :(') #if not hasattr(bge.logic, 'video'): matID = VideoTexture.materialID(obj, 'IMplaceholder.jpg') bge.logic.video = VideoTexture.Texture(obj, matID) movie = bge.logic.expandPath("//../textures/videos/sintel_game_intro.ogg") bge.logic.video.source = VideoTexture.VideoFFmpeg(movie) #bge.logic.video.source.scale = True bge.logic.video.source.play() print (movie)
# get video video = obj["Video"] # update the video video.refresh(True) #print scene.render.fps #print video.source.maxrate, video.source.minrate # if video hasn't been added else: # import VideoTexture module import VideoTexture # get matID for the movie screen matID = VideoTexture.materialID(obj, 'MAScreenZ') print (matID) # get the texture video = VideoTexture.Texture(obj, matID) movieName = obj['movie'] # get movie path movie = bge.logic.expandPath('//' + movieName) print(movie) # get movie video.source = VideoTexture.VideoFFmpeg(movie) # set scaling
import VideoTexture from bge import logic as GameLogic contr = GameLogic.getCurrentController() obj = contr.owner # -- Check if the "video" property has been defined in the object if 'video' not in obj: #-- Get the material that is using our texture #matID = VideoTexture.materialID(obj, 'MAa_video2014-02-20-17-41-16-163') # -- Create the video texture # GameLogic.video = VideoTexture.Texture(obj, matID) # Suppose 1st material is the video one obj['video'] = VideoTexture.Texture(obj, 0) # -- Get the path to the video file from the 'video_path' object property movie = GameLogic.expandPath(obj['video_path']) # -- Load the file obj['video'].source = VideoTexture.VideoFFmpeg(movie) # play video in loop obj['video'].source.repeat = -1 # -- play the video obj['video'].source.play()
# get the current controller controller = GameLogic.getCurrentController() # get object script is attached to obj = controller.owner # check to see video has been added if "Video" in obj: # # get video video = obj["Video"] # update the video video.refresh(True) # if video hasn't been added else: # # get matID for the movie screen matID = VideoTexture.materialID(obj, "MA" + obj['material']) # get the texture video = VideoTexture.Texture(obj, matID) movieName = obj['movie'] # get movie path movie = GameLogic.expandPath('c:/Movie/' + movieName) # get movie video.source = VideoTexture.VideoFFmpeg(movie) # set scaling video.source.scale = True
# update the texture obj["RenderToTexture"].refresh(True) # if RenderToTexture hasn't been added else: # import VideoTexture module import VideoTexture # get a list of objects in the scene objList = scene.objects # get camera name being used for render to texture camName = obj['cam'] # get camera object cam = objList[camName] # get the texture material ID matID = VideoTexture.materialID(obj, "MA" + obj['material']) # set the texture renderToTexture = VideoTexture.Texture(obj, matID) # get the texture image renderToTexture.source = VideoTexture.ImageRender(scene, cam) # save RenderToTexture as an object variable obj["RenderToTexture"] = renderToTexture
# get video video = obj["Video"] # update the video video.refresh(True) # if video hasn't been added else: # import VideoTexture module import VideoTexture # get matID for the movie screen matID = VideoTexture.materialID(obj, "MA" + obj['material']) # get the texture video = VideoTexture.Texture(obj, matID) movieName = obj['movie'] # get movie path movie = GameLogic.expandPath('//' + movieName) # get movie video.source = VideoTexture.VideoFFmpeg(movie) # set scaling video.source.scale = True
import VideoTexture import bge.logic contr = bge.logic.getCurrentController() obj = contr.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(bge.logic, 'video'): # identify a static texture by name matID = VideoTexture.materialID(obj, 'IMvideo.png') # create a dynamic texture that will replace the static texture bge.logic.video = VideoTexture.Texture(obj, matID) # define a source of image for the texture, here a movie movie = bge.logic.expandPath('//trailer_400p.ogg') bge.logic.video.source = VideoTexture.VideoFFmpeg(movie) bge.logic.video.source.scale = True # quick off the movie, but it wont play in the background bge.logic.video.source.play() # you need to call this function every frame to ensure update of the texture. bge.logic.video.refresh(True)
# Tutorial for using RenderToTexture.py can be found at www.tutorialsforblender3d.com # Released under the Creative Commons Attribution 3.0 Unported License. If you use this code, please include this information header. import GameLogic as g cont = g.getCurrentController() obj = cont.owner for scene in g.getSceneList(): if scene.name == "Main": break if "RenderToTexture" in obj: obj["RenderToTexture"].refresh(True) else: import VideoTexture cam = scene.objects[obj["camera"]] matID = VideoTexture.materialID(obj, "MA"+ obj["material"]) renderToTexture = VideoTexture.Texture(obj, matID) renderToTexture.source = VideoTexture.ImageRender(scene,cam) obj["RenderToTexture"] = renderToTexture